OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 141 Rev 150
Line 6... Line 6...
6
import java.util.HashSet;
6
import java.util.HashSet;
7
import java.util.List;
7
import java.util.List;
8
import java.util.Map;
8
import java.util.Map;
9
import java.util.Set;
9
import java.util.Set;
10
 
10
 
-
 
11
import javax.swing.JCheckBox;
11
import javax.swing.JComponent;
12
import javax.swing.JComponent;
-
 
13
import javax.swing.JToggleButton;
12
 
14
 
13
import org.openconcerto.erp.config.ComptaPropsConfiguration;
15
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
16
import org.openconcerto.sql.PropsConfiguration;
14
import org.openconcerto.sql.element.GroupSQLComponent;
17
import org.openconcerto.sql.element.GroupSQLComponent;
15
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.element.SQLElement;
16
import org.openconcerto.sql.model.DBRoot;
19
import org.openconcerto.sql.model.DBRoot;
-
 
20
import org.openconcerto.sql.model.FieldMapper;
17
import org.openconcerto.sql.model.SQLDataSource;
21
import org.openconcerto.sql.model.SQLDataSource;
-
 
22
import org.openconcerto.sql.model.SQLField;
18
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRow;
19
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowAccessor;
20
import org.openconcerto.sql.model.SQLRowMode;
25
import org.openconcerto.sql.model.SQLRowMode;
21
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLSelect;
23
import org.openconcerto.sql.model.SQLTable;
28
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.Where;
29
import org.openconcerto.sql.model.Where;
-
 
30
import org.openconcerto.sql.request.ComboSQLRequest;
-
 
31
import org.openconcerto.sql.sqlobject.ElementComboBox;
25
import org.openconcerto.sql.sqlobject.SQLTextCombo;
32
import org.openconcerto.sql.sqlobject.SQLTextCombo;
26
import org.openconcerto.ui.JLabelBold;
33
import org.openconcerto.ui.JLabelBold;
27
import org.openconcerto.ui.component.ITextArea;
34
import org.openconcerto.ui.component.ITextArea;
28
import org.openconcerto.ui.date.DateRange;
35
import org.openconcerto.ui.date.DateRange;
29
import org.openconcerto.ui.date.DateRangeTable;
36
import org.openconcerto.ui.date.DateRangeTable;
-
 
37
import org.openconcerto.utils.CollectionUtils;
30
import org.openconcerto.utils.ExceptionHandler;
38
import org.openconcerto.utils.ExceptionHandler;
-
 
39
import org.openconcerto.utils.StringUtils;
31
 
40
 
32
public class OperationSQLComponent extends GroupSQLComponent {
41
public class OperationSQLComponent extends GroupSQLComponent {
33
 
42
 
34
    public OperationSQLComponent(SQLElement element) {
43
    public OperationSQLComponent(SQLElement element) {
35
        super(element, new OperationGroup());
44
        super(element, new OperationGroup());
Line 37... Line 46...
37
 
46
 
38
    @Override
47
    @Override
39
    public JComponent createEditor(String id) {
48
    public JComponent createEditor(String id) {
40
        if (id.equals("operation.description")) {
49
        if (id.equals("operation.description")) {
41
            return new ITextArea(15, 3);
50
            return new ITextArea(15, 3);
-
 
51
        } else if (id.equals("operation.freeTime")) {
-
 
52
            return new JCheckBox();
42
        } else if (id.equals("operation.dates")) {
53
        } else if (id.equals("operation.dates")) {
43
            return new DateRangeTable(true, false, false);
54
            return new DateRangeTable(true, false, false);
44
        } else if (id.equals("operation.type") || id.equals("operation.status")) {
55
        } else if (id.equals("operation.type") || id.equals("operation.status")) {
45
            return new SQLTextCombo();
56
            return new SQLTextCombo() {
-
 
57
                @Override
-
 
58
                public boolean canComplete(String originalText) {
-
 
59
                    return originalText != null && !originalText.trim().isEmpty();
-
 
60
                }
-
 
61
            };
-
 
62
        } else if (id.equals("operation.user")) {
-
 
63
            // do not show desactivated users
-
 
64
            final FieldMapper fieldMapper = PropsConfiguration.getInstance().getFieldMapper();
-
 
65
            final SQLField field = fieldMapper.getSQLFieldForItem(id);
-
 
66
            final SQLElement foreignElement = getElement().getForeignElement(field.getName());
-
 
67
            final ElementComboBox comp = new ElementComboBox();
-
 
68
            final ComboSQLRequest comboRequest = foreignElement.getComboRequest();
-
 
69
            final SQLTable userTable = foreignElement.getTable();
-
 
70
            comboRequest.setWhere(new Where(userTable.getField("DISABLED"), "=", false));
-
 
71
            comp.init(foreignElement, comboRequest);
-
 
72
            comp.setOpaque(false);
-
 
73
            return comp;
-
 
74
 
46
        }
75
        }
47
        return super.createEditor(id);
76
        return super.createEditor(id);
-
 
77
 
48
    }
78
    }
49
 
79
 
50
    @Override
80
    @Override
51
    protected Set<String> createRequiredNames() {
81
    protected Set<String> createRequiredNames() {
52
        Set<String> s = new HashSet<String>();
82
        Set<String> s = new HashSet<String>();
Line 71... Line 101...
71
 
101
 
72
    @Override
102
    @Override
73
    public void select(final SQLRowAccessor r) {
103
    public void select(final SQLRowAccessor r) {
74
        super.select(r);
104
        super.select(r);
75
 
105
 
-
 
106
        final boolean isFreeTime;
76
        if (r != null && r.getID() > this.getTable().getUndefinedID()) {
107
        if (r != null && r.getID() > this.getTable().getUndefinedID()) {
77
            SQLSelect select = new SQLSelect();
108
            SQLSelect select = new SQLSelect();
78
            int idGroup = r.getInt("ID_CALENDAR_ITEM_GROUP");
109
            int idGroup = r.getInt("ID_CALENDAR_ITEM_GROUP");
79
            final SQLTable calendarItemTable = r.getTable().getTable("CALENDAR_ITEM");
110
            final SQLTable calendarItemTable = r.getTable().getTable("CALENDAR_ITEM");
80
            select.addSelectStar(calendarItemTable);
111
            select.addSelectStar(calendarItemTable);
81
            select.setWhere(calendarItemTable.getField("ID_CALENDAR_ITEM_GROUP"), "=", idGroup);
112
            select.setWhere(calendarItemTable.getField("ID_CALENDAR_ITEM_GROUP"), "=", idGroup);
82
            final SQLDataSource ds = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getDBSystemRoot().getDataSource();
113
            final SQLDataSource ds = calendarItemTable.getDBSystemRoot().getDataSource();
83
            @SuppressWarnings("unchecked")
114
            @SuppressWarnings("unchecked")
84
            final List<Map<String, Object>> result = ds.execute(select.asString());
115
            final List<Map<String, Object>> result = ds.execute(select.asString());
-
 
116
            boolean freeTimeTmp = false;
85
            final List<DateRange> ranges = new ArrayList<DateRange>();
117
            final List<DateRange> ranges = new ArrayList<DateRange>();
86
            for (Map<String, Object> row : result) {
118
            for (Map<String, Object> row : result) {
87
                final DateRange range = new DateRange();
119
                final DateRange range = new DateRange();
88
                final Date dStart = (Date) row.get("START");
120
                final Date dStart = (Date) row.get("START");
89
                final Date dEnd = (Date) row.get("END");
121
                final Date dEnd = (Date) row.get("END");
90
                range.setStart(dStart.getTime());
122
                range.setStart(dStart.getTime());
91
                range.setStop(dEnd.getTime());
123
                range.setStop(dEnd.getTime());
92
                ranges.add(range);
124
                ranges.add(range);
-
 
125
                freeTimeTmp |= row.get("FLAGS") == null ? false : StringUtils.fastSplit((String) row.get("FLAGS"), ',').contains(ModuleOperation.FREE_TIME_FLAG.getTypeId());
93
            }
126
            }
94
 
-
 
-
 
127
            isFreeTime = freeTimeTmp;
95
            getDateRangeTable().fillFrom(ranges);
128
            getDateRangeTable().fillFrom(ranges);
96
 
-
 
97
        } else {
129
        } else {
98
            getDateRangeTable().clear();
130
            getDateRangeTable().clear();
-
 
131
            isFreeTime = false;
99
        }
132
        }
-
 
133
        ((JToggleButton) getEditor("operation.freeTime")).setSelected(isFreeTime);
100
    }
134
    }
101
 
135
 
102
    @Override
136
    @Override
103
    public void update() {
137
    public void update() {
104
        super.update();
138
        super.update();
Line 152... Line 186...
152
                rowItem.put("START", new Date(dateRange.getStart()));
186
                rowItem.put("START", new Date(dateRange.getStart()));
153
                rowItem.put("END", new Date(dateRange.getStop()));
187
                rowItem.put("END", new Date(dateRange.getStop()));
154
                rowItem.put("DURATION_S", (dateRange.getStop() - dateRange.getStart()) / 1000);
188
                rowItem.put("DURATION_S", (dateRange.getStop() - dateRange.getStart()) / 1000);
155
                rowItem.put("SUMMARY", operationRow.getForeignRow("ID_SITE").getString("NAME") + "\n" + operationRow.getString("TYPE"));
189
                rowItem.put("SUMMARY", operationRow.getForeignRow("ID_SITE").getString("NAME") + "\n" + operationRow.getString("TYPE"));
156
                rowItem.put("DESCRIPTION", operationRow.getString("DESCRIPTION"));
190
                rowItem.put("DESCRIPTION", operationRow.getString("DESCRIPTION"));
-
 
191
                final List<String> flags = new ArrayList<>();
-
 
192
                final boolean isFreeTime = ((JToggleButton) getEditor("operation.freeTime")).isSelected();
-
 
193
                if (isFreeTime)
-
 
194
                    flags.add(ModuleOperation.FREE_TIME_FLAG.getTypeId());
-
 
195
                if (!StringUtils.isEmpty(operationRow.getString("PLANNER_UID")))
157
                rowItem.put("FLAGS", "");
196
                    flags.add("planned");
-
 
197
                rowItem.put("FLAGS", CollectionUtils.join(flags, ","));
158
                rowItem.put("STATUS", operationRow.getString("STATUS"));
198
                rowItem.put("STATUS", operationRow.getString("STATUS"));
159
                rowItem.put("ID_CALENDAR_ITEM_GROUP", calendarGroupRow.getID());
199
                rowItem.put("ID_CALENDAR_ITEM_GROUP", calendarGroupRow.getID());
160
                rowItem.put("SOURCE_ID", idOperation);
200
                rowItem.put("SOURCE_ID", idOperation);
161
                rowItem.put("SOURCE_TABLE", ModuleOperation.TABLE_OPERATION);
201
                rowItem.put("SOURCE_TABLE", ModuleOperation.TABLE_OPERATION);
162
                // apply old UIDs
202
                // apply old UIDs