OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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