KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > dialog > view > BasicDialogView


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.dialog.view;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import org.objectweb.fractal.gui.Constants;
29 import org.objectweb.fractal.gui.dialog.model.DialogModel;
30 import org.objectweb.fractal.gui.model.ClientInterface;
31 import org.objectweb.fractal.gui.model.Component;
32 import org.objectweb.fractal.gui.model.Configuration;
33 import org.objectweb.fractal.gui.model.ConfigurationListener;
34 import org.objectweb.fractal.gui.model.Interface;
35 import org.objectweb.fractal.gui.model.ServerInterface;
36 import org.objectweb.fractal.swing.JPanelImpl;
37
38 import java.awt.BorderLayout JavaDoc;
39 import java.awt.Color JavaDoc;
40 import java.awt.GridBagConstraints JavaDoc;
41 import java.awt.GridBagLayout JavaDoc;
42 import java.awt.Insets JavaDoc;
43 import java.awt.event.ActionEvent JavaDoc;
44 import java.awt.event.ActionListener JavaDoc;
45 import java.awt.Dimension JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49 import java.util.HashMap JavaDoc;
50
51 import javax.swing.BorderFactory JavaDoc;
52 import javax.swing.DefaultCellEditor JavaDoc;
53 import javax.swing.JButton JavaDoc;
54 import javax.swing.JComboBox JavaDoc;
55 import javax.swing.JComponent JavaDoc;
56 import javax.swing.JLabel JavaDoc;
57 import javax.swing.JPanel JavaDoc;
58 import javax.swing.JScrollPane JavaDoc;
59 import javax.swing.JTable JavaDoc;
60 import javax.swing.JTextField JavaDoc;
61 import javax.swing.ListSelectionModel JavaDoc;
62 import javax.swing.SwingConstants JavaDoc;
63 import javax.swing.event.ListSelectionEvent JavaDoc;
64 import javax.swing.event.ListSelectionListener JavaDoc;
65
66 /**
67  * A configuration view that displays the configuration's root component as a
68  * dialog.
69  */

70
71 public class BasicDialogView extends JPanelImpl implements
72   ConfigurationListener,
73   BindingController
74 {
75
76   /**
77    * A mandatory client interface bound to a {@link Configuration configuration}
78    * model. This is the configuration whose root component is displayed by this
79    * view.
80    */

81
82   public final static String JavaDoc CONFIGURATION_BINDING = "configuration";
83
84   /**
85    * A mandatory client interface bound to a {@link DialogModel dialog} model.
86    * This is the model displayed by this view.
87    */

88
89   public final static String JavaDoc DIALOG_MODEL_BINDING = "dialog-model";
90
91   /**
92    * An optional client interface bound to a {@link JComponent} inner component.
93    * This optional inner swing component can, for example, display a graph
94    * representation of the component that is displayed by this dialog.
95    */

96
97   public final static String JavaDoc INNER_GRAPH_VIEW_BINDING = "inner-graph-view";
98
99   /**
100    * A collection client interface bound to the {@link DialogViewListener
101    * listeners} of this view.
102    */

103
104   public final static String JavaDoc DIALOG_VIEW_LISTENERS_BINDING = "dialog-listeners";
105
106   /**
107    * The configuration client interface.
108    */

109
110   private Configuration configuration;
111
112   /**
113    * The dialog model client interface.
114    */

115
116   private DialogModel model;
117
118   /**
119    * The inner graph view client interface.
120    */

121
122   private JComponent JavaDoc innerGraphView;
123
124   /**
125    * The listeners client interface.
126    */

127
128   private Map JavaDoc listeners;
129
130   private JPanel JavaDoc innerGraphPanel;
131
132   private JTextField JavaDoc nameField;
133
134   private JTextField JavaDoc typeField;
135
136   private JTextField JavaDoc classField;
137 // private CompletionJTextField classField;
138

139   private JTable JavaDoc[] itfTable;
140
141   private JComboBox JavaDoc contingencyComboBox;
142
143   private JComboBox JavaDoc cardinalityComboBox;
144
145   private JButton JavaDoc[] itfAddButton;
146
147   private JButton JavaDoc[] itfRemoveButton;
148
149   private JTable JavaDoc attrTable;
150
151   private JButton JavaDoc attrAddButton;
152
153   private JButton JavaDoc attrRemoveButton;
154
155   private JButton JavaDoc classFieldButton;
156
157   private JTextField JavaDoc attrControllerField;
158
159   private JTextField JavaDoc tmplDescField;
160
161   private JTextField JavaDoc compDescField;
162
163   private ActionListener JavaDoc buttonListener;
164
165   private ListSelectionListener JavaDoc listListener;
166
167   private ClassFieldButtonListener classFieldButtonListener;
168
169   // -------------------------------------------------------------------------
170
// Initialization
171
// -------------------------------------------------------------------------
172

173   /**
174    * Constructs a new {@link BasicDialogView} component.
175    */

176
177   public BasicDialogView () {
178     listeners = new HashMap JavaDoc();
179
180     itfTable = new JTable JavaDoc[2];
181     itfAddButton = new JButton JavaDoc[2];
182     itfRemoveButton = new JButton JavaDoc[2];
183     buttonListener = new ButtonListener();
184     classFieldButtonListener = new ClassFieldButtonListener ();
185     listListener = new ListListener();
186
187     GridBagLayout JavaDoc bagLayout = new GridBagLayout JavaDoc();
188     setLayout(bagLayout);
189
190     JPanel JavaDoc hPanel = createHeaderPanel();
191
192     contingencyComboBox = new JComboBox JavaDoc();
193     contingencyComboBox.addItem("mandatory");
194     contingencyComboBox.addItem("optional");
195
196     cardinalityComboBox = new JComboBox JavaDoc();
197     cardinalityComboBox.addItem("single");
198     cardinalityComboBox.addItem("collection");
199
200     JPanel JavaDoc cPanel = new JPanel JavaDoc();
201     cPanel.setLayout(new BorderLayout JavaDoc());
202     cPanel.add(new JLabel JavaDoc("Client interfaces"), "North");
203     cPanel.add(createInterfacesPanel(0), "Center");
204
205     JPanel JavaDoc sPanel = new JPanel JavaDoc();
206     sPanel.setLayout(new BorderLayout JavaDoc());
207     sPanel.add(new JLabel JavaDoc("Server interfaces"), "North");
208     sPanel.add(createInterfacesPanel(1), "Center");
209
210     JPanel JavaDoc aPanel = new JPanel JavaDoc();
211     aPanel.setLayout(new BorderLayout JavaDoc());
212     aPanel.add(new JLabel JavaDoc("Attributes"), "North");
213     aPanel.add(createAttributesPanel(), "Center");
214
215     JPanel JavaDoc bPanel = createControllerPanel();
216
217     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
218     constraints.insets = new Insets JavaDoc(3, 3, 3, 3);
219     constraints.gridy = 1;
220     constraints.fill = GridBagConstraints.HORIZONTAL;
221     constraints.weightx = 1;
222     constraints.weighty = 0;
223     bagLayout.setConstraints(hPanel, constraints);
224     add(hPanel);
225
226     constraints.gridy = 2;
227     constraints.fill = GridBagConstraints.BOTH;
228     constraints.weighty = 1;
229     bagLayout.setConstraints(sPanel, constraints);
230     add(sPanel);
231
232     constraints.gridy = 3;
233     constraints.weighty = 2;
234     bagLayout.setConstraints(cPanel, constraints);
235     add(cPanel);
236
237     constraints.gridy = 4;
238     constraints.weighty = 1;
239     bagLayout.setConstraints(aPanel, constraints);
240     add(aPanel);
241
242     constraints.gridy = 5;
243     constraints.fill = GridBagConstraints.HORIZONTAL;
244     constraints.weighty = 0;
245     bagLayout.setConstraints(bPanel, constraints);
246     add(bPanel);
247   }
248
249   /**
250    * Creates the panel that contains the name, type and implementation fields.
251    *
252    * @return the created panel.
253    */

254
255   private JPanel JavaDoc createHeaderPanel () {
256     JPanel JavaDoc panel = new JPanel JavaDoc();
257
258     GridBagLayout JavaDoc bagLayout = new GridBagLayout JavaDoc();
259     panel.setLayout(bagLayout);
260
261     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
262     JLabel JavaDoc label = new JLabel JavaDoc("Name", SwingConstants.LEFT);
263     constraints.fill = GridBagConstraints.NONE;
264     constraints.anchor = GridBagConstraints.NORTHWEST;
265     bagLayout.setConstraints(label, constraints);
266     panel.add(label);
267
268     nameField = new JTextField JavaDoc(30);
269     constraints.fill = GridBagConstraints.HORIZONTAL;
270     constraints.weightx = 1;
271     bagLayout.setConstraints(nameField, constraints);
272     panel.add(nameField);
273
274     label = new JLabel JavaDoc("Type ", SwingConstants.LEFT);
275     constraints.gridy = 1;
276     constraints.fill = GridBagConstraints.NONE;
277     constraints.anchor = GridBagConstraints.NORTHWEST;
278     constraints.weightx = 0;
279     bagLayout.setConstraints(label, constraints);
280     panel.add(label);
281
282     typeField = new JTextField JavaDoc(30);
283     constraints.fill = GridBagConstraints.HORIZONTAL;
284     constraints.weightx = 1;
285     bagLayout.setConstraints(typeField, constraints);
286     panel.add(typeField);
287
288     label = new JLabel JavaDoc("Class ", SwingConstants.LEFT);
289     constraints.gridy = 2;
290     constraints.fill = GridBagConstraints.NONE;
291     constraints.weightx = 0;
292     bagLayout.setConstraints(label, constraints);
293     panel.add(label);
294
295     classField = new JTextField JavaDoc(49);
296 /*
297     classField = new CompletionJTextField(30, this);
298     classField.makeList();
299     classField.mliste.setVisible(false);
300     constraints.fill = GridBagConstraints.HORIZONTAL;
301     constraints.weightx = 1;
302     bagLayout.setConstraints(classField, constraints);
303     panel.add(classField);
304 */

305     JPanel JavaDoc classPanel = new JPanel JavaDoc (new BorderLayout JavaDoc());
306     classFieldButton = new JButton JavaDoc("Impl.");
307     classFieldButton.setBackground(new Color JavaDoc(204, 255, 204));
308     classFieldButton.setPreferredSize(new Dimension JavaDoc (80, 20));
309     classFieldButton.addActionListener(classFieldButtonListener);
310     classPanel.add(classField, BorderLayout.WEST);
311     classPanel.add(classFieldButton, BorderLayout.EAST);
312     constraints.fill = GridBagConstraints.HORIZONTAL;
313     constraints.weightx = 1;
314     bagLayout.setConstraints(classPanel, constraints);
315     panel.add(classPanel);
316
317     return panel;
318   }
319
320   /**
321    * Creates a panel that contains an interface list and its associated buttons.
322    *
323    * @param i the number of this panel. 0 = client, 1 = server interfaces.
324    * @return the created panel.
325    */

326
327   private JPanel JavaDoc createInterfacesPanel (final int i) {
328     itfTable[i] = new JTable JavaDoc();
329     JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(itfTable[i]);
330     itfTable[i].setDefaultRenderer(
331       Object JavaDoc.class,
332       new InterfaceTableCellRenderer());
333
334     itfAddButton[i] = new JButton JavaDoc("Add");
335     itfAddButton[i].addActionListener(buttonListener);
336     itfRemoveButton[i] = new JButton JavaDoc("Remove");
337     itfRemoveButton[i].addActionListener(buttonListener);
338     itfRemoveButton[i].setEnabled(false);
339
340     JPanel JavaDoc panel = new JPanel JavaDoc();
341     GridBagLayout JavaDoc bagLayout = new GridBagLayout JavaDoc();
342     panel.setLayout(bagLayout);
343
344     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
345     constraints.gridheight = GridBagConstraints.REMAINDER;
346     constraints.fill = GridBagConstraints.BOTH;
347     constraints.weightx = 1;
348     constraints.weighty = 1;
349     bagLayout.setConstraints(scrollPane, constraints);
350     panel.add(scrollPane);
351
352     constraints.gridx = 1;
353     constraints.gridy = 0;
354     constraints.gridheight = 1;
355     constraints.fill = GridBagConstraints.HORIZONTAL;
356     constraints.weightx = 0;
357     constraints.weighty = 0;
358     bagLayout.setConstraints(itfAddButton[i], constraints);
359     panel.add(itfAddButton[i]);
360
361     constraints.gridx = 1;
362     constraints.gridy = 1;
363     bagLayout.setConstraints(itfRemoveButton[i], constraints);
364     panel.add(itfRemoveButton[i]);
365
366     constraints.gridx = 1;
367     constraints.gridy = 2;
368     constraints.gridheight = GridBagConstraints.REMAINDER;
369     constraints.fill = GridBagConstraints.BOTH;
370     JPanel JavaDoc emptyPanel = new JPanel JavaDoc();
371     bagLayout.setConstraints(emptyPanel, constraints);
372     panel.add(emptyPanel);
373
374     return panel;
375   }
376
377   /**
378    * Creates the panel that contains the attibute table and its asociated
379    * buttons.
380    *
381    * @return the created panel.
382    */

383
384   private JPanel JavaDoc createAttributesPanel () {
385     attrTable = new JTable JavaDoc();
386     JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(attrTable);
387
388     attrAddButton = new JButton JavaDoc("Add");
389     attrAddButton.addActionListener(buttonListener);
390     attrRemoveButton = new JButton JavaDoc("Remove");
391     attrRemoveButton.addActionListener(buttonListener);
392     attrRemoveButton.setEnabled(false);
393
394     JPanel JavaDoc panel = new JPanel JavaDoc();
395     GridBagLayout JavaDoc bagLayout = new GridBagLayout JavaDoc();
396     panel.setLayout(bagLayout);
397
398     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
399     constraints.gridheight = GridBagConstraints.REMAINDER;
400     constraints.fill = GridBagConstraints.BOTH;
401     constraints.weightx = 1;
402     constraints.weighty = 1;
403     bagLayout.setConstraints(scrollPane, constraints);
404     panel.add(scrollPane);
405
406     constraints.gridx = 1;
407     constraints.gridy = 0;
408     constraints.gridheight = 1;
409     constraints.fill = GridBagConstraints.HORIZONTAL;
410     constraints.weightx = 0;
411     constraints.weighty = 0;
412     bagLayout.setConstraints(attrAddButton, constraints);
413     panel.add(attrAddButton);
414
415     constraints.gridx = 1;
416     constraints.gridy = 1;
417     bagLayout.setConstraints(attrRemoveButton, constraints);
418     panel.add(attrRemoveButton);
419
420     constraints.gridx = 1;
421     constraints.gridy = 2;
422     constraints.gridheight = GridBagConstraints.REMAINDER;
423     constraints.fill = GridBagConstraints.BOTH;
424     JPanel JavaDoc emptyPanel = new JPanel JavaDoc();
425     bagLayout.setConstraints(emptyPanel, constraints);
426     panel.add(emptyPanel);
427
428     return panel;
429   }
430
431   /**
432    * Creates the panel that contains the attribute controller and the controller
433    * descriptor fields.
434    *
435    * @return the constructed panel.
436    */

437
438   private JPanel JavaDoc createControllerPanel () {
439     JPanel JavaDoc panel = new JPanel JavaDoc();
440
441     GridBagLayout JavaDoc bagLayout = new GridBagLayout JavaDoc();
442     panel.setLayout(bagLayout);
443
444     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
445
446     JLabel JavaDoc label = new JLabel JavaDoc("Attribute controller:", SwingConstants.LEFT);
447     constraints.fill = GridBagConstraints.NONE;
448     constraints.anchor = GridBagConstraints.NORTHWEST;
449     constraints.insets = new Insets JavaDoc(0, 0, 0, 3);
450     bagLayout.setConstraints(label, constraints);
451     panel.add(label);
452
453     attrControllerField = new JTextField JavaDoc();
454     constraints.fill = GridBagConstraints.HORIZONTAL;
455     constraints.insets = new Insets JavaDoc(0, 0, 0, 0);
456     constraints.weightx = 1;
457     bagLayout.setConstraints(attrControllerField, constraints);
458     panel.add(attrControllerField);
459
460     label = new JLabel JavaDoc("Template controller descriptor:", SwingConstants.LEFT);
461     constraints.gridy = 1;
462     constraints.fill = GridBagConstraints.NONE;
463     constraints.anchor = GridBagConstraints.NORTHWEST;
464     constraints.insets = new Insets JavaDoc(0, 0, 0, 3);
465     constraints.weightx = 0;
466     bagLayout.setConstraints(label, constraints);
467     panel.add(label);
468
469     tmplDescField = new JTextField JavaDoc();
470     constraints.fill = GridBagConstraints.HORIZONTAL;
471     constraints.insets = new Insets JavaDoc(0, 0, 0, 0);
472     constraints.weightx = 1;
473     bagLayout.setConstraints(tmplDescField, constraints);
474     panel.add(tmplDescField);
475
476     label = new JLabel JavaDoc("Component controller descriptor:", SwingConstants.LEFT);
477     constraints.gridy = 2;
478     constraints.fill = GridBagConstraints.NONE;
479     constraints.insets = new Insets JavaDoc(0, 0, 0, 3);
480     constraints.weightx = 0;
481     bagLayout.setConstraints(label, constraints);
482     panel.add(label);
483
484     compDescField = new JTextField JavaDoc();
485     constraints.fill = GridBagConstraints.HORIZONTAL;
486     constraints.insets = new Insets JavaDoc(0, 0, 0, 0);
487     constraints.weightx = 1;
488     bagLayout.setConstraints(compDescField, constraints);
489     panel.add(compDescField);
490
491     return panel;
492   }
493
494   // -------------------------------------------------------------------------
495
// Implementation of the BindingController interface
496
// -------------------------------------------------------------------------
497

498   public String JavaDoc[] listFc () {
499     int size = listeners.size();
500     String JavaDoc[] names = new String JavaDoc[size + 3];
501     listeners.keySet().toArray(names);
502     names[size] = CONFIGURATION_BINDING;
503     names[size + 1] = DIALOG_MODEL_BINDING;
504     names[size + 2] = INNER_GRAPH_VIEW_BINDING;
505     return names;
506   }
507
508   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
509     if (CONFIGURATION_BINDING.equals(clientItfName)) {
510       return configuration;
511     } else if (DIALOG_MODEL_BINDING.equals(clientItfName)) {
512       return model;
513     } else if (INNER_GRAPH_VIEW_BINDING.equals(clientItfName)) {
514       return innerGraphView;
515     } else if (clientItfName.startsWith(DIALOG_VIEW_LISTENERS_BINDING)) {
516       return listeners.get(clientItfName);
517     }
518     return null;
519   }
520
521   public void bindFc (
522     final String JavaDoc clientItfName,
523     final Object JavaDoc serverItf)
524   {
525     if (CONFIGURATION_BINDING.equals(clientItfName)) {
526       configuration = (Configuration) serverItf;
527     } else if (DIALOG_MODEL_BINDING.equals(clientItfName)) {
528       model = (DialogModel)serverItf;
529       for (int i = 0; i < 2; ++i) {
530         if (i == 0) {
531           itfTable[i].setModel(model.getClientInterfacesTableModel());
532           itfTable[i].setSelectionModel(
533             model.getClientInterfacesTableSelectionModel());
534         } else {
535           itfTable[i].setModel(model.getServerInterfacesTableModel());
536           itfTable[i].setSelectionModel(
537             model.getServerInterfacesTableSelectionModel());
538         }
539         itfTable[i].getColumn("Contingency").setCellEditor(
540           new DefaultCellEditor JavaDoc(contingencyComboBox));
541         itfTable[i].getColumn("Cardinality").setCellEditor(
542           new DefaultCellEditor JavaDoc(cardinalityComboBox));
543         // specifies the relative widths of the columns (the absolute values are
544
// voluntarily big, so that only the relative values are taken into
545
// account)
546
itfTable[i].getColumn("Name").setPreferredWidth(1000);
547         itfTable[i].getColumn("Signature").setPreferredWidth(4000);
548         itfTable[i].getColumn("Contingency").setPreferredWidth(1000);
549         itfTable[i].getColumn("Cardinality").setPreferredWidth(1000);
550         itfTable[i].getSelectionModel().addListSelectionListener(listListener);
551       }
552       attrTable.setModel(model.getAttributesTableModel());
553       attrTable.setSelectionModel(model.getAttributesTableSelectionModel());
554       attrTable.getSelectionModel().addListSelectionListener(listListener);
555       nameField.setDocument(model.getNameFieldModel());
556       typeField.setDocument(model.getTypeFieldModel());
557       classField.setDocument(model.getImplementationFieldModel());
558       attrControllerField.setDocument(model.getAttrControllerFieldModel());
559       tmplDescField.setDocument(model.getTmplControllerDescFieldModel());
560       compDescField.setDocument(model.getCompControllerDescFieldModel());
561     } else if (INNER_GRAPH_VIEW_BINDING.equals(clientItfName)) {
562       innerGraphView = (JComponent JavaDoc)serverItf;
563
564       innerGraphPanel = new JPanel JavaDoc();
565       innerGraphPanel.setLayout(new BorderLayout JavaDoc());
566       innerGraphPanel.setBorder(BorderFactory.createLoweredBevelBorder());
567       innerGraphPanel.add(innerGraphView, "Center");
568
569       GridBagLayout JavaDoc bagLayout = (GridBagLayout JavaDoc)getLayout();
570       GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
571       constraints.insets = new Insets JavaDoc(3, 3, 3, 3);
572       constraints.fill = GridBagConstraints.BOTH;
573       constraints.weightx = 1;
574       constraints.weighty = 6;
575       bagLayout.setConstraints(innerGraphPanel, constraints);
576       add(innerGraphPanel);
577     } else if (clientItfName.startsWith(DIALOG_VIEW_LISTENERS_BINDING)) {
578       listeners.put(clientItfName, serverItf);
579     }
580   }
581
582   public void unbindFc (final String JavaDoc clientItfName) {
583     if (CONFIGURATION_BINDING.equals(clientItfName)) {
584       configuration = null;
585     } else if (DIALOG_MODEL_BINDING.equals(clientItfName)) {
586       model = null;
587     } else if (INNER_GRAPH_VIEW_BINDING.equals(clientItfName)) {
588       innerGraphView = null;
589       remove(innerGraphPanel);
590     } else if (clientItfName.startsWith(DIALOG_VIEW_LISTENERS_BINDING)) {
591       listeners.remove(clientItfName);
592     }
593   }
594
595   // -------------------------------------------------------------------------
596
// Implementation of the ConfigurationListener interface
597
// -------------------------------------------------------------------------
598

599   public void changeCountChanged (Component component, long changeCount) {
600     // does nothing
601
}
602
603   public void rootComponentChanged (final Component oldValue) {
604     statusChanged();
605   }
606
607   public void nameChanged (final Component component, final String JavaDoc oldValue) {
608     if (component == configuration.getRootComponent()) {
609       statusChanged();
610     }
611   }
612
613   public void typeChanged (final Component component, final String JavaDoc oldValue) {
614     if (component == configuration.getRootComponent()) {
615       statusChanged();
616     }
617   }
618
619   public void implementationChanged (
620     final Component component,
621     final String JavaDoc oldValue)
622   {
623     if (component == configuration.getRootComponent()) {
624       statusChanged();
625     }
626   }
627
628   public void interfaceNameChanged (final Interface i, final String JavaDoc oldValue) {
629     // does nothing
630
}
631
632   public void interfaceSignatureChanged (
633     final Interface i,
634     final String JavaDoc oldValue)
635   {
636     // does nothing
637
}
638
639   public void interfaceContingencyChanged (
640     final Interface i,
641     final boolean oldValue)
642   {
643     // does nothing
644
}
645
646   public void interfaceCardinalityChanged (
647     final Interface i,
648     final boolean oldValue)
649   {
650     // does nothing
651
}
652
653   public void clientInterfaceAdded (
654     final Component component,
655     final ClientInterface i,
656     final int index)
657   {
658     // does nothing
659
}
660
661   public void clientInterfaceRemoved (
662     final Component component,
663     final ClientInterface i,
664     final int index)
665   {
666     // does nothing
667
}
668
669   public void serverInterfaceAdded (
670     final Component component,
671     final ServerInterface i,
672     final int index)
673   {
674     // does nothing
675
}
676
677   public void serverInterfaceRemoved (
678     final Component component,
679     final ServerInterface i,
680     final int index)
681   {
682     // does nothing
683
}
684
685   public void interfaceBound (
686     final ClientInterface citf,
687     final ServerInterface sitf)
688   {
689     // does nothing
690
}
691
692   public void interfaceRebound (
693     final ClientInterface citf,
694     final ServerInterface oldSitf)
695   {
696     // does nothing
697
}
698
699   public void interfaceUnbound (
700     final ClientInterface citf,
701     final ServerInterface sitf)
702   {
703     // does nothing
704
}
705
706   public void attributeControllerChanged (
707     final Component component,
708     final String JavaDoc oldValue)
709   {
710     if (component == configuration.getRootComponent()) {
711       statusChanged();
712     }
713   }
714
715   public void attributeChanged (
716     final Component component,
717     final String JavaDoc attributeName,
718     final String JavaDoc oldValue)
719   {
720     if (component == configuration.getRootComponent()) {
721       statusChanged();
722     }
723   }
724
725   public void templateControllerDescriptorChanged (
726     final Component component,
727     final String JavaDoc oldValue)
728   {
729     // does nothing
730
}
731
732   public void componentControllerDescriptorChanged (
733     final Component component,
734     final String JavaDoc oldValue)
735   {
736     // does nothing
737
}
738
739   public void subComponentAdded (
740     final Component parent,
741     final Component child,
742     final int index)
743   {
744     if (parent == configuration.getRootComponent()) {
745       statusChanged();
746     }
747   }
748
749   public void subComponentRemoved (
750     final Component parent,
751     final Component child,
752     final int index)
753   {
754     if (parent == configuration.getRootComponent()) {
755       statusChanged();
756     }
757   }
758
759   /**
760    * Updates the colors of the text fields to reflect a change in the
761    * component's status. This method is called each time the component's status
762    * may have changed.
763    */

764
765   private void statusChanged () {
766     long status = configuration.getRootComponent().getStatus();
767     nameField.setBackground(
768       (status & Component.NAME_MISSING) == 0 ?
769       Color.white :
770       Constants.ERROR_COLOR);
771     /*typeField.setBackground(
772       (status & Component.TYPE_MISSING) == 0 ?
773       Color.white :
774       Constants.ERROR_COLOR);*/

775     classField.setBackground(
776       (status & Component.IMPLEMENTATION_MISSING) == 0 ?
777       Color.white :
778       Constants.ERROR_COLOR);
779     classField.setForeground(
780       (status & Component.IMPLEMENTATION_CLASS_NOT_FOUND) == 0 ?
781       Color.black :
782       Constants.ERROR_COLOR);
783     attrControllerField.setBackground(
784       (status & Component.ATTRIBUTE_CONTROLLER_MISSING) == 0 ?
785       Color.white :
786       Constants.ERROR_COLOR);
787     attrControllerField.setForeground(
788       (status & Component.ATTRIBUTE_CONTROLLER_CLASS_NOT_FOUND) == 0 ?
789       Color.black :
790       Constants.ERROR_COLOR);
791   }
792
793   // -------------------------------------------------------------------------
794
// Other methods
795
// -------------------------------------------------------------------------
796

797   public void setVisible (final boolean visible) {
798     super.setVisible(visible);
799     if (innerGraphView != null) {
800       innerGraphView.setVisible(visible);
801     }
802   }
803
804   /**
805    * An action listener used to notify the listeners of this view when buttons
806    * are clicked.
807    */

808
809   class ButtonListener implements ActionListener JavaDoc {
810
811     public void actionPerformed (final ActionEvent JavaDoc e) {
812       Object JavaDoc o = e.getSource();
813       List JavaDoc listeners = new ArrayList JavaDoc(BasicDialogView.this.listeners.values());
814       if (o == itfAddButton[0]) {
815         for (int i = 0; i < listeners.size(); ++i) {
816           DialogViewListener l = (DialogViewListener)listeners.get(i);
817           l.addClientInterfaceButtonClicked();
818         }
819       } else if (o == itfAddButton[1]) {
820         for (int i = 0; i < listeners.size(); ++i) {
821           DialogViewListener l = (DialogViewListener)listeners.get(i);
822           l.addServerInterfaceButtonClicked();
823         }
824       } else if (o == itfRemoveButton[0]) {
825         for (int i = 0; i < listeners.size(); ++i) {
826           DialogViewListener l = (DialogViewListener)listeners.get(i);
827           l.removeClientInterfaceButtonClicked();
828         }
829         itfRemoveButton[0].setEnabled(false);
830       } else if (o == itfRemoveButton[1]) {
831         for (int i = 0; i < listeners.size(); ++i) {
832           DialogViewListener l = (DialogViewListener)listeners.get(i);
833           l.removeServerInterfaceButtonClicked();
834         }
835         itfRemoveButton[1].setEnabled(false);
836       } else if (o == attrAddButton) {
837         for (int i = 0; i < listeners.size(); ++i) {
838           DialogViewListener l = (DialogViewListener)listeners.get(i);
839           l.addAttributeButtonClicked();
840         }
841       } else if (o == attrRemoveButton) {
842         for (int i = 0; i < listeners.size(); ++i) {
843           DialogViewListener l = (DialogViewListener)listeners.get(i);
844           l.removeAttributeButtonClicked();
845         }
846       }
847     }
848   }
849
850   /**
851    * A table selection listener to enable or disable the "add" and "remove"
852    * buttons when the selection of a table changes.
853    */

854
855   class ListListener implements ListSelectionListener JavaDoc {
856
857     public void valueChanged (final ListSelectionEvent JavaDoc e) {
858       ListSelectionModel JavaDoc l;
859       l = model.getClientInterfacesTableSelectionModel();
860       if (e.getSource() == l) {
861         itfRemoveButton[0].setEnabled(!l.isSelectionEmpty());
862       }
863       l = model.getServerInterfacesTableSelectionModel();
864       if (e.getSource() == l) {
865         itfRemoveButton[1].setEnabled(!l.isSelectionEmpty());
866       }
867       l = model.getAttributesTableSelectionModel();
868       if (e.getSource() == l) {
869         attrRemoveButton.setEnabled(!l.isSelectionEmpty());
870       }
871     }
872   }
873
874   /**
875    * A specific button listener to fill classField.
876    */

877
878   class ClassFieldButtonListener implements ActionListener JavaDoc {
879     public void actionPerformed (final ActionEvent JavaDoc e) {
880       if (e.getActionCommand().equals("Impl.")) {
881         String JavaDoc st = ClassSelector.initSelector();
882         if (st.length() < 1) classField.setText(st);
883         else {
884           int i = st.indexOf(".class");
885           if (i < 0) {
886             classField.setText(st);
887           } else {
888             classField.setText(st.substring(0, i));
889           }
890         }
891         statusChanged ();
892       }
893     }
894   }
895 }
896
Popular Tags