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 34... Line 34...
34
        super(extension);
34
        super(extension);
35
        fillModel();
35
        fillModel();
36
    }
36
    }
37
 
37
 
38
    public void fillModel() {
38
    public void fillModel() {
39
        newModel.fillFromDescriptor(extension);
39
        this.newModel.fillFromDescriptor(this.extension);
40
        tree.setModel(newModel);
40
        this.tree.setModel(this.newModel);
41
        tree.expandRow(0);
41
        this.tree.expandRow(0);
42
    }
42
    }
43
 
43
 
44
    @Override
44
    @Override
45
    public JComponent createLeftComponent() {
45
    public JComponent createLeftComponent() {
46
        final JPanel panel = new JPanel();
46
        final JPanel panel = new JPanel();
Line 52... Line 52...
52
        c.weightx = 1;
52
        c.weightx = 1;
53
        c.weighty = 0;
53
        c.weighty = 0;
54
        c.insets = new Insets(2, 2, 2, 0);
54
        c.insets = new Insets(2, 2, 2, 0);
55
 
55
 
56
        panel.add(new JLabel("Menus"), c);
56
        panel.add(new JLabel("Menus"), c);
57
        newModel = new MenuItemTreeModel();
57
        this.newModel = new MenuItemTreeModel();
58
        tree = new JTree() {
58
        this.tree = new JTree() {
59
            @Override
59
            @Override
60
            public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
60
            public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
61
                final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
61
                final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
62
                if (userObject == null) {
62
                if (userObject == null) {
63
                    return "null";
63
                    return "null";
Line 67... Line 67...
67
                    return " " + d.getId();
67
                    return " " + d.getId();
68
                }
68
                }
69
                return userObject.toString();
69
                return userObject.toString();
70
            }
70
            }
71
        };
71
        };
72
        tree.setModel(newModel);
72
        this.tree.setModel(this.newModel);
73
        tree.setRootVisible(false);
73
        this.tree.setRootVisible(false);
74
        tree.setShowsRootHandles(true);
74
        this.tree.setShowsRootHandles(true);
75
        tree.expandRow(0);
75
        this.tree.expandRow(0);
76
        final DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer() {
76
        final DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer() {
77
            @Override
77
            @Override
78
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
78
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
79
 
79
 
80
                final JLabel r = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
80
                final JLabel r = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
Line 83... Line 83...
83
                    r.setForeground(Color.LIGHT_GRAY);
83
                    r.setForeground(Color.LIGHT_GRAY);
84
                }
84
                }
85
                if (tr.getUserObject() instanceof Item) {
85
                if (tr.getUserObject() instanceof Item) {
86
                    r.setText(((Item) tr.getUserObject()).getId());
86
                    r.setText(((Item) tr.getUserObject()).getId());
87
                }
87
                }
-
 
88
                if (sel) {
-
 
89
                    r.setForeground(Color.WHITE);
-
 
90
                }
88
                return r;
91
                return r;
89
            }
92
            }
90
        };
93
        };
91
 
94
 
92
        treeRenderer.setLeafIcon(null);
95
        treeRenderer.setLeafIcon(null);
93
        tree.setCellRenderer(treeRenderer);
96
        this.tree.setCellRenderer(treeRenderer);
94
        final JScrollPane comp2 = new JScrollPane(tree);
97
        final JScrollPane comp2 = new JScrollPane(this.tree);
95
        comp2.setMinimumSize(new Dimension(250, 150));
98
        comp2.setMinimumSize(new Dimension(250, 150));
96
        comp2.setPreferredSize(new Dimension(250, 150));
99
        comp2.setPreferredSize(new Dimension(250, 150));
97
        c.weighty = 1;
100
        c.weighty = 1;
98
        c.gridy++;
101
        c.gridy++;
99
        c.insets = new Insets(0, 0, 0, 0);
102
        c.insets = new Insets(0, 0, 0, 0);
100
        panel.add(comp2, c);
103
        panel.add(comp2, c);
101
 
104
 
102
        // init
105
        // init
103
 
106
 
104
        tree.addMouseListener(new MouseAdapter() {
107
        this.tree.addMouseListener(new MouseAdapter() {
105
 
108
 
106
            @Override
109
            @Override
107
            public void mousePressed(MouseEvent e) {
110
            public void mousePressed(MouseEvent e) {
108
                final TreePath selectionPath = tree.getSelectionPath();
111
                final TreePath selectionPath = MenuTranslationPanel.this.tree.getSelectionPath();
109
                if (selectionPath == null) {
112
                if (selectionPath == null) {
110
                    setRightPanel(new JPanel());
113
                    setRightPanel(new JPanel());
111
                } else {
114
                } else {
112
                    Item i = (Item) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
115
                    Item i = (Item) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject();
113
                    setRightPanel(new MenuTranslationItemEditor(i, extension));
116
                    setRightPanel(new MenuTranslationItemEditor(i, MenuTranslationPanel.this.extension));
114
                }
117
                }
115
            }
118
            }
116
        });
119
        });
117
        return panel;
120
        return panel;
118
    }
121
    }