KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfClientComponents > gui > GuiClient


1 package ist.coach.coachEmfClientComponents.gui;
2
3 import javax.swing.border.Border JavaDoc;
4 import javax.swing.border.EtchedBorder JavaDoc;
5 import javax.swing.border.Border JavaDoc;
6 import javax.swing.BorderFactory JavaDoc;
7 import javax.swing.JFrame JavaDoc;
8 import javax.swing.JTree JavaDoc;
9 import javax.swing.JPanel JavaDoc;
10 import javax.swing.JTextArea JavaDoc;
11 import javax.swing.JScrollPane JavaDoc;
12 import javax.swing.tree.*;
13 import javax.swing.JPopupMenu JavaDoc;
14 import javax.swing.JMenuItem JavaDoc;
15 import javax.swing.JMenu JavaDoc;
16 import javax.swing.JMenuBar JavaDoc;
17 import javax.swing.JSplitPane JavaDoc;
18 import javax.swing.JButton JavaDoc;
19 import javax.swing.JOptionPane JavaDoc;
20 import javax.swing.JCheckBoxMenuItem JavaDoc;
21 import javax.swing.JRadioButtonMenuItem JavaDoc;
22 import javax.swing.event.TreeSelectionEvent JavaDoc;
23 import javax.swing.event.TreeModelListener JavaDoc;
24 import javax.swing.event.TreeModelEvent JavaDoc;
25 import javax.swing.tree.TreeSelectionModel JavaDoc;
26 import javax.swing.JTextField JavaDoc;
27
28 import javax.swing.event.ListSelectionListener JavaDoc;
29 import javax.swing.ListSelectionModel JavaDoc;
30 import javax.swing.event.ListSelectionEvent JavaDoc;
31
32 import java.awt.event.MouseEvent JavaDoc;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.awt.event.ItemEvent JavaDoc;
35 import java.awt.event.MouseListener JavaDoc;
36 import java.awt.event.ActionListener JavaDoc;
37 import java.awt.event.ItemListener JavaDoc;
38 import java.awt.GridLayout JavaDoc;
39 import java.awt.BorderLayout JavaDoc;
40 import java.awt.Dimension JavaDoc;
41
42 import java.util.Hashtable JavaDoc;
43 import java.util.Enumeration JavaDoc;
44 import java.util.Properties JavaDoc;
45
46 import ist.coach.coachEmfCommon.Utils;
47 import ist.coach.coachEmfClientComponents.InvokeSetData;
48 //import org.omg.CosNaming.NameComponent;
49

50 public class GuiClient extends JFrame JavaDoc
51 implements MouseListener JavaDoc, Runnable JavaDoc {
52
53     GuiMaster master;
54     private String JavaDoc name;
55     //Hashtable objectVisualTypeTable;
56
Properties JavaDoc objectVisualTypeProps;
57     Hashtable JavaDoc actions_popups;
58     Hashtable JavaDoc alarmTableH, logTableH;
59
60     final MOTree treePanel;
61
62     private SubordinateListener subListener;
63     private PropertiesListener propertiesListener;
64     private DeleteListener deleteListener;
65     private RefreshListener refreshListener;
66
67     private AlarmTableModel alarmModel = null;
68     private LogTableModel logModel = null;
69
70     JCheckBoxMenuItem JavaDoc[] cbox_item;
71     ClientListener clientListener;
72     AlarmButtonListener alarmButtonListener;
73     LogButtonListener logButtonListener;
74
75     int logSelectedRow, logSelectedCol, alarmSelectedRow, alarmSelectedCol;
76     JTextField JavaDoc logTextField, alarmTextField;
77
78
79     private static final String JavaDoc typesConfigFile = "elementTypes.conf";
80
81     public GuiClient(String JavaDoc name,
82             String JavaDoc root_name, GuiMaster master) {
83
84         super(name);
85         this.master = master;
86         set_name(name);
87
88         configure_data();
89         clientListener = new ClientListener();
90         alarmButtonListener = new AlarmButtonListener();
91         logButtonListener = new LogButtonListener();
92
93
94         logTextField = new JTextField JavaDoc(60);
95         logTextField.setEditable(false);
96         logTextField.setBackground(java.awt.Color.LIGHT_GRAY);
97         java.awt.Font JavaDoc textDisplayFont = logTextField.getFont();
98         textDisplayFont = textDisplayFont.deriveFont((float) textDisplayFont.getSize()-1);
99         logTextField.setFont(textDisplayFont);
100
101         alarmTextField = new JTextField JavaDoc(60);
102         alarmTextField.setEditable(false);
103         alarmTextField.setBackground(java.awt.Color.LIGHT_GRAY);
104         alarmTextField.setFont(textDisplayFont);
105
106         treePanel = new MOTree(this, root_name);
107         treePanel.setBorder(BorderFactory.createTitledBorder(GuiMessages.gui_client_mib));
108         treePanel.addMouseListener(this);
109         treePanel.tree.addMouseListener(this);
110
111         AlarmTypeItemListener alarmTypeListener = new AlarmTypeItemListener();
112         HeartbeatTypeItemListener heartbeatTypeItemListener = new HeartbeatTypeItemListener();
113
114         LogTypeItemListener logTypeListener = new LogTypeItemListener();
115         // Constructs and shows the GUI.
116

117         JMenuBar JavaDoc centralBar = new JMenuBar JavaDoc();
118         JMenu JavaDoc fileMenu = new JMenu JavaDoc("File");
119         JMenuItem JavaDoc exitItem = new JMenuItem JavaDoc(GuiMessages.exit_str);
120         exitItem.addActionListener(clientListener);
121         fileMenu.add(exitItem);
122         centralBar.add(fileMenu);
123         setJMenuBar(centralBar);
124
125             /** Setup the LOG Panel ****/
126         JPanel JavaDoc logPanel = new JPanel JavaDoc();
127         logPanel.setLayout(new BorderLayout JavaDoc());
128
129                   // set up menu bar to hold log options
130
JMenuBar JavaDoc logMenuBar = new JMenuBar JavaDoc();
131         logMenuBar.setBorderPainted(true);
132         logMenuBar.setBorder(BorderFactory.createLineBorder(java.awt.Color.black));
133         logMenuBar.setMargin(new java.awt.Insets JavaDoc(0,0,0,0));
134
135                   // set up log menu to filter logs
136
JMenu JavaDoc logTypeMenu = new JMenu JavaDoc(GuiMessages.log_menu_title);
137         logTypeMenu.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
138
139         logTypeMenu.getAccessibleContext().setAccessibleDescription(
140             GuiMessages.log_filter_event_types);
141
142         cbox_item = new JCheckBoxMenuItem JavaDoc[logTableH.size()];
143         int j = 0;
144         for (Enumeration JavaDoc e = logTableH.keys(); e.hasMoreElements();) {
145             cbox_item[j] = new JCheckBoxMenuItem JavaDoc((String JavaDoc) e.nextElement(), true);
146             cbox_item[j].addItemListener(logTypeListener);
147             logTypeMenu.add(cbox_item[j]);
148             j++;
149         }
150         logMenuBar.add(logTypeMenu);
151                 // add archives button to LogTable
152
JButton JavaDoc log_archives_button = new JButton JavaDoc(GuiMessages.log_archives_title);
153         log_archives_button.addActionListener(logButtonListener);
154         log_archives_button.setToolTipText(GuiMessages.log_archives_tooltip_str);
155         logMenuBar.add(log_archives_button);
156
157                 // add clear button to Log Table
158
logMenuBar.add(javax.swing.Box.createHorizontalGlue());
159         JButton JavaDoc log_clear_button = new JButton JavaDoc(GuiMessages.clear_str);
160         log_clear_button.addActionListener(logButtonListener);
161         log_clear_button.setToolTipText(GuiMessages.clear_tooltip_str);
162         logMenuBar.add(log_clear_button);
163
164
165                 // Setup thr log Tanle panel....
166
JLogTable logTable = new JLogTable(logModel);
167         logTable.setPreferredScrollableViewportSize(new Dimension JavaDoc(700, 150)); //700, 200
168
logTable.setCellSelectionEnabled(false);
169         //logTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
170

171         logTable.getColumnModel().getColumn(AlarmTableModel.TIME_C).setPreferredWidth(120);
172         logTable.getColumnModel().getColumn(AlarmTableModel.EVENT_C).setPreferredWidth(100);
173         logTable.getColumnModel().getColumn(AlarmTableModel.SOURCE_C).setPreferredWidth(200);
174         logTable.getColumnModel().getColumn(AlarmTableModel.SOURCE_T_C).setPreferredWidth(100);
175         logTable.getColumnModel().getColumn(AlarmTableModel.ID_C).setPreferredWidth(60);
176         logTable.getColumnModel().getColumn(AlarmTableModel.DETAILS_C).setPreferredWidth(120);
177
178         JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(logTable);
179 /** get selections **/
180         logTable.getColumnModel().getSelectionModel().
181             addListSelectionListener( new ListSelectionListener JavaDoc() {
182
183                 public void valueChanged(ListSelectionEvent JavaDoc e) {
184
185                     if(e.getValueIsAdjusting()) return;
186                     ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)e.getSource();
187                     if (! lsm.isSelectionEmpty()) {
188                         logSelectedCol = lsm.getMinSelectionIndex();
189                         if (logModel.getValueAt(logSelectedRow, logSelectedCol) != null)
190                             logTextField.setText((String JavaDoc) logModel.getValueAt(
191                                     logSelectedRow, logSelectedCol));
192                     }
193                 }
194         });
195         logTable.getSelectionModel().addListSelectionListener(new ListSelectionListener JavaDoc() {
196
197             public void valueChanged(ListSelectionEvent JavaDoc e) {
198
199                     if(e.getValueIsAdjusting()) return;
200                     ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)e.getSource();
201                     if (! lsm.isSelectionEmpty()) {
202                         logSelectedRow = lsm.getMinSelectionIndex();
203                         if (logModel.getValueAt(logSelectedRow, logSelectedCol) != null)
204                             logTextField.setText((String JavaDoc) logModel.getValueAt( logSelectedRow, logSelectedCol));
205                     }
206             }
207             }
208         );
209 /** end - get selections **/
210         scrollPane.setPreferredSize(new Dimension JavaDoc(250, 150)); //300, 500
211
scrollPane.setMinimumSize(new Dimension JavaDoc(100, 100));
212         logPanel.add(logMenuBar, BorderLayout.NORTH);
213         logPanel.add(scrollPane);
214
215         logPanel.add(logTextField, BorderLayout.SOUTH);
216         logPanel.setBorder(BorderFactory.createTitledBorder(GuiMessages.gui_client_log));
217
218
219                     /****Position Log Panel ***/
220         JSplitPane JavaDoc splitPane = new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT,
221                 treePanel, logPanel);
222         splitPane.setOneTouchExpandable(true);
223         splitPane.setDividerLocation(150);
224
225         //Provide a preferred size for the split pane
226
splitPane.setPreferredSize(new Dimension JavaDoc(700, 400)); //700, 500
227
getContentPane().add(splitPane);
228
229                 /* Setup the Alarm Panel */
230           // set up menu bar to hold alarm options
231
JMenuBar JavaDoc alarmMenuBar = new JMenuBar JavaDoc();
232         alarmMenuBar.setBorderPainted(true);
233         alarmMenuBar.setBorder(BorderFactory.createLineBorder(java.awt.Color.black));
234         alarmMenuBar.setMargin(new java.awt.Insets JavaDoc(0,0,0,0));
235
236           // set up alarm menu to subscribe/unsubscribe to alarms
237
JMenu JavaDoc alarmTypeMenu = new JMenu JavaDoc(GuiMessages.alarm_menu_title);
238         alarmTypeMenu.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
239
240         alarmTypeMenu.getAccessibleContext().setAccessibleDescription(
241             GuiMessages.alarm_filter_event_types);
242
243         cbox_item = new JCheckBoxMenuItem JavaDoc[alarmTableH.size()];
244         int k = 0;
245         for (Enumeration JavaDoc e = alarmTableH.keys(); e.hasMoreElements();) {
246             cbox_item[k] = new JCheckBoxMenuItem JavaDoc((String JavaDoc) e.nextElement(), true);
247             cbox_item[k].addItemListener(alarmTypeListener);
248             alarmTypeMenu.add(cbox_item[k]);
249             k++;
250         }
251         alarmMenuBar.add(alarmTypeMenu);
252
253           // set up heatbeat period options
254
JMenu JavaDoc heartbeatTypeMenu = new JMenu JavaDoc(GuiMessages.heartbeat_menu_title);
255         heartbeatTypeMenu.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
256
257         javax.swing.ButtonGroup JavaDoc group = new javax.swing.ButtonGroup JavaDoc();
258         heartbeatTypeMenu.getAccessibleContext().setAccessibleDescription(
259             GuiMessages.heartbeat_tooltip_str);
260         JRadioButtonMenuItem JavaDoc[] heartbeat_items = new JRadioButtonMenuItem JavaDoc[5];
261         heartbeat_items[0] = new JRadioButtonMenuItem JavaDoc(GuiMessages.heartbeat_period_200, false);
262         heartbeat_items[1] = new JRadioButtonMenuItem JavaDoc(GuiMessages.heartbeat_period_100, true);
263         heartbeat_items[2] = new JRadioButtonMenuItem JavaDoc(GuiMessages.heartbeat_period_50, false);
264         heartbeat_items[3] = new JRadioButtonMenuItem JavaDoc(GuiMessages.heartbeat_period_20, false);
265         heartbeat_items[4] = new JRadioButtonMenuItem JavaDoc(GuiMessages.heartbeat_period_0, false);
266
267         for (int h = 0; h < heartbeat_items.length; h++) {
268             heartbeat_items[h].addItemListener(heartbeatTypeItemListener);
269             group.add(heartbeat_items[h]);
270             heartbeatTypeMenu.add(heartbeat_items[h]);
271         }
272         alarmMenuBar.add(heartbeatTypeMenu);
273
274         // add clear button
275
alarmMenuBar.add(javax.swing.Box.createHorizontalGlue());
276         JButton JavaDoc clear_button = new JButton JavaDoc(GuiMessages.clear_str);
277         clear_button.addActionListener(alarmButtonListener);
278         clear_button.setToolTipText(GuiMessages.clear_tooltip_str);
279         alarmMenuBar.add(clear_button);
280
281
282         JPanel JavaDoc alarmPanel = new JPanel JavaDoc();
283         alarmPanel.setLayout(new BorderLayout JavaDoc());
284
285         JAlarmTable alarmTable = new JAlarmTable(alarmModel);
286         alarmTable.setPreferredScrollableViewportSize(new Dimension JavaDoc(700, 150)); //700, 200
287
alarmTable.setCellSelectionEnabled(false);
288         //alarmTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
289
alarmTable.getColumnModel().getColumn(AlarmTableModel.TIME_C).setPreferredWidth(120);
290         alarmTable.getColumnModel().getColumn(AlarmTableModel.EVENT_C).setPreferredWidth(100);
291         alarmTable.getColumnModel().getColumn(AlarmTableModel.SOURCE_C).setPreferredWidth(100);
292         alarmTable.getColumnModel().getColumn(AlarmTableModel.SOURCE_T_C).setPreferredWidth(100);
293         alarmTable.getColumnModel().getColumn(AlarmTableModel.ID_C).setPreferredWidth(60);
294         alarmTable.getColumnModel().getColumn(AlarmTableModel.DETAILS_C).setPreferredWidth(220);
295 /** get selections **/
296         alarmTable.getColumnModel().getSelectionModel().
297             addListSelectionListener( new ListSelectionListener JavaDoc() {
298
299                 public void valueChanged(ListSelectionEvent JavaDoc e) {
300
301                     if(e.getValueIsAdjusting()) return;
302                     ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)e.getSource();
303                     if (! lsm.isSelectionEmpty()) {
304                         alarmSelectedCol = lsm.getMinSelectionIndex();
305                         if (alarmModel.getValueAt(alarmSelectedRow, alarmSelectedCol) != null)
306                             alarmTextField.setText((String JavaDoc) alarmModel.getValueAt(
307                                 alarmSelectedRow, alarmSelectedCol));
308                     }
309                 }
310         });
311         alarmTable.getSelectionModel().addListSelectionListener(new ListSelectionListener JavaDoc() {
312
313             public void valueChanged(ListSelectionEvent JavaDoc e) {
314
315                     if(e.getValueIsAdjusting()) return;
316                     ListSelectionModel JavaDoc lsm = (ListSelectionModel JavaDoc)e.getSource();
317                     if (! lsm.isSelectionEmpty()) {
318                         alarmSelectedRow = lsm.getMinSelectionIndex();
319                         if (alarmModel.getValueAt(alarmSelectedRow, alarmSelectedCol) != null)
320                             alarmTextField.setText((String JavaDoc) alarmModel.getValueAt( alarmSelectedRow, alarmSelectedCol));
321                     }
322             }
323             }
324         );
325 /** end - get selections **/
326         JScrollPane JavaDoc alarmScrollPane = new JScrollPane JavaDoc(alarmTable);
327
328         alarmScrollPane.setPreferredSize(new Dimension JavaDoc(200, 150));
329         alarmScrollPane.setMinimumSize(new Dimension JavaDoc(10, 10));
330         alarmPanel.add(alarmMenuBar, BorderLayout.NORTH);
331         alarmPanel.add(alarmScrollPane);
332         alarmPanel.add(alarmTextField, BorderLayout.SOUTH);
333         alarmPanel.setBorder(BorderFactory.createTitledBorder(GuiMessages.gui_client_alarms));
334
335         JSplitPane JavaDoc alarmSplitPane = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT,
336             splitPane, alarmPanel);
337         alarmSplitPane.setOneTouchExpandable(true);
338             //300
339
alarmSplitPane.setDividerLocation(400);
340
341         getContentPane().add(alarmSplitPane);
342
343
344         subListener = new SubordinateListener(this);
345         propertiesListener = new PropertiesListener();
346         deleteListener = new DeleteListener();
347         refreshListener = new RefreshListener();
348
349
350         // update tree model
351
String JavaDoc[] children = getContained(
352             ((MOTreeObject) treePanel.rootNode.getUserObject()).key());
353
354         if (children != null && children.length > 0) {
355             for(int i = 0; i < children.length; i++)
356                 create(treePanel.rootNode, children[i]);
357         }
358         pack();
359         show();
360
361     }
362
363     //HACK THREAD
364
public void run() {}
365     public void configure_data() {
366
367         // HACK - needs improvement
368
// this part could be externally configured through
369
// properties file
370
//
371

372         objectVisualTypeProps = new Properties JavaDoc();
373         try {
374             System.out.println("Loading file " + typesConfigFile);
375             objectVisualTypeProps.load(GuiClient.class.getResourceAsStream(typesConfigFile));
376         }
377         catch (Exception JavaDoc e) {
378             e.printStackTrace();
379             return;
380         }
381
382         //objectVisualTypeTable = new Hashtable();
383
actions_popups = new Hashtable JavaDoc();
384         alarmTableH = new Hashtable JavaDoc();
385         logTableH = new Hashtable JavaDoc();
386
387         alarmModel = new AlarmTableModel();
388         logModel = new LogTableModel();
389 /**********************************
390         objectVisualTypeTable.put("ManagedObject",
391             "ist.coach.coachEmfClientComponents.gui.MOTreeObject");
392
393         objectVisualTypeTable.put("ManagedElement",
394             "ist.coach.coachEmfClientComponents.gui.VisualManagedElement");
395
396         objectVisualTypeTable.put("IpNode",
397             "ist.coach.coachEmfClientComponents.gui.VisualIpNode");
398
399         objectVisualTypeTable.put("LogicalInterface",
400             "ist.coach.coachEmfClientComponents.gui.VisualLogicalInterface");
401
402         objectVisualTypeTable.put("IpProtocolMonitor",
403             "ist.coach.coachEmfClientComponents.gui.VisualIpProtocolMonitor");
404
405         objectVisualTypeTable.put("IpAddressData",
406              "ist.coach.coachEmfClientComponents.gui.VisualIpAddressData");
407
408         objectVisualTypeTable.put("IpRoutingEntry",
409              "ist.coach.coachEmfClientComponents.gui.VisualIpRoutingEntry");
410
411         objectVisualTypeTable.put("IpToMACAddress",
412                "ist.coach.coachEmfClientComponents.gui.VisualIpToMACAddress");
413 ********************************************/

414         alarmTableH.put(GuiMessages.object_creation_alarm,
415                             GuiMaster.OBJECT_CREATION_ALARM);
416         alarmTableH.put(GuiMessages.object_deletion_alarm,
417                             GuiMaster.OBJECT_DELETION_ALARM);
418         alarmTableH.put(GuiMessages.state_changed_alarm,
419                             GuiMaster.STATE_CHANGED_ALARM);
420         alarmTableH.put(GuiMessages.operation_violation_alarm,
421                             GuiMaster.OPERATIONAL_ALARM);
422         alarmTableH.put(GuiMessages.channel_change_alarm,
423                             GuiMaster.CHANNEL_CHANGE_ALARM);
424         alarmTableH.put(GuiMessages.heartbeat_alarm,
425                             GuiMaster.HEARTBEAT_ALARM);
426
427         logTableH.put(GuiMessages.info_log,
428                             GuiMaster.INFO_LOG);
429         logTableH.put(GuiMessages.error_log,
430                             GuiMaster.ERROR_LOG);
431         logTableH.put(GuiMessages.warning_log,
432                             GuiMaster.WARNING_LOG);
433     }
434
435     public void set_name(String JavaDoc name) {
436         this.name = name;
437         setTitle(name);
438     }
439
440     public synchronized void print(String JavaDoc dateR, String JavaDoc eventType, String JavaDoc source,
441             String JavaDoc sourceClass, String JavaDoc notifId, String JavaDoc details) {
442
443       //System.err.println("GuiClient> print log event is called...");
444
if (logModel == null)
445             return;
446         //System.err.println("GuiClient> print proceed to update log table...");
447
logModel.updateLogTable(dateR,
448                         eventType,
449                         source,
450                         sourceClass,
451                         notifId,
452                         details);
453     }
454     public static synchronized void println(String JavaDoc msg) {
455         System.err.println(msg);
456
457     }
458
459     public synchronized void print_alarm(String JavaDoc dateR, String JavaDoc eventType, String JavaDoc source,
460             String JavaDoc sourceClass, String JavaDoc notifId, String JavaDoc details) {
461
462
463         if (alarmModel == null)
464             return;
465
466         alarmModel.updateAlarmTable(dateR,
467                     eventType,
468                     source,
469                     sourceClass,
470                     notifId,
471                      details);
472
473     }
474
475
476 public JPopupMenu JavaDoc get_menu(String JavaDoc visual_class_name) {
477
478     if (actions_popups.containsKey(visual_class_name))
479         return (JPopupMenu JavaDoc) actions_popups.get(visual_class_name);
480
481     // else proceed to create
482
//
483
JPopupMenu JavaDoc popup = new JPopupMenu JavaDoc();
484     String JavaDoc[] subordinate_names = null;
485     Class JavaDoc object_class = null;
486     boolean canRefresh = false;
487     try {
488         object_class = Class.forName(visual_class_name);
489         subordinate_names =
490                     (String JavaDoc[])object_class.
491                                 getDeclaredField("subordinate_names").get(null);
492         canRefresh = (boolean) ((Boolean JavaDoc) object_class.
493                                 getDeclaredField("canRefresh").get(null)).booleanValue();
494     }
495     catch(java.lang.ClassNotFoundException JavaDoc ex1) {
496         System.err.println("mouseClicked> ClassNotFoundException " +
497         ex1.getMessage());
498     }
499     catch(java.lang.IllegalAccessException JavaDoc ex2) {
500         System.err.println("mouseClicked> IllegalAccessException " +
501         ex2.getMessage());
502     }
503     catch(java.lang.NoSuchFieldException JavaDoc ex3) {
504         System.err.println("mouseClicked> NoSuchFieldException " +
505                 ex3.getMessage());
506             // ex3.printStackTrace();
507
}
508
509
510            // If managers can create subordinate objects
511
if (subordinate_names.length > 0) {
512        JMenu JavaDoc create_menu = new JMenu JavaDoc(GuiMessages.options_create);
513        JMenuItem JavaDoc subordinate;
514         for (int i = 0; i < subordinate_names.length; i++) {
515               if (objectVisualTypeProps.getProperty(subordinate_names[i])== null)
516                       continue;
517               subordinate = new JMenuItem JavaDoc(subordinate_names[i]);
518               subordinate.addActionListener(subListener);
519               create_menu.add(subordinate);
520         }
521         popup.add(create_menu);
522     }
523
524     JMenuItem JavaDoc properties_item = new JMenuItem JavaDoc(GuiMessages.options_properties);
525     properties_item.addActionListener(propertiesListener);
526     popup.add(properties_item);
527
528     JMenuItem JavaDoc delete_item = new JMenuItem JavaDoc(GuiMessages.options_delete);
529     delete_item.addActionListener(deleteListener);
530     popup.add(delete_item);
531
532     if (canRefresh) {
533         JMenuItem JavaDoc refresh_item = new JMenuItem JavaDoc(GuiMessages.options_refresh);
534         refresh_item.addActionListener(refreshListener);
535         popup.add(refresh_item);
536     }
537     actions_popups.put(visual_class_name, popup);
538     return popup;
539 }
540
541 public String JavaDoc getObjectType(String JavaDoc key) {
542
543     //System.err.println("getObjectType called for " + key);
544
String JavaDoc obj_type = new String JavaDoc();
545     //String obj_type = MOTreeObject.object_type;
546
String JavaDoc label = key;
547
548     int lastIndex = key.lastIndexOf("/");
549     int objIndex = 0;
550     if (lastIndex > 0) {
551         String JavaDoc object_id = key.substring(0, lastIndex);
552         if (object_id != null && object_id.length() > 0 &&
553                 (objIndex = object_id.lastIndexOf("/")) > 0) {
554
555                         // label contains both name and kind
556

557                 label = object_id.substring(objIndex+1);
558         }
559     }
560     if (label!= null && label.length() > 0) {
561         lastIndex =label.lastIndexOf(".");
562
563         if (lastIndex > 0)
564             obj_type = label.substring(lastIndex+1);
565     }
566
567     return obj_type;
568 }
569
570 public String JavaDoc[] getContained(String JavaDoc key) {
571     return master.getContained(key);
572 }
573
574 //
575
// this operation is called by the GUI on start-up for recursive creation
576
//
577
public void create(DefaultMutableTreeNode parent, String JavaDoc key) {
578
579     DefaultMutableTreeNode node = create(parent, key, getObjectType(key));
580     String JavaDoc [] children = master.getContained(key);
581     for (int i = 0; i < children.length; i++)
582         create(node, children[i]);
583 }
584
585 //
586
// this operation is called by the recursive create on start-up
587
//
588
public DefaultMutableTreeNode create(DefaultMutableTreeNode parent,
589         String JavaDoc key, String JavaDoc obj_type) {
590
591     DefaultMutableTreeNode node = new DefaultMutableTreeNode();
592    // String visual_class = (String) objectVisualTypeTable.get(obj_type);
593
String JavaDoc visual_class = (String JavaDoc) objectVisualTypeProps.getProperty(obj_type);
594     //System.err.println("Visually create " + visual_class + " with key= " + key);
595

596     Class JavaDoc vtype;
597     Class JavaDoc[] consArgsClass = new Class JavaDoc[] {String JavaDoc.class};
598     java.lang.reflect.Constructor JavaDoc vtype_constructor;
599
600     try {
601         vtype = Class.forName(visual_class);
602         vtype_constructor = vtype.getConstructor(consArgsClass);
603         node = treePanel.addObject(parent, vtype_constructor.newInstance(new Object JavaDoc[] {key}));
604
605         //treePanel.addObject(new MOTreeObject(key));
606
//treePanel.addObject(new MOTreeObject(key, obj));
607
}
608     catch(java.lang.IllegalArgumentException JavaDoc e1) {
609             System.err.println("IllegalArgumentException");
610     }
611     catch(java.lang.IllegalAccessException JavaDoc e2) {
612             System.err.println("IllegalAccessException");
613     }
614     catch(java.lang.ClassNotFoundException JavaDoc e3) {
615             System.err.println("ClassNotFoundException");
616     }
617     catch(java.lang.NoSuchMethodException JavaDoc e4) {
618           System.err.println("NoSuchMethodException");
619     }
620     catch(java.lang.InstantiationException JavaDoc e5) {
621           System.err.println("InstantiationException");
622     }
623     catch(java.lang.reflect.InvocationTargetException JavaDoc e6) {
624           System.err.println("InvocationTargetException:" + e6.getMessage());
625             e6.printStackTrace();
626     }
627
628     return node;
629 }
630
631 public void create(String JavaDoc key, String JavaDoc obj_type) {
632
633     //String visual_class = (String) objectVisualTypeTable.get(obj_type);
634
String JavaDoc visual_class = (String JavaDoc) objectVisualTypeProps.getProperty(obj_type);
635
636     Class JavaDoc vtype;
637     Class JavaDoc[] consArgsClass = new Class JavaDoc[] {String JavaDoc.class};
638     java.lang.reflect.Constructor JavaDoc vtype_constructor;
639
640     try {
641         vtype = Class.forName(visual_class);
642         vtype_constructor = vtype.getConstructor(consArgsClass);
643         treePanel.addObject(vtype_constructor.newInstance(new Object JavaDoc[] {key}));
644
645         //treePanel.addObject(new MOTreeObject(key));
646
//treePanel.addObject(new MOTreeObject(key, obj));
647
}
648     catch(java.lang.IllegalArgumentException JavaDoc e1) {
649             System.err.println("IllegalArgumentException");
650     }
651     catch(java.lang.IllegalAccessException JavaDoc e2) {
652             System.err.println("IllegalAccessException");
653     }
654     catch(java.lang.ClassNotFoundException JavaDoc e3) {
655             System.err.println("ClassNotFoundException");
656     }
657     catch(java.lang.NoSuchMethodException JavaDoc e4) {
658           System.err.println("NoSuchMethodException");
659     }
660     catch(java.lang.InstantiationException JavaDoc e5) {
661           System.err.println("InstantiationException");
662     }
663     catch(java.lang.reflect.InvocationTargetException JavaDoc e6) {
664           System.err.println("InvocationTargetException:" + e6.getMessage());
665             e6.printStackTrace();
666     }
667
668 }
669
670 /*
671  * MouseListener Operations
672  *
673  */

674     public void mousePressed(MouseEvent JavaDoc e) {
675     }
676
677     public void mouseReleased(MouseEvent JavaDoc e) {
678     }
679
680     public void mouseEntered(MouseEvent JavaDoc e) {
681     }
682
683     public void mouseExited(MouseEvent JavaDoc e) {
684     }
685
686 public void mouseClicked(MouseEvent JavaDoc e) {
687
688         if (javax.swing.SwingUtilities.isRightMouseButton(e)) {
689             JPopupMenu JavaDoc popup = null;
690
691                 String JavaDoc object_class = treePanel.getCurrentTreeSelection().
692                     getUserObject().getClass().getName();
693                 popup = get_menu(object_class);
694
695             if (popup != null) {
696                 popup.show(e.getComponent(),
697                 e.getX(), e.getY());
698             }
699             else
700                 System.err.println("popup is null or event doesn't trigger popup");
701     }
702 }
703
704 protected String JavaDoc getClassName(Object JavaDoc o) {
705         String JavaDoc classString = o.getClass().getName();
706         int dotIndex = classString.lastIndexOf(".");
707         return classString.substring(dotIndex+1);
708 }
709
710 public void showAttributesError(String JavaDoc error_str) {
711
712         JOptionPane.showMessageDialog(treePanel,
713             error_str,
714             GuiMessages.options_properties,
715             JOptionPane.WARNING_MESSAGE);
716 }
717
718 public void showCreateError(String JavaDoc error_str) {
719
720         JOptionPane.showMessageDialog(treePanel,
721             error_str,
722             GuiMessages.options_create,
723             JOptionPane.WARNING_MESSAGE);
724 }
725
726 public void showDeleteError(String JavaDoc error_str) {
727
728         JOptionPane.showMessageDialog(treePanel,
729             error_str,
730             GuiMessages.options_delete,
731             JOptionPane.WARNING_MESSAGE);
732 }
733
734 private class SubordinateListener implements ActionListener JavaDoc {
735
736     GuiClient parent = null;
737     public SubordinateListener(GuiClient parent) {
738         this.parent = parent;
739     }
740
741     public void actionPerformed(ActionEvent JavaDoc e) {
742
743 /*****
744         println("Subordinate action has been caught!");
745         String s = "Action event detected."
746                    + "\n"
747                    + " Event source: " + source.getText()
748                    + " (an instance of " + getClassName(source) + ")";
749
750         println(s + "\n");
751         println("Parent node : " +
752             ((MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject()).key());
753
754             // GuiMessages.options_create,
755             //MOTreeObject.create_arg_name,
756             //MOTreeObject.create_arg_editor, master,
757 ******/

758
759         JMenuItem JavaDoc source = (JMenuItem JavaDoc)(e.getSource());
760         //String visual_class = (String) objectVisualTypeTable.get(source.getText());
761
String JavaDoc visual_class = (String JavaDoc) objectVisualTypeProps.getProperty(source.getText());
762
763         //String visual_class = treePanel.getCurrentTreeSelection().getUserObject().getClass().getName();
764
//println("Object to be created = " + visual_class);
765
//HACK THREAD
766
/****
767         CreateParamsFrame createFrame = new CreateParamsFrame(
768             visual_class,
769         ((MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject()).key(),
770                 master,
771                 parent,
772                 source.getX(), source.getY());
773 ******/

774       new Thread JavaDoc(new CreateParamsFrame(
775             visual_class,
776             ((MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject()).key(),
777             master,
778             parent,
779             source.getX(), source.getY()));
780
781     }
782 }
783 private class PropertiesListener implements ActionListener JavaDoc {
784     public void actionPerformed(ActionEvent JavaDoc e) {
785
786         JMenuItem JavaDoc source = (JMenuItem JavaDoc)(e.getSource());
787
788         try {
789             MOTreeObject tree_object = (MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject();
790             String JavaDoc v_class = tree_object.getClass().getName();
791
792             String JavaDoc object_class = (String JavaDoc)Class.forName(v_class).getDeclaredField("object_type").get(null);
793
794             //System.err.println("GuiClient> attributeGet is called for " +
795
// object_class + " " + tree_object.key() + "...");
796

797             intt.itu.itut_x780.ManagedObjectValueType attributes =
798                 master.attributesGet(
799                     object_class,
800                     tree_object.key(),
801                     new String JavaDoc[0]);
802
803             if (attributes == null) {
804                 showAttributesError(GuiMessages.reply_error);
805                 return;
806             }
807
808             Object JavaDoc[] values = tree_object.translate_values(attributes);
809
810             if (values.length > 0)
811                 new AttributesFrame(v_class, //tree_object.key(),
812
tree_object,
813                        values, master,
814                        source.getX(), source.getY());
815             else
816                 showAttributesError(GuiMessages.reply_error);
817
818         }
819         catch(java.lang.ClassNotFoundException JavaDoc e1) {
820             System.err.println("java.lang.ClassNotFoundException");
821         }
822         catch(java.lang.NoSuchFieldException JavaDoc e2) {
823              System.err.println("java.lang.NoSuchFieldException ");
824         }
825          catch(java.lang.IllegalAccessException JavaDoc e3) {
826             System.err.println("IllegalAccessException");
827         }
828         catch(java.lang.IllegalArgumentException JavaDoc e4) {
829             System.err.println("IllegalArgumentException");
830         }
831
832     }
833 }
834 private class DeleteListener implements ActionListener JavaDoc {
835     public void actionPerformed(ActionEvent JavaDoc e) {
836
837         JMenuItem JavaDoc source = (JMenuItem JavaDoc)(e.getSource());
838         DefaultMutableTreeNode selection = treePanel.getCurrentTreeSelection();
839         String JavaDoc object_key = ((MOTreeObject) selection.getUserObject()).key();
840
841         boolean res = master.removeByManager(object_key);
842
843
844         if (res) {
845             //println(object_key + "removed ok");
846
treePanel.removeCurrentNode();
847
848             JOptionPane.showMessageDialog(treePanel,
849                GuiMessages.reply_ok,
850                GuiMessages.options_delete,
851                JOptionPane.WARNING_MESSAGE);
852         }
853     }
854 }
855
856 private class RefreshListener implements ActionListener JavaDoc {
857     public void actionPerformed(ActionEvent JavaDoc e) {
858
859         try {
860
861             MOTreeObject tree_object =
862                     (MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject();
863             String JavaDoc v_class = tree_object.getClass().getName();
864
865             System.err.println("Class = " + v_class);
866
867             String JavaDoc object_class = (String JavaDoc) tree_object.getClass().
868                 getDeclaredField("object_type").get(null);
869
870             String JavaDoc[] param_name = (String JavaDoc [])
871                     tree_object.getClass().getDeclaredField("create_arg_name").get(null);
872
873             String JavaDoc obj_key = tree_object.key();
874
875             intt.itu.itut_x780.ManagedObjectValueType attributes =
876                 master.attributesGet(
877                     object_class,
878                     obj_key,
879                     new String JavaDoc[0]);
880
881             if (attributes == null) {
882                 showAttributesError(GuiMessages.reply_error);
883                 return;
884             }
885
886
887             DefaultMutableTreeNode parent_node =
888                 (DefaultMutableTreeNode) treePanel.getCurrentTreeSelection().getParent();
889             MOTreeObject superior_object = (MOTreeObject) parent_node.getUserObject();
890             //(MOTreeObject) treePanel.getCurrentTreeSelection().getParent().getUserObject();
891

892             System.err.println("Superior object key = " + superior_object.key());
893             System.err.println("object key = " + obj_key);
894             boolean res = master.removeByManager(obj_key);
895
896                     //delete from Gui
897
treePanel.removeCurrentNode();
898
899             String JavaDoc[] values = new String JavaDoc[0];
900             if (object_class.equals("IpNode")) {
901
902                 ist.coach.coachEmsMib.IpNodeValueType ipnode_attributes =
903                         (ist.coach.coachEmsMib.IpNodeValueType) attributes;
904                 values = new String JavaDoc[12];
905                 values[0] = new String JavaDoc(Utils.name2id(obj_key));
906                 values[1] = new String JavaDoc(ipnode_attributes.domainName);
907                 values[2] = new String JavaDoc(ipnode_attributes.hostname);
908                 values[3] = new String JavaDoc(ipnode_attributes.managementIPAddress);
909                 values[4] = String.valueOf(ipnode_attributes.supportedSnmpVersions);
910                 values[5] = new String JavaDoc(ipnode_attributes.userLabel);
911                 values[6] = new String JavaDoc(ipnode_attributes.vendorName);
912                 values[7] = new String JavaDoc(ipnode_attributes.version);
913                 values[8] = new String JavaDoc(ipnode_attributes.locationName);
914                 values[9] = String.valueOf(ipnode_attributes.snmpPort);
915                 values[10] = new String JavaDoc(ipnode_attributes.sysName);
916                 values[11] = new String JavaDoc(ipnode_attributes.sysContact);
917 /**********
918                 for(int k = 0; k < values.length; k++)
919                     System.err.println("---->VALUE[" + k + "] = " +
920                                         values[k]);
921 ************/

922             }
923             String JavaDoc new_object_name = master.createByManager(object_class,
924                 param_name, values, superior_object.key());
925
926                     // repaint in Gui
927
create(obj_key, object_class);
928
929         }
930         catch(java.lang.NoSuchFieldException JavaDoc e2) {
931              System.err.println("java.lang.NoSuchFieldException ");
932         }
933          catch(java.lang.IllegalAccessException JavaDoc e3) {
934             System.err.println("IllegalAccessException");
935         }
936         catch(java.lang.IllegalArgumentException JavaDoc e4) {
937             System.err.println("IllegalArgumentException");
938         }
939
940     }
941 }
942
943 private class ClientListener implements ActionListener JavaDoc {
944
945     public void actionPerformed(ActionEvent JavaDoc e) {
946         JMenuItem JavaDoc source = (JMenuItem JavaDoc)(e.getSource());
947         if (source.getText().equals(GuiMessages.exit_str)) {
948             System.exit(0);
949         }
950     }
951 }
952
953 private class LogTypeItemListener implements ItemListener JavaDoc {
954     public void itemStateChanged(ItemEvent JavaDoc e) {
955
956         JCheckBoxMenuItem JavaDoc source = (JCheckBoxMenuItem JavaDoc)(e.getItem());
957         if (e.getStateChange() == ItemEvent.SELECTED) {
958             master.subscribe_log((String JavaDoc) logTableH.get(source.getText()));
959         }
960         else
961             master.unsubscribe_log((String JavaDoc) logTableH.get(source.getText()));
962
963     }
964 }
965
966 private class AlarmButtonListener implements ActionListener JavaDoc {
967
968     public void actionPerformed(ActionEvent JavaDoc e) {
969         JButton JavaDoc source = (JButton JavaDoc) (e.getSource());
970         if (source.getText().equals(GuiMessages.clear_str)) {
971             alarmModel.clear();
972         }
973     }
974 }
975 private class LogButtonListener implements ActionListener JavaDoc {
976
977     public void actionPerformed(ActionEvent JavaDoc e) {
978         JButton JavaDoc source = (JButton JavaDoc) (e.getSource());
979         if (source.getText().equals(GuiMessages.clear_str)) {
980             logModel.clear();
981         }
982         else {
983           if (source.getText().equals(GuiMessages.log_archives_title)) {
984             new Thread JavaDoc(new LogArchiveFrame(
985               master,
986               source.getX(), source.getY()));
987           }
988         }
989     }
990 }
991 private class AlarmTypeItemListener implements ItemListener JavaDoc {
992     public void itemStateChanged(ItemEvent JavaDoc e) {
993
994         JCheckBoxMenuItem JavaDoc source = (JCheckBoxMenuItem JavaDoc)(e.getItem());
995         if (e.getStateChange() == ItemEvent.SELECTED) {
996             master.subscribe_alarm((String JavaDoc) alarmTableH.get(source.getText()));
997         }
998         else
999             master.unsubscribe_alarm((String JavaDoc) alarmTableH.get(source.getText()));
1000
1001    }
1002}
1003
1004private class HeartbeatTypeItemListener implements ItemListener JavaDoc {
1005    public void itemStateChanged(ItemEvent JavaDoc e) {
1006
1007        JRadioButtonMenuItem JavaDoc source = (JRadioButtonMenuItem JavaDoc)(e.getItem());
1008        if (e.getStateChange() == ItemEvent.SELECTED) {
1009            short period = 100;
1010            if (source.getText().equals(GuiMessages.heartbeat_period_200))
1011              period = 200;
1012            else
1013            if (source.getText().equals(GuiMessages.heartbeat_period_100))
1014              period = 100;
1015            else
1016            if (source.getText().equals(GuiMessages.heartbeat_period_50))
1017              period = 50;
1018            else
1019            if (source.getText().equals(GuiMessages.heartbeat_period_20))
1020              period = 20;
1021            else
1022            if (source.getText().equals(GuiMessages.heartbeat_period_0))
1023              period = 0;
1024
1025            master.set_heartbeat_period(period);
1026        }
1027      }
1028}
1029
1030}
1031
Popular Tags