OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Rev 156 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 151
Line 91... Line 91...
91
    public UserCommonSQLElement() {
91
    public UserCommonSQLElement() {
92
        super("USER_COMMON");
92
        super("USER_COMMON");
93
        this.familyNameFirst = false;
93
        this.familyNameFirst = false;
94
    }
94
    }
95
 
95
 
96
    public UserCommonSQLElement(DBRoot root, final boolean familyNameFirst) {
96
    public UserCommonSQLElement(final DBRoot root, final boolean familyNameFirst) {
97
        super(root.findTable("USER_COMMON"));
97
        super(root.findTable("USER_COMMON"));
98
        this.familyNameFirst = familyNameFirst;
98
        this.familyNameFirst = familyNameFirst;
99
    }
99
    }
100
 
100
 
101
    @Override
101
    @Override
Line 117... Line 117...
117
        }
117
        }
118
        return l;
118
        return l;
119
    }
119
    }
120
 
120
 
121
    @Override
121
    @Override
122
    protected synchronized void _initTableSource(SQLTableModelSource res) {
122
    protected synchronized void _initTableSource(final SQLTableModelSource res) {
123
        super._initTableSource(res);
123
        super._initTableSource(res);
124
        // current user in bold
124
        // current user in bold
125
        for (final SQLTableModelColumn col : res.getColumns()) {
125
        for (final SQLTableModelColumn col : res.getColumns()) {
126
            if (col.getValueClass().equals(String.class)) {
126
            if (col.getValueClass().equals(String.class)) {
127
                col.setRenderer(new DefaultTableCellRenderer() {
127
                col.setRenderer(new DefaultTableCellRenderer() {
128
                    @Override
128
                    @Override
129
                    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
129
                    public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
130
                        final JLabel res = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
130
                        final JLabel res = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
131
                        final boolean isCurrentUser = ITableModel.getLine(table.getModel(), row).getRow().getID() == UserManager.getUserID();
131
                        final boolean isCurrentUser = ITableModel.getLine(table.getModel(), row).getRow().getID() == UserManager.getUserID();
132
                        final int targetStyle = isCurrentUser ? Font.BOLD : Font.PLAIN;
132
                        final int targetStyle = isCurrentUser ? Font.BOLD : Font.PLAIN;
133
                        if ((res.getFont().getStyle() & targetStyle) == 0) {
133
                        if ((res.getFont().getStyle() & targetStyle) == 0) {
134
                            res.setFont(res.getFont().deriveFont(targetStyle));
134
                            res.setFont(res.getFont().deriveFont(targetStyle));
Line 152... Line 152...
152
        }
152
        }
153
        return l;
153
        return l;
154
    }
154
    }
155
 
155
 
156
    @Override
156
    @Override
157
    protected void _initComboRequest(ComboSQLRequest req) {
157
    protected void _initComboRequest(final ComboSQLRequest req) {
158
        super._initComboRequest(req);
158
        super._initComboRequest(req);
159
        req.setFieldSeparator(" ");
159
        req.setFieldSeparator(" ");
160
    }
160
    }
161
 
161
 
162
    @Override
162
    @Override
Line 187... Line 187...
187
        {
187
        {
188
            final SQLTable t = getTable().getDBSystemRoot().getGraph().findReferentTable(getTable(), "ACCES_SOCIETE");
188
            final SQLTable t = getTable().getDBSystemRoot().getGraph().findReferentTable(getTable(), "ACCES_SOCIETE");
189
            this.accessSocieteElem = t == null ? null : getDirectory().getElement(t);
189
            this.accessSocieteElem = t == null ? null : getDirectory().getElement(t);
190
        }
190
        }
191
 
191
 
192
        protected UserSQLComponent(SQLElement element) {
192
        protected UserSQLComponent(final SQLElement element) {
193
            super(element);
193
            super(element);
194
        }
194
        }
195
 
195
 
196
        protected final JPasswordField getPassField() {
196
        protected final JPasswordField getPassField() {
197
            return this.passField;
197
            return this.passField;
Line 331... Line 331...
331
                this.add(textMail, c);
331
                this.add(textMail, c);
332
                this.addView(textMail, "MAIL");
332
                this.addView(textMail, "MAIL");
333
            }
333
            }
334
            if (getTable().contains("OUT")) {
334
            if (getTable().contains("OUT")) {
335
                c.gridx++;
335
                c.gridx++;
336
                JCheckBox boxOut = new JCheckBox(getLabelFor("OUT"));
336
                final JCheckBox boxOut = new JCheckBox(getLabelFor("OUT"));
337
                c.gridwidth = 1;
337
                c.gridwidth = 1;
338
                c.weightx = 1;
338
                c.weightx = 1;
339
                c.gridwidth = GridBagConstraints.REMAINDER;
339
                c.gridwidth = GridBagConstraints.REMAINDER;
340
                this.add(boxOut, c);
340
                this.add(boxOut, c);
341
                this.addView(boxOut, "OUT");
341
                this.addView(boxOut, "OUT");
342
            } else {
342
            } else {
343
                if (getTable().contains("DISABLED")) {
343
                if (getTable().contains("DISABLED")) {
344
                    c.gridx++;
344
                    c.gridx++;
345
                    JCheckBox boxDisabled = new JCheckBox(getLabelFor("DISABLED"));
345
                    final JCheckBox boxDisabled = new JCheckBox(getLabelFor("DISABLED"));
346
                    c.gridwidth = 1;
346
                    c.gridwidth = 1;
347
                    c.weightx = 1;
347
                    c.weightx = 1;
348
                    c.gridwidth = GridBagConstraints.REMAINDER;
348
                    c.gridwidth = GridBagConstraints.REMAINDER;
349
                    this.add(boxDisabled, c);
349
                    this.add(boxDisabled, c);
350
                    this.addView(boxDisabled, "DISABLED");
350
                    this.addView(boxDisabled, "DISABLED");
351
                }
351
                }
352
            }
352
            }
353
            c.gridy++;
353
            c.gridy++;
354
            if (getTable().contains("TEL")) {
354
            if (getTable().contains("TEL")) {
355
                c.gridx = 0;
355
                c.gridx = 0;
356
                JLabel labelTel = new JLabel(getLabelFor("TEL"));
356
                final JLabel labelTel = new JLabel(getLabelFor("TEL"));
357
                c.gridwidth = 1;
357
                c.gridwidth = 1;
358
                c.weightx = 0;
358
                c.weightx = 0;
359
                this.add(labelTel, c);
359
                this.add(labelTel, c);
360
                JTextField fieldTel = new JTextField(20);
360
                final JTextField fieldTel = new JTextField(20);
361
                c.gridx++;
361
                c.gridx++;
362
                c.weightx = 1;
362
                c.weightx = 1;
363
                this.add(fieldTel, c);
363
                this.add(fieldTel, c);
364
                this.addView(fieldTel, "TEL");
364
                this.addView(fieldTel, "TEL");
365
            }
365
            }
366
            if (getTable().contains("CALENDAR_USER")) {
366
            if (getTable().contains("CALENDAR_USER")) {
367
                c.gridx = 2;
367
                c.gridx = 2;
368
                JCheckBox boxCalUser = new JCheckBox(getLabelFor("CALENDAR_USER"));
368
                final JCheckBox boxCalUser = new JCheckBox(getLabelFor("CALENDAR_USER"));
369
                c.weightx = 1;
369
                c.weightx = 1;
370
                c.gridwidth = GridBagConstraints.REMAINDER;
370
                c.gridwidth = GridBagConstraints.REMAINDER;
371
                this.add(boxCalUser, c);
371
                this.add(boxCalUser, c);
372
                this.addView(boxCalUser, "CALENDAR_USER");
372
                this.addView(boxCalUser, "CALENDAR_USER");
373
            }
373
            }
374
 
374
 
375
            boolean gestionHoraire = false;
375
            final boolean gestionHoraire = false;
376
            if (Configuration.getInstance().getAppName().startsWith("OpenConcerto") && gestionHoraire) {
376
            if (Configuration.getInstance().getAppName().startsWith("OpenConcerto") && gestionHoraire) {
377
 
377
 
378
                c.gridwidth = 1;
378
                c.gridwidth = 1;
379
                JPanel panelHoraires = new JPanel(new GridBagLayout());
379
                final JPanel panelHoraires = new JPanel(new GridBagLayout());
380
                GridBagConstraints cH = new DefaultGridBagConstraints();
380
                final GridBagConstraints cH = new DefaultGridBagConstraints();
381
 
381
 
382
                createHalfDay(panelHoraires, cH, "Matin :", "MATIN", 8, 12);
382
                createHalfDay(panelHoraires, cH, "Matin :", "MATIN", 8, 12);
383
                createHalfDay(panelHoraires, cH, "Après midi :", "MIDI", 13, 17);
383
                createHalfDay(panelHoraires, cH, "Après midi :", "MIDI", 13, 17);
384
 
384
 
385
                c.gridy++;
385
                c.gridy++;
Line 396... Line 396...
396
                c.gridx = 0;
396
                c.gridx = 0;
397
                c.gridwidth = 4;
397
                c.gridwidth = 4;
398
 
398
 
399
                this.add(new JLabelBold("Accés aux sociétés"), c);
399
                this.add(new JLabelBold("Accés aux sociétés"), c);
400
                c.gridy++;
400
                c.gridy++;
401
                noCompanyLimitCheckBox = new JCheckBox("ne pas limiter l'accès à certaines sociétés");
401
                this.noCompanyLimitCheckBox = new JCheckBox("ne pas limiter l'accès à certaines sociétés");
402
                this.add(noCompanyLimitCheckBox, c);
402
                this.add(this.noCompanyLimitCheckBox, c);
403
 
403
 
404
                c.gridy++;
404
                c.gridy++;
405
                c.weighty = 1;
405
                c.weighty = 1;
406
                c.fill = GridBagConstraints.BOTH;
406
                c.fill = GridBagConstraints.BOTH;
407
                final SQLElement companyElement = this.accessSocieteElem.getForeignElement("ID_SOCIETE_COMMON");
407
                final SQLElement companyElement = this.accessSocieteElem.getForeignElement("ID_SOCIETE_COMMON");
Line 409... Line 409...
409
                tableElements.add(new SQLTableElement(companyElement.getTable().getField("NOM")));
409
                tableElements.add(new SQLTableElement(companyElement.getTable().getField("NOM")));
410
                final RowValuesTableModel model = new RowValuesTableModel(companyElement, tableElements, companyElement.getTable().getKey(), false);
410
                final RowValuesTableModel model = new RowValuesTableModel(companyElement, tableElements, companyElement.getTable().getKey(), false);
411
                this.table = new QuickAssignPanel(companyElement, "ID", model);
411
                this.table = new QuickAssignPanel(companyElement, "ID", model);
412
                this.add(this.table, c);
412
                this.add(this.table, c);
413
 
413
 
414
                noCompanyLimitCheckBox.addItemListener(new ItemListener() {
414
                this.noCompanyLimitCheckBox.addItemListener(new ItemListener() {
415
                    @Override
415
                    @Override
416
                    public void itemStateChanged(ItemEvent e) {
416
                    public void itemStateChanged(final ItemEvent e) {
417
                        table.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
417
                        UserSQLComponent.this.table.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
418
                    }
418
                    }
419
                });
419
                });
420
                getView("ADMIN").addValueListener(new PropertyChangeListener() {
420
                getView("ADMIN").addValueListener(new PropertyChangeListener() {
421
                    @Override
421
                    @Override
422
                    public void propertyChange(PropertyChangeEvent evt) {
422
                    public void propertyChange(final PropertyChangeEvent evt) {
423
                        final boolean selected = evt.getNewValue() == Boolean.TRUE;
423
                        final boolean selected = evt.getNewValue() == Boolean.TRUE;
424
                        noCompanyLimitCheckBox.setEnabled(!selected);
424
                        UserSQLComponent.this.noCompanyLimitCheckBox.setEnabled(!selected);
425
                        if (selected)
425
                        if (selected)
426
                            noCompanyLimitCheckBox.setSelected(true);
426
                            UserSQLComponent.this.noCompanyLimitCheckBox.setSelected(true);
427
                    }
427
                    }
428
                });
428
                });
429
                noCompanyLimitCheckBox.setSelected(true);
429
                this.noCompanyLimitCheckBox.setSelected(true);
430
            }
430
            }
431
 
431
 
432
            this.addRequiredSQLObject(textLogin, "LOGIN");
432
            this.addRequiredSQLObject(textLogin, "LOGIN");
433
            this.addView(new SimpleRowItemView<String>(new TextValueWrapper(this.encryptedPass)) {
433
            this.addView(new SimpleRowItemView<String>(new TextValueWrapper(this.encryptedPass)) {
434
                @Override
434
                @Override
Line 441... Line 441...
441
            this.addSQLObject(textPrenom, "PRENOM");
441
            this.addSQLObject(textPrenom, "PRENOM");
442
            this.addSQLObject(textSurnom, "SURNOM");
442
            this.addSQLObject(textSurnom, "SURNOM");
443
 
443
 
444
            this.getPassField().getDocument().addDocumentListener(new SimpleDocumentListener() {
444
            this.getPassField().getDocument().addDocumentListener(new SimpleDocumentListener() {
445
                @Override
445
                @Override
446
                public void update(DocumentEvent e) {
446
                public void update(final DocumentEvent e) {
447
                    updateEncrypted();
447
                    updateEncrypted();
448
                    fireValidChange();
448
                    fireValidChange();
449
                }
449
                }
450
            });
450
            });
451
            this.getPassFieldConfirm().getDocument().addDocumentListener(new SimpleDocumentListener() {
451
            this.getPassFieldConfirm().getDocument().addDocumentListener(new SimpleDocumentListener() {
452
                @Override
452
                @Override
453
                public void update(DocumentEvent e) {
453
                public void update(final DocumentEvent e) {
454
                    fireValidChange();
454
                    fireValidChange();
455
                }
455
                }
456
            });
456
            });
457
 
457
 
458
            this.addViews(c);
458
            this.addViews(c);
Line 461... Line 461...
461
        protected void addViews(final GridBagConstraints c) {
461
        protected void addViews(final GridBagConstraints c) {
462
        }
462
        }
463
 
463
 
464
        // après midi arrivée 13:30
464
        // après midi arrivée 13:30
465
        // __________ départ 17:53
465
        // __________ départ 17:53
466
        private void createHalfDay(JPanel panelHoraires, GridBagConstraints cH, String label, String field, int startHour, int endHour) {
466
        private void createHalfDay(final JPanel panelHoraires, final GridBagConstraints cH, final String label, final String field, final int startHour, final int endHour) {
467
            panelHoraires.add(new JLabel(label), cH);
467
            panelHoraires.add(new JLabel(label), cH);
468
            cH.gridx++;
468
            cH.gridx++;
469
            createTime(panelHoraires, cH, "arrivée", field + "_A", startHour);
469
            createTime(panelHoraires, cH, "arrivée", field + "_A", startHour);
470
            cH.gridy++;
470
            cH.gridy++;
471
            cH.gridx = 1;
471
            cH.gridx = 1;
Line 473... Line 473...
473
            cH.gridy++;
473
            cH.gridy++;
474
            cH.gridx = 0;
474
            cH.gridx = 0;
475
        }
475
        }
476
 
476
 
477
        // départ 17:53
477
        // départ 17:53
478
        private void createTime(JPanel panelHoraires, GridBagConstraints cH, String label, String field, int hour) {
478
        private void createTime(final JPanel panelHoraires, final GridBagConstraints cH, final String label, final String field, final int hour) {
479
            panelHoraires.add(new JLabel(label), cH);
479
            panelHoraires.add(new JLabel(label), cH);
480
            cH.gridx++;
480
            cH.gridx++;
481
 
481
 
482
            final ISpinner spinHourMA = createSpinner(panelHoraires, cH, true, hour);
482
            final ISpinner spinHourMA = createSpinner(panelHoraires, cH, true, hour);
483
            final ISpinner spinMinMA = createSpinner(panelHoraires, cH, false, 0);
483
            final ISpinner spinMinMA = createSpinner(panelHoraires, cH, false, 0);
Line 485... Line 485...
485
            this.addView(new SimpleRowItemView<Integer>(spinHourMA), "HEURE_" + field, null);
485
            this.addView(new SimpleRowItemView<Integer>(spinHourMA), "HEURE_" + field, null);
486
            this.addView(new SimpleRowItemView<Integer>(spinMinMA), "MINUTE_" + field, null);
486
            this.addView(new SimpleRowItemView<Integer>(spinMinMA), "MINUTE_" + field, null);
487
        }
487
        }
488
 
488
 
489
        // 17 h or 53 min
489
        // 17 h or 53 min
490
        private ISpinner createSpinner(JPanel panelHoraires, GridBagConstraints cH, final boolean hour, int value) {
490
        private ISpinner createSpinner(final JPanel panelHoraires, final GridBagConstraints cH, final boolean hour, final int value) {
491
            ISpinnerIntegerModel modelHourMA = new ISpinnerIntegerModel(0, hour ? 23 : 59, value);
491
            final ISpinnerIntegerModel modelHourMA = new ISpinnerIntegerModel(0, hour ? 23 : 59, value);
492
            ISpinner spinHourMA = new ISpinner(modelHourMA);
492
            final ISpinner spinHourMA = new ISpinner(modelHourMA);
493
            panelHoraires.add(spinHourMA.getComp(), cH);
493
            panelHoraires.add(spinHourMA.getComp(), cH);
494
            cH.gridx++;
494
            cH.gridx++;
495
            panelHoraires.add(new JLabel(hour ? "h" : "min"), cH);
495
            panelHoraires.add(new JLabel(hour ? "h" : "min"), cH);
496
            cH.gridx++;
496
            cH.gridx++;
497
            return spinHourMA;
497
            return spinHourMA;
Line 518... Line 518...
518
        public void select(final SQLRowAccessor row) {
518
        public void select(final SQLRowAccessor row) {
519
            // show something in the user-visible text fields, but do it before the real select
519
            // show something in the user-visible text fields, but do it before the real select
520
            // so that this.encryptedPass (which will be updated by updateEncrypted() and thus
520
            // so that this.encryptedPass (which will be updated by updateEncrypted() and thus
521
            // have a bogus value) will be changed to its database value and thus the user can
521
            // have a bogus value) will be changed to its database value and thus the user can
522
            // update any field without changing the password.
522
            // update any field without changing the password.
523
            if (table != null) {
523
            if (this.table != null) {
524
                table.getModel().clearRows();
524
                this.table.getModel().clearRows();
525
            }
525
            }
526
            if (row != null) {
526
            if (row != null) {
527
                final String bogusPass = "bogusPass!";
527
                final String bogusPass = "bogusPass!";
528
                this.getPassField().setText(bogusPass);
528
                this.getPassField().setText(bogusPass);
529
                this.getPassFieldConfirm().setText(bogusPass);
529
                this.getPassFieldConfirm().setText(bogusPass);
530
                // Allowed companies
530
                // Allowed companies
531
                if (this.accessSocieteElem != null) {
531
                if (this.accessSocieteElem != null) {
532
                    final SQLTable tableCompanyAccess = this.accessSocieteElem.getTable();
532
                    final SQLTable tableCompanyAccess = this.accessSocieteElem.getTable();
533
                    SQLRowValues graph = new SQLRowValues(tableCompanyAccess);
533
                    final SQLRowValues graph = new SQLRowValues(tableCompanyAccess);
534
                    graph.put("ID", null);
534
                    graph.put("ID", null);
535
                    graph.putRowValues("ID_SOCIETE_COMMON").put("NOM", null);
535
                    graph.putRowValues("ID_SOCIETE_COMMON").put("NOM", null);
536
                    SQLRowValuesListFetcher f = new SQLRowValuesListFetcher(graph);
536
                    final SQLRowValuesListFetcher f = new SQLRowValuesListFetcher(graph);
537
                    f.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
537
                    f.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
538
                        @Override
538
                        @Override
539
                        public SQLSelect transformChecked(SQLSelect input) {
539
                        public SQLSelect transformChecked(final SQLSelect input) {
540
                            input.setWhere(new Where(tableCompanyAccess.getField("ID_USER_COMMON"), "=", row.getID()));
540
                            input.setWhere(new Where(tableCompanyAccess.getField("ID_USER_COMMON"), "=", row.getID()));
541
                            return input;
541
                            return input;
542
                        }
542
                        }
543
                    });
543
                    });
544
                    List<SQLRowValues> companies = f.fetch();
544
                    final List<SQLRowValues> companies = f.fetch();
545
 
545
 
546
                    for (SQLRowValues r : companies) {
546
                    for (final SQLRowValues r : companies) {
547
                        table.getModel().addRow(r.getForeign("ID_SOCIETE_COMMON").asRowValues());
547
                        this.table.getModel().addRow(r.getForeign("ID_SOCIETE_COMMON").asRowValues());
548
                    }
548
                    }
549
                    noCompanyLimitCheckBox.setSelected(companies.isEmpty());
549
                    this.noCompanyLimitCheckBox.setSelected(companies.isEmpty());
550
                }
550
                }
551
            }
551
            }
552
            super.select(row);
552
            super.select(row);
553
        }
553
        }
554
 
554
 
Line 559... Line 559...
559
                insertCompanyAccessForUser(id);
559
                insertCompanyAccessForUser(id);
560
            }
560
            }
561
            return id;
561
            return id;
562
        }
562
        }
563
 
563
 
564
        private void insertCompanyAccessForUser(int id) {
564
        private void insertCompanyAccessForUser(final int id) {
565
            final SQLTable tableCompanyAccess = this.getDirectory().getElement("ACCES_SOCIETE").getTable();
565
            final SQLTable tableCompanyAccess = this.getDirectory().getElement("ACCES_SOCIETE").getTable();
566
            int stop = table.getModel().getRowCount();
566
            final int stop = this.table.getModel().getRowCount();
567
            for (int i = 0; i < stop; i++) {
567
            for (int i = 0; i < stop; i++) {
568
                SQLRowValues rCompany = table.getModel().getRowValuesAt(i);
568
                final SQLRowValues rCompany = this.table.getModel().getRowValuesAt(i);
569
                SQLRowValues rAccess = new SQLRowValues(tableCompanyAccess);
569
                final SQLRowValues rAccess = new SQLRowValues(tableCompanyAccess);
570
                rAccess.put("ID_USER_COMMON", id);
570
                rAccess.put("ID_USER_COMMON", id);
571
                rAccess.put("ID_SOCIETE_COMMON", rCompany.getID());
571
                rAccess.put("ID_SOCIETE_COMMON", rCompany.getID());
572
                try {
572
                try {
573
                    rAccess.commit();
573
                    rAccess.commit();
574
                } catch (SQLException e) {
574
                } catch (final SQLException e) {
575
                    ExceptionHandler.handle("Unable to store company access", e);
575
                    ExceptionHandler.handle("Unable to store company access", e);
576
                }
576
                }
577
            }
577
            }
578
        }
578
        }
579
 
579