OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 153 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 153 Rev 181
Line 72... Line 72...
72
import net.jcip.annotations.GuardedBy;
72
import net.jcip.annotations.GuardedBy;
73
 
73
 
74
public class OperationExportPanel extends JPanel {
74
public class OperationExportPanel extends JPanel {
75
 
75
 
76
    @GuardedBy("EDT")
76
    @GuardedBy("EDT")
77
    static private final DateFormat DF = new SimpleDateFormat("yyyyMMdd");
77
    private static final DateFormat DF = new SimpleDateFormat("yyyyMMdd");
78
 
78
 
79
    final JCheckBox lockedCheckBox = new JCheckBox("verrouillées uniquement");
79
    final JCheckBox lockedCheckBox = new JCheckBox("verrouillées uniquement");
80
    final JButton bPrint = new JButton("Exporter");
80
    final JButton bPrint = new JButton("Exporter");
81
 
81
 
82
    public OperationExportPanel(final OperationCalendarManager manager, final List<SQLRowValues> rowsSite) {
82
    public OperationExportPanel(final OperationCalendarManager manager, final List<SQLRowValues> rowsSite) {
83
        lockedCheckBox.setSelected(true);
83
        this.lockedCheckBox.setSelected(true);
84
        //
84
        //
85
        this.setLayout(new GridBagLayout());
85
        this.setLayout(new GridBagLayout());
86
        final GridBagConstraints c = new DefaultGridBagConstraints();
86
        final GridBagConstraints c = new DefaultGridBagConstraints();
87
        final JLabel l = new JLabel("Date de début", SwingConstants.RIGHT);
87
        final JLabel l = new JLabel("Date de début", SwingConstants.RIGHT);
88
        this.add(l, c);
88
        this.add(l, c);
Line 139... Line 139...
139
        g.add(radio2);
139
        g.add(radio2);
140
 
140
 
141
        //
141
        //
142
        final JPanel p = new JPanel();
142
        final JPanel p = new JPanel();
143
        p.setLayout(new FlowLayout(FlowLayout.RIGHT));
143
        p.setLayout(new FlowLayout(FlowLayout.RIGHT));
144
        p.add(lockedCheckBox);
144
        p.add(this.lockedCheckBox);
145
        p.add(bPrint);
145
        p.add(this.bPrint);
146
        c.gridwidth = 2;
146
        c.gridwidth = 2;
147
        c.gridx = 0;
147
        c.gridx = 0;
148
        c.gridy++;
148
        c.gridy++;
149
        c.fill = GridBagConstraints.NONE;
149
        c.fill = GridBagConstraints.NONE;
150
        c.anchor = GridBagConstraints.SOUTHEAST;
150
        c.anchor = GridBagConstraints.SOUTHEAST;
151
        this.add(p, c);
151
        this.add(p, c);
152
        //
152
        //
153
 
153
 
154
        bPrint.addActionListener(new ActionListener() {
154
        this.bPrint.addActionListener(new ActionListener() {
155
 
155
 
156
            @Override
156
            @Override
157
            public void actionPerformed(ActionEvent e) {
157
            public void actionPerformed(ActionEvent e) {
158
                if (d1.getDate().after(d2.getDate())) {
158
                if (d1.getDate().after(d2.getDate())) {
159
                    return;
159
                    return;
160
                }
160
                }
161
                final String statusVal = statusCombo.getValue();
161
                final String statusVal = statusCombo.getValue();
162
                final List<String> states = StringUtils.isEmpty(statusVal, true) ? null : Collections.singletonList(statusVal);
162
                final List<String> states = StringUtils.isEmpty(statusVal, true) ? null : Collections.singletonList(statusVal);
163
                final List<JCalendarItem> items = manager.getItemIn(d1.getDate(), d2.getDate(), null, states);
163
                final List<JCalendarItem> items = manager.getItemIn(d1.getDate(), d2.getDate(), manager.getAllUsers(), states);
164
                final List<JCalendarItemDB> itemsToExport = new ArrayList<JCalendarItemDB>(items.size());
164
                final List<JCalendarItemDB> itemsToExport = new ArrayList<>(items.size());
165
                if (lockedCheckBox.isSelected()) {
165
                if (OperationExportPanel.this.lockedCheckBox.isSelected()) {
166
                    for (JCalendarItem jCalendarItem : items) {
166
                    for (JCalendarItem jCalendarItem : items) {
167
                        JCalendarItemDB i = (JCalendarItemDB) jCalendarItem;
167
                        JCalendarItemDB i = (JCalendarItemDB) jCalendarItem;
168
                        if (i.getFlagsString().contains("locked")) {
168
                        if (i.getFlagsString().contains("locked")) {
169
                            itemsToExport.add(i);
169
                            itemsToExport.add(i);
170
                        }
170
                        }
Line 174... Line 174...
174
                        JCalendarItemDB i = (JCalendarItemDB) jCalendarItem;
174
                        JCalendarItemDB i = (JCalendarItemDB) jCalendarItem;
175
                        itemsToExport.add(i);
175
                        itemsToExport.add(i);
176
                    }
176
                    }
177
                }
177
                }
178
                if (rowsSite != null && !rowsSite.isEmpty()) {
178
                if (rowsSite != null && !rowsSite.isEmpty()) {
179
                    final Set<String> allowedSites = new HashSet<String>();
179
                    final Set<String> allowedSites = new HashSet<>();
180
                    for (SQLRowValues r : rowsSite) {
180
                    for (SQLRowValues r : rowsSite) {
181
                        String siteName = r.getString("NAME");
181
                        String siteName = r.getString("NAME");
182
                        allowedSites.add(siteName);
182
                        allowedSites.add(siteName);
183
                    }
183
                    }
184
                    final List<JCalendarItemDB> filtered = new ArrayList<JCalendarItemDB>(itemsToExport.size());
184
                    final List<JCalendarItemDB> filtered = new ArrayList<>(itemsToExport.size());
185
                    for (JCalendarItemDB i : itemsToExport) {
185
                    for (JCalendarItemDB i : itemsToExport) {
186
                        if (allowedSites.contains(i.getSiteName())) {
186
                        if (allowedSites.contains(i.getSiteName())) {
187
                            filtered.add(i);
187
                            filtered.add(i);
188
                        }
188
                        }
189
                    }
189
                    }
Line 216... Line 216...
216
 
216
 
217
            }
217
            }
218
        });
218
        });
219
    }
219
    }
220
 
220
 
221
    static private final class Planner implements Comparable<Planner> {
221
    private static final class Planner implements Comparable<Planner> {
222
 
222
 
223
        static private final BigDecimal MS_PER_HOUR = BigDecimal.valueOf(1000 * 3600);
223
        private static final BigDecimal MS_PER_HOUR = BigDecimal.valueOf(1000 * 3600);
224
 
224
 
225
        private final String uid;
225
        private final String uid;
226
        private final String xml;
226
        private final String xml;
227
        private Date rangeStart;
227
        private Date rangeStart;
228
        private Date startTime;
228
        private Date startTime;
Line 254... Line 254...
254
                final Document doc = JDOM2Utils.parseStringDocument(this.xml);
254
                final Document doc = JDOM2Utils.parseStringDocument(this.xml);
255
                this.rangeStart = new Date(Long.valueOf(doc.getRootElement().getChild("range").getAttributeValue("start")));
255
                this.rangeStart = new Date(Long.valueOf(doc.getRootElement().getChild("range").getAttributeValue("start")));
256
 
256
 
257
                final Element scheduleElem = doc.getRootElement().getChild("schedule");
257
                final Element scheduleElem = doc.getRootElement().getChild("schedule");
258
                this.startTime = new Date(Long.valueOf(scheduleElem.getAttributeValue("start")));
258
                this.startTime = new Date(Long.valueOf(scheduleElem.getAttributeValue("start")));
259
                final long endTime = Long.valueOf(scheduleElem.getAttributeValue("end"));
259
                final long endTime = Long.parseLong(scheduleElem.getAttributeValue("end"));
260
                this.hours = DecimalUtils.round(BigDecimal.valueOf(endTime - this.startTime.getTime()).divide(MS_PER_HOUR, DecimalUtils.HIGH_PRECISION), 5);
260
                this.hours = DecimalUtils.round(BigDecimal.valueOf(endTime - this.startTime.getTime()).divide(MS_PER_HOUR, DecimalUtils.HIGH_PRECISION), 5);
261
            } catch (Exception e) {
261
            } catch (Exception e) {
262
                throw new IllegalStateException("couldn't get start for " + this.xml, e);
262
                throw new IllegalStateException("couldn't get start for " + this.xml, e);
263
            }
263
            }
264
        }
264
        }