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 41... Line 41...
41
        c.weighty = 0;
41
        c.weighty = 0;
42
        c.insets = new Insets(2, 2, 2, 0);
42
        c.insets = new Insets(2, 2, 2, 0);
43
        if (title != null) {
43
        if (title != null) {
44
            this.add(new JLabel(title), c);
44
            this.add(new JLabel(title), c);
45
        }
45
        }
46
        list = new JList(dataModel);
46
        this.list = new JList(dataModel);
47
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
47
        this.list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
48
        final JScrollPane comp2 = new JScrollPane(list);
48
        final JScrollPane comp2 = new JScrollPane(this.list);
49
        comp2.setMinimumSize(new Dimension(150, 150));
49
        comp2.setMinimumSize(new Dimension(150, 150));
50
        comp2.setPreferredSize(new Dimension(150, 150));
50
        comp2.setPreferredSize(new Dimension(150, 150));
51
        c.weighty = 1;
51
        c.weighty = 1;
52
        c.gridy++;
52
        c.gridy++;
53
        c.insets = new Insets(0, 0, 0, 0);
53
        c.insets = new Insets(0, 0, 0, 0);
Line 62... Line 62...
62
            c.insets = new Insets(2, 2, 2, 0);
62
            c.insets = new Insets(2, 2, 2, 0);
63
            final JButton addButton = new JButton(addLabel);
63
            final JButton addButton = new JButton(addLabel);
64
            this.add(addButton, c);
64
            this.add(addButton, c);
65
            c.gridy++;
65
            c.gridy++;
66
            if (canRename) {
66
            if (canRename) {
67
                renameButton = new JButton("Renommer");
67
                this.renameButton = new JButton("Renommer");
68
                this.add(renameButton, c);
68
                this.add(this.renameButton, c);
69
                renameButton.setEnabled(false);
69
                this.renameButton.setEnabled(false);
70
                renameButton.addActionListener(new ActionListener() {
70
                this.renameButton.addActionListener(new ActionListener() {
71
 
71
 
72
                    @Override
72
                    @Override
73
                    public void actionPerformed(ActionEvent e) {
73
                    public void actionPerformed(ActionEvent e) {
74
                        if (list.getSelectedValue() != null) {
74
                        if (EditableListPanel.this.list.getSelectedValue() != null) {
75
                            renameItem(list.getSelectedValue());
75
                            renameItem(EditableListPanel.this.list.getSelectedValue());
76
                        }
76
                        }
77
                    }
77
                    }
78
 
78
 
79
                });
79
                });
80
                c.gridy++;
80
                c.gridy++;
81
            }
81
            }
82
 
82
 
83
            removeButton = new JButton("Supprimer");
83
            this.removeButton = new JButton("Supprimer");
84
            removeButton.setEnabled(false);
84
            this.removeButton.setEnabled(false);
85
            this.add(removeButton, c);
85
            this.add(this.removeButton, c);
86
 
86
 
87
            // init
87
            // init
88
 
88
 
89
            addButton.addActionListener(new ActionListener() {
89
            addButton.addActionListener(new ActionListener() {
90
 
90
 
Line 96... Line 96...
96
                    }
96
                    }
97
                }
97
                }
98
 
98
 
99
            });
99
            });
100
 
100
 
101
            removeButton.addActionListener(new ActionListener() {
101
            this.removeButton.addActionListener(new ActionListener() {
102
                @Override
102
                @Override
103
                public void actionPerformed(ActionEvent e) {
103
                public void actionPerformed(ActionEvent e) {
104
                    if (list.getSelectedValue() != null) {
104
                    if (EditableListPanel.this.list.getSelectedValue() != null) {
105
                        removeItem(list.getSelectedValue());
105
                        removeItem(EditableListPanel.this.list.getSelectedValue());
106
                    }
106
                    }
107
                }
107
                }
108
            });
108
            });
109
        }
109
        }
110
        list.addListSelectionListener(new ListSelectionListener() {
110
        this.list.addListSelectionListener(new ListSelectionListener() {
111
 
111
 
112
            @Override
112
            @Override
113
            public void valueChanged(ListSelectionEvent e) {
113
            public void valueChanged(ListSelectionEvent e) {
114
                final Object selectedValue = list.getSelectedValue();
114
                final Object selectedValue = EditableListPanel.this.list.getSelectedValue();
115
                if (removeButton != null) {
115
                if (EditableListPanel.this.removeButton != null) {
116
                    removeButton.setEnabled(selectedValue != null);
116
                    EditableListPanel.this.removeButton.setEnabled(selectedValue != null);
117
                }
117
                }
118
                if (renameButton != null) {
118
                if (EditableListPanel.this.renameButton != null) {
119
                    renameButton.setEnabled(selectedValue != null);
119
                    EditableListPanel.this.renameButton.setEnabled(selectedValue != null);
120
                }
120
                }
121
                if (!e.getValueIsAdjusting() && selectedValue != null) {
121
                if (!e.getValueIsAdjusting() && selectedValue != null) {
122
 
122
 
123
                    itemSelected(selectedValue);
123
                    itemSelected(selectedValue);
124
 
124
 
Line 134... Line 134...
134
 
134
 
135
    /**
135
    /**
136
     * Select an item in the list
136
     * Select an item in the list
137
     * */
137
     * */
138
    public void selectItem(Object item) {
138
    public void selectItem(Object item) {
139
        list.setSelectedValue(item, true);
139
        this.list.setSelectedValue(item, true);
140
    }
140
    }
141
 
141
 
142
    /**
142
    /**
143
     * Called when the user click "add"
143
     * Called when the user click "add"
144
     * */
144
     * */
Line 160... Line 160...
160
     * @param item the item, null if all the items are deselected
160
     * @param item the item, null if all the items are deselected
161
     * */
161
     * */
162
    public abstract void itemSelected(Object item);
162
    public abstract void itemSelected(Object item);
163
 
163
 
164
    public void reload() {
164
    public void reload() {
165
        list.invalidate();
165
        this.list.invalidate();
166
        list.repaint();
166
        this.list.repaint();
167
    }
167
    }
168
}
168
}