1 package org.devaki.nextobjects.ui.workspace.models.objects;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.awt.Dimension;
22 import java.awt.GridBagConstraints;
23 import java.awt.GridBagLayout;
24 import java.awt.Insets;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.FocusAdapter;
28 import java.awt.event.FocusEvent;
29 import javax.swing.BorderFactory;
30 import javax.swing.ButtonGroup;
31 import javax.swing.JDialog;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.JRadioButton;
35 import javax.swing.JScrollPane;
36 import javax.swing.JTabbedPane;
37 import javax.swing.SwingConstants;
38 import javax.swing.WindowConstants;
39 import javax.swing.event.DocumentEvent;
40 import javax.swing.event.DocumentListener;
41 import org.devaki.nextobjects.NextObjects;
42 import org.devaki.nextobjects.ui.components.CustomButton;
43 import org.devaki.nextobjects.ui.components.CustomComboBox;
44 import org.devaki.nextobjects.ui.components.CustomTextArea;
45 import org.devaki.nextobjects.ui.components.CustomTextField;
46 import org.devaki.nextobjects.workspace.models.ConceptualModel;
47 import org.devaki.nextobjects.workspace.models.objects.AssociationLink;
48 import org.devaki.nextobjects.workspace.models.objects.Entity;
49 import org.devaki.nextobjects.workspace.models.objects.Association;
50 /***
51 * This is the editor for an association link
52 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
53 */
54 public class AssociationLinkEdit extends JDialog
55 {
56 /***
57 * The context association link
58 */
59 private AssociationLink myAssociationLink;
60 /***
61 * Label introducing name
62 */
63 private JLabel jLabelName = new JLabel("Name");
64 /***
65 * Label introducing description
66 */
67 private JLabel jLabelDescription = new JLabel("Description");
68 /***
69 * Label introducing the parent association
70 */
71 private JLabel jLabelParent = new JLabel("Parent Association");
72 /***
73 * Label introducing the linked entity
74 */
75 private JLabel jLabelChild = new JLabel("Linked Entity");
76 /***
77 * Textfield for setting an human readable name for the association
78 */
79 private CustomTextField jTextFieldName =
80 new CustomTextField(
81 "",
82 "Name of the association link in the schema",
83 true);
84 /***
85 * Textarea for setting a description to the association linkl
86 */
87 private CustomTextArea jTextAreaDescription =
88 new CustomTextArea(
89 "",
90 "Description of the association link",
91 true,
92 true);
93 /***
94 * Textarea for setting notes
95 */
96 private CustomTextArea jTextAreaNotes =
97 new CustomTextArea("", "Notes about the association link", true, true);
98 /***
99 * The Ok button
100 */
101 private CustomButton jButtonOK = new CustomButton("OK", "", true, false);
102 /***
103 * The cnacel button
104 */
105 private CustomButton jButtonCancel =
106 new CustomButton("Cancel", "", true, false);
107 /***
108 * Combobox to choose the parent association
109 */
110 private CustomComboBox jComboBoxParent =
111 new CustomComboBox("Change Parent Association", true);
112 /***
113 * Combobox to choose the child association
114 */
115 private CustomComboBox jComboBoxChild =
116 new CustomComboBox("Change Linked Entity", true);
117 /***
118 * The button group, only one can be selected ...
119 */
120 private ButtonGroup buttonGroup = new ButtonGroup();
121 /***
122 * Button card 0,1
123 */
124 private JRadioButton jRadioButton01 = new JRadioButton("0,1");
125 /***
126 * Button card 1,1
127 */
128 private JRadioButton jRadioButton11 = new JRadioButton("1,1");
129 /***
130 * Button card 0,1
131 */
132 private JRadioButton jRadioButton0N = new JRadioButton("0,n");
133 /***
134 * Button card 1,n
135 */
136 private JRadioButton jRadioButton1N = new JRadioButton("1,n");
137 /***
138 * The tabbed pane
139 */
140 private JTabbedPane jTabbedPane = new JTabbedPane(SwingConstants.TOP);
141 /***
142 * The general panel
143 */
144 private JPanel jPanelGeneral = new JPanel(new GridBagLayout());
145 /***
146 * The general propertie panel
147 */
148 private JPanel jPanelGeneralProperties = new JPanel(new GridBagLayout());
149 /***
150 * The cards panel
151 */
152 private JPanel jPanelGeneralCards = new JPanel(new GridBagLayout());
153 /***
154 * The cards button panem
155 */
156 private JPanel jPanelGeneralCardsButtons = new JPanel(new GridBagLayout());
157 /***
158 * The notes panel
159 */
160 private JPanel jPanelNotes = new JPanel(new GridBagLayout());
161 /***
162 * Construct a new 'AssociationLinkEdit' object
163 */
164 public AssociationLinkEdit()
165 {
166 super(NextObjects.getReference());
167 /*** Initialization **/
168
169 this.setSize(new Dimension(457, 500));
170
171 this.setLocationRelativeTo(null);
172
173 this.setModal(true);
174
175 this.setResizable(false);
176
177 this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
178 /*** Components properties **/
179
180
181 this.buttonGroup.add(jRadioButton01);
182 this.buttonGroup.add(jRadioButton11);
183 this.buttonGroup.add(jRadioButton0N);
184 this.buttonGroup.add(jRadioButton1N);
185
186
187 this.getContentPane().setLayout(new GridBagLayout());
188
189 this.jPanelGeneralProperties.setBorder(
190 BorderFactory.createTitledBorder("Properties"));
191 this.jPanelGeneralCards.setBorder(
192 BorderFactory.createTitledBorder("Cards"));
193 /*** Listeners **/
194
195 this.jButtonOK.addActionListener(new ActionListener()
196 {
197
198 public final void actionPerformed(final ActionEvent e)
199 {
200 closingWindow(true);
201 }
202 });
203 jButtonCancel.addActionListener(new ActionListener()
204 {
205
206 public final void actionPerformed(final ActionEvent e)
207 {
208 closingWindow(false);
209 }
210 });
211
212 this.jTextFieldName.addFocusListener(new FocusAdapter()
213 {
214
215 public final void focusGained(final FocusEvent e)
216 {
217 jTextFieldName.selectAll();
218 }
219 });
220
221 this
222 .jTextFieldName
223 .getDocument()
224 .addDocumentListener(new DocumentListener()
225 {
226
227 public final void changedUpdate(final DocumentEvent e)
228 {
229 }
230
231 public final void insertUpdate(final DocumentEvent e)
232 {
233 enablingOKButton();
234 }
235
236 public final void removeUpdate(final DocumentEvent e)
237 {
238 enablingOKButton();
239 }
240 });
241 /*** Assembling components **/
242
243 this.jPanelGeneralProperties.add(
244 this.jLabelName,
245 new GridBagConstraints(
246 0,
247 0,
248 1,
249 1,
250 0.0,
251 0.0,
252 GridBagConstraints.WEST,
253 GridBagConstraints.NONE,
254 new Insets(5, 5, 0, 5),
255 0,
256 0));
257 this.jPanelGeneralProperties.add(
258 this.jTextFieldName,
259 new GridBagConstraints(
260 1,
261 0,
262 1,
263 1,
264 0.0,
265 0.0,
266 GridBagConstraints.CENTER,
267 GridBagConstraints.HORIZONTAL,
268 new Insets(5, 0, 0, 5),
269 0,
270 0));
271 this.jPanelGeneralProperties.add(
272 this.jLabelDescription,
273 new GridBagConstraints(
274 0,
275 1,
276 1,
277 1,
278 0.0,
279 0.0,
280 GridBagConstraints.NORTHWEST,
281 GridBagConstraints.NONE,
282 new Insets(5, 5, 0, 5),
283 0,
284 0));
285 this.jPanelGeneralProperties.add(
286 new JScrollPane(this.jTextAreaDescription),
287 new GridBagConstraints(
288 1,
289 1,
290 1,
291 1,
292 1.0,
293 1.0,
294 GridBagConstraints.CENTER,
295 GridBagConstraints.BOTH,
296 new Insets(5, 0, 5, 5),
297 0,
298 0));
299
300 this.jPanelGeneralCardsButtons.add(
301 this.jRadioButton01,
302 new GridBagConstraints(
303 0,
304 0,
305 1,
306 1,
307 1.0,
308 0.0,
309 GridBagConstraints.EAST,
310 GridBagConstraints.NONE,
311 new Insets(5, 5, 0, 5),
312 0,
313 0));
314 this.jPanelGeneralCardsButtons.add(
315 this.jRadioButton11,
316 new GridBagConstraints(
317 1,
318 0,
319 1,
320 1,
321 1.0,
322 0.0,
323 GridBagConstraints.WEST,
324 GridBagConstraints.NONE,
325 new Insets(5, 0, 0, 5),
326 0,
327 0));
328 this.jPanelGeneralCardsButtons.add(
329 this.jRadioButton0N,
330 new GridBagConstraints(
331 0,
332 1,
333 1,
334 1,
335 1.0,
336 0.0,
337 GridBagConstraints.EAST,
338 GridBagConstraints.NONE,
339 new Insets(5, 5, 5, 5),
340 0,
341 0));
342 this.jPanelGeneralCardsButtons.add(
343 this.jRadioButton1N,
344 new GridBagConstraints(
345 1,
346 1,
347 1,
348 1,
349 1.0,
350 0.0,
351 GridBagConstraints.WEST,
352 GridBagConstraints.NONE,
353 new Insets(5, 0, 5, 5),
354 0,
355 0));
356
357 this.jPanelGeneralCards.add(
358 this.jLabelParent,
359 new GridBagConstraints(
360 0,
361 0,
362 1,
363 1,
364 0.0,
365 0.0,
366 GridBagConstraints.WEST,
367 GridBagConstraints.NONE,
368 new Insets(5, 5, 0, 5),
369 0,
370 0));
371 this.jPanelGeneralCards.add(
372 this.jComboBoxParent,
373 new GridBagConstraints(
374 1,
375 0,
376 1,
377 1,
378 1.0,
379 0.0,
380 GridBagConstraints.CENTER,
381 GridBagConstraints.HORIZONTAL,
382 new Insets(5, 0, 0, 5),
383 0,
384 0));
385 this.jPanelGeneralCards.add(
386 this.jLabelChild,
387 new GridBagConstraints(
388 0,
389 1,
390 1,
391 1,
392 0.0,
393 0.0,
394 GridBagConstraints.WEST,
395 GridBagConstraints.NONE,
396 new Insets(5, 5, 0, 5),
397 0,
398 0));
399 this.jPanelGeneralCards.add(
400 this.jComboBoxChild,
401 new GridBagConstraints(
402 1,
403 1,
404 1,
405 1,
406 1.0,
407 0.0,
408 GridBagConstraints.CENTER,
409 GridBagConstraints.HORIZONTAL,
410 new Insets(5, 0, 0, 5),
411 0,
412 0));
413 this.jPanelGeneralCards.add(
414 this.jPanelGeneralCardsButtons,
415 new GridBagConstraints(
416 0,
417 2,
418 2,
419 1,
420 1.0,
421 0.0,
422 GridBagConstraints.CENTER,
423 GridBagConstraints.HORIZONTAL,
424 new Insets(5, 5, 5, 5),
425 0,
426 0));
427
428 this.jPanelGeneral.add(
429 this.jPanelGeneralProperties,
430 new GridBagConstraints(
431 0,
432 0,
433 1,
434 1,
435 1.0,
436 1.0,
437 GridBagConstraints.CENTER,
438 GridBagConstraints.BOTH,
439 new Insets(5, 5, 0, 5),
440 0,
441 0));
442 this.jPanelGeneral.add(
443 this.jPanelGeneralCards,
444 new GridBagConstraints(
445 0,
446 1,
447 1,
448 1,
449 0.0,
450 0.0,
451 GridBagConstraints.CENTER,
452 GridBagConstraints.BOTH,
453 new Insets(5, 5, 5, 5),
454 0,
455 0));
456
457 this.jPanelNotes.add(
458 new JScrollPane(this.jTextAreaNotes),
459 new GridBagConstraints(
460 0,
461 0,
462 1,
463 1,
464 1.0,
465 1.0,
466 GridBagConstraints.CENTER,
467 GridBagConstraints.BOTH,
468 new Insets(5, 5, 5, 5),
469 0,
470 0));
471
472 this.jTabbedPane.add(this.jPanelGeneral, "General");
473 this.jTabbedPane.add(this.jPanelNotes, "Notes");
474
475 this.getContentPane().add(
476 this.jTabbedPane,
477 new GridBagConstraints(
478 0,
479 0,
480 2,
481 1,
482 1.0,
483 1.0,
484 GridBagConstraints.CENTER,
485 GridBagConstraints.BOTH,
486 new Insets(5, 5, 0, 5),
487 0,
488 0));
489 this.getContentPane().add(
490 this.jButtonOK,
491 new GridBagConstraints(
492 0,
493 1,
494 1,
495 1,
496 1.0,
497 0.0,
498 GridBagConstraints.EAST,
499 GridBagConstraints.NONE,
500 new Insets(5, 5, 5, 5),
501 0,
502 0));
503 this.getContentPane().add(
504 this.jButtonCancel,
505 new GridBagConstraints(
506 1,
507 1,
508 1,
509 1,
510 0.0,
511 0.0,
512 GridBagConstraints.CENTER,
513 GridBagConstraints.NONE,
514 new Insets(5, 0, 5, 5),
515 0,
516 0));
517 }
518 /***
519 * What to do before closing the window
520 * @param isOK save it
521 */
522 private void closingWindow(final boolean isOK)
523 {
524
525 if (isOK)
526 {
527 this.saveData();
528 }
529
530
531 this.dispose();
532 }
533 /***
534 * Enable or disable the 'OK' button depending on the length of
535 * 'jTextFieldName'
536 */
537 private void enablingOKButton()
538 {
539 if (this.jTextFieldName.getText().length() != 0)
540 {
541
542
543 this.jButtonOK.setEnabled(true);
544 }
545
546
547 else
548 {
549 this.jButtonOK.setEnabled(false);
550 }
551 }
552 /***
553 * Get the informations from the selected AssociationLink
554 * @param pAssociationLink the context association link
555 */
556 public final void setData(final AssociationLink pAssociationLink)
557 {
558
559 this.setTitle(
560 new StringBuffer()
561 .append("Properties of '")
562 .append(pAssociationLink.getName())
563 .append("' - nextObjects")
564 .toString());
565
566 this.myAssociationLink = pAssociationLink;
567
568 this.jTextFieldName.setText(this.myAssociationLink.getName());
569 this.jTextAreaDescription.setText(
570 this.myAssociationLink.getDescription());
571 this.jComboBoxParent.setData(
572 ((ConceptualModel) this.myAssociationLink.getMyModel())
573 .getAssociations());
574 this.jComboBoxParent.setSelectedItem(
575 this.myAssociationLink.getParentClass());
576 this.jComboBoxChild.setData(
577 ((ConceptualModel) this.myAssociationLink.getMyModel())
578 .getEntities());
579 this.jComboBoxChild.setSelectedItem(
580 this.myAssociationLink.getChildClass());
581 switch (this.myAssociationLink.getCard())
582 {
583 case ConceptualModel.ASSO_01 :
584 this.jRadioButton01.setSelected(true);
585 break;
586 case ConceptualModel.ASSO_11 :
587 this.jRadioButton11.setSelected(true);
588 break;
589 case ConceptualModel.ASSO_0N :
590 this.jRadioButton0N.setSelected(true);
591 break;
592 case ConceptualModel.ASSO_1N :
593 this.jRadioButton1N.setSelected(true);
594 break;
595 }
596 this.jTextAreaNotes.setText(this.myAssociationLink.getNotes());
597
598 this.getRootPane().setDefaultButton(this.jButtonOK);
599
600 this.show();
601 }
602 /***
603 * Save the informations into the edited object
604 */
605 public final void saveData()
606 {
607 this.myAssociationLink.setName(this.jTextFieldName.getText());
608 this.myAssociationLink.setDescription(
609 this.jTextAreaDescription.getText());
610
611 if (this.jRadioButton01.isSelected())
612 {
613 this.myAssociationLink.setCard(ConceptualModel.ASSO_01);
614 }
615 else if (this.jRadioButton11.isSelected())
616 {
617 this.myAssociationLink.setCard(ConceptualModel.ASSO_11);
618 }
619 else if (this.jRadioButton0N.isSelected())
620 {
621 this.myAssociationLink.setCard(ConceptualModel.ASSO_0N);
622 }
623 else if (this.jRadioButton1N.isSelected())
624 {
625 this.myAssociationLink.setCard(ConceptualModel.ASSO_1N);
626 }
627 this.myAssociationLink.setNotes(this.jTextAreaNotes.getText());
628 this.myAssociationLink.setParentClass(
629 (Association) this.jComboBoxParent.getSelectedItem());
630 this.myAssociationLink.setChildClass(
631 (Entity) this.jComboBoxChild.getSelectedItem());
632
633 this.myAssociationLink.getMyModel().getModelView().setFullRefresh(true);
634 this.myAssociationLink.getMyModel().getModelView().drawingArea.repaint();
635
636 }
637 }