OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 153 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 153 Rev 181
1
package org.openconcerto.modules.operation;
1
package org.openconcerto.modules.operation;
2
 
2
 
3
import static org.openconcerto.sql.TM.getTM;
3
import static org.openconcerto.sql.TM.getTM;
4
 
4
 
5
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionEvent;
6
import java.io.IOException;
6
import java.io.IOException;
7
import java.sql.SQLException;
7
import java.sql.SQLException;
8
import java.util.ArrayList;
8
import java.util.ArrayList;
9
import java.util.HashSet;
9
import java.util.HashSet;
10
import java.util.List;
10
import java.util.List;
11
import java.util.Set;
11
import java.util.Set;
12
 
12
 
13
import javax.swing.AbstractAction;
13
import javax.swing.AbstractAction;
14
import javax.swing.ImageIcon;
14
import javax.swing.ImageIcon;
15
import javax.swing.JFrame;
15
import javax.swing.JFrame;
16
import javax.swing.SwingUtilities;
16
import javax.swing.SwingUtilities;
17
 
17
 
18
import org.jopencalendar.model.Flag;
18
import org.jopencalendar.model.Flag;
19
import org.jopencalendar.model.JCalendarItem;
19
import org.jopencalendar.model.JCalendarItem;
20
import org.jopencalendar.model.JCalendarItemPart;
20
import org.jopencalendar.model.JCalendarItemPart;
21
import org.jopencalendar.ui.DayView;
21
import org.jopencalendar.ui.DayView;
22
import org.openconcerto.erp.config.ComptaPropsConfiguration;
22
import org.openconcerto.erp.config.ComptaPropsConfiguration;
23
import org.openconcerto.erp.config.MainFrame;
23
import org.openconcerto.erp.config.MainFrame;
24
import org.openconcerto.erp.generationDoc.TemplateManager;
24
import org.openconcerto.erp.generationDoc.TemplateManager;
25
import org.openconcerto.erp.modules.AbstractModule;
25
import org.openconcerto.erp.modules.AbstractModule;
26
import org.openconcerto.erp.modules.ComponentsContext;
26
import org.openconcerto.erp.modules.ComponentsContext;
27
import org.openconcerto.erp.modules.DBContext;
27
import org.openconcerto.erp.modules.DBContext;
28
import org.openconcerto.erp.modules.MenuContext;
28
import org.openconcerto.erp.modules.MenuContext;
29
import org.openconcerto.erp.modules.ModuleFactory;
29
import org.openconcerto.erp.modules.ModuleFactory;
30
import org.openconcerto.modules.operation.action.LockAction;
30
import org.openconcerto.modules.operation.action.LockAction;
31
import org.openconcerto.sql.element.SQLElement;
31
import org.openconcerto.sql.element.SQLElement;
32
import org.openconcerto.sql.element.SQLElementDirectory;
32
import org.openconcerto.sql.element.SQLElementDirectory;
33
import org.openconcerto.sql.model.SQLRowValues;
33
import org.openconcerto.sql.model.SQLRowValues;
34
import org.openconcerto.sql.utils.SQLCreateTable;
34
import org.openconcerto.sql.utils.SQLCreateTable;
35
import org.openconcerto.sql.view.list.IListe;
35
import org.openconcerto.sql.view.list.IListe;
36
import org.openconcerto.sql.view.list.RowAction;
36
import org.openconcerto.sql.view.list.RowAction;
37
import org.openconcerto.ui.FrameUtil;
37
import org.openconcerto.ui.FrameUtil;
38
import org.openconcerto.utils.i18n.TranslationManager;
38
import org.openconcerto.utils.i18n.TranslationManager;
39
 
39
 
40
public final class ModuleOperation extends AbstractModule {
40
public final class ModuleOperation extends AbstractModule {
41
    public static final String OPERATIONS_REPORT_TEMPLATE_ID = "Operations Report";
41
    public static final String OPERATIONS_REPORT_TEMPLATE_ID = "Operations Report";
42
    public static final String OPERATIONS_REPORT_TEMPLATE2_ID = "Operations Report2";
42
    public static final String OPERATIONS_REPORT_TEMPLATE2_ID = "Operations Report2";
43
    // -Dmodule.dir=../"Module Operation" -Dgestion.confFile=Configuration/main.properties -ea
43
    // -Dmodule.dir=../"Module Operation" -Dgestion.confFile=Configuration/main.properties -ea
44
    public static final String TABLE_SITE = "SITE";
44
    public static final String TABLE_SITE = "SITE";
45
    public static final String TABLE_OPERATION = "OPERATION";
45
    public static final String TABLE_OPERATION = "OPERATION";
46
 
46
 
47
    public static final Flag FREE_TIME_FLAG = new Flag("freeTime", null, "Non travaillé", "");
47
    public static final Flag FREE_TIME_FLAG = new Flag("freeTime", null, "Non travaillé", "");
48
 
48
 
49
    public ModuleOperation(ModuleFactory f) throws IOException {
49
    public ModuleOperation(ModuleFactory f) throws IOException {
50
        super(f);
50
        super(f);
51
    }
51
    }
52
 
52
 
53
    @Override
53
    @Override
54
    protected void setupElements(SQLElementDirectory dir) {
54
    protected void setupElements(SQLElementDirectory dir) {
55
        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
55
        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
56
        conf.getFieldMapper().addMapperStreamFromClass(ModuleOperation.class);
56
        conf.getFieldMapper().addMapperStreamFromClass(ModuleOperation.class);
57
 
57
 
58
        dir.addSQLElement(new SiteSQLElement(this));
58
        dir.addSQLElement(new SiteSQLElement(this));
59
        dir.addSQLElement(new OperationSQLElement(this));
59
        dir.addSQLElement(new OperationSQLElement(this));
60
 
60
 
61
        // SQLRequestLog.setEnabled(true);
61
        // SQLRequestLog.setEnabled(true);
62
        // SQLRequestLog.showFrame();
62
        // SQLRequestLog.showFrame();
63
        TemplateManager.getInstance().register(OPERATIONS_REPORT_TEMPLATE_ID);
63
        TemplateManager.getInstance().register(OPERATIONS_REPORT_TEMPLATE_ID);
64
        TemplateManager.getInstance().register(OPERATIONS_REPORT_TEMPLATE2_ID);
64
        TemplateManager.getInstance().register(OPERATIONS_REPORT_TEMPLATE2_ID);
65
        // Translation loading
-
 
66
        TranslationManager.getInstance().addTranslationStreamFromClass(this.getClass());
-
 
67
    }
65
    }
68
 
66
 
69
    @Override
67
    @Override
70
    protected void setupMenu(MenuContext ctxt) {
68
    protected void setupMenu(MenuContext ctxt) {
71
        ctxt.addMenuItem(ctxt.createListAction(TABLE_SITE), "operation");
69
        ctxt.addMenuItem(ctxt.createListAction(TABLE_SITE), "operation");
72
        final SQLElement element = ctxt.getElement(TABLE_OPERATION);
70
        final SQLElement element = ctxt.getElement(TABLE_OPERATION);
73
        final AbstractAction aOperations = new AbstractAction(getTM().trM("listAction.name", "element", element.getName())) {
71
        final AbstractAction aOperations = new AbstractAction(getTM().trM("listAction.name", "element", element.getName())) {
74
 
72
 
75
            @Override
73
            @Override
76
            public void actionPerformed(ActionEvent e) {
74
            public void actionPerformed(ActionEvent e) {
77
                JFrame f = new JFrame("Gérer les interventions");
75
                JFrame f = new JFrame("Gérer les interventions");
78
                f.setContentPane(new OperationHistoryPanel());
76
                f.setContentPane(new OperationHistoryPanel());
79
                f.pack();
77
                f.pack();
80
                f.setLocationRelativeTo(null);
78
                f.setLocationRelativeTo(null);
81
                FrameUtil.showPacked(f);
79
                FrameUtil.showPacked(f);
82
 
80
 
83
            }
81
            }
84
        };
82
        };
85
        ctxt.addMenuItem(aOperations, "operation");
83
        ctxt.addMenuItem(aOperations, "operation");
86
 
84
 
87
        // final AbstractAction aExport = new
85
        // final AbstractAction aExport = new
88
        // AbstractAction(TranslationManager.getInstance().getTranslationForMenu("operation.export"))
86
        // AbstractAction(TranslationManager.getInstance().getTranslationForMenu("operation.export"))
89
        // {
87
        // {
90
        //
88
        //
91
        // @Override
89
        // @Override
92
        // public void actionPerformed(ActionEvent e) {
90
        // public void actionPerformed(ActionEvent e) {
93
        // JFrame f = new JFrame("Export");
91
        // JFrame f = new JFrame("Export");
94
        // f.setContentPane(new OperationExportPanel(new OperationCalendarManager("all")));
92
        // f.setContentPane(new OperationExportPanel(new OperationCalendarManager("all")));
95
        // f.pack();
93
        // f.pack();
96
        // f.setLocationRelativeTo(null);
94
        // f.setLocationRelativeTo(null);
97
        // FrameUtil.showPacked(f);
95
        // FrameUtil.showPacked(f);
98
        //
96
        //
99
        // }
97
        // }
100
        // };
98
        // };
101
        // ctxt.addMenuItem(aExport, "operation");
99
        // ctxt.addMenuItem(aExport, "operation");
102
 
100
 
103
        final SQLElement elementSite = ctxt.getElement(TABLE_SITE);
101
        final SQLElement elementSite = ctxt.getElement(TABLE_SITE);
104
        final RowAction editAction = new RowAction(new AbstractAction(TranslationManager.getInstance().getTranslationForMenu("operation.export")) {
102
        final RowAction editAction = new RowAction(new AbstractAction(TranslationManager.getInstance().getTranslationForMenu("operation.export")) {
105
 
103
 
106
            @Override
104
            @Override
107
            public void actionPerformed(ActionEvent e) {
105
            public void actionPerformed(ActionEvent e) {
108
                final List<SQLRowValues> rows = IListe.get(e).getSelectedRows();
106
                final List<SQLRowValues> rows = IListe.get(e).getSelectedRows();
109
                JFrame f = new JFrame("Export");
107
                JFrame f = new JFrame("Export");
110
                f.setContentPane(new OperationExportPanel(new OperationCalendarManager("all"), rows));
108
                f.setContentPane(new OperationExportPanel(new OperationCalendarManager("all"), rows));
111
                f.pack();
109
                f.pack();
112
                f.setLocationRelativeTo(null);
110
                f.setLocationRelativeTo(null);
113
                FrameUtil.showPacked(f);
111
                FrameUtil.showPacked(f);
114
            }
112
            }
115
        }, true) {
113
        }, true) {
116
            @Override
114
            @Override
117
            public boolean enabledFor(IListeEvent evt) {
115
            public boolean enabledFor(IListeEvent evt) {
118
                return true;
116
                return true;
119
            }
117
            }
120
 
118
 
121
        };
119
        };
122
        // editAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
120
        // editAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
123
        elementSite.getRowActions().add(editAction);
121
        elementSite.getRowActions().add(editAction);
124
 
122
 
125
    }
123
    }
126
 
124
 
127
    @Override
125
    @Override
128
    protected void setupComponents(ComponentsContext ctxt) {
126
    protected void setupComponents(ComponentsContext ctxt) {
129
 
127
 
130
    }
128
    }
131
 
129
 
132
    @Override
130
    @Override
133
    protected void install(DBContext ctxt) throws SQLException, IOException {
131
    protected void install(DBContext ctxt) throws SQLException, IOException {
134
        super.install(ctxt);
132
        super.install(ctxt);
135
        if (ctxt.getRoot().getTable(TABLE_SITE) == null) {
133
        if (ctxt.getRoot().getTable(TABLE_SITE) == null) {
136
            final SQLCreateTable createTableSite = ctxt.getCreateTable(TABLE_SITE);
134
            final SQLCreateTable createTableSite = ctxt.getCreateTable(TABLE_SITE);
137
            createTableSite.addVarCharColumn("NAME", 500);
135
            createTableSite.addVarCharColumn("NAME", 500);
138
            createTableSite.addForeignColumn("CLIENT");
136
            createTableSite.addForeignColumn("CLIENT");
139
            createTableSite.addForeignColumn("ADRESSE");
137
            createTableSite.addForeignColumn("ADRESSE");
140
            createTableSite.addVarCharColumn("COMMENT", 10000);
138
            createTableSite.addVarCharColumn("COMMENT", 10000);
141
            createTableSite.addVarCharColumn("INFO", 10000);
139
            createTableSite.addVarCharColumn("INFO", 10000);
142
            final SQLCreateTable createTableOperation = ctxt.getCreateTable(TABLE_OPERATION);
140
            final SQLCreateTable createTableOperation = ctxt.getCreateTable(TABLE_OPERATION);
143
            createTableOperation.addForeignColumn(createTableSite);
141
            createTableOperation.addForeignColumn(createTableSite);
144
            createTableOperation.addForeignColumn("ID_USER_COMMON", ctxt.getRoot().findTable("USER_COMMON"));
142
            createTableOperation.addForeignColumn("ID_USER_COMMON", ctxt.getRoot().findTable("USER_COMMON"));
145
            createTableOperation.addVarCharColumn("TYPE", 200);
143
            createTableOperation.addVarCharColumn("TYPE", 200);
146
            createTableOperation.addVarCharColumn("STATUS", 200);
144
            createTableOperation.addVarCharColumn("STATUS", 200);
147
            createTableOperation.addForeignColumn("CALENDAR_ITEM_GROUP");
145
            createTableOperation.addForeignColumn("CALENDAR_ITEM_GROUP");
148
            createTableOperation.addVarCharColumn("DESCRIPTION", 10000);
146
            createTableOperation.addVarCharColumn("DESCRIPTION", 10000);
149
            createTableOperation.addVarCharColumn("PLANNER_UID", 2048);
147
            createTableOperation.addVarCharColumn("PLANNER_UID", 2048);
150
            createTableOperation.addVarCharColumn("PLANNER_XML", 2048);
148
            createTableOperation.addVarCharColumn("PLANNER_XML", 2048);
-
 
149
 
-
 
150
            ctxt.executeSQL();
-
 
151
            // SQLTable.setUndefID(ctxt.getRoot().getSchema(), TABLE_SITE, null);
-
 
152
            // SQLTable.setUndefID(ctxt.getRoot().getSchema(), TABLE_OPERATION, null);
151
        }
153
        }
152
    }
154
    }
153
 
155
 
154
    static OperationCalendarPanel comp;
156
    static OperationCalendarPanel comp;
155
    static DailyOperationCalendarPanel comp2;
157
    static DailyOperationCalendarPanel comp2;
156
 
158
 
157
    @Override
159
    @Override
158
    protected void start() {
160
    protected void start() {
159
        ImageIcon icon = new ImageIcon(DayView.class.getResource("auto.png"));
161
        ImageIcon icon = new ImageIcon(DayView.class.getResource("auto.png"));
160
        Flag.register(new Flag("planned", icon, "Planifié", ""));
162
        Flag.register(new Flag("planned", icon, "Planifié", ""));
161
        icon = new ImageIcon(LockAction.class.getResource("locked.png"));
163
        icon = new ImageIcon(LockAction.class.getResource("locked.png"));
162
        Flag.register(new Flag("locked", icon, "Verrouillé", ""));
164
        Flag.register(new Flag("locked", icon, "Verrouillé", ""));
163
        Flag.register(FREE_TIME_FLAG);
165
        Flag.register(FREE_TIME_FLAG);
164
 
166
 
165
        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
167
        final ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
166
        comp = new OperationCalendarPanel(conf);
168
        comp = new OperationCalendarPanel(conf);
167
        comp2 = new DailyOperationCalendarPanel(conf);
169
        comp2 = new DailyOperationCalendarPanel(conf);
168
 
170
 
169
        MainFrame.getInstance().getTabbedPane().addTab("Planning", comp);
171
        MainFrame.getInstance().getTabbedPane().addTab("Planning", comp);
170
        MainFrame.getInstance().getTabbedPane().addTab("Planning journalier", comp2);
172
        MainFrame.getInstance().getTabbedPane().addTab("Planning journalier", comp2);
171
        MainFrame.getInstance().getTabbedPane().addTab("Chantiers", new GanttChantierPanel());
173
        MainFrame.getInstance().getTabbedPane().addTab("Chantiers", new GanttChantierPanel());
172
        MainFrame.getInstance().getTabbedPane().setSelectedIndex(1);
174
        MainFrame.getInstance().getTabbedPane().setSelectedIndex(1);
173
    }
175
    }
174
 
176
 
175
    public static void reloadCalendars() {
177
    public static void reloadCalendars() {
176
        if (!SwingUtilities.isEventDispatchThread()) {
178
        if (!SwingUtilities.isEventDispatchThread()) {
177
            throw new IllegalAccessError("Must be called in EDT");
179
            throw new IllegalAccessError("Must be called in EDT");
178
        }
180
        }
179
        comp.reload();
181
        comp.reload();
180
        comp2.reload();
182
        comp2.reload();
181
    }
183
    }
182
 
184
 
183
    @Override
185
    @Override
184
    protected void stop() {
186
    protected void stop() {
185
    }
187
    }
186
 
188
 
187
    public static List<Long> getOperationIdsFrom(Set<JCalendarItemDB> toDelete) {
189
    public static List<Long> getOperationIdsFrom(Set<JCalendarItemDB> toDelete) {
188
        final List<Long> ids = new ArrayList<Long>();
190
        final List<Long> ids = new ArrayList<Long>();
189
        for (JCalendarItemDB jCalendarItemDB : toDelete) {
191
        for (JCalendarItemDB jCalendarItemDB : toDelete) {
190
            if (jCalendarItemDB.getSourceElement().getClass() != OperationSQLElement.class) {
192
            if (jCalendarItemDB.getSourceElement().getClass() != OperationSQLElement.class) {
191
                throw new IllegalStateException("Table is not " + ModuleOperation.TABLE_OPERATION + " but " + jCalendarItemDB.getSource());
193
                throw new IllegalStateException("Table is not " + ModuleOperation.TABLE_OPERATION + " but " + jCalendarItemDB.getSource());
192
 
194
 
193
            }
195
            }
194
            final long sourceId = jCalendarItemDB.getSource().getID();
196
            final long sourceId = jCalendarItemDB.getSource().getID();
195
            if (!ids.contains(sourceId)) {
197
            if (!ids.contains(sourceId)) {
196
                ids.add(sourceId);
198
                ids.add(sourceId);
197
            }
199
            }
198
        }
200
        }
199
        return ids;
201
        return ids;
200
    }
202
    }
201
 
203
 
202
    public static Set<JCalendarItemDB> getItemDB(List<JCalendarItemPart> parts) {
204
    public static Set<JCalendarItemDB> getItemDB(List<JCalendarItemPart> parts) {
203
        Set<JCalendarItemDB> result = new HashSet<JCalendarItemDB>();
205
        Set<JCalendarItemDB> result = new HashSet<JCalendarItemDB>();
204
        for (JCalendarItemPart part : parts) {
206
        for (JCalendarItemPart part : parts) {
205
            JCalendarItem item = part.getItem();
207
            JCalendarItem item = part.getItem();
206
            if (item instanceof JCalendarItemDB) {
208
            if (item instanceof JCalendarItemDB) {
207
                result.add((JCalendarItemDB) item);
209
                result.add((JCalendarItemDB) item);
208
            }
210
            }
209
        }
211
        }
210
        return result;
212
        return result;
211
    }
213
    }
212
}
214
}