17 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.sql.users;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.sql.Configuration;
|
73 |
ilm |
17 |
import org.openconcerto.sql.TM;
|
17 |
ilm |
18 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
19 |
import org.openconcerto.sql.element.SQLComponent;
|
80 |
ilm |
20 |
import org.openconcerto.sql.element.SQLElement;
|
132 |
ilm |
21 |
import org.openconcerto.sql.model.DBRoot;
|
17 |
ilm |
22 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
23 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
80 |
ilm |
24 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
25 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
|
|
|
26 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
27 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
28 |
import org.openconcerto.sql.model.Where;
|
17 |
ilm |
29 |
import org.openconcerto.sql.request.ComboSQLRequest;
|
|
|
30 |
import org.openconcerto.sql.sqlobject.itemview.SimpleRowItemView;
|
|
|
31 |
import org.openconcerto.sql.ui.Login;
|
80 |
ilm |
32 |
import org.openconcerto.sql.view.QuickAssignPanel;
|
144 |
ilm |
33 |
import org.openconcerto.sql.view.list.ITableModel;
|
80 |
ilm |
34 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
|
|
35 |
import org.openconcerto.sql.view.list.SQLTableElement;
|
144 |
ilm |
36 |
import org.openconcerto.sql.view.list.SQLTableModelColumn;
|
|
|
37 |
import org.openconcerto.sql.view.list.SQLTableModelSource;
|
17 |
ilm |
38 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
39 |
import org.openconcerto.ui.ISpinner;
|
|
|
40 |
import org.openconcerto.ui.ISpinnerIntegerModel;
|
80 |
ilm |
41 |
import org.openconcerto.ui.JLabelBold;
|
93 |
ilm |
42 |
import org.openconcerto.ui.component.InteractionMode;
|
67 |
ilm |
43 |
import org.openconcerto.ui.valuewrapper.TextValueWrapper;
|
17 |
ilm |
44 |
import org.openconcerto.ui.warning.JLabelWarning;
|
80 |
ilm |
45 |
import org.openconcerto.utils.ExceptionHandler;
|
132 |
ilm |
46 |
import org.openconcerto.utils.ListMap;
|
80 |
ilm |
47 |
import org.openconcerto.utils.cc.ITransformer;
|
21 |
ilm |
48 |
import org.openconcerto.utils.checks.ValidState;
|
17 |
ilm |
49 |
import org.openconcerto.utils.text.SimpleDocumentListener;
|
|
|
50 |
|
144 |
ilm |
51 |
import java.awt.Component;
|
|
|
52 |
import java.awt.Font;
|
17 |
ilm |
53 |
import java.awt.GridBagConstraints;
|
|
|
54 |
import java.awt.GridBagLayout;
|
|
|
55 |
import java.awt.Insets;
|
80 |
ilm |
56 |
import java.awt.event.ItemEvent;
|
|
|
57 |
import java.awt.event.ItemListener;
|
|
|
58 |
import java.beans.PropertyChangeEvent;
|
|
|
59 |
import java.beans.PropertyChangeListener;
|
|
|
60 |
import java.sql.SQLException;
|
17 |
ilm |
61 |
import java.util.ArrayList;
|
|
|
62 |
import java.util.List;
|
|
|
63 |
|
|
|
64 |
import javax.swing.BorderFactory;
|
|
|
65 |
import javax.swing.JCheckBox;
|
|
|
66 |
import javax.swing.JLabel;
|
|
|
67 |
import javax.swing.JPanel;
|
|
|
68 |
import javax.swing.JPasswordField;
|
144 |
ilm |
69 |
import javax.swing.JTable;
|
17 |
ilm |
70 |
import javax.swing.JTextField;
|
|
|
71 |
import javax.swing.SwingConstants;
|
|
|
72 |
import javax.swing.event.DocumentEvent;
|
144 |
ilm |
73 |
import javax.swing.table.DefaultTableCellRenderer;
|
17 |
ilm |
74 |
|
|
|
75 |
// FIXME Login user unique ?
|
156 |
ilm |
76 |
public class UserCommonSQLElement extends SQLElement {
|
17 |
ilm |
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Set this system property to "true" if this should generate old style passwords.
|
|
|
80 |
*/
|
|
|
81 |
public static final String LEGACY_PASSWORDS = "org.openconcerto.sql.legacyPasswords";
|
|
|
82 |
|
144 |
ilm |
83 |
private final boolean familyNameFirst;
|
|
|
84 |
|
156 |
ilm |
85 |
public UserCommonSQLElement(final DBRoot root) {
|
|
|
86 |
this(root, false);
|
17 |
ilm |
87 |
}
|
|
|
88 |
|
151 |
ilm |
89 |
public UserCommonSQLElement(final DBRoot root, final boolean familyNameFirst) {
|
156 |
ilm |
90 |
// allow subclass to keep same code
|
|
|
91 |
super(root.findTable("USER_COMMON"), null, "sql.user");
|
144 |
ilm |
92 |
this.familyNameFirst = familyNameFirst;
|
132 |
ilm |
93 |
}
|
|
|
94 |
|
17 |
ilm |
95 |
@Override
|
|
|
96 |
protected List<String> getListFields() {
|
144 |
ilm |
97 |
final List<String> l = new ArrayList<>(5);
|
|
|
98 |
if (this.familyNameFirst) {
|
|
|
99 |
l.add("NOM");
|
|
|
100 |
l.add("PRENOM");
|
|
|
101 |
} else {
|
|
|
102 |
l.add("PRENOM");
|
|
|
103 |
l.add("NOM");
|
|
|
104 |
}
|
17 |
ilm |
105 |
l.add("LOGIN");
|
132 |
ilm |
106 |
if (getTable().contains("DISABLED")) {
|
|
|
107 |
l.add("DISABLED");
|
|
|
108 |
}
|
93 |
ilm |
109 |
if (getTable().contains("OUT")) {
|
|
|
110 |
l.add("OUT");
|
|
|
111 |
}
|
17 |
ilm |
112 |
return l;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
@Override
|
151 |
ilm |
116 |
protected synchronized void _initTableSource(final SQLTableModelSource res) {
|
144 |
ilm |
117 |
super._initTableSource(res);
|
|
|
118 |
// current user in bold
|
|
|
119 |
for (final SQLTableModelColumn col : res.getColumns()) {
|
|
|
120 |
if (col.getValueClass().equals(String.class)) {
|
|
|
121 |
col.setRenderer(new DefaultTableCellRenderer() {
|
|
|
122 |
@Override
|
151 |
ilm |
123 |
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
|
144 |
ilm |
124 |
final JLabel res = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
125 |
final boolean isCurrentUser = ITableModel.getLine(table.getModel(), row).getRow().getID() == UserManager.getUserID();
|
|
|
126 |
final int targetStyle = isCurrentUser ? Font.BOLD : Font.PLAIN;
|
|
|
127 |
if ((res.getFont().getStyle() & targetStyle) == 0) {
|
|
|
128 |
res.setFont(res.getFont().deriveFont(targetStyle));
|
|
|
129 |
}
|
|
|
130 |
return res;
|
|
|
131 |
}
|
|
|
132 |
});
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
@Override
|
17 |
ilm |
138 |
protected List<String> getComboFields() {
|
144 |
ilm |
139 |
final List<String> l = new ArrayList<>(2);
|
|
|
140 |
if (this.familyNameFirst) {
|
|
|
141 |
l.add("NOM");
|
|
|
142 |
l.add("PRENOM");
|
|
|
143 |
} else {
|
|
|
144 |
l.add("PRENOM");
|
|
|
145 |
l.add("NOM");
|
|
|
146 |
}
|
17 |
ilm |
147 |
return l;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
@Override
|
151 |
ilm |
151 |
protected void _initComboRequest(final ComboSQLRequest req) {
|
142 |
ilm |
152 |
super._initComboRequest(req);
|
|
|
153 |
req.setFieldSeparator(" ");
|
17 |
ilm |
154 |
}
|
|
|
155 |
|
|
|
156 |
@Override
|
132 |
ilm |
157 |
public ListMap<String, String> getShowAs() {
|
|
|
158 |
return ListMap.singleton(null, "PRENOM", "NOM");
|
17 |
ilm |
159 |
}
|
|
|
160 |
|
|
|
161 |
/*
|
|
|
162 |
* (non-Javadoc)
|
151 |
ilm |
163 |
*
|
17 |
ilm |
164 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
|
|
165 |
*/
|
|
|
166 |
@Override
|
|
|
167 |
public SQLComponent createComponent() {
|
144 |
ilm |
168 |
return new UserSQLComponent(this);
|
|
|
169 |
}
|
17 |
ilm |
170 |
|
144 |
ilm |
171 |
protected static class UserSQLComponent extends BaseSQLComponent {
|
17 |
ilm |
172 |
|
144 |
ilm |
173 |
private JPasswordField passField;
|
|
|
174 |
private JPasswordField passFieldConfirm;
|
|
|
175 |
private JPanel panelWarning;
|
|
|
176 |
private final SQLElement accessSocieteElem;
|
|
|
177 |
private QuickAssignPanel table;
|
|
|
178 |
// TODO transform into real SQLRowItemView
|
|
|
179 |
private final JTextField encryptedPass = new JTextField();
|
|
|
180 |
private JCheckBox noCompanyLimitCheckBox;
|
|
|
181 |
{
|
|
|
182 |
final SQLTable t = getTable().getDBSystemRoot().getGraph().findReferentTable(getTable(), "ACCES_SOCIETE");
|
|
|
183 |
this.accessSocieteElem = t == null ? null : getDirectory().getElement(t);
|
|
|
184 |
}
|
80 |
ilm |
185 |
|
151 |
ilm |
186 |
protected UserSQLComponent(final SQLElement element) {
|
144 |
ilm |
187 |
super(element);
|
|
|
188 |
}
|
67 |
ilm |
189 |
|
144 |
ilm |
190 |
protected final JPasswordField getPassField() {
|
|
|
191 |
return this.passField;
|
|
|
192 |
}
|
67 |
ilm |
193 |
|
144 |
ilm |
194 |
protected final JPasswordField getPassFieldConfirm() {
|
|
|
195 |
return this.passFieldConfirm;
|
|
|
196 |
}
|
17 |
ilm |
197 |
|
144 |
ilm |
198 |
@Override
|
|
|
199 |
public void addViews() {
|
|
|
200 |
final GridBagConstraints c = new GridBagConstraints();
|
|
|
201 |
c.insets = new Insets(0, 0, 0, 0);
|
|
|
202 |
c.gridx = 0;
|
|
|
203 |
c.gridy = 0;
|
|
|
204 |
c.weightx = 0;
|
|
|
205 |
c.weighty = 0;
|
|
|
206 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
207 |
c.anchor = GridBagConstraints.WEST;
|
17 |
ilm |
208 |
|
144 |
ilm |
209 |
this.panelWarning = new JPanel(new GridBagLayout());
|
|
|
210 |
this.panelWarning.setBorder(BorderFactory.createEmptyBorder());
|
|
|
211 |
final JLabelWarning labelWarning = new JLabelWarning();
|
|
|
212 |
this.panelWarning.add(labelWarning, c);
|
|
|
213 |
final JLabel labelTextWarning = new JLabel(TM.tr("user.passwordsDontMatch.short"));
|
|
|
214 |
c.gridx++;
|
|
|
215 |
this.panelWarning.add(labelTextWarning, c);
|
17 |
ilm |
216 |
|
144 |
ilm |
217 |
final GridBagLayout layout = new GridBagLayout();
|
|
|
218 |
this.setLayout(layout);
|
17 |
ilm |
219 |
|
144 |
ilm |
220 |
// Login
|
|
|
221 |
c.gridx = 0;
|
|
|
222 |
c.insets = new Insets(2, 2, 1, 2);
|
|
|
223 |
final JLabel labelLogin = new JLabel(getLabelFor("LOGIN"));
|
|
|
224 |
labelLogin.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
225 |
this.add(labelLogin, c);
|
|
|
226 |
final JTextField textLogin = new JTextField();
|
|
|
227 |
c.gridx++;
|
|
|
228 |
DefaultGridBagConstraints.lockMinimumSize(textLogin);
|
|
|
229 |
c.weightx = 1;
|
|
|
230 |
this.add(textLogin, c);
|
17 |
ilm |
231 |
|
144 |
ilm |
232 |
// Warning
|
|
|
233 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
234 |
c.gridx++;
|
|
|
235 |
c.insets = new Insets(0, 0, 0, 0);
|
|
|
236 |
this.add(this.panelWarning, c);
|
|
|
237 |
this.panelWarning.setVisible(false);
|
17 |
ilm |
238 |
|
144 |
ilm |
239 |
// Pass
|
|
|
240 |
c.gridy++;
|
|
|
241 |
c.gridwidth = 1;
|
|
|
242 |
c.gridx = 0;
|
|
|
243 |
c.weightx = 0;
|
|
|
244 |
c.insets = new Insets(2, 2, 1, 2);
|
|
|
245 |
final JLabel labelPass = new JLabel(getLabelFor("PASSWORD"));
|
|
|
246 |
labelPass.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
247 |
this.add(labelPass, c);
|
|
|
248 |
this.passField = new JPasswordField(15);
|
|
|
249 |
c.gridx++;
|
|
|
250 |
c.weightx = 1;
|
|
|
251 |
DefaultGridBagConstraints.lockMinimumSize(this.getPassField());
|
|
|
252 |
this.add(this.getPassField(), c);
|
|
|
253 |
|
|
|
254 |
// Confirmation password
|
|
|
255 |
c.gridx++;
|
|
|
256 |
c.weightx = 0;
|
|
|
257 |
final JLabel labelConfirmationPass = new JLabel(getLabelFor("PASSWORD_CONFIRM"));
|
|
|
258 |
labelConfirmationPass.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
259 |
this.add(labelConfirmationPass, c);
|
|
|
260 |
this.passFieldConfirm = new JPasswordField(15);
|
|
|
261 |
c.gridx++;
|
|
|
262 |
c.weightx = 1;
|
|
|
263 |
DefaultGridBagConstraints.lockMinimumSize(this.getPassFieldConfirm());
|
|
|
264 |
this.add(this.getPassFieldConfirm(), c);
|
|
|
265 |
|
|
|
266 |
// Nom
|
|
|
267 |
c.gridx = 0;
|
|
|
268 |
c.gridy++;
|
|
|
269 |
c.weightx = 0;
|
|
|
270 |
final JLabel labelNom = new JLabel(getLabelFor("NOM"));
|
|
|
271 |
labelNom.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
272 |
this.add(labelNom, c);
|
|
|
273 |
final JTextField textNom = new JTextField();
|
|
|
274 |
c.gridx++;
|
|
|
275 |
c.weightx = 1;
|
|
|
276 |
this.add(textNom, c);
|
|
|
277 |
|
|
|
278 |
// Prenom
|
|
|
279 |
c.gridx++;
|
|
|
280 |
c.weightx = 0;
|
|
|
281 |
final JLabel labelPrenom = new JLabel(getLabelFor("PRENOM"));
|
|
|
282 |
labelPrenom.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
283 |
this.add(labelPrenom, c);
|
|
|
284 |
final JTextField textPrenom = new JTextField();
|
|
|
285 |
c.gridx++;
|
|
|
286 |
c.weightx = 1;
|
|
|
287 |
this.add(textPrenom, c);
|
|
|
288 |
|
|
|
289 |
// Surnom
|
|
|
290 |
c.gridx = 0;
|
|
|
291 |
c.gridy++;
|
|
|
292 |
c.weightx = 0;
|
|
|
293 |
final JLabel labelSurnom = new JLabel(getLabelFor("SURNOM"));
|
|
|
294 |
labelSurnom.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
295 |
this.add(labelSurnom, c);
|
|
|
296 |
final JTextField textSurnom = new JTextField();
|
|
|
297 |
c.gridx++;
|
|
|
298 |
c.weightx = 1;
|
|
|
299 |
this.add(textSurnom, c);
|
|
|
300 |
|
|
|
301 |
if (this.getTable().contains("ADMIN")) {
|
|
|
302 |
final JCheckBox checkAdmin = new JCheckBox(getLabelFor("ADMIN"));
|
17 |
ilm |
303 |
c.gridx++;
|
144 |
ilm |
304 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
17 |
ilm |
305 |
c.weightx = 0;
|
144 |
ilm |
306 |
this.add(checkAdmin, c);
|
|
|
307 |
this.addView(checkAdmin, "ADMIN");
|
|
|
308 |
}
|
17 |
ilm |
309 |
|
144 |
ilm |
310 |
c.gridy++;
|
|
|
311 |
c.gridwidth = 1;
|
|
|
312 |
c.gridx = 0;
|
|
|
313 |
c.weightx = 0;
|
|
|
314 |
|
|
|
315 |
if (getTable().contains("MAIL")) {
|
|
|
316 |
final JLabel labelMail = new JLabel(getLabelFor("MAIL"));
|
|
|
317 |
labelMail.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
318 |
c.anchor = GridBagConstraints.NORTHWEST;
|
|
|
319 |
this.add(labelMail, c);
|
17 |
ilm |
320 |
c.gridx++;
|
144 |
ilm |
321 |
final JTextField textMail = new JTextField();
|
|
|
322 |
c.gridwidth = 1;
|
17 |
ilm |
323 |
c.weightx = 1;
|
|
|
324 |
|
144 |
ilm |
325 |
this.add(textMail, c);
|
|
|
326 |
this.addView(textMail, "MAIL");
|
|
|
327 |
}
|
|
|
328 |
if (getTable().contains("OUT")) {
|
17 |
ilm |
329 |
c.gridx++;
|
151 |
ilm |
330 |
final JCheckBox boxOut = new JCheckBox(getLabelFor("OUT"));
|
144 |
ilm |
331 |
c.gridwidth = 1;
|
17 |
ilm |
332 |
c.weightx = 1;
|
144 |
ilm |
333 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
334 |
this.add(boxOut, c);
|
|
|
335 |
this.addView(boxOut, "OUT");
|
|
|
336 |
} else {
|
|
|
337 |
if (getTable().contains("DISABLED")) {
|
|
|
338 |
c.gridx++;
|
151 |
ilm |
339 |
final JCheckBox boxDisabled = new JCheckBox(getLabelFor("DISABLED"));
|
144 |
ilm |
340 |
c.gridwidth = 1;
|
|
|
341 |
c.weightx = 1;
|
|
|
342 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
343 |
this.add(boxDisabled, c);
|
|
|
344 |
this.addView(boxDisabled, "DISABLED");
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
c.gridy++;
|
|
|
348 |
if (getTable().contains("TEL")) {
|
17 |
ilm |
349 |
c.gridx = 0;
|
151 |
ilm |
350 |
final JLabel labelTel = new JLabel(getLabelFor("TEL"));
|
144 |
ilm |
351 |
c.gridwidth = 1;
|
17 |
ilm |
352 |
c.weightx = 0;
|
144 |
ilm |
353 |
this.add(labelTel, c);
|
151 |
ilm |
354 |
final JTextField fieldTel = new JTextField(20);
|
17 |
ilm |
355 |
c.gridx++;
|
|
|
356 |
c.weightx = 1;
|
144 |
ilm |
357 |
this.add(fieldTel, c);
|
|
|
358 |
this.addView(fieldTel, "TEL");
|
|
|
359 |
}
|
|
|
360 |
if (getTable().contains("CALENDAR_USER")) {
|
|
|
361 |
c.gridx = 2;
|
151 |
ilm |
362 |
final JCheckBox boxCalUser = new JCheckBox(getLabelFor("CALENDAR_USER"));
|
144 |
ilm |
363 |
c.weightx = 1;
|
|
|
364 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
365 |
this.add(boxCalUser, c);
|
|
|
366 |
this.addView(boxCalUser, "CALENDAR_USER");
|
|
|
367 |
}
|
17 |
ilm |
368 |
|
151 |
ilm |
369 |
final boolean gestionHoraire = false;
|
144 |
ilm |
370 |
if (Configuration.getInstance().getAppName().startsWith("OpenConcerto") && gestionHoraire) {
|
17 |
ilm |
371 |
|
|
|
372 |
c.gridwidth = 1;
|
151 |
ilm |
373 |
final JPanel panelHoraires = new JPanel(new GridBagLayout());
|
|
|
374 |
final GridBagConstraints cH = new DefaultGridBagConstraints();
|
17 |
ilm |
375 |
|
144 |
ilm |
376 |
createHalfDay(panelHoraires, cH, "Matin :", "MATIN", 8, 12);
|
|
|
377 |
createHalfDay(panelHoraires, cH, "Après midi :", "MIDI", 13, 17);
|
17 |
ilm |
378 |
|
132 |
ilm |
379 |
c.gridy++;
|
144 |
ilm |
380 |
c.gridx = 0;
|
|
|
381 |
c.gridwidth = GridBagConstraints.REMAINDER;
|
|
|
382 |
c.weightx = 1;
|
|
|
383 |
c.weighty = 0;
|
|
|
384 |
panelHoraires.setBorder(BorderFactory.createTitledBorder("Horaires"));
|
|
|
385 |
this.add(panelHoraires, c);
|
|
|
386 |
}
|
17 |
ilm |
387 |
|
144 |
ilm |
388 |
if (this.accessSocieteElem != null) {
|
|
|
389 |
c.gridy++;
|
|
|
390 |
c.gridx = 0;
|
|
|
391 |
c.gridwidth = 4;
|
17 |
ilm |
392 |
|
144 |
ilm |
393 |
this.add(new JLabelBold("Accés aux sociétés"), c);
|
|
|
394 |
c.gridy++;
|
151 |
ilm |
395 |
this.noCompanyLimitCheckBox = new JCheckBox("ne pas limiter l'accès à certaines sociétés");
|
|
|
396 |
this.add(this.noCompanyLimitCheckBox, c);
|
17 |
ilm |
397 |
|
144 |
ilm |
398 |
c.gridy++;
|
|
|
399 |
c.weighty = 1;
|
|
|
400 |
c.fill = GridBagConstraints.BOTH;
|
|
|
401 |
final SQLElement companyElement = this.accessSocieteElem.getForeignElement("ID_SOCIETE_COMMON");
|
|
|
402 |
final List<SQLTableElement> tableElements = new ArrayList<>();
|
|
|
403 |
tableElements.add(new SQLTableElement(companyElement.getTable().getField("NOM")));
|
|
|
404 |
final RowValuesTableModel model = new RowValuesTableModel(companyElement, tableElements, companyElement.getTable().getKey(), false);
|
|
|
405 |
this.table = new QuickAssignPanel(companyElement, "ID", model);
|
|
|
406 |
this.add(this.table, c);
|
17 |
ilm |
407 |
|
151 |
ilm |
408 |
this.noCompanyLimitCheckBox.addItemListener(new ItemListener() {
|
67 |
ilm |
409 |
@Override
|
151 |
ilm |
410 |
public void itemStateChanged(final ItemEvent e) {
|
|
|
411 |
UserSQLComponent.this.table.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
|
17 |
ilm |
412 |
}
|
|
|
413 |
});
|
144 |
ilm |
414 |
getView("ADMIN").addValueListener(new PropertyChangeListener() {
|
17 |
ilm |
415 |
@Override
|
151 |
ilm |
416 |
public void propertyChange(final PropertyChangeEvent evt) {
|
144 |
ilm |
417 |
final boolean selected = evt.getNewValue() == Boolean.TRUE;
|
151 |
ilm |
418 |
UserSQLComponent.this.noCompanyLimitCheckBox.setEnabled(!selected);
|
144 |
ilm |
419 |
if (selected)
|
151 |
ilm |
420 |
UserSQLComponent.this.noCompanyLimitCheckBox.setSelected(true);
|
17 |
ilm |
421 |
}
|
|
|
422 |
});
|
151 |
ilm |
423 |
this.noCompanyLimitCheckBox.setSelected(true);
|
17 |
ilm |
424 |
}
|
|
|
425 |
|
144 |
ilm |
426 |
this.addRequiredSQLObject(textLogin, "LOGIN");
|
|
|
427 |
this.addView(new SimpleRowItemView<String>(new TextValueWrapper(this.encryptedPass)) {
|
|
|
428 |
@Override
|
|
|
429 |
public void setEditable(final InteractionMode mode) {
|
|
|
430 |
mode.applyTo(getPassField());
|
|
|
431 |
mode.applyTo(getPassFieldConfirm());
|
|
|
432 |
}
|
|
|
433 |
}, "PASSWORD", REQ);
|
|
|
434 |
this.addSQLObject(textNom, "NOM");
|
|
|
435 |
this.addSQLObject(textPrenom, "PRENOM");
|
|
|
436 |
this.addSQLObject(textSurnom, "SURNOM");
|
17 |
ilm |
437 |
|
144 |
ilm |
438 |
this.getPassField().getDocument().addDocumentListener(new SimpleDocumentListener() {
|
|
|
439 |
@Override
|
151 |
ilm |
440 |
public void update(final DocumentEvent e) {
|
144 |
ilm |
441 |
updateEncrypted();
|
|
|
442 |
fireValidChange();
|
|
|
443 |
}
|
|
|
444 |
});
|
|
|
445 |
this.getPassFieldConfirm().getDocument().addDocumentListener(new SimpleDocumentListener() {
|
|
|
446 |
@Override
|
151 |
ilm |
447 |
public void update(final DocumentEvent e) {
|
144 |
ilm |
448 |
fireValidChange();
|
|
|
449 |
}
|
|
|
450 |
});
|
17 |
ilm |
451 |
|
144 |
ilm |
452 |
this.addViews(c);
|
|
|
453 |
}
|
17 |
ilm |
454 |
|
144 |
ilm |
455 |
protected void addViews(final GridBagConstraints c) {
|
|
|
456 |
}
|
17 |
ilm |
457 |
|
144 |
ilm |
458 |
// après midi arrivée 13:30
|
|
|
459 |
// __________ départ 17:53
|
151 |
ilm |
460 |
private void createHalfDay(final JPanel panelHoraires, final GridBagConstraints cH, final String label, final String field, final int startHour, final int endHour) {
|
144 |
ilm |
461 |
panelHoraires.add(new JLabel(label), cH);
|
|
|
462 |
cH.gridx++;
|
|
|
463 |
createTime(panelHoraires, cH, "arrivée", field + "_A", startHour);
|
|
|
464 |
cH.gridy++;
|
|
|
465 |
cH.gridx = 1;
|
|
|
466 |
createTime(panelHoraires, cH, "départ", field + "_D", endHour);
|
|
|
467 |
cH.gridy++;
|
|
|
468 |
cH.gridx = 0;
|
|
|
469 |
}
|
17 |
ilm |
470 |
|
144 |
ilm |
471 |
// départ 17:53
|
151 |
ilm |
472 |
private void createTime(final JPanel panelHoraires, final GridBagConstraints cH, final String label, final String field, final int hour) {
|
144 |
ilm |
473 |
panelHoraires.add(new JLabel(label), cH);
|
|
|
474 |
cH.gridx++;
|
17 |
ilm |
475 |
|
144 |
ilm |
476 |
final ISpinner spinHourMA = createSpinner(panelHoraires, cH, true, hour);
|
|
|
477 |
final ISpinner spinMinMA = createSpinner(panelHoraires, cH, false, 0);
|
17 |
ilm |
478 |
|
144 |
ilm |
479 |
this.addView(new SimpleRowItemView<Integer>(spinHourMA), "HEURE_" + field, null);
|
|
|
480 |
this.addView(new SimpleRowItemView<Integer>(spinMinMA), "MINUTE_" + field, null);
|
|
|
481 |
}
|
17 |
ilm |
482 |
|
144 |
ilm |
483 |
// 17 h or 53 min
|
151 |
ilm |
484 |
private ISpinner createSpinner(final JPanel panelHoraires, final GridBagConstraints cH, final boolean hour, final int value) {
|
|
|
485 |
final ISpinnerIntegerModel modelHourMA = new ISpinnerIntegerModel(0, hour ? 23 : 59, value);
|
|
|
486 |
final ISpinner spinHourMA = new ISpinner(modelHourMA);
|
144 |
ilm |
487 |
panelHoraires.add(spinHourMA.getComp(), cH);
|
|
|
488 |
cH.gridx++;
|
|
|
489 |
panelHoraires.add(new JLabel(hour ? "h" : "min"), cH);
|
|
|
490 |
cH.gridx++;
|
|
|
491 |
return spinHourMA;
|
|
|
492 |
}
|
80 |
ilm |
493 |
|
144 |
ilm |
494 |
private void updateEncrypted() {
|
|
|
495 |
final String pass = String.valueOf(this.getPassField().getPassword());
|
|
|
496 |
final String dbPass = Boolean.getBoolean(LEGACY_PASSWORDS) ? '"' + pass + '"' : pass;
|
|
|
497 |
this.encryptedPass.setText(Login.encodePassword(dbPass));
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
private boolean checkValidityPassword() {
|
|
|
501 |
final boolean b = String.valueOf(this.getPassField().getPassword()).equalsIgnoreCase(String.valueOf(this.getPassFieldConfirm().getPassword()));
|
|
|
502 |
this.panelWarning.setVisible(!b);
|
|
|
503 |
return b;
|
|
|
504 |
}
|
|
|
505 |
|
|
|
506 |
@Override
|
|
|
507 |
public synchronized ValidState getValidState() {
|
|
|
508 |
return super.getValidState().and(ValidState.createCached(checkValidityPassword(), TM.tr("user.passwordsDontMatch")));
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
@Override
|
|
|
512 |
public void select(final SQLRowAccessor row) {
|
|
|
513 |
// show something in the user-visible text fields, but do it before the real select
|
|
|
514 |
// so that this.encryptedPass (which will be updated by updateEncrypted() and thus
|
|
|
515 |
// have a bogus value) will be changed to its database value and thus the user can
|
|
|
516 |
// update any field without changing the password.
|
151 |
ilm |
517 |
if (this.table != null) {
|
|
|
518 |
this.table.getModel().clearRows();
|
144 |
ilm |
519 |
}
|
|
|
520 |
if (row != null) {
|
|
|
521 |
final String bogusPass = "bogusPass!";
|
|
|
522 |
this.getPassField().setText(bogusPass);
|
|
|
523 |
this.getPassFieldConfirm().setText(bogusPass);
|
|
|
524 |
// Allowed companies
|
|
|
525 |
if (this.accessSocieteElem != null) {
|
|
|
526 |
final SQLTable tableCompanyAccess = this.accessSocieteElem.getTable();
|
151 |
ilm |
527 |
final SQLRowValues graph = new SQLRowValues(tableCompanyAccess);
|
144 |
ilm |
528 |
graph.put("ID", null);
|
|
|
529 |
graph.putRowValues("ID_SOCIETE_COMMON").put("NOM", null);
|
151 |
ilm |
530 |
final SQLRowValuesListFetcher f = new SQLRowValuesListFetcher(graph);
|
144 |
ilm |
531 |
f.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
|
|
|
532 |
@Override
|
151 |
ilm |
533 |
public SQLSelect transformChecked(final SQLSelect input) {
|
144 |
ilm |
534 |
input.setWhere(new Where(tableCompanyAccess.getField("ID_USER_COMMON"), "=", row.getID()));
|
|
|
535 |
return input;
|
80 |
ilm |
536 |
}
|
144 |
ilm |
537 |
});
|
151 |
ilm |
538 |
final List<SQLRowValues> companies = f.fetch();
|
144 |
ilm |
539 |
|
151 |
ilm |
540 |
for (final SQLRowValues r : companies) {
|
|
|
541 |
this.table.getModel().addRow(r.getForeign("ID_SOCIETE_COMMON").asRowValues());
|
17 |
ilm |
542 |
}
|
151 |
ilm |
543 |
this.noCompanyLimitCheckBox.setSelected(companies.isEmpty());
|
17 |
ilm |
544 |
}
|
|
|
545 |
}
|
144 |
ilm |
546 |
super.select(row);
|
|
|
547 |
}
|
17 |
ilm |
548 |
|
144 |
ilm |
549 |
@Override
|
|
|
550 |
public int insert(SQLRow order) {
|
|
|
551 |
int id = super.insert(order);
|
|
|
552 |
if (this.table != null && !noCompanyLimitCheckBox.isSelected()) {
|
|
|
553 |
insertCompanyAccessForUser(id);
|
17 |
ilm |
554 |
}
|
144 |
ilm |
555 |
return id;
|
|
|
556 |
}
|
17 |
ilm |
557 |
|
151 |
ilm |
558 |
private void insertCompanyAccessForUser(final int id) {
|
144 |
ilm |
559 |
final SQLTable tableCompanyAccess = this.getDirectory().getElement("ACCES_SOCIETE").getTable();
|
151 |
ilm |
560 |
final int stop = this.table.getModel().getRowCount();
|
144 |
ilm |
561 |
for (int i = 0; i < stop; i++) {
|
151 |
ilm |
562 |
final SQLRowValues rCompany = this.table.getModel().getRowValuesAt(i);
|
|
|
563 |
final SQLRowValues rAccess = new SQLRowValues(tableCompanyAccess);
|
144 |
ilm |
564 |
rAccess.put("ID_USER_COMMON", id);
|
|
|
565 |
rAccess.put("ID_SOCIETE_COMMON", rCompany.getID());
|
|
|
566 |
try {
|
|
|
567 |
rAccess.commit();
|
151 |
ilm |
568 |
} catch (final SQLException e) {
|
144 |
ilm |
569 |
ExceptionHandler.handle("Unable to store company access", e);
|
80 |
ilm |
570 |
}
|
|
|
571 |
}
|
144 |
ilm |
572 |
}
|
80 |
ilm |
573 |
|
144 |
ilm |
574 |
@Override
|
|
|
575 |
public void update() {
|
|
|
576 |
super.update();
|
|
|
577 |
if (this.table != null) {
|
|
|
578 |
final SQLTable tableCompanyAccess = this.getDirectory().getElement("ACCES_SOCIETE").getTable();
|
|
|
579 |
String query = "DELETE FROM " + tableCompanyAccess.getSQL() + " WHERE \"ID_USER_COMMON\" = " + getSelectedID();
|
|
|
580 |
tableCompanyAccess.getDBSystemRoot().getDataSource().execute(query);
|
|
|
581 |
if (!noCompanyLimitCheckBox.isSelected()) {
|
|
|
582 |
insertCompanyAccessForUser(getSelectedID());
|
17 |
ilm |
583 |
}
|
|
|
584 |
}
|
144 |
ilm |
585 |
}
|
17 |
ilm |
586 |
}
|
|
|
587 |
}
|