OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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