OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 153 | Details | Compare with Previous | Last modification | View Log | RSS feed

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