1 package ist.coach.coachEmfClientComponents.gui; 2 3 import javax.swing.border.Border ; 4 import javax.swing.border.EtchedBorder ; 5 import javax.swing.border.Border ; 6 import javax.swing.BorderFactory ; 7 import javax.swing.JFrame ; 8 import javax.swing.JTree ; 9 import javax.swing.JPanel ; 10 import javax.swing.JTextArea ; 11 import javax.swing.JScrollPane ; 12 import javax.swing.tree.*; 13 import javax.swing.JPopupMenu ; 14 import javax.swing.JMenuItem ; 15 import javax.swing.JMenu ; 16 import javax.swing.JMenuBar ; 17 import javax.swing.JSplitPane ; 18 import javax.swing.JButton ; 19 import javax.swing.JOptionPane ; 20 import javax.swing.JCheckBoxMenuItem ; 21 import javax.swing.JRadioButtonMenuItem ; 22 import javax.swing.event.TreeSelectionEvent ; 23 import javax.swing.event.TreeModelListener ; 24 import javax.swing.event.TreeModelEvent ; 25 import javax.swing.tree.TreeSelectionModel ; 26 import javax.swing.JTextField ; 27 28 import javax.swing.event.ListSelectionListener ; 29 import javax.swing.ListSelectionModel ; 30 import javax.swing.event.ListSelectionEvent ; 31 32 import java.awt.event.MouseEvent ; 33 import java.awt.event.ActionEvent ; 34 import java.awt.event.ItemEvent ; 35 import java.awt.event.MouseListener ; 36 import java.awt.event.ActionListener ; 37 import java.awt.event.ItemListener ; 38 import java.awt.GridLayout ; 39 import java.awt.BorderLayout ; 40 import java.awt.Dimension ; 41 42 import java.util.Hashtable ; 43 import java.util.Enumeration ; 44 import java.util.Properties ; 45 46 import ist.coach.coachEmfCommon.Utils; 47 import ist.coach.coachEmfClientComponents.InvokeSetData; 48 50 public class GuiClient extends JFrame 51 implements MouseListener , Runnable { 52 53 GuiMaster master; 54 private String name; 55 Properties objectVisualTypeProps; 57 Hashtable actions_popups; 58 Hashtable 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 [] cbox_item; 71 ClientListener clientListener; 72 AlarmButtonListener alarmButtonListener; 73 LogButtonListener logButtonListener; 74 75 int logSelectedRow, logSelectedCol, alarmSelectedRow, alarmSelectedCol; 76 JTextField logTextField, alarmTextField; 77 78 79 private static final String typesConfigFile = "elementTypes.conf"; 80 81 public GuiClient(String name, 82 String 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 (60); 95 logTextField.setEditable(false); 96 logTextField.setBackground(java.awt.Color.LIGHT_GRAY); 97 java.awt.Font textDisplayFont = logTextField.getFont(); 98 textDisplayFont = textDisplayFont.deriveFont((float) textDisplayFont.getSize()-1); 99 logTextField.setFont(textDisplayFont); 100 101 alarmTextField = new JTextField (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 117 JMenuBar centralBar = new JMenuBar (); 118 JMenu fileMenu = new JMenu ("File"); 119 JMenuItem exitItem = new JMenuItem (GuiMessages.exit_str); 120 exitItem.addActionListener(clientListener); 121 fileMenu.add(exitItem); 122 centralBar.add(fileMenu); 123 setJMenuBar(centralBar); 124 125 126 JPanel logPanel = new JPanel (); 127 logPanel.setLayout(new BorderLayout ()); 128 129 JMenuBar logMenuBar = new JMenuBar (); 131 logMenuBar.setBorderPainted(true); 132 logMenuBar.setBorder(BorderFactory.createLineBorder(java.awt.Color.black)); 133 logMenuBar.setMargin(new java.awt.Insets (0,0,0,0)); 134 135 JMenu logTypeMenu = new JMenu (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 [logTableH.size()]; 143 int j = 0; 144 for (Enumeration e = logTableH.keys(); e.hasMoreElements();) { 145 cbox_item[j] = new JCheckBoxMenuItem ((String ) e.nextElement(), true); 146 cbox_item[j].addItemListener(logTypeListener); 147 logTypeMenu.add(cbox_item[j]); 148 j++; 149 } 150 logMenuBar.add(logTypeMenu); 151 JButton log_archives_button = new JButton (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 logMenuBar.add(javax.swing.Box.createHorizontalGlue()); 159 JButton log_clear_button = new JButton (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 JLogTable logTable = new JLogTable(logModel); 167 logTable.setPreferredScrollableViewportSize(new Dimension (700, 150)); logTable.setCellSelectionEnabled(false); 169 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 scrollPane = new JScrollPane (logTable); 179 180 logTable.getColumnModel().getSelectionModel(). 181 addListSelectionListener( new ListSelectionListener () { 182 183 public void valueChanged(ListSelectionEvent e) { 184 185 if(e.getValueIsAdjusting()) return; 186 ListSelectionModel lsm = (ListSelectionModel )e.getSource(); 187 if (! lsm.isSelectionEmpty()) { 188 logSelectedCol = lsm.getMinSelectionIndex(); 189 if (logModel.getValueAt(logSelectedRow, logSelectedCol) != null) 190 logTextField.setText((String ) logModel.getValueAt( 191 logSelectedRow, logSelectedCol)); 192 } 193 } 194 }); 195 logTable.getSelectionModel().addListSelectionListener(new ListSelectionListener () { 196 197 public void valueChanged(ListSelectionEvent e) { 198 199 if(e.getValueIsAdjusting()) return; 200 ListSelectionModel lsm = (ListSelectionModel )e.getSource(); 201 if (! lsm.isSelectionEmpty()) { 202 logSelectedRow = lsm.getMinSelectionIndex(); 203 if (logModel.getValueAt(logSelectedRow, logSelectedCol) != null) 204 logTextField.setText((String ) logModel.getValueAt( logSelectedRow, logSelectedCol)); 205 } 206 } 207 } 208 ); 209 210 scrollPane.setPreferredSize(new Dimension (250, 150)); scrollPane.setMinimumSize(new Dimension (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 220 JSplitPane splitPane = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, 221 treePanel, logPanel); 222 splitPane.setOneTouchExpandable(true); 223 splitPane.setDividerLocation(150); 224 225 splitPane.setPreferredSize(new Dimension (700, 400)); getContentPane().add(splitPane); 228 229 230 JMenuBar alarmMenuBar = new JMenuBar (); 232 alarmMenuBar.setBorderPainted(true); 233 alarmMenuBar.setBorder(BorderFactory.createLineBorder(java.awt.Color.black)); 234 alarmMenuBar.setMargin(new java.awt.Insets (0,0,0,0)); 235 236 JMenu alarmTypeMenu = new JMenu (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 [alarmTableH.size()]; 244 int k = 0; 245 for (Enumeration e = alarmTableH.keys(); e.hasMoreElements();) { 246 cbox_item[k] = new JCheckBoxMenuItem ((String ) e.nextElement(), true); 247 cbox_item[k].addItemListener(alarmTypeListener); 248 alarmTypeMenu.add(cbox_item[k]); 249 k++; 250 } 251 alarmMenuBar.add(alarmTypeMenu); 252 253 JMenu heartbeatTypeMenu = new JMenu (GuiMessages.heartbeat_menu_title); 255 heartbeatTypeMenu.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 256 257 javax.swing.ButtonGroup group = new javax.swing.ButtonGroup (); 258 heartbeatTypeMenu.getAccessibleContext().setAccessibleDescription( 259 GuiMessages.heartbeat_tooltip_str); 260 JRadioButtonMenuItem [] heartbeat_items = new JRadioButtonMenuItem [5]; 261 heartbeat_items[0] = new JRadioButtonMenuItem (GuiMessages.heartbeat_period_200, false); 262 heartbeat_items[1] = new JRadioButtonMenuItem (GuiMessages.heartbeat_period_100, true); 263 heartbeat_items[2] = new JRadioButtonMenuItem (GuiMessages.heartbeat_period_50, false); 264 heartbeat_items[3] = new JRadioButtonMenuItem (GuiMessages.heartbeat_period_20, false); 265 heartbeat_items[4] = new JRadioButtonMenuItem (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 alarmMenuBar.add(javax.swing.Box.createHorizontalGlue()); 276 JButton clear_button = new JButton (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 alarmPanel = new JPanel (); 283 alarmPanel.setLayout(new BorderLayout ()); 284 285 JAlarmTable alarmTable = new JAlarmTable(alarmModel); 286 alarmTable.setPreferredScrollableViewportSize(new Dimension (700, 150)); alarmTable.setCellSelectionEnabled(false); 288 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 296 alarmTable.getColumnModel().getSelectionModel(). 297 addListSelectionListener( new ListSelectionListener () { 298 299 public void valueChanged(ListSelectionEvent e) { 300 301 if(e.getValueIsAdjusting()) return; 302 ListSelectionModel lsm = (ListSelectionModel )e.getSource(); 303 if (! lsm.isSelectionEmpty()) { 304 alarmSelectedCol = lsm.getMinSelectionIndex(); 305 if (alarmModel.getValueAt(alarmSelectedRow, alarmSelectedCol) != null) 306 alarmTextField.setText((String ) alarmModel.getValueAt( 307 alarmSelectedRow, alarmSelectedCol)); 308 } 309 } 310 }); 311 alarmTable.getSelectionModel().addListSelectionListener(new ListSelectionListener () { 312 313 public void valueChanged(ListSelectionEvent e) { 314 315 if(e.getValueIsAdjusting()) return; 316 ListSelectionModel lsm = (ListSelectionModel )e.getSource(); 317 if (! lsm.isSelectionEmpty()) { 318 alarmSelectedRow = lsm.getMinSelectionIndex(); 319 if (alarmModel.getValueAt(alarmSelectedRow, alarmSelectedCol) != null) 320 alarmTextField.setText((String ) alarmModel.getValueAt( alarmSelectedRow, alarmSelectedCol)); 321 } 322 } 323 } 324 ); 325 326 JScrollPane alarmScrollPane = new JScrollPane (alarmTable); 327 328 alarmScrollPane.setPreferredSize(new Dimension (200, 150)); 329 alarmScrollPane.setMinimumSize(new Dimension (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 alarmSplitPane = new JSplitPane (JSplitPane.VERTICAL_SPLIT, 336 splitPane, alarmPanel); 337 alarmSplitPane.setOneTouchExpandable(true); 338 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 String [] 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 public void run() {} 365 public void configure_data() { 366 367 372 objectVisualTypeProps = new Properties (); 373 try { 374 System.out.println("Loading file " + typesConfigFile); 375 objectVisualTypeProps.load(GuiClient.class.getResourceAsStream(typesConfigFile)); 376 } 377 catch (Exception e) { 378 e.printStackTrace(); 379 return; 380 } 381 382 actions_popups = new Hashtable (); 384 alarmTableH = new Hashtable (); 385 logTableH = new Hashtable (); 386 387 alarmModel = new AlarmTableModel(); 388 logModel = new LogTableModel(); 389 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 name) { 436 this.name = name; 437 setTitle(name); 438 } 439 440 public synchronized void print(String dateR, String eventType, String source, 441 String sourceClass, String notifId, String details) { 442 443 if (logModel == null) 445 return; 446 logModel.updateLogTable(dateR, 448 eventType, 449 source, 450 sourceClass, 451 notifId, 452 details); 453 } 454 public static synchronized void println(String msg) { 455 System.err.println(msg); 456 457 } 458 459 public synchronized void print_alarm(String dateR, String eventType, String source, 460 String sourceClass, String notifId, String 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 get_menu(String visual_class_name) { 477 478 if (actions_popups.containsKey(visual_class_name)) 479 return (JPopupMenu ) actions_popups.get(visual_class_name); 480 481 JPopupMenu popup = new JPopupMenu (); 484 String [] subordinate_names = null; 485 Class object_class = null; 486 boolean canRefresh = false; 487 try { 488 object_class = Class.forName(visual_class_name); 489 subordinate_names = 490 (String [])object_class. 491 getDeclaredField("subordinate_names").get(null); 492 canRefresh = (boolean) ((Boolean ) object_class. 493 getDeclaredField("canRefresh").get(null)).booleanValue(); 494 } 495 catch(java.lang.ClassNotFoundException ex1) { 496 System.err.println("mouseClicked> ClassNotFoundException " + 497 ex1.getMessage()); 498 } 499 catch(java.lang.IllegalAccessException ex2) { 500 System.err.println("mouseClicked> IllegalAccessException " + 501 ex2.getMessage()); 502 } 503 catch(java.lang.NoSuchFieldException ex3) { 504 System.err.println("mouseClicked> NoSuchFieldException " + 505 ex3.getMessage()); 506 } 508 509 510 if (subordinate_names.length > 0) { 512 JMenu create_menu = new JMenu (GuiMessages.options_create); 513 JMenuItem 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 (subordinate_names[i]); 518 subordinate.addActionListener(subListener); 519 create_menu.add(subordinate); 520 } 521 popup.add(create_menu); 522 } 523 524 JMenuItem properties_item = new JMenuItem (GuiMessages.options_properties); 525 properties_item.addActionListener(propertiesListener); 526 popup.add(properties_item); 527 528 JMenuItem delete_item = new JMenuItem (GuiMessages.options_delete); 529 delete_item.addActionListener(deleteListener); 530 popup.add(delete_item); 531 532 if (canRefresh) { 533 JMenuItem refresh_item = new JMenuItem (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 getObjectType(String key) { 542 543 String obj_type = new String (); 545 String label = key; 547 548 int lastIndex = key.lastIndexOf("/"); 549 int objIndex = 0; 550 if (lastIndex > 0) { 551 String object_id = key.substring(0, lastIndex); 552 if (object_id != null && object_id.length() > 0 && 553 (objIndex = object_id.lastIndexOf("/")) > 0) { 554 555 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 [] getContained(String key) { 571 return master.getContained(key); 572 } 573 574 public void create(DefaultMutableTreeNode parent, String key) { 578 579 DefaultMutableTreeNode node = create(parent, key, getObjectType(key)); 580 String [] children = master.getContained(key); 581 for (int i = 0; i < children.length; i++) 582 create(node, children[i]); 583 } 584 585 public DefaultMutableTreeNode create(DefaultMutableTreeNode parent, 589 String key, String obj_type) { 590 591 DefaultMutableTreeNode node = new DefaultMutableTreeNode(); 592 String visual_class = (String ) objectVisualTypeProps.getProperty(obj_type); 594 596 Class vtype; 597 Class [] consArgsClass = new Class [] {String .class}; 598 java.lang.reflect.Constructor 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 [] {key})); 604 605 } 608 catch(java.lang.IllegalArgumentException e1) { 609 System.err.println("IllegalArgumentException"); 610 } 611 catch(java.lang.IllegalAccessException e2) { 612 System.err.println("IllegalAccessException"); 613 } 614 catch(java.lang.ClassNotFoundException e3) { 615 System.err.println("ClassNotFoundException"); 616 } 617 catch(java.lang.NoSuchMethodException e4) { 618 System.err.println("NoSuchMethodException"); 619 } 620 catch(java.lang.InstantiationException e5) { 621 System.err.println("InstantiationException"); 622 } 623 catch(java.lang.reflect.InvocationTargetException e6) { 624 System.err.println("InvocationTargetException:" + e6.getMessage()); 625 e6.printStackTrace(); 626 } 627 628 return node; 629 } 630 631 public void create(String key, String obj_type) { 632 633 String visual_class = (String ) objectVisualTypeProps.getProperty(obj_type); 635 636 Class vtype; 637 Class [] consArgsClass = new Class [] {String .class}; 638 java.lang.reflect.Constructor 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 [] {key})); 644 645 } 648 catch(java.lang.IllegalArgumentException e1) { 649 System.err.println("IllegalArgumentException"); 650 } 651 catch(java.lang.IllegalAccessException e2) { 652 System.err.println("IllegalAccessException"); 653 } 654 catch(java.lang.ClassNotFoundException e3) { 655 System.err.println("ClassNotFoundException"); 656 } 657 catch(java.lang.NoSuchMethodException e4) { 658 System.err.println("NoSuchMethodException"); 659 } 660 catch(java.lang.InstantiationException e5) { 661 System.err.println("InstantiationException"); 662 } 663 catch(java.lang.reflect.InvocationTargetException e6) { 664 System.err.println("InvocationTargetException:" + e6.getMessage()); 665 e6.printStackTrace(); 666 } 667 668 } 669 670 674 public void mousePressed(MouseEvent e) { 675 } 676 677 public void mouseReleased(MouseEvent e) { 678 } 679 680 public void mouseEntered(MouseEvent e) { 681 } 682 683 public void mouseExited(MouseEvent e) { 684 } 685 686 public void mouseClicked(MouseEvent e) { 687 688 if (javax.swing.SwingUtilities.isRightMouseButton(e)) { 689 JPopupMenu popup = null; 690 691 String 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 getClassName(Object o) { 705 String classString = o.getClass().getName(); 706 int dotIndex = classString.lastIndexOf("."); 707 return classString.substring(dotIndex+1); 708 } 709 710 public void showAttributesError(String 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 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 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 { 735 736 GuiClient parent = null; 737 public SubordinateListener(GuiClient parent) { 738 this.parent = parent; 739 } 740 741 public void actionPerformed(ActionEvent e) { 742 743 758 759 JMenuItem source = (JMenuItem )(e.getSource()); 760 String visual_class = (String ) objectVisualTypeProps.getProperty(source.getText()); 762 763 774 new Thread (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 { 784 public void actionPerformed(ActionEvent e) { 785 786 JMenuItem source = (JMenuItem )(e.getSource()); 787 788 try { 789 MOTreeObject tree_object = (MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject(); 790 String v_class = tree_object.getClass().getName(); 791 792 String object_class = (String )Class.forName(v_class).getDeclaredField("object_type").get(null); 793 794 797 intt.itu.itut_x780.ManagedObjectValueType attributes = 798 master.attributesGet( 799 object_class, 800 tree_object.key(), 801 new String [0]); 802 803 if (attributes == null) { 804 showAttributesError(GuiMessages.reply_error); 805 return; 806 } 807 808 Object [] values = tree_object.translate_values(attributes); 809 810 if (values.length > 0) 811 new AttributesFrame(v_class, tree_object, 813 values, master, 814 source.getX(), source.getY()); 815 else 816 showAttributesError(GuiMessages.reply_error); 817 818 } 819 catch(java.lang.ClassNotFoundException e1) { 820 System.err.println("java.lang.ClassNotFoundException"); 821 } 822 catch(java.lang.NoSuchFieldException e2) { 823 System.err.println("java.lang.NoSuchFieldException "); 824 } 825 catch(java.lang.IllegalAccessException e3) { 826 System.err.println("IllegalAccessException"); 827 } 828 catch(java.lang.IllegalArgumentException e4) { 829 System.err.println("IllegalArgumentException"); 830 } 831 832 } 833 } 834 private class DeleteListener implements ActionListener { 835 public void actionPerformed(ActionEvent e) { 836 837 JMenuItem source = (JMenuItem )(e.getSource()); 838 DefaultMutableTreeNode selection = treePanel.getCurrentTreeSelection(); 839 String object_key = ((MOTreeObject) selection.getUserObject()).key(); 840 841 boolean res = master.removeByManager(object_key); 842 843 844 if (res) { 845 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 { 857 public void actionPerformed(ActionEvent e) { 858 859 try { 860 861 MOTreeObject tree_object = 862 (MOTreeObject) treePanel.getCurrentTreeSelection().getUserObject(); 863 String v_class = tree_object.getClass().getName(); 864 865 System.err.println("Class = " + v_class); 866 867 String object_class = (String ) tree_object.getClass(). 868 getDeclaredField("object_type").get(null); 869 870 String [] param_name = (String []) 871 tree_object.getClass().getDeclaredField("create_arg_name").get(null); 872 873 String 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 [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 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 treePanel.removeCurrentNode(); 898 899 String [] values = new String [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 [12]; 905 values[0] = new String (Utils.name2id(obj_key)); 906 values[1] = new String (ipnode_attributes.domainName); 907 values[2] = new String (ipnode_attributes.hostname); 908 values[3] = new String (ipnode_attributes.managementIPAddress); 909 values[4] = String.valueOf(ipnode_attributes.supportedSnmpVersions); 910 values[5] = new String (ipnode_attributes.userLabel); 911 values[6] = new String (ipnode_attributes.vendorName); 912 values[7] = new String (ipnode_attributes.version); 913 values[8] = new String (ipnode_attributes.locationName); 914 values[9] = String.valueOf(ipnode_attributes.snmpPort); 915 values[10] = new String (ipnode_attributes.sysName); 916 values[11] = new String (ipnode_attributes.sysContact); 917 922 } 923 String new_object_name = master.createByManager(object_class, 924 param_name, values, superior_object.key()); 925 926 create(obj_key, object_class); 928 929 } 930 catch(java.lang.NoSuchFieldException e2) { 931 System.err.println("java.lang.NoSuchFieldException "); 932 } 933 catch(java.lang.IllegalAccessException e3) { 934 System.err.println("IllegalAccessException"); 935 } 936 catch(java.lang.IllegalArgumentException e4) { 937 System.err.println("IllegalArgumentException"); 938 } 939 940 } 941 } 942 943 private class ClientListener implements ActionListener { 944 945 public void actionPerformed(ActionEvent e) { 946 JMenuItem source = (JMenuItem )(e.getSource()); 947 if (source.getText().equals(GuiMessages.exit_str)) { 948 System.exit(0); 949 } 950 } 951 } 952 953 private class LogTypeItemListener implements ItemListener { 954 public void itemStateChanged(ItemEvent e) { 955 956 JCheckBoxMenuItem source = (JCheckBoxMenuItem )(e.getItem()); 957 if (e.getStateChange() == ItemEvent.SELECTED) { 958 master.subscribe_log((String ) logTableH.get(source.getText())); 959 } 960 else 961 master.unsubscribe_log((String ) logTableH.get(source.getText())); 962 963 } 964 } 965 966 private class AlarmButtonListener implements ActionListener { 967 968 public void actionPerformed(ActionEvent e) { 969 JButton source = (JButton ) (e.getSource()); 970 if (source.getText().equals(GuiMessages.clear_str)) { 971 alarmModel.clear(); 972 } 973 } 974 } 975 private class LogButtonListener implements ActionListener { 976 977 public void actionPerformed(ActionEvent e) { 978 JButton source = (JButton ) (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 (new LogArchiveFrame( 985 master, 986 source.getX(), source.getY())); 987 } 988 } 989 } 990 } 991 private class AlarmTypeItemListener implements ItemListener { 992 public void itemStateChanged(ItemEvent e) { 993 994 JCheckBoxMenuItem source = (JCheckBoxMenuItem )(e.getItem()); 995 if (e.getStateChange() == ItemEvent.SELECTED) { 996 master.subscribe_alarm((String ) alarmTableH.get(source.getText())); 997 } 998 else 999 master.unsubscribe_alarm((String ) alarmTableH.get(source.getText())); 1000 1001 } 1002} 1003 1004private class HeartbeatTypeItemListener implements ItemListener { 1005 public void itemStateChanged(ItemEvent e) { 1006 1007 JRadioButtonMenuItem source = (JRadioButtonMenuItem )(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 |