OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 162 Rev 181
Line 89... Line 89...
89
import org.openconcerto.utils.i18n.TranslationManager;
89
import org.openconcerto.utils.i18n.TranslationManager;
90
 
90
 
91
public class Extension {
91
public class Extension {
92
 
92
 
93
    // Descriptors of the extension
93
    // Descriptors of the extension
94
    private List<ElementDescriptor> elementList = new ArrayList<ElementDescriptor>();
94
    private List<ElementDescriptor> elementList = new ArrayList<>();
95
    private List<TableDescritor> createTableList = new ArrayList<TableDescritor>();
95
    private List<TableDescritor> createTableList = new ArrayList<>();
96
    private List<TableDescritor> modifyTableList = new ArrayList<TableDescritor>();
96
    private List<TableDescritor> modifyTableList = new ArrayList<>();
97
    private List<ListDescriptor> createListList = new ArrayList<ListDescriptor>();
97
    private List<ListDescriptor> createListList = new ArrayList<>();
98
    private List<TableTranslation> tableTranslations = new ArrayList<TableTranslation>();
98
    private List<TableTranslation> tableTranslations = new ArrayList<>();
99
    private List<FieldTranslation> fieldTranslations = new ArrayList<FieldTranslation>();
99
    private List<FieldTranslation> fieldTranslations = new ArrayList<>();
100
    private List<MenuTranslation> menuTranslations = new ArrayList<MenuTranslation>();
100
    private List<MenuTranslation> menuTranslations = new ArrayList<>();
101
    private List<ActionTranslation> actionTranslations = new ArrayList<ActionTranslation>();
101
    private List<ActionTranslation> actionTranslations = new ArrayList<>();
102
    private List<ComponentDescritor> createComponentList = new ArrayList<ComponentDescritor>();
102
    private List<ComponentDescritor> createComponentList = new ArrayList<>();
103
    private List<ComponentDescritor> modifyComponentList = new ArrayList<ComponentDescritor>();
103
    private List<ComponentDescritor> modifyComponentList = new ArrayList<>();
104
    private List<MenuDescriptor> createMenuList = new ArrayList<MenuDescriptor>();
104
    private List<MenuDescriptor> createMenuList = new ArrayList<>();
105
    private List<MenuDescriptor> removeMenuList = new ArrayList<MenuDescriptor>();
105
    private List<MenuDescriptor> removeMenuList = new ArrayList<>();
106
    private List<ActionDescriptor> createActionList = new ArrayList<ActionDescriptor>();
106
    private List<ActionDescriptor> createActionList = new ArrayList<>();
107
 
107
 
108
    // Listeners
108
    // Listeners
109
    private List<ChangeListener> listeners = new ArrayList<ChangeListener>();
109
    private List<ChangeListener> listeners = new ArrayList<>();
110
 
110
 
111
    private String name;
111
    private String name;
112
    private boolean notSaved;
112
    private boolean notSaved;
113
    private boolean autoStart;
113
    private boolean autoStart;
114
    private boolean isStarted;
114
    private boolean isStarted;
Line 117... Line 117...
117
        this.name = name;
117
        this.name = name;
118
        this.notSaved = true;
118
        this.notSaved = true;
119
    }
119
    }
120
 
120
 
121
    public void clearAll() {
121
    public void clearAll() {
122
        elementList.clear();
122
        this.elementList.clear();
123
        createTableList.clear();
123
        this.createTableList.clear();
124
        modifyTableList.clear();
124
        this.modifyTableList.clear();
125
        createListList.clear();
125
        this.createListList.clear();
126
        tableTranslations.clear();
126
        this.tableTranslations.clear();
127
        fieldTranslations.clear();
127
        this.fieldTranslations.clear();
128
        menuTranslations.clear();
128
        this.menuTranslations.clear();
129
        actionTranslations.clear();
129
        this.actionTranslations.clear();
130
        createComponentList.clear();
130
        this.createComponentList.clear();
131
        modifyComponentList.clear();
131
        this.modifyComponentList.clear();
132
        createMenuList.clear();
132
        this.createMenuList.clear();
133
        removeMenuList.clear();
133
        this.removeMenuList.clear();
134
        createActionList.clear();
134
        this.createActionList.clear();
135
        listeners.clear();
135
        this.listeners.clear();
136
 
136
 
137
        notSaved = true;
137
        this.notSaved = true;
138
        autoStart = false;
138
        this.autoStart = false;
139
        isStarted = false;
139
        this.isStarted = false;
140
 
140
 
141
    }
141
    }
142
 
142
 
143
    boolean isStarted() {
143
    boolean isStarted() {
144
        return this.isStarted;
144
        return this.isStarted;
145
    }
145
    }
146
 
146
 
147
    public boolean isAutoStart() {
147
    public boolean isAutoStart() {
148
        return autoStart;
148
        return this.autoStart;
149
    }
149
    }
150
 
150
 
151
    public void start(DBRoot root, boolean inModuleStart) throws SQLException {
151
    public void start(DBRoot root, boolean inModuleStart) throws SQLException {
152
 
152
 
153
        // Ensure that database is configured
153
        // Ensure that database is configured
154
        boolean databaseOk = setupDatabase(root);
154
        boolean databaseOk = setupDatabase(root);
155
        if (!databaseOk) {
155
        if (!databaseOk) {
156
            Log.get().severe("Extension " + this.getName() + " not started due to database error");
156
            Log.get().severe("Extension " + this.getName() + " not started due to database error");
157
            return;
157
            return;
158
        }
158
        }
159
        // Register translations
-
 
160
        registerTranslations(root);
-
 
161
        // Create menus
159
        // Create menus
162
        if (!inModuleStart) {
-
 
163
            final MenuAndActions copy = MenuManager.getInstance().copyMenuAndActions();
160
        final MenuAndActions copy = MenuManager.getInstance().copyMenuAndActions();
164
            registerMenuActions(copy);
161
        registerMenuActions(copy);
-
 
162
        // Register translations before setting menu
-
 
163
        registerTranslations(root);
165
            MenuManager.getInstance().setMenuAndActions(copy);
164
        MenuManager.getInstance().setMenuAndActions(copy);
166
        }
165
 
167
        Log.get().info("Extension " + this.getName() + " started");
166
        Log.get().info("Extension " + this.getName() + " started");
168
        this.isStarted = true;
167
        this.isStarted = true;
169
        this.autoStart = true;
168
        this.autoStart = true;
170
        fireChanged();
169
        fireChanged();
171
    }
170
    }
Line 280... Line 279...
280
                            return editFrame;
279
                            return editFrame;
281
 
280
 
282
                        }
281
                        }
283
                    }, menuDescriptor.getId(), true);
282
                    }, menuDescriptor.getId(), true);
284
                }
283
                }
285
            } else if (menuDescriptor.getType().equals(MenuDescriptor.LIST)) {
284
            } else if (menuDescriptor.getType().equals(MenuDescriptor.GROUP)) {
286
                // No action to register
285
                // TODO
287
            } else {
286
            } else {
288
                Log.get().warning("unknown type " + menuDescriptor.getType());
287
                Log.get().warning("unknown type " + menuDescriptor.getType());
289
            }
288
            }
290
        }
289
        }
291
 
290
 
292
        // System.err.println("****" + MenuManager.getInstance().getActionForId("test1"));
-
 
293
        //
-
 
294
        // final MenuAndActions copy = MenuManager.getInstance().copyMenuAndActions();
-
 
295
        // // create group
-
 
296
        // final Group group = copy.getGroup();
-
 
297
        initMenuGroup(menuAndActions.getGroup());
291
        initMenuGroup(menuAndActions.getGroup());
298
        // MenuManager.getInstance().setMenuAndActions(copy);
-
 
299
        // System.err.println("*******" + MenuManager.getInstance().getActionForId("test1"));
-
 
300
    }
292
    }
301
 
293
 
302
    public SQLTableModelSourceOnline createSource(SQLElement element, ListSQLRequest req, ListDescriptor listDesc) {
294
    public SQLTableModelSourceOnline createSource(SQLElement element, ListSQLRequest req, ListDescriptor listDesc) {
303
        final SQLTableModelSourceOnline source = new SQLTableModelSourceOnline(req, element);
295
        final SQLTableModelSourceOnline source = new SQLTableModelSourceOnline(req, element);
304
        final List<SQLTableModelColumn> cols = new ArrayList<>();
296
        final List<SQLTableModelColumn> cols = new ArrayList<>();
305
        for (ColumnDescriptor cDesc : listDesc.getColumns()) {
297
        for (ColumnDescriptor cDesc : listDesc.getColumns()) {
306
            final String fieldspath = cDesc.getFieldsPaths();
298
            final String fieldspath = cDesc.getFieldsPaths();
307
            final String[] paths = fieldspath.split(",");
299
            final String[] paths = fieldspath.split(",");
308
            final Set<FieldPath> fps = new LinkedHashSet<FieldPath>();
300
            final Set<FieldPath> fps = new LinkedHashSet<>();
309
            for (int i = 0; i < paths.length; i++) {
301
            for (int i = 0; i < paths.length; i++) {
310
                // LOCAL, id_batiment.id_site.nom
302
                // LOCAL, id_batiment.id_site.nom
311
                final SQLName name = SQLName.parse(paths[i].trim());
303
                final SQLName name = SQLName.parse(paths[i].trim());
312
 
304
 
313
                final PathBuilder p = new PathBuilder(element.getTable());
305
                final PathBuilder p = new PathBuilder(element.getTable());
Line 415... Line 407...
415
        }
407
        }
416
        return null;
408
        return null;
417
    }
409
    }
418
 
410
 
419
    private boolean setupDatabase(DBRoot root) throws SQLException {
411
    private boolean setupDatabase(DBRoot root) throws SQLException {
420
        List<ChangeTable<?>> changesToApply = new ArrayList<ChangeTable<?>>();
412
        List<ChangeTable<?>> changesToApply = new ArrayList<>();
421
        List<SQLCreateTable> createToApply = new ArrayList<SQLCreateTable>();
413
        List<SQLCreateTable> createToApply = new ArrayList<>();
422
        // Create fields and tables if needed
414
        // Create fields and tables if needed
423
        final List<TableDescritor> t = new ArrayList<TableDescritor>();
415
        final List<TableDescritor> t = new ArrayList<>();
424
        t.addAll(this.createTableList);
416
        t.addAll(this.createTableList);
425
        t.addAll(this.modifyTableList);
417
        t.addAll(this.modifyTableList);
426
        Set<String> tableNames = new HashSet<String>();
418
        Set<String> tableNames = new HashSet<>();
427
        for (TableDescritor tDesc : t) {
419
        for (TableDescritor tDesc : t) {
428
            String tableName = tDesc.getName();
420
            String tableName = tDesc.getName();
429
            tableNames.add(tableName);
421
            tableNames.add(tableName);
430
            final SQLTable table = root.getTable(tableName);
422
            final SQLTable table = root.getTable(tableName);
431
            final ChangeTable<?> createTable;
423
            final ChangeTable<?> createTable;
Line 481... Line 473...
481
                        createTable.addColumn(fieldName, "time");
473
                        createTable.addColumn(fieldName, "time");
482
                    } else if (type.equals(FieldDescriptor.TYPE_DATETIME)) {
474
                    } else if (type.equals(FieldDescriptor.TYPE_DATETIME)) {
483
                        createTable.addDateAndTimeColumn(fieldName);
475
                        createTable.addDateAndTimeColumn(fieldName);
484
                    } else if (type.equals(FieldDescriptor.TYPE_REF)) {
476
                    } else if (type.equals(FieldDescriptor.TYPE_REF)) {
485
                        // created later
477
                        // created later
486
                        mustAdd = false;
-
 
487
                    }
478
                    }
488
                    mustAdd = true;
479
                    mustAdd = true;
489
                } else {
480
                } else {
490
                    // Le champs existe, on ne fait rien
481
                    // Le champs existe, on ne fait rien
491
                    // checker les types
482
                    // checker les types
Line 518... Line 509...
518
            final SQLTable table = root.getTable(tDesc.getName());
509
            final SQLTable table = root.getTable(tDesc.getName());
519
            for (FieldDescriptor fDesc : tDesc.getFields()) {
510
            for (FieldDescriptor fDesc : tDesc.getFields()) {
520
                final SQLField f = (table == null) ? null : table.getFieldRaw(fDesc.getName());
511
                final SQLField f = (table == null) ? null : table.getFieldRaw(fDesc.getName());
521
                if (f == null && fDesc.getType().equals(FieldDescriptor.TYPE_REF)) {
512
                if (f == null && fDesc.getType().equals(FieldDescriptor.TYPE_REF)) {
522
                    final String fTableName = fDesc.getForeignTable();
513
                    final String fTableName = fDesc.getForeignTable();
-
 
514
                    if (fTableName == null || fTableName.isEmpty()) {
-
 
515
                        JOptionPane.showMessageDialog(new JFrame(),
-
 
516
                                "L'extension ne peut pas s'installer car le champs référence " + fDesc.getName() + " de la table " + tDesc.getName() + " ne définit pas de table étrangère");
-
 
517
                        return false;
-
 
518
                    } else {
523
                    final SQLTable fTable = root.getTable(fTableName);
519
                        final SQLTable fTable = root.getTable(fTableName);
524
                    if (fTable != null) {
520
                        if (fTable != null) {
525
                        final AlterTable mTable = new AlterTable(table);
521
                            final AlterTable mTable = new AlterTable(table);
526
                        mTable.addForeignColumn(fDesc.getName(), fTable);
522
                            mTable.addForeignColumn(fDesc.getName(), fTable);
527
                        changesToApply.add(mTable);
523
                            changesToApply.add(mTable);
Line 530... Line 526...
530
                        return false;
526
                            return false;
531
                    }
527
                        }
532
                }
528
                    }
533
            }
529
                }
534
        }
530
            }
-
 
531
        }
535
        // Create foreign keys
532
        // Create foreign keys
536
        if (!changesToApply.isEmpty()) {
533
        if (!changesToApply.isEmpty()) {
537
            for (String change : ChangeTable.cat(changesToApply)) {
534
            for (String change : ChangeTable.cat(changesToApply)) {
538
                root.getDBSystemRoot().getDataSource().execute(change);
535
                root.getDBSystemRoot().getDataSource().execute(change);
539
            }
536
            }
Line 556... Line 553...
556
        // TODO : remove menu changes
553
        // TODO : remove menu changes
557
        fireChanged();
554
        fireChanged();
558
    }
555
    }
559
 
556
 
560
    public String getName() {
557
    public String getName() {
561
        return name;
558
        return this.name;
562
    }
559
    }
563
 
560
 
564
    @SuppressWarnings("unchecked")
561
    @SuppressWarnings("unchecked")
565
    public void importFromXML(String xml) {
562
    public void importFromXML(String xml) {
566
 
563
 
Line 591... Line 588...
591
                    final List<Element> fields = eTable.getChildren("field");
588
                    final List<Element> fields = eTable.getChildren("field");
592
                    for (Element field : fields) {
589
                    for (Element field : fields) {
593
                        FieldDescriptor f = createFieldDescriptorFrom(name, field);
590
                        FieldDescriptor f = createFieldDescriptorFrom(name, field);
594
                        tDesc.add(f);
591
                        tDesc.add(f);
595
                    }
592
                    }
596
                    if (tDesc.getFields().size() > 0) {
593
                    if (!tDesc.getFields().isEmpty()) {
597
                        if (type.equals("create")) {
594
                        if (type.equals("create")) {
598
                            this.createTableList.add(tDesc);
595
                            this.createTableList.add(tDesc);
599
                        } else if (type.equals("modify")) {
596
                        } else if (type.equals("modify")) {
600
                            this.modifyTableList.add(tDesc);
597
                            this.modifyTableList.add(tDesc);
601
                        } else {
598
                        } else {
Line 655... Line 652...
655
                        mainTable = refid;
652
                        mainTable = refid;
656
                    }
653
                    }
657
                    listDesc.setMainTable(mainTable);
654
                    listDesc.setMainTable(mainTable);
658
                    final List<Element> columns = eList.getChildren("column");
655
                    final List<Element> columns = eList.getChildren("column");
659
                    for (Element field : columns) {
656
                    for (Element field : columns) {
660
                        ColumnDescriptor f = createColumnDescriptorFrom(mainTable, field);
657
                        ColumnDescriptor f = createColumnDescriptorFrom(field);
661
                        listDesc.add(f);
658
                        listDesc.add(f);
662
                    }
659
                    }
663
                    if (listDesc.getColumnCount() > 0) {
660
                    if (listDesc.getColumnCount() > 0) {
664
                        if (type.equals("create")) {
661
                        if (type.equals("create")) {
665
                            this.createListList.add(listDesc);
662
                            this.createListList.add(listDesc);
Line 754... Line 751...
754
            } catch (Exception e) {
751
            } catch (Exception e) {
755
                System.err.println("SimpleXMLAddon.importFromXML(): parsing error :" + e.getMessage());
752
                System.err.println("SimpleXMLAddon.importFromXML(): parsing error :" + e.getMessage());
756
                e.printStackTrace();
753
                e.printStackTrace();
757
            }
754
            }
758
        }
755
        }
759
        notSaved = false;
756
        this.notSaved = false;
760
 
757
 
761
        fireChanged();
758
        fireChanged();
762
    }
759
    }
763
 
760
 
764
    String toXML() {
761
    String toXML() {
Line 822... Line 819...
822
                eTable.addContent(eField);
819
                eTable.addContent(eField);
823
            }
820
            }
824
            rootElement.addContent(eTable);
821
            rootElement.addContent(eTable);
825
        }
822
        }
826
        // Translations
823
        // Translations
827
        final HashSet<String> locales = new HashSet<String>();
824
        final HashSet<String> locales = new HashSet<>();
828
        for (Translation tr : tableTranslations) {
825
        for (Translation tr : this.tableTranslations) {
829
            locales.add(tr.getLocale());
826
            locales.add(tr.getLocale());
830
        }
827
        }
831
        for (Translation tr : fieldTranslations) {
828
        for (Translation tr : this.fieldTranslations) {
832
            locales.add(tr.getLocale());
829
            locales.add(tr.getLocale());
833
        }
830
        }
834
        for (Translation tr : menuTranslations) {
831
        for (Translation tr : this.menuTranslations) {
835
            locales.add(tr.getLocale());
832
            locales.add(tr.getLocale());
836
        }
833
        }
837
        for (Translation tr : actionTranslations) {
834
        for (Translation tr : this.actionTranslations) {
838
            locales.add(tr.getLocale());
835
            locales.add(tr.getLocale());
839
        }
836
        }
840
        final List<String> lLocales = new ArrayList<String>(locales);
837
        final List<String> lLocales = new ArrayList<>(locales);
841
        Collections.sort(lLocales);
838
        Collections.sort(lLocales);
842
        for (String locale : lLocales) {
839
        for (String locale : lLocales) {
843
            final Element eTranslation = new Element("translation");
840
            final Element eTranslation = new Element("translation");
844
            eTranslation.setAttribute("locale", locale);
841
            eTranslation.setAttribute("locale", locale);
845
            rootElement.addContent(eTranslation);
842
            rootElement.addContent(eTranslation);
846
            // Tables
843
            // Tables
847
            for (TableTranslation tTranslation : tableTranslations) {
844
            for (TableTranslation tTranslation : this.tableTranslations) {
848
                if (tTranslation.getLocale().equals(locale)) {
845
                if (tTranslation.getLocale().equals(locale)) {
849
                    final Element eTable = new Element("element");
846
                    final Element eTable = new Element("element");
850
                    eTable.setAttribute("refid", tTranslation.getTableName());
847
                    eTable.setAttribute("refid", tTranslation.getTableName());
851
                    final String singular = tTranslation.getSingular();
848
                    final String singular = tTranslation.getSingular();
852
                    if (singular != null && !singular.isEmpty()) {
849
                    if (singular != null && !singular.isEmpty()) {
Line 854... Line 851...
854
                    }
851
                    }
855
                    final String plural = tTranslation.getPlural();
852
                    final String plural = tTranslation.getPlural();
856
                    if (plural != null && !plural.isEmpty()) {
853
                    if (plural != null && !plural.isEmpty()) {
857
                        eTable.setAttribute("plural", plural);
854
                        eTable.setAttribute("plural", plural);
858
                    }
855
                    }
859
                    for (FieldTranslation fTranslation : fieldTranslations) {
856
                    for (FieldTranslation fTranslation : this.fieldTranslations) {
860
                        // Fields
857
                        // Fields
861
                        if (fTranslation.getLocale().equals(locale) && fTranslation.getTableName().equals(tTranslation.getTableName())) {
858
                        if (fTranslation.getLocale().equals(locale) && fTranslation.getTableName().equals(tTranslation.getTableName())) {
862
                            final Element eField = new Element("item");
859
                            final Element eField = new Element("item");
863
                            eField.setAttribute("id", fTranslation.getFieldName());
860
                            eField.setAttribute("id", fTranslation.getFieldName());
864
                            eField.setAttribute("label", fTranslation.getLabel());
861
                            eField.setAttribute("label", fTranslation.getLabel());
Line 871... Line 868...
871
                    eTranslation.addContent(eTable);
868
                    eTranslation.addContent(eTable);
872
 
869
 
873
                }
870
                }
874
            }
871
            }
875
            // Menus
872
            // Menus
876
            for (MenuTranslation tMenu : menuTranslations) {
873
            for (MenuTranslation tMenu : this.menuTranslations) {
877
                if (tMenu.getLocale().equals(locale)) {
874
                if (tMenu.getLocale().equals(locale)) {
878
                    final Element eMenu = new Element("menu");
875
                    final Element eMenu = new Element("menu");
879
                    eMenu.setAttribute("refid", tMenu.getId());
876
                    eMenu.setAttribute("refid", tMenu.getId());
880
                    eMenu.setAttribute("label", tMenu.getLabel());
877
                    eMenu.setAttribute("label", tMenu.getLabel());
881
                    eTranslation.addContent(eMenu);
878
                    eTranslation.addContent(eMenu);
882
                }
879
                }
883
            }
880
            }
884
 
881
 
885
            // Actions
882
            // Actions
886
            for (ActionTranslation tAction : actionTranslations) {
883
            for (ActionTranslation tAction : this.actionTranslations) {
887
                if (tAction.getLocale().equals(locale)) {
884
                if (tAction.getLocale().equals(locale)) {
888
                    final Element eMenu = new Element("action");
885
                    final Element eMenu = new Element("action");
889
                    eMenu.setAttribute("refid", tAction.getId());
886
                    eMenu.setAttribute("refid", tAction.getId());
890
                    eMenu.setAttribute("label", tAction.getLabel());
887
                    eMenu.setAttribute("label", tAction.getLabel());
891
                    eTranslation.addContent(eMenu);
888
                    eTranslation.addContent(eMenu);
Line 1074... Line 1071...
1074
            f.setLink(createFieldDescriptorFrom(field.getAttributeValue("ftable"), child));
1071
            f.setLink(createFieldDescriptorFrom(field.getAttributeValue("ftable"), child));
1075
        }
1072
        }
1076
        return f;
1073
        return f;
1077
    }
1074
    }
1078
 
1075
 
1079
    private ColumnDescriptor createColumnDescriptorFrom(String table, Element field) {
1076
    private ColumnDescriptor createColumnDescriptorFrom(Element field) {
1080
        final ColumnDescriptor f = new ColumnDescriptor(field.getAttributeValue("id"));
1077
        final ColumnDescriptor f = new ColumnDescriptor(field.getAttributeValue("id"));
1081
        f.setFieldsPaths(field.getAttributeValue("fields"));
1078
        f.setFieldsPaths(field.getAttributeValue("fields"));
1082
        f.setStyle(field.getAttributeValue("style"));
1079
        f.setStyle(field.getAttributeValue("style"));
1083
        return f;
1080
        return f;
1084
    }
1081
    }
1085
 
1082
 
1086
    private void fireChanged() {
1083
    private void fireChanged() {
1087
        for (ChangeListener listener : listeners) {
1084
        for (ChangeListener listener : this.listeners) {
1088
            listener.stateChanged(new ChangeEvent(this));
1085
            listener.stateChanged(new ChangeEvent(this));
1089
        }
1086
        }
1090
 
1087
 
1091
    }
1088
    }
1092
 
1089
 
1093
    public List<TableDescritor> getCreateTableList() {
1090
    public List<TableDescritor> getCreateTableList() {
1094
        return createTableList;
1091
        return this.createTableList;
1095
    }
1092
    }
1096
 
1093
 
1097
    public void addCreateTable(TableDescritor value) {
1094
    public void addCreateTable(TableDescritor value) {
1098
        this.createTableList.add(value);
1095
        this.createTableList.add(value);
1099
        setChanged();
1096
        setChanged();
Line 1103... Line 1100...
1103
        this.createTableList.remove(value);
1100
        this.createTableList.remove(value);
1104
        setChanged();
1101
        setChanged();
1105
    }
1102
    }
1106
 
1103
 
1107
    public List<TableDescritor> getModifyTableList() {
1104
    public List<TableDescritor> getModifyTableList() {
1108
        return modifyTableList;
1105
        return this.modifyTableList;
1109
    }
1106
    }
1110
 
1107
 
1111
    public List<ListDescriptor> getCreateListList() {
1108
    public List<ListDescriptor> getCreateListList() {
1112
        return createListList;
1109
        return this.createListList;
1113
    }
1110
    }
1114
 
1111
 
1115
    public ListDescriptor getCreateListFromId(String id) {
1112
    public ListDescriptor getCreateListFromId(String id) {
1116
        for (ListDescriptor listDescriptor : this.createListList) {
1113
        for (ListDescriptor listDescriptor : this.createListList) {
1117
            if (listDescriptor.getId().equals(id)) {
1114
            if (listDescriptor.getId().equals(id)) {
Line 1152... Line 1149...
1152
        return td;
1149
        return td;
1153
    }
1150
    }
1154
 
1151
 
1155
    public SQLTable getSQLTable(TableDescritor tableDesc) {
1152
    public SQLTable getSQLTable(TableDescritor tableDesc) {
1156
        try {
1153
        try {
1157
            SQLTable t = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable(tableDesc.getName());
1154
            return ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable(tableDesc.getName());
1158
            return t;
-
 
1159
        } catch (Exception e) {
1155
        } catch (Exception e) {
1160
            return null;
1156
            return null;
1161
        }
1157
        }
1162
    }
1158
    }
1163
 
1159
 
Line 1205... Line 1201...
1205
        String query = "DELETE FROM " + extensionTable.getSQL() + " WHERE \"IDENTIFIER\" = " + SQLBase.quoteStringStd(this.getName());
1201
        String query = "DELETE FROM " + extensionTable.getSQL() + " WHERE \"IDENTIFIER\" = " + SQLBase.quoteStringStd(this.getName());
1206
        extensionTable.getDBSystemRoot().getDataSource().execute(query);
1202
        extensionTable.getDBSystemRoot().getDataSource().execute(query);
1207
    }
1203
    }
1208
 
1204
 
1209
    public List<String> getAllKnownTableNames() {
1205
    public List<String> getAllKnownTableNames() {
1210
        final List<String> l = new ArrayList<String>();
1206
        final List<String> l = new ArrayList<>();
1211
        final Set<String> s = new HashSet<String>();
1207
        final Set<String> s = new HashSet<>();
1212
        for (SQLTable t : AllTableListModel.getAllDatabaseTables()) {
1208
        for (SQLTable t : AllTableListModel.getAllDatabaseTables()) {
1213
            s.add(t.getName());
1209
            s.add(t.getName());
1214
        }
1210
        }
1215
        for (TableDescritor td : this.getCreateTableList()) {
1211
        for (TableDescritor td : this.getCreateTableList()) {
1216
            s.add(td.getName());
1212
            s.add(td.getName());
Line 1238... Line 1234...
1238
        }
1234
        }
1239
        return null;
1235
        return null;
1240
    }
1236
    }
1241
 
1237
 
1242
    public List<String> getTranslatedFieldOfTable(String tableName) {
1238
    public List<String> getTranslatedFieldOfTable(String tableName) {
1243
        final List<String> l = new ArrayList<String>();
1239
        final List<String> l = new ArrayList<>();
1244
        for (FieldTranslation tr : this.fieldTranslations) {
1240
        for (FieldTranslation tr : this.fieldTranslations) {
1245
            if (tr.getTableName().equals(tableName)) {
1241
            if (tr.getTableName().equals(tableName)) {
1246
                l.add(tr.getFieldName());
1242
                l.add(tr.getFieldName());
1247
            }
1243
            }
1248
        }
1244
        }
Line 1279... Line 1275...
1279
        this.createComponentList.remove(desc);
1275
        this.createComponentList.remove(desc);
1280
        setChanged();
1276
        setChanged();
1281
    }
1277
    }
1282
 
1278
 
1283
    public List<MenuDescriptor> getCreateMenuList() {
1279
    public List<MenuDescriptor> getCreateMenuList() {
1284
        return createMenuList;
1280
        return this.createMenuList;
1285
    }
1281
    }
1286
 
1282
 
1287
    public void addCreateMenu(MenuDescriptor desc) {
1283
    public void addCreateMenu(MenuDescriptor desc) {
1288
        this.createMenuList.add(desc);
1284
        this.createMenuList.add(desc);
1289
    }
1285
    }
Line 1296... Line 1292...
1296
        }
1292
        }
1297
        return null;
1293
        return null;
1298
    }
1294
    }
1299
 
1295
 
1300
    public List<MenuDescriptor> getRemoveMenuList() {
1296
    public List<MenuDescriptor> getRemoveMenuList() {
1301
        return removeMenuList;
1297
        return this.removeMenuList;
1302
    }
1298
    }
1303
 
1299
 
1304
    public void addRemoveMenu(MenuDescriptor desc) {
1300
    public void addRemoveMenu(MenuDescriptor desc) {
1305
        this.removeRemoveMenuForId(desc.getId());
1301
        this.removeRemoveMenuForId(desc.getId());
1306
        this.removeMenuList.add(desc);
1302
        this.removeMenuList.add(desc);
1307
    }
1303
    }
1308
 
1304
 
1309
    public List<String> getAllKnownFieldName(String tableName) {
1305
    public List<String> getAllKnownFieldName(String tableName) {
1310
        final Set<String> l = new HashSet<String>();
1306
        final Set<String> l = new HashSet<>();
1311
        // fields created in the extension
1307
        // fields created in the extension
1312
 
1308
 
1313
        final List<TableDescritor> desc = getCreateTableList();
1309
        final List<TableDescritor> desc = getCreateTableList();
1314
        for (TableDescritor tableDescritor : desc) {
1310
        for (TableDescritor tableDescritor : desc) {
1315
            if (tableDescritor.getName().equals(tableName)) {
1311
            if (tableDescritor.getName().equals(tableName)) {
Line 1330... Line 1326...
1330
                }
1326
                }
1331
 
1327
 
1332
            }
1328
            }
1333
        }
1329
        }
1334
 
1330
 
1335
        return new ArrayList<String>(l);
1331
        return new ArrayList<>(l);
1336
    }
1332
    }
1337
 
1333
 
1338
    public List<String> getAllKnownActionNames() {
1334
    public List<String> getAllKnownActionNames() {
1339
        ArrayList<String> s = new ArrayList<String>();
1335
        final Set<String> s = new HashSet<>();
1340
        Collection<SQLElement> elements = ComptaPropsConfiguration.getInstanceCompta().getDirectory().getElements();
1336
        Collection<SQLElement> elements = ComptaPropsConfiguration.getInstanceCompta().getDirectory().getElements();
1341
        for (SQLElement element : elements) {
1337
        for (SQLElement element : elements) {
1342
            Collection<IListeAction> actions = element.getRowActions();
1338
            Collection<IListeAction> actions = element.getRowActions();
1343
            for (IListeAction action : actions) {
1339
            for (IListeAction action : actions) {
1344
                if (action instanceof RowAction) {
1340
                if (action instanceof RowAction) {
Line 1347... Line 1343...
1347
                    if (id != null)
1343
                    if (id != null)
1348
                        s.add(id);
1344
                        s.add(id);
1349
                }
1345
                }
1350
            }
1346
            }
1351
        }
1347
        }
-
 
1348
        final List<String> list = new ArrayList<>(s);
1352
        Collections.sort(s);
1349
        Collections.sort(list);
1353
        return s;
1350
        return list;
1354
    }
1351
    }
1355
 
1352
 
1356
    public List<String> getActionNames() {
1353
    public List<String> getActionNames() {
1357
        ArrayList<String> s = new ArrayList<String>();
1354
        ArrayList<String> s = new ArrayList<>();
1358
        for (ActionDescriptor action : this.createActionList) {
1355
        for (ActionDescriptor action : this.createActionList) {
1359
            s.add(action.getId());
1356
            s.add(action.getId());
1360
        }
1357
        }
1361
        Collections.sort(s);
1358
        Collections.sort(s);
1362
        return s;
1359
        return s;
Line 1371... Line 1368...
1371
            }
1368
            }
1372
        });
1369
        });
1373
        return this.createActionList;
1370
        return this.createActionList;
1374
    }
1371
    }
1375
 
1372
 
-
 
1373
    public void addCreateAction(ActionDescriptor obj) {
-
 
1374
        this.createActionList.add(obj);
-
 
1375
        setChanged();
-
 
1376
    }
-
 
1377
 
-
 
1378
    public void removeCreateAction(ActionDescriptor obj) {
-
 
1379
        this.createActionList.remove(obj);
-
 
1380
        setChanged();
-
 
1381
    }
-
 
1382
 
1376
    public boolean isEmpty() {
1383
    public boolean isEmpty() {
1377
        return createTableList.isEmpty() && modifyTableList.isEmpty() && createListList.isEmpty() && tableTranslations.isEmpty() && fieldTranslations.isEmpty() && menuTranslations.isEmpty()
1384
        return this.createTableList.isEmpty() && this.modifyTableList.isEmpty() && this.createListList.isEmpty() && this.tableTranslations.isEmpty() && this.fieldTranslations.isEmpty()
1378
                && actionTranslations.isEmpty() && createComponentList.isEmpty() && modifyComponentList.isEmpty() && createMenuList.isEmpty() && removeMenuList.isEmpty() && createActionList.isEmpty();
1385
                && this.menuTranslations.isEmpty() && this.actionTranslations.isEmpty() && this.createComponentList.isEmpty() && this.modifyComponentList.isEmpty() && this.createMenuList.isEmpty()
-
 
1386
                && this.removeMenuList.isEmpty() && this.createActionList.isEmpty();
1379
    }
1387
    }
1380
 
1388
 
1381
    public String getTableNameForElementId(String id) {
1389
    public String getTableNameForElementId(String id) {
1382
        for (ElementDescriptor element : this.elementList) {
1390
        for (ElementDescriptor element : this.elementList) {
1383
            if (element.getId().equals(id)) {
1391
            if (element.getId().equals(id)) {
Line 1395... Line 1403...
1395
        }
1403
        }
1396
        return null;
1404
        return null;
1397
    }
1405
    }
1398
 
1406
 
1399
    public List<MenuTranslation> getMenuTranslations() {
1407
    public List<MenuTranslation> getMenuTranslations() {
1400
        return menuTranslations;
1408
        return this.menuTranslations;
-
 
1409
    }
-
 
1410
 
-
 
1411
    public MenuTranslation getMenuTranslation(String menuId, String locale) {
-
 
1412
        for (MenuTranslation tr : this.menuTranslations) {
-
 
1413
            if (tr.getId().equals(menuId) && tr.getLocale().equals(locale)) {
-
 
1414
                return tr;
-
 
1415
            }
-
 
1416
        }
-
 
1417
        return null;
1401
    }
1418
    }
1402
 
1419
 
1403
    public List<ActionTranslation> getActionTranslations() {
1420
    public List<ActionTranslation> getActionTranslations() {
1404
        return actionTranslations;
1421
        return this.actionTranslations;
1405
    }
1422
    }
1406
 
1423
 
1407
    public List<FieldTranslation> getFieldTranslations() {
1424
    public List<FieldTranslation> getFieldTranslations() {
1408
        return fieldTranslations;
1425
        return this.fieldTranslations;
1409
    }
1426
    }
1410
 
1427
 
1411
    public void removeChangeListener(ChangeListener listener) {
1428
    public void removeChangeListener(ChangeListener listener) {
1412
        this.listeners.remove(listener);
1429
        this.listeners.remove(listener);
1413
 
1430
 
Line 1427... Line 1444...
1427
        initMenuGroup(group);
1444
        initMenuGroup(group);
1428
        registerMenuActions(ctxt.getMenuAndActions());
1445
        registerMenuActions(ctxt.getMenuAndActions());
1429
    }
1446
    }
1430
 
1447
 
1431
    public void removeRemoveMenuForId(String id) {
1448
    public void removeRemoveMenuForId(String id) {
1432
        for (int i = removeMenuList.size() - 1; i >= 0; i--) {
1449
        for (int i = this.removeMenuList.size() - 1; i >= 0; i--) {
1433
            final MenuDescriptor m = removeMenuList.get(i);
1450
            final MenuDescriptor m = this.removeMenuList.get(i);
1434
            if (m.getId().equals(id)) {
1451
            if (m.getId().equals(id)) {
1435
                removeMenuList.remove(i);
1452
                this.removeMenuList.remove(i);
1436
            }
1453
            }
1437
        }
1454
        }
1438
 
1455
 
1439
    }
1456
    }
1440
 
1457
 
1441
    public void removeCreateMenuForId(String id) {
1458
    public void removeCreateMenuForId(String id) {
1442
        for (int i = createMenuList.size() - 1; i >= 0; i--) {
1459
        for (int i = this.createMenuList.size() - 1; i >= 0; i--) {
1443
            final MenuDescriptor m = createMenuList.get(i);
1460
            final MenuDescriptor m = this.createMenuList.get(i);
1444
            if (m.getId().equals(id)) {
1461
            if (m.getId().equals(id)) {
1445
                createMenuList.remove(i);
1462
                this.createMenuList.remove(i);
1446
            }
1463
            }
1447
        }
1464
        }
1448
 
1465
 
1449
    }
1466
    }
1450
 
1467
 
1451
    public MenuDescriptor getRemoveMenuItemFromId(String itemId) {
1468
    public MenuDescriptor getRemoveMenuItemFromId(String itemId) {
1452
        for (MenuDescriptor m : removeMenuList) {
1469
        for (MenuDescriptor m : this.removeMenuList) {
1453
            if (m.getId().equals(itemId)) {
1470
            if (m.getId().equals(itemId)) {
1454
                return m;
1471
                return m;
1455
            }
1472
            }
1456
        }
1473
        }
1457
        return null;
1474
        return null;
1458
    }
1475
    }
1459
 
1476
 
1460
    public void renameMenuItem(String previousId, String newId) {
1477
    public void renameMenuItem(String previousId, String newId) {
1461
        if (!previousId.equals(newId)) {
1478
        if (!previousId.equals(newId)) {
1462
            final List<MenuDescriptor> descs = new ArrayList<MenuDescriptor>(createMenuList.size() + removeMenuList.size());
1479
            final List<MenuDescriptor> descs = new ArrayList<>(this.createMenuList.size() + this.removeMenuList.size());
1463
            descs.addAll(createMenuList);
1480
            descs.addAll(this.createMenuList);
1464
            descs.addAll(removeMenuList);
1481
            descs.addAll(this.removeMenuList);
1465
            for (MenuDescriptor m : descs) {
1482
            for (MenuDescriptor m : descs) {
1466
                if (m.getId().equals(previousId)) {
1483
                if (m.getId().equals(previousId)) {
1467
                    m.setId(newId);
1484
                    m.setId(newId);
1468
                }
1485
                }
1469
            }
1486
            }
Line 1471... Line 1488...
1471
        }
1488
        }
1472
 
1489
 
1473
    }
1490
    }
1474
 
1491
 
1475
    public void moveMenuItem(String itemId, String parentId) {
1492
    public void moveMenuItem(String itemId, String parentId) {
1476
        for (MenuDescriptor m : createMenuList) {
1493
        for (MenuDescriptor m : this.createMenuList) {
1477
            if (m.getId().equals(itemId)) {
1494
            if (m.getId().equals(itemId)) {
1478
                m.setInsertInMenu(parentId);
1495
                m.setInsertInMenu(parentId);
1479
            }
1496
            }
1480
        }
1497
        }
1481
 
1498
 
Line 1538... Line 1555...
1538
            this.fieldTranslations.add(fTranslation);
1555
            this.fieldTranslations.add(fTranslation);
1539
        }
1556
        }
1540
        fTranslation.setLabel(text);
1557
        fTranslation.setLabel(text);
1541
 
1558
 
1542
    }
1559
    }
-
 
1560
 
1543
}
1561
}