OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 153 Rev 181
Line 57... Line 57...
57
        this.add(new JLabel("Identifiant", SwingConstants.RIGHT), c);
57
        this.add(new JLabel("Identifiant", SwingConstants.RIGHT), c);
58
        c.gridx++;
58
        c.gridx++;
59
        c.fill = GridBagConstraints.HORIZONTAL;
59
        c.fill = GridBagConstraints.HORIZONTAL;
60
        c.weightx = 1;
60
        c.weightx = 1;
61
        c.gridwidth = 2;
61
        c.gridwidth = 2;
62
        textId = new JTextField();
62
        this.textId = new JTextField();
63
 
63
 
64
        this.add(textId, c);
64
        this.add(this.textId, c);
65
        c.gridy++;
65
        c.gridy++;
66
 
66
 
67
        c.gridwidth = 1;
67
        c.gridwidth = 1;
68
        if (!this.isEditingGroup) {
68
        if (!this.isEditingGroup) {
69
            c.weightx = 0;
69
            c.weightx = 0;
70
            c.gridx = 0;
70
            c.gridx = 0;
71
            this.add(new JLabel("Action", SwingConstants.RIGHT), c);
71
            this.add(new JLabel("Action", SwingConstants.RIGHT), c);
72
            c.gridx++;
72
            c.gridx++;
73
 
73
 
74
            c.fill = GridBagConstraints.HORIZONTAL;
74
            c.fill = GridBagConstraints.HORIZONTAL;
75
            comboActionType = new JComboBox();
75
            this.comboActionType = new JComboBox();
76
 
76
 
77
            this.add(comboActionType, c);
77
            this.add(this.comboActionType, c);
78
            c.gridx++;
78
            c.gridx++;
79
            c.weightx = 1;
79
            c.weightx = 1;
80
            comboActionChoice = new JComboBox();
80
            this.comboActionChoice = new JComboBox();
81
            this.add(comboActionChoice, c);
81
            this.add(this.comboActionChoice, c);
82
 
82
 
83
            c.gridy++;
83
            c.gridy++;
84
        }
84
        }
85
 
85
 
86
        c.fill = GridBagConstraints.HORIZONTAL;
86
        c.fill = GridBagConstraints.HORIZONTAL;
87
        c.gridx = 1;
87
        c.gridx = 1;
88
        c.weightx = 0;
88
        c.weightx = 0;
89
        c.fill = GridBagConstraints.NONE;
89
        c.fill = GridBagConstraints.NONE;
90
        shownInMenu = new JCheckBox("Afficher dans le menu");
90
        this.shownInMenu = new JCheckBox("Afficher dans le menu");
91
 
91
 
92
        this.add(shownInMenu, c);
92
        this.add(this.shownInMenu, c);
93
 
93
 
94
        JPanel spacer = new JPanel();
94
        JPanel spacer = new JPanel();
95
        c.gridx = 1;
95
        c.gridx = 1;
96
        c.gridy++;
96
        c.gridy++;
97
        c.weighty = 1;
97
        c.weighty = 1;
98
 
98
 
99
        this.add(spacer, c);
99
        this.add(spacer, c);
100
        initUIFrom(item.getId());
100
        initUIFrom(item.getId());
101
 
101
 
102
        // Listeners
102
        // Listeners
103
        if (!isEditingGroup) {
103
        if (!this.isEditingGroup) {
104
            // comboActionType
104
            // comboActionType
105
            comboActionType.addActionListener(new ActionListener() {
105
            this.comboActionType.addActionListener(new ActionListener() {
106
 
106
 
107
                @Override
107
                @Override
108
                public void actionPerformed(ActionEvent e) {
108
                public void actionPerformed(ActionEvent e) {
109
                    JComboBox cb = (JComboBox) e.getSource();
109
                    JComboBox cb = (JComboBox) e.getSource();
110
                    int type = cb.getSelectedIndex();
110
                    int type = cb.getSelectedIndex();
111
                    if (type == 0) {
111
                    if (type == 0) {
112
                        // Saisie
112
                        // Saisie
113
                        comboActionChoice.setModel(new DefaultComboBoxModel(componentIds));
113
                        MenuItemEditor.this.comboActionChoice.setModel(new DefaultComboBoxModel(MenuItemEditor.this.componentIds));
114
 
114
 
115
                        MenuDescriptor desc = extension.getCreateMenuItemFromId(item.getId());
115
                        MenuDescriptor desc = extension.getCreateMenuItemFromId(item.getId());
116
                        desc.setType(MenuDescriptor.CREATE);
116
                        desc.setType(MenuDescriptor.CREATE);
117
                        desc.setListId(null);
117
                        desc.setListId(null);
118
                        if (componentIds.size() > 0) {
118
                        if (MenuItemEditor.this.componentIds.size() > 0) {
119
                            comboActionChoice.setSelectedIndex(0);
119
                            MenuItemEditor.this.comboActionChoice.setSelectedIndex(0);
120
                            desc.setComponentId(comboActionChoice.getSelectedItem().toString());
120
                            desc.setComponentId(MenuItemEditor.this.comboActionChoice.getSelectedItem().toString());
121
                        } else {
121
                        } else {
122
                            desc.setComponentId(null);
122
                            desc.setComponentId(null);
123
                        }
123
                        }
124
                        extension.setChanged();
124
                        extension.setChanged();
125
                    } else {
125
                    } else {
126
                        // Liste
126
                        // Liste
127
                        comboActionChoice.setModel(new DefaultComboBoxModel(listIds));
127
                        MenuItemEditor.this.comboActionChoice.setModel(new DefaultComboBoxModel(MenuItemEditor.this.listIds));
128
                        MenuDescriptor desc = extension.getCreateMenuItemFromId(item.getId());
128
                        MenuDescriptor desc = extension.getCreateMenuItemFromId(item.getId());
129
                        desc.setType(MenuDescriptor.LIST);
129
                        desc.setType(MenuDescriptor.LIST);
130
                        if (listIds.size() > 0) {
130
                        if (MenuItemEditor.this.listIds.size() > 0) {
131
                            comboActionChoice.setSelectedIndex(0);
131
                            MenuItemEditor.this.comboActionChoice.setSelectedIndex(0);
132
                            desc.setListId(comboActionChoice.getSelectedItem().toString());
132
                            desc.setListId(MenuItemEditor.this.comboActionChoice.getSelectedItem().toString());
133
                        } else {
133
                        } else {
134
                            desc.setListId(null);
134
                            desc.setListId(null);
135
                        }
135
                        }
136
                        desc.setComponentId(null);
136
                        desc.setComponentId(null);
137
                        extension.setChanged();
137
                        extension.setChanged();
138
                    }
138
                    }
139
 
139
 
140
                }
140
                }
141
            });
141
            });
142
            comboActionChoice.addActionListener(new ActionListener() {
142
            this.comboActionChoice.addActionListener(new ActionListener() {
143
 
143
 
144
                @Override
144
                @Override
145
                public void actionPerformed(ActionEvent e) {
145
                public void actionPerformed(ActionEvent e) {
146
                    MenuDescriptor desc = extension.getCreateMenuItemFromId(item.getId());
146
                    MenuDescriptor desc = extension.getCreateMenuItemFromId(item.getId());
147
                    if (desc.getType().equals(MenuDescriptor.CREATE)) {
147
                    if (desc.getType().equals(MenuDescriptor.CREATE)) {
148
                        desc.setComponentId(comboActionChoice.getSelectedItem().toString());
148
                        desc.setComponentId(MenuItemEditor.this.comboActionChoice.getSelectedItem().toString());
149
                    } else if (desc.getType().equals(MenuDescriptor.LIST)) {
149
                    } else if (desc.getType().equals(MenuDescriptor.LIST)) {
150
                        desc.setListId(comboActionChoice.getSelectedItem().toString());
150
                        desc.setListId(MenuItemEditor.this.comboActionChoice.getSelectedItem().toString());
151
                    } else {
151
                    } else {
152
                        desc.setComponentId(null);
152
                        desc.setComponentId(null);
153
                        desc.setListId(null);
153
                        desc.setListId(null);
154
                    }
154
                    }
155
                }
155
                }
156
            });
156
            });
157
 
157
 
158
        }
158
        }
159
        shownInMenu.addActionListener(new ActionListener() {
159
        this.shownInMenu.addActionListener(new ActionListener() {
160
 
160
 
161
            @Override
161
            @Override
162
            public void actionPerformed(ActionEvent e) {
162
            public void actionPerformed(ActionEvent e) {
163
                final boolean selected = shownInMenu.isSelected();
163
                final boolean selected = MenuItemEditor.this.shownInMenu.isSelected();
164
 
164
 
165
                treeModel.setActive(selected, item.getId());
165
                MenuItemEditor.this.treeModel.setActive(selected, item.getId());
166
            }
166
            }
167
        });
167
        });
168
 
168
 
169
    }
169
    }
170
 
170
 
171
    private void initUIFrom(String itemId) {
171
    private void initUIFrom(String itemId) {
172
        boolean hasCreated = extension.getCreateMenuItemFromId(itemId) != null;
172
        boolean hasCreated = this.extension.getCreateMenuItemFromId(itemId) != null;
173
        textId.setEnabled(hasCreated);
173
        this.textId.setEnabled(hasCreated);
174
        previousId = itemId;
174
        this.previousId = itemId;
175
        if (hasCreated) {
175
        if (hasCreated) {
176
            textId.getDocument().addDocumentListener(new DocumentListener() {
176
            this.textId.getDocument().addDocumentListener(new DocumentListener() {
177
 
177
 
178
                @Override
178
                @Override
179
                public void removeUpdate(DocumentEvent e) {
179
                public void removeUpdate(DocumentEvent e) {
180
                    changedUpdate(e);
180
                    changedUpdate(e);
181
                }
181
                }
Line 185... Line 185...
185
                    changedUpdate(e);
185
                    changedUpdate(e);
186
                }
186
                }
187
 
187
 
188
                @Override
188
                @Override
189
                public void changedUpdate(DocumentEvent e) {
189
                public void changedUpdate(DocumentEvent e) {
190
                    String t = textId.getText();
190
                    String t = MenuItemEditor.this.textId.getText();
191
                    System.err.println("MenuItemEditor.initUIFrom(...).new DocumentListener() {...}.changedUpdate()" + t);
191
                    System.err.println("MenuItemEditor.initUIFrom(...).new DocumentListener() {...}.changedUpdate()" + t);
192
 
192
 
193
                    if (!previousId.equals(t)) {
193
                    if (!MenuItemEditor.this.previousId.equals(t)) {
194
                        treeModel.renameMenuItem(previousId, t);
194
                        MenuItemEditor.this.treeModel.renameMenuItem(MenuItemEditor.this.previousId, t);
195
                        previousId = t;
195
                        MenuItemEditor.this.previousId = t;
196
 
196
 
197
                    }
197
                    }
198
                }
198
                }
199
            });
199
            });
200
        }
200
        }
201
 
201
 
202
        shownInMenu.setSelected(extension.getRemoveMenuItemFromId(itemId) == null);
202
        this.shownInMenu.setSelected(this.extension.getRemoveMenuItemFromId(itemId) == null);
203
        if (textId != null) {
203
        if (this.textId != null) {
204
            textId.setText(itemId);
204
            this.textId.setText(itemId);
205
        }
205
        }
206
        if (!isEditingGroup) {
206
        if (!this.isEditingGroup) {
207
            comboActionType.setEnabled(true);
207
            this.comboActionType.setEnabled(true);
208
            comboActionChoice.setEnabled(true);
208
            this.comboActionChoice.setEnabled(true);
209
            final Action actionForId = MenuManager.getInstance().getActionForId(itemId);
209
            final Action actionForId = MenuManager.getInstance().getActionForId(itemId);
210
            if (hasCreated) {
210
            if (hasCreated) {
211
                MenuDescriptor desc = extension.getCreateMenuItemFromId(itemId);
211
                MenuDescriptor desc = this.extension.getCreateMenuItemFromId(itemId);
212
                comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Saisie", "Liste" }));
212
                this.comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Saisie", "Liste" }));
213
                //
213
                //
214
                final List<ComponentDescritor> compDescList = extension.getCreateComponentList();
214
                final List<ComponentDescritor> compDescList = this.extension.getCreateComponentList();
215
                componentIds = new Vector<String>(compDescList.size());
215
                this.componentIds = new Vector<String>(compDescList.size());
216
                for (ComponentDescritor componentDescritor : compDescList) {
216
                for (ComponentDescritor componentDescritor : compDescList) {
217
                    final String id = componentDescritor.getId();
217
                    final String id = componentDescritor.getId();
218
                    if (id != null) {
218
                    if (id != null) {
219
                        componentIds.add(id);
219
                        this.componentIds.add(id);
220
                    }
220
                    }
221
                }
221
                }
222
 
222
 
223
                Collections.sort(componentIds);
223
                Collections.sort(this.componentIds);
224
 
224
 
225
                final List<ListDescriptor> listDescList = extension.getCreateListList();
225
                final List<ListDescriptor> listDescList = this.extension.getCreateListList();
226
                listIds = new Vector<>(listDescList.size());
226
                this.listIds = new Vector<>(listDescList.size());
227
                for (ListDescriptor listDescritor : listDescList) {
227
                for (ListDescriptor listDescritor : listDescList) {
228
                    final String id = listDescritor.getId();
228
                    final String id = listDescritor.getId();
229
                    if (id != null) {
229
                    if (id != null) {
230
                        listIds.add(id);
230
                        this.listIds.add(id);
231
                    }
231
                    }
232
                }
232
                }
233
 
233
 
234
                Collections.sort(listIds);
234
                Collections.sort(this.listIds);
235
                //
235
                //
236
 
236
 
237
                String type = desc.getType();
237
                String type = desc.getType();
238
                if (type.equals(MenuDescriptor.CREATE)) {
238
                if (type.equals(MenuDescriptor.CREATE)) {
239
                    final String componentId = desc.getComponentId();
239
                    final String componentId = desc.getComponentId();
240
                    if (!componentIds.contains(componentId) && componentId != null) {
240
                    if (!this.componentIds.contains(componentId) && componentId != null) {
241
                        componentIds.add(componentId);
241
                        this.componentIds.add(componentId);
242
                    }
242
                    }
243
                    comboActionType.setSelectedIndex(0);
243
                    this.comboActionType.setSelectedIndex(0);
244
                    comboActionChoice.setModel(new DefaultComboBoxModel(componentIds));
244
                    this.comboActionChoice.setModel(new DefaultComboBoxModel(this.componentIds));
245
                    comboActionChoice.setSelectedItem(componentId);
245
                    this.comboActionChoice.setSelectedItem(componentId);
246
 
246
 
247
                } else if (type.equals(MenuDescriptor.LIST)) {
247
                } else if (type.equals(MenuDescriptor.LIST)) {
248
                    final String listId = desc.getListId();
248
                    final String listId = desc.getListId();
249
                    if (!listIds.contains(listId) && listId != null) {
249
                    if (!this.listIds.contains(listId) && listId != null) {
250
                        listIds.add(listId);
250
                        this.listIds.add(listId);
251
                    }
251
                    }
252
                    comboActionType.setSelectedIndex(1);
252
                    this.comboActionType.setSelectedIndex(1);
253
                    comboActionChoice.setModel(new DefaultComboBoxModel(listIds));
253
                    this.comboActionChoice.setModel(new DefaultComboBoxModel(this.listIds));
254
                    comboActionChoice.setSelectedItem(listId);
254
                    this.comboActionChoice.setSelectedItem(listId);
255
 
255
 
256
                } else {
256
                } else {
257
                    throw new IllegalArgumentException("Unknown type " + type);
257
                    throw new IllegalArgumentException("Unknown type " + type);
258
                }
258
                }
259
            } else {
259
            } else {
Line 261... Line 261...
261
                    if (actionForId instanceof CreateFrameAbstractAction) {
261
                    if (actionForId instanceof CreateFrameAbstractAction) {
262
                        CreateFrameAbstractAction a = (CreateFrameAbstractAction) actionForId;
262
                        CreateFrameAbstractAction a = (CreateFrameAbstractAction) actionForId;
263
                        JFrame frame = a.createFrame();
263
                        JFrame frame = a.createFrame();
264
                        if (frame != null) {
264
                        if (frame != null) {
265
                            if (frame instanceof EditFrame) {
265
                            if (frame instanceof EditFrame) {
266
                                comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Saisie" }));
266
                                this.comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Saisie" }));
267
                            } else if (frame instanceof IListFrame) {
267
                            } else if (frame instanceof IListFrame) {
268
                                comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Liste" }));
268
                                this.comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Liste" }));
269
                            } else {
269
                            } else {
270
                                comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Autre" }));
270
                                this.comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Autre" }));
271
                            }
271
                            }
272
 
272
 
273
                            comboActionChoice.setModel(new DefaultComboBoxModel(new String[] { frame.getTitle() }));
273
                            this.comboActionChoice.setModel(new DefaultComboBoxModel(new String[] { frame.getTitle() }));
274
                        } else {
274
                        } else {
275
                            comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Autre" }));
275
                            comboActionType.setModel(new DefaultComboBoxModel(new String[] { "Autre" }));
276
                            comboActionChoice.setModel(new DefaultComboBoxModel(new String[] { actionForId.getClass().getName() }));
276
                            comboActionChoice.setModel(new DefaultComboBoxModel(new String[] { actionForId.getClass().getName() }));
277
                        }
277
                        }
278
 
278