OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 74 Rev 181
Line 59... Line 59...
59
        c.weightx = 1;
59
        c.weightx = 1;
60
        c.weighty = 0;
60
        c.weighty = 0;
61
        c.insets = new Insets(2, 2, 2, 0);
61
        c.insets = new Insets(2, 2, 2, 0);
62
 
62
 
63
        panel.add(new JLabelBold("Champs et groupes"), c);
63
        panel.add(new JLabelBold("Champs et groupes"), c);
64
        newModel = new ItemTreeModel();
64
        this.newModel = new ItemTreeModel();
65
        tree = new ReorderableJTree() {
65
        this.tree = new ReorderableJTree() {
66
            @Override
66
            @Override
67
            public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
67
            public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
68
                final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
68
                final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
69
                if (userObject == null) {
69
                if (userObject == null) {
70
                    return "null";
70
                    return "null";
Line 74... Line 74...
74
                    return " " + d.getId();
74
                    return " " + d.getId();
75
                }
75
                }
76
                return userObject.toString();
76
                return userObject.toString();
77
            }
77
            }
78
        };
78
        };
79
        tree.setModel(newModel);
79
        this.tree.setModel(this.newModel);
80
        tree.setRootVisible(false);
80
        this.tree.setRootVisible(false);
81
        tree.setShowsRootHandles(true);
81
        this.tree.setShowsRootHandles(true);
82
        tree.expandRow(0);
82
        this.tree.expandRow(0);
83
        final DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer() {
83
        final DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer() {
84
            @Override
84
            @Override
85
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
85
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
86
 
86
 
87
                final JLabel r = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
87
                final JLabel r = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
Line 95... Line 95...
95
                return r;
95
                return r;
96
            }
96
            }
97
        };
97
        };
98
 
98
 
99
        treeRenderer.setLeafIcon(null);
99
        treeRenderer.setLeafIcon(null);
100
        tree.setCellRenderer(treeRenderer);
100
        this.tree.setCellRenderer(treeRenderer);
101
        final JScrollPane comp2 = new JScrollPane(tree);
101
        final JScrollPane comp2 = new JScrollPane(this.tree);
102
        comp2.setMinimumSize(new Dimension(250, 150));
102
        comp2.setMinimumSize(new Dimension(250, 150));
103
        comp2.setPreferredSize(new Dimension(250, 150));
103
        comp2.setPreferredSize(new Dimension(250, 150));
104
        c.weighty = 1;
104
        c.weighty = 1;
105
        c.gridy++;
105
        c.gridy++;
106
        c.insets = new Insets(0, 0, 0, 0);
106
        c.insets = new Insets(0, 0, 0, 0);
Line 137... Line 137...
137
        });
137
        });
138
 
138
 
139
        showHideButton.addActionListener(new ActionListener() {
139
        showHideButton.addActionListener(new ActionListener() {
140
            @Override
140
            @Override
141
            public void actionPerformed(ActionEvent e) {
141
            public void actionPerformed(ActionEvent e) {
142
                newModel.toggleActive(tree.getSelectionPath());
142
                GroupEditor.this.newModel.toggleActive(GroupEditor.this.tree.getSelectionPath());
143
            }
143
            }
144
        });
144
        });
145
 
145
 
146
        hideCheckbox.addActionListener(new ActionListener() {
146
        hideCheckbox.addActionListener(new ActionListener() {
147
 
147
 
148
            @Override
148
            @Override
149
            public void actionPerformed(ActionEvent e) {
149
            public void actionPerformed(ActionEvent e) {
150
                newModel.setShowAll(hideCheckbox.isSelected());
150
                GroupEditor.this.newModel.setShowAll(hideCheckbox.isSelected());
151
                setMainTable(n.getTable());
151
                setMainTable(GroupEditor.this.n.getTable());
152
                setRightPanel(new JPanel());
152
                setRightPanel(new JPanel());
153
            }
153
            }
154
        });
154
        });
155
 
155
 
156
        tree.addTreeSelectionListener(new TreeSelectionListener() {
156
        this.tree.addTreeSelectionListener(new TreeSelectionListener() {
157
 
157
 
158
            @Override
158
            @Override
159
            public void valueChanged(TreeSelectionEvent e) {
159
            public void valueChanged(TreeSelectionEvent e) {
160
                final Object selectedValue = tree.getSelectionPath();
160
                final Object selectedValue = GroupEditor.this.tree.getSelectionPath();
161
                showHideButton.setEnabled((selectedValue != null));
161
                showHideButton.setEnabled((selectedValue != null));
162
            }
162
            }
163
        });
163
        });
164
        tree.addMouseListener(new MouseAdapter() {
164
        this.tree.addMouseListener(new MouseAdapter() {
165
            @Override
165
            @Override
166
            public void mouseClicked(MouseEvent e) {
166
            public void mouseClicked(MouseEvent e) {
167
                if (e.getClickCount() > 1) {
167
                if (e.getClickCount() > 1) {
168
                    newModel.toggleActive(tree.getSelectionPath());
168
                    GroupEditor.this.newModel.toggleActive(GroupEditor.this.tree.getSelectionPath());
169
                }
169
                }
170
            }
170
            }
171
 
171
 
172
            @Override
172
            @Override
173
            public void mousePressed(MouseEvent e) {
173
            public void mousePressed(MouseEvent e) {
174
                final TreePath selectionPath = tree.getSelectionPath();
174
                final TreePath selectionPath = GroupEditor.this.tree.getSelectionPath();
175
                if (selectionPath == null) {
175
                if (selectionPath == null) {
176
                    setRightPanel(new JPanel());
176
                    setRightPanel(new JPanel());
177
                } else {
177
                } else {
178
                    Item i = (Item) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
178
                    Item i = (Item) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
179
                    setRightPanel(new ItemEditor(i, n));
179
                    setRightPanel(new ItemEditor(i, GroupEditor.this.n));
180
                }
180
                }
181
            }
181
            }
182
        });
182
        });
183
        return panel;
183
        return panel;
184
    }
184
    }
185
 
185
 
186
    protected void addNewGroup() {
186
    protected void addNewGroup() {
187
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (tree.getModel().getRoot())).getFirstChild();
187
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (this.tree.getModel().getRoot())).getFirstChild();
188
        DefaultMutableTreeNode node = root;
188
        DefaultMutableTreeNode node = root;
189
        if (node.getChildCount() > 0) {
189
        if (node.getChildCount() > 0) {
190
            node = (DefaultMutableTreeNode) node.getFirstChild();
190
            node = (DefaultMutableTreeNode) node.getFirstChild();
191
        }
191
        }
192
        if (tree.getSelectionPath() != null) {
192
        if (this.tree.getSelectionPath() != null) {
193
            node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
193
            node = (DefaultMutableTreeNode) this.tree.getLastSelectedPathComponent();
194
        }
194
        }
195
        if (node != root) {
195
        if (node != root) {
196
            DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Group("group" + node.getParent().getChildCount() + 1));
196
            DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Group("group" + node.getParent().getChildCount() + 1));
197
            final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
197
            final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
198
            parent.insert(newNode, parent.getIndex(node));
198
            parent.insert(newNode, parent.getIndex(node));
199
            newModel.reload();
199
            this.newModel.reload();
200
            tree.setSelectionPath(new TreePath(newModel.getPathToRoot(newNode)));
200
            this.tree.setSelectionPath(new TreePath(this.newModel.getPathToRoot(newNode)));
201
        }
201
        }
202
 
202
 
203
    }
203
    }
204
 
204
 
205
    public void setMainTable(String table) {
205
    public void setMainTable(String table) {
206
        n.setTable(table);
206
        this.n.setTable(table);
207
 
207
 
208
        initGroupFromTable(extension.getAllKnownFieldName(table));
208
        initGroupFromTable(this.extension.getAllKnownFieldName(table));
209
        newModel.fillFromGroup(n, this.tableGroup);
209
        this.newModel.fillFromGroup(this.n, this.tableGroup);
210
 
210
 
211
        tree.expandRow(0);
211
        this.tree.expandRow(0);
212
    }
212
    }
213
 
213
 
214
    public void initGroupFromTable(List<String> fields) {
214
    public void initGroupFromTable(List<String> fields) {
215
        System.out.println("GroupEditor.initGroupFromTable()");
215
        System.out.println("GroupEditor.initGroupFromTable()");
216
        System.out.println("GroupEditor.initGroupFromTable Component group");
216
        System.out.println("GroupEditor.initGroupFromTable Component group");
217
 
217
 
218
        this.tableGroup = new Group(n.getId());
218
        this.tableGroup = new Group(this.n.getId());
219
        for (String field : fields) {
219
        for (String field : fields) {
220
            Item i = n.getItemFromId(field);
220
            Item i = this.n.getItemFromId(field);
221
            Item newItem = new Item(field);
221
            Item newItem = new Item(field);
222
 
222
 
223
            if (i != null) {
223
            if (i != null) {
224
                System.out.println("GroupEditor.initGroupFromTable() searching found: " + i + ":" + i.getLocalHint());
224
                System.out.println("GroupEditor.initGroupFromTable() searching found: " + i + ":" + i.getLocalHint());
225
                newItem.setLocalHint(new LayoutHints(i.getLocalHint()));
225
                newItem.setLocalHint(new LayoutHints(i.getLocalHint()));
Line 230... Line 230...
230
 
230
 
231
    }
231
    }
232
 
232
 
233
    public Group getFilteredGroup() {
233
    public Group getFilteredGroup() {
234
        // Parcours du Tree
234
        // Parcours du Tree
235
        Group filteredGroup = new Group(n.getId());
235
        Group filteredGroup = new Group(this.n.getId());
236
        if (n.getTable() == null) {
236
        if (this.n.getTable() == null) {
237
            throw new IllegalStateException("Not table defined for " + n);
237
            throw new IllegalStateException("Not table defined for " + this.n);
238
        }
238
        }
239
        walk(newModel, filteredGroup, newModel.getRoot());
239
        walk(this.newModel, filteredGroup, this.newModel.getRoot());
240
        filteredGroup = (Group) filteredGroup.getItem(0);
240
        filteredGroup = (Group) filteredGroup.getItem(0);
241
 
241
 
242
        return filteredGroup;
242
        return filteredGroup;
243
    }
243
    }
244
 
244
 
Line 254... Line 254...
254
                    gr.add(item);
254
                    gr.add(item);
255
                    walk(model, item, child);
255
                    walk(model, item, child);
256
                } else {
256
                } else {
257
                    final Item item = new Item(userObject.getId());
257
                    final Item item = new Item(userObject.getId());
258
                    item.setLocalHint(new LayoutHints(userObject.getLocalHint()));
258
                    item.setLocalHint(new LayoutHints(userObject.getLocalHint()));
259
                    final SQLTable table = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable(n.getTable());
259
                    final SQLTable table = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable(this.n.getTable());
260
                    if (table.contains(userObject.getId())) {
260
                    if (table.contains(userObject.getId())) {
261
                        SQLField field = table.getField(userObject.getId());
261
                        SQLField field = table.getField(userObject.getId());
262
                        if (!field.isPrimaryKey() && !field.getName().endsWith("ORDRE") && !field.getName().endsWith("ARCHIVE")) {
262
                        if (!field.isPrimaryKey() && !field.getName().endsWith("ORDRE") && !field.getName().endsWith("ARCHIVE")) {
263
                            gr.add(item);
263
                            gr.add(item);
264
                        }
264
                        }