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 47... Line 47...
47
        super(extension);
47
        super(extension);
48
        fillModel();
48
        fillModel();
49
    }
49
    }
50
 
50
 
51
    public void fillModel() {
51
    public void fillModel() {
52
        newModel.fillFromDescriptor(extension);
52
        this.newModel.fillFromDescriptor(this.extension);
53
        tree.setModel(newModel);
53
        this.tree.setModel(this.newModel);
54
        expand();
54
        expand();
55
 
55
 
56
    }
56
    }
57
 
57
 
58
    private void expand() {
58
    private void expand() {
59
        tree.expandRow(0);
59
        this.tree.expandRow(0);
60
 
60
 
61
        final List<MenuDescriptor> m = new ArrayList<MenuDescriptor>();
61
        final List<MenuDescriptor> m = new ArrayList<MenuDescriptor>();
62
        m.addAll(extension.getCreateMenuList());
62
        m.addAll(this.extension.getCreateMenuList());
63
        m.addAll(extension.getRemoveMenuList());
63
        m.addAll(this.extension.getRemoveMenuList());
64
        for (MenuDescriptor menuDescriptor : m) {
64
        for (MenuDescriptor menuDescriptor : m) {
65
            final DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
65
            final DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.tree.getModel().getRoot();
66
            @SuppressWarnings("unchecked")
66
            @SuppressWarnings("unchecked")
67
            final Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration();
67
            final Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration();
68
            while (e.hasMoreElements()) {
68
            while (e.hasMoreElements()) {
69
                final DefaultMutableTreeNode node = e.nextElement();
69
                final DefaultMutableTreeNode node = e.nextElement();
70
                final Object userObject = node.getUserObject();
70
                final Object userObject = node.getUserObject();
71
                if (userObject != null) {
71
                if (userObject != null) {
72
                    final String nodeLabel = ((Item) userObject).getId();
72
                    final String nodeLabel = ((Item) userObject).getId();
73
                    if (nodeLabel != null && nodeLabel.equals(menuDescriptor.getId())) {
73
                    if (nodeLabel != null && nodeLabel.equals(menuDescriptor.getId())) {
74
                        final TreePath path = new TreePath(((DefaultMutableTreeNode) node.getParent()).getPath());
74
                        final TreePath path = new TreePath(((DefaultMutableTreeNode) node.getParent()).getPath());
75
                        tree.expandPath(path);
75
                        this.tree.expandPath(path);
76
                    }
76
                    }
77
                }
77
                }
78
            }
78
            }
79
        }
79
        }
80
    }
80
    }
Line 90... Line 90...
90
        c.weightx = 1;
90
        c.weightx = 1;
91
        c.weighty = 0;
91
        c.weighty = 0;
92
        c.insets = new Insets(2, 2, 2, 0);
92
        c.insets = new Insets(2, 2, 2, 0);
93
 
93
 
94
        panel.add(new JLabel("Menus"), c);
94
        panel.add(new JLabel("Menus"), c);
95
        newModel = new MenuItemTreeModel();
95
        this.newModel = new MenuItemTreeModel();
96
        tree = new ReorderableJTree();
96
        this.tree = new ReorderableJTree();
97
        tree.setModel(newModel);
97
        this.tree.setModel(this.newModel);
98
        tree.setRootVisible(false);
98
        this.tree.setRootVisible(false);
99
        tree.setShowsRootHandles(true);
99
        this.tree.setShowsRootHandles(true);
100
 
100
 
101
        final DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer() {
101
        final DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer() {
102
            @Override
102
            @Override
103
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
103
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
104
                final ActivableMutableTreeNode tr = (ActivableMutableTreeNode) value;
104
                final ActivableMutableTreeNode tr = (ActivableMutableTreeNode) value;
Line 107... Line 107...
107
                    value = id;
107
                    value = id;
108
                }
108
                }
109
                final JLabel r = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
109
                final JLabel r = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
110
                if (tr.getUserObject() instanceof Item) {
110
                if (tr.getUserObject() instanceof Item) {
111
                    final String id = ((Item) tr.getUserObject()).getId();
111
                    final String id = ((Item) tr.getUserObject()).getId();
112
                    if (extension.getCreateMenuItemFromId(id) != null) {
112
                    if (MainMenuGroupEditor.this.extension.getCreateMenuItemFromId(id) != null) {
113
                        r.setForeground(new Color(50, 80, 150));
113
                        r.setForeground(new Color(50, 80, 150));
114
                    }
114
                    }
115
                }
115
                }
116
                if (!tr.isActive()) {
116
                if (!tr.isActive()) {
117
                    r.setForeground(Color.LIGHT_GRAY);
117
                    r.setForeground(Color.LIGHT_GRAY);
118
                }
118
                }
-
 
119
                if (sel) {
-
 
120
                    r.setForeground(Color.WHITE);
-
 
121
                }
119
                return r;
122
                return r;
120
            }
123
            }
121
        };
124
        };
122
 
125
 
123
        treeRenderer.setLeafIcon(null);
126
        treeRenderer.setLeafIcon(null);
124
        tree.setCellRenderer(treeRenderer);
127
        this.tree.setCellRenderer(treeRenderer);
125
        final JScrollPane comp2 = new JScrollPane(tree);
128
        final JScrollPane comp2 = new JScrollPane(this.tree);
126
        comp2.setMinimumSize(new Dimension(250, 150));
129
        comp2.setMinimumSize(new Dimension(250, 150));
127
        comp2.setPreferredSize(new Dimension(250, 150));
130
        comp2.setPreferredSize(new Dimension(250, 150));
128
        c.weighty = 1;
131
        c.weighty = 1;
129
        c.gridy++;
132
        c.gridy++;
130
        c.insets = new Insets(0, 0, 0, 0);
133
        c.insets = new Insets(0, 0, 0, 0);
Line 168... Line 171...
168
 
171
 
169
        });
172
        });
170
        removeButton.addActionListener(new ActionListener() {
173
        removeButton.addActionListener(new ActionListener() {
171
            @Override
174
            @Override
172
            public void actionPerformed(ActionEvent e) {
175
            public void actionPerformed(ActionEvent e) {
173
                final TreePath selectionPath = tree.getSelectionPath();
176
                final TreePath selectionPath = MainMenuGroupEditor.this.tree.getSelectionPath();
174
                if (selectionPath != null) {
177
                if (selectionPath != null) {
175
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
178
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
176
                    if (node.getUserObject() != null) {
179
                    if (node.getUserObject() != null) {
177
                        String idToDelete = ((Item) node.getUserObject()).getId();
180
                        String idToDelete = ((Item) node.getUserObject()).getId();
178
                        extension.removeCreateMenuForId(idToDelete);
181
                        MainMenuGroupEditor.this.extension.removeCreateMenuForId(idToDelete);
179
                        extension.setChanged();
182
                        MainMenuGroupEditor.this.extension.setChanged();
180
                        fillModel();
183
                        fillModel();
181
                    }
184
                    }
182
 
185
 
183
                }
186
                }
184
            }
187
            }
185
        });
188
        });
186
        hideCheckbox.addActionListener(new ActionListener() {
189
        hideCheckbox.addActionListener(new ActionListener() {
187
 
190
 
188
            @Override
191
            @Override
189
            public void actionPerformed(ActionEvent e) {
192
            public void actionPerformed(ActionEvent e) {
190
                newModel.setShowAll(hideCheckbox.isSelected());
193
                MainMenuGroupEditor.this.newModel.setShowAll(hideCheckbox.isSelected());
191
                newModel.fillFromDescriptor(extension);
194
                MainMenuGroupEditor.this.newModel.fillFromDescriptor(MainMenuGroupEditor.this.extension);
192
            }
195
            }
193
 
196
 
194
        });
197
        });
195
        tree.addTreeSelectionListener(new TreeSelectionListener() {
198
        this.tree.addTreeSelectionListener(new TreeSelectionListener() {
196
 
199
 
197
            @Override
200
            @Override
198
            public void valueChanged(TreeSelectionEvent e) {
201
            public void valueChanged(TreeSelectionEvent e) {
199
                final TreePath selectionPath = tree.getSelectionPath();
202
                final TreePath selectionPath = MainMenuGroupEditor.this.tree.getSelectionPath();
200
                if (selectionPath != null) {
203
                if (selectionPath != null) {
201
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
204
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
202
                    if (node.getUserObject() != null) {
205
                    if (node.getUserObject() != null) {
203
                        String selectedId = ((Item) node.getUserObject()).getId();
206
                        String selectedId = ((Item) node.getUserObject()).getId();
204
                        removeButton.setEnabled(extension.getCreateMenuItemFromId(selectedId) != null);
207
                        removeButton.setEnabled(MainMenuGroupEditor.this.extension.getCreateMenuItemFromId(selectedId) != null);
205
                    }
208
                    }
206
                } else {
209
                } else {
207
                    removeButton.setEnabled(false);
210
                    removeButton.setEnabled(false);
208
                }
211
                }
209
 
212
 
210
            }
213
            }
211
        });
214
        });
212
        tree.addMouseListener(new MouseAdapter() {
215
        this.tree.addMouseListener(new MouseAdapter() {
213
            @Override
216
            @Override
214
            public void mouseClicked(MouseEvent e) {
217
            public void mouseClicked(MouseEvent e) {
215
                if (e.getClickCount() > 1) {
218
                if (e.getClickCount() > 1) {
216
                    newModel.toggleActive(tree.getSelectionPath());
219
                    MainMenuGroupEditor.this.newModel.toggleActive(MainMenuGroupEditor.this.tree.getSelectionPath());
217
                }
220
                }
218
            }
221
            }
219
 
222
 
220
            @Override
223
            @Override
221
            public void mousePressed(MouseEvent e) {
224
            public void mousePressed(MouseEvent e) {
222
                final TreePath selectionPath = tree.getSelectionPath();
225
                final TreePath selectionPath = MainMenuGroupEditor.this.tree.getSelectionPath();
223
                if (selectionPath == null) {
226
                if (selectionPath == null) {
224
                    setRightPanel(new JPanel());
227
                    setRightPanel(new JPanel());
225
                } else {
228
                } else {
226
                    Item i = (Item) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
229
                    Item i = (Item) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
227
                    setRightPanel(new MenuItemEditor(newModel, i, extension));
230
                    setRightPanel(new MenuItemEditor(MainMenuGroupEditor.this.newModel, i, MainMenuGroupEditor.this.extension));
228
                }
231
                }
229
            }
232
            }
230
        });
233
        });
231
        tree.getModel().addTreeModelListener(new TreeModelListener() {
234
        this.tree.getModel().addTreeModelListener(new TreeModelListener() {
232
 
235
 
233
            @Override
236
            @Override
234
            public void treeStructureChanged(TreeModelEvent e) {
237
            public void treeStructureChanged(TreeModelEvent e) {
235
                // Postpone expand because default behaviour is collapsing tree
238
                // Postpone expand because default behaviour is collapsing tree
236
                SwingUtilities.invokeLater(new Runnable() {
239
                SwingUtilities.invokeLater(new Runnable() {
Line 255... Line 258...
255
        });
258
        });
256
        return panel;
259
        return panel;
257
    }
260
    }
258
 
261
 
259
    protected void addNewGroup() {
262
    protected void addNewGroup() {
260
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (tree.getModel().getRoot())).getFirstChild();
263
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (this.tree.getModel().getRoot())).getFirstChild();
261
        DefaultMutableTreeNode node = root;
264
        DefaultMutableTreeNode node = root;
262
        if (node.getChildCount() > 0) {
265
        if (node.getChildCount() > 0) {
263
            node = (DefaultMutableTreeNode) node.getFirstChild();
266
            node = (DefaultMutableTreeNode) node.getFirstChild();
264
        }
267
        }
265
        if (tree.getSelectionPath() != null) {
268
        if (this.tree.getSelectionPath() != null) {
266
            node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
269
            node = (DefaultMutableTreeNode) this.tree.getLastSelectedPathComponent();
267
        }
270
        }
268
        if (node != root) {
271
        if (node != root) {
269
            final String newGroupId = "group" + node.getParent().getChildCount() + 1;
272
            final String newGroupId = "group" + node.getParent().getChildCount() + 1;
270
            DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Group(newGroupId));
273
            DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Group(newGroupId));
271
            final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
274
            final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
272
            parent.insert(newNode, parent.getIndex(node));
275
            parent.insert(newNode, parent.getIndex(node));
273
 
276
 
274
            final MenuDescriptor desc = new MenuDescriptor(newGroupId);
277
            final MenuDescriptor desc = new MenuDescriptor(newGroupId);
275
            desc.setType(MenuDescriptor.GROUP);
278
            desc.setType(MenuDescriptor.GROUP);
276
            desc.setInsertInMenu(((Item) parent.getUserObject()).getId());
279
            desc.setInsertInMenu(((Item) parent.getUserObject()).getId());
277
            extension.addCreateMenu(desc);
280
            this.extension.addCreateMenu(desc);
278
            extension.setChanged();
281
            this.extension.setChanged();
279
 
282
 
280
            newModel.reload();
283
            this.newModel.reload();
281
            tree.setSelectionPath(new TreePath(newModel.getPathToRoot(newNode)));
284
            this.tree.setSelectionPath(new TreePath(this.newModel.getPathToRoot(newNode)));
282
        }
285
        }
283
        extension.setChanged();
286
        this.extension.setChanged();
284
    }
287
    }
285
 
288
 
286
    protected void addNewItem() {
289
    protected void addNewItem() {
287
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (tree.getModel().getRoot())).getFirstChild();
290
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (this.tree.getModel().getRoot())).getFirstChild();
288
        DefaultMutableTreeNode node = root;
291
        DefaultMutableTreeNode node = root;
289
        if (node.getChildCount() > 0) {
292
        if (node.getChildCount() > 0) {
290
            node = (DefaultMutableTreeNode) node.getFirstChild();
293
            node = (DefaultMutableTreeNode) node.getFirstChild();
291
        }
294
        }
292
        if (tree.getSelectionPath() != null) {
295
        if (this.tree.getSelectionPath() != null) {
293
            node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
296
            node = (DefaultMutableTreeNode) this.tree.getLastSelectedPathComponent();
294
        }
297
        }
295
        if (node != root) {
298
        if (node != root) {
296
            final String newActionId = "action" + node.getParent().getChildCount() + 1;
299
            final String newActionId = "action" + node.getParent().getChildCount() + 1;
297
            DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Item(newActionId));
300
            DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Item(newActionId));
298
            final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
301
            final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
299
            parent.insert(newNode, parent.getIndex(node));
302
            parent.insert(newNode, parent.getIndex(node));
300
            final MenuDescriptor desc = new MenuDescriptor(newActionId);
303
            final MenuDescriptor desc = new MenuDescriptor(newActionId);
301
            desc.setType(MenuDescriptor.CREATE);
304
            desc.setType(MenuDescriptor.CREATE);
302
            desc.setInsertInMenu(((Item) parent.getUserObject()).getId());
305
            desc.setInsertInMenu(((Item) parent.getUserObject()).getId());
303
            extension.addCreateMenu(desc);
306
            this.extension.addCreateMenu(desc);
304
            extension.setChanged();
307
            this.extension.setChanged();
305
            newModel.reload();
308
            this.newModel.reload();
306
            tree.setSelectionPath(new TreePath(newModel.getPathToRoot(newNode)));
309
            this.tree.setSelectionPath(new TreePath(this.newModel.getPathToRoot(newNode)));
307
        }
310
        }
308
 
311
 
309
    }
312
    }
310
 
313
 
311
    // public Group getFilteredGroup() {
314
    // public Group getFilteredGroup() {