1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF)                              */
3 /* (C) Copyright IBM Corp. 2006                                              */
4 /*                                                                           */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0.    */
6 /*****************************************************************************/
7 
8 package com.ibm.staf.service.eventmanager;
9 
10 import java.awt.*;
11 import java.awt.event.*;
12 import java.util.*;
13 import java.io.*;
14 import javax.swing.*;
15 import javax.swing.table.*;
16 import javax.swing.border.*;
17 import javax.swing.event.*;
18 import javax.swing.plaf.metal.*;
19 import com.ibm.staf.*;
20 import com.ibm.staf.service.*;
21 
22 public class EventManagerUI extends JFrame implements ActionListener,
23                                                       MouseListener,
24                                                       KeyListener
25 {
26     JMenuBar fMenuBar;
27     JMenu fFileMenu;
28     JMenuItem fFileExit;
29     JMenuItem fFileNew;
30     JMenu fViewMenu;
31     JMenuItem fViewRefresh;
32     JMenuItem fViewServiceLogLast100;
33     JMenuItem fViewServiceLogForID;
34     JMenuItem fViewServiceLogForSubmittedCommand;
35     JMenuItem fViewEntireServiceLog;
36     JMenuItem fViewDeleteServiceLog;
37     JMenu fSelectedMenu;
38     JMenuItem fSelectedEdit;
39     JMenuItem fSelectedEnable;
40     JMenuItem fSelectedDisable;
41     JMenuItem fSelectedTrigger;
42     JMenuItem fSelectedTriggerWithScript;
43     JMenuItem fSelectedCopyToNewRegistration;
44     JMenuItem fSelectedUnregister;
45     JMenu fHelpMenu;
46     JMenuItem fHelpAbout;
47     JLabel fInstructionLabel;
48     JLabel fRegistrationIDLabel;
49     JTextField fServiceMachineTF = new JTextField(15);
50     JTextField fServiceNameTF = new JTextField(8);
51     JTextField fDescriptionTF;
52     JTextField fMachineTF;
53     JCheckBox fPythonMachine;
54     JTextField fServiceTF;
55     JCheckBox fPythonService;
56     JTextField fRequestTF;
57     JCheckBox fPythonRequest;
58     JTextArea fPrepareTA;
59     JTextField fTypeTF;
60     JTextField fSubtypeTF;
61     JCheckBox fEnabledCB;
62     JButton fRegisterButton;
63     JButton fCancelButton;
64     JDialog fRegistrationDialog;
65     java.util.List fEntryList;
66     JTable fIDTable;
67     Vector<String> fColumnNames;
68     STAFHandle fHandle;
69     JPopupMenu fPopupMenu = new JPopupMenu();
70     JMenuItem fPopupMenuEdit = new JMenuItem("Edit");
71     JMenuItem fPopupMenuEnable = new JMenuItem("Enable");
72     JMenuItem fPopupMenuDisable = new JMenuItem("Disable");
73     JMenuItem fPopupMenuTrigger = new JMenuItem("Trigger");
74     JMenuItem fPopupMenuTriggerWithScript =
75         new JMenuItem("Trigger with script...");
76     JMenuItem fPopupMenuCopyToNewRegistration =
77         new JMenuItem("Copy to new registration");
78     JMenuItem fPopupMenuUnregister = new JMenuItem("Unregister");
79     JTextArea fScriptTextArea;
80     JButton fScriptTriggerButton;
81     JButton fScriptCancelButton;
82     JDialog fScriptDialog;
83     JDialog fStafCommandsDialog;
84     JComboBox fStafCommands;
85     JButton fStafCommandsOkButton;
86     JButton fStafCommandsCancelButton;
87 
88     String fServiceMachine = "";
89     String fServiceName = "";
90     String fLogName = "";
91 
EventManagerUI()92     public EventManagerUI()
93     {
94         try
95         {
96             fHandle = new STAFHandle("STAF/EventManager/UI");
97         }
98         catch (STAFException e)
99         {
100             System.out.println("STAF must be running to execute " +
101                                "EventManagerUI");
102             System.exit(0);
103         }
104 
105         UIManager.put("Table.focusCellHighlightBorder", "none");
106 
107         fServiceMachineTF.setText("local");
108         fServiceNameTF.setText("EventManager");
109 
110         fServiceMachine = "local";
111         fServiceName = "EventManager";
112         assignLogName();
113 
114         Vector idData = getRegistrationTable();
115 
116         JPanel idPanel = new JPanel();
117         idPanel.setLayout(new BorderLayout());
118 
119         fMenuBar = new JMenuBar();
120         fFileMenu = new JMenu("File");
121         fFileNew = new JMenuItem("New Registration...");
122         fFileMenu.add(fFileNew);
123         fFileNew.addActionListener(this);
124         fFileExit = new JMenuItem("Exit");
125         fFileMenu.add(fFileExit);
126         fFileExit.addActionListener(this);
127         fMenuBar.add(fFileMenu);
128 
129         fViewMenu = new JMenu("View");
130         fViewRefresh = new JMenuItem("Refresh");
131         fViewMenu.add(fViewRefresh);
132         fViewRefresh.addActionListener(this);
133         fViewMenu.insertSeparator(3);
134         fViewServiceLogForID = new JMenuItem("Service Log for ID...");
135         fViewMenu.add(fViewServiceLogForID);
136         fViewServiceLogForID.addActionListener(this);
137         fViewServiceLogLast100 = new JMenuItem("Service Log last 100 records");
138         fViewMenu.add(fViewServiceLogLast100);
139         fViewServiceLogLast100.addActionListener(this);
140         fViewServiceLogForSubmittedCommand = new
141             JMenuItem("Service Log for submitted STAF command...");
142         fViewMenu.add(fViewServiceLogForSubmittedCommand);
143         fViewServiceLogForSubmittedCommand.addActionListener(this);
144         fViewEntireServiceLog = new JMenuItem("Entire Service Log");
145         fViewMenu.add(fViewEntireServiceLog);
146         fViewEntireServiceLog.addActionListener(this);
147         fViewDeleteServiceLog = new JMenuItem("Delete Service Log");
148         fViewMenu.add(fViewDeleteServiceLog);
149         fViewDeleteServiceLog.addActionListener(this);
150         fMenuBar.add(fViewMenu);
151 
152         fSelectedMenu = new JMenu("Selected");
153         fSelectedMenu.setEnabled(false);
154         fSelectedEdit = new JMenuItem("Edit");
155         fSelectedMenu.add(fSelectedEdit);
156         fSelectedEdit.addActionListener(this);
157         fSelectedMenu.insertSeparator(1);
158         fSelectedEnable = new JMenuItem("Enable");
159         fSelectedMenu.add(fSelectedEnable);
160         fSelectedEnable.addActionListener(this);
161         fSelectedDisable = new JMenuItem("Disable");
162         fSelectedMenu.add(fSelectedDisable);
163         fSelectedDisable.addActionListener(this);
164         fSelectedMenu.insertSeparator(5);
165         fSelectedTrigger = new JMenuItem("Trigger");
166         fSelectedMenu.add(fSelectedTrigger);
167         fSelectedTrigger.addActionListener(this);
168         fSelectedTriggerWithScript = new JMenuItem("Trigger with script...");
169         fSelectedMenu.add(fSelectedTriggerWithScript);
170         fSelectedTriggerWithScript.addActionListener(this);
171         fSelectedMenu.insertSeparator(9);
172         fSelectedCopyToNewRegistration =
173             new JMenuItem("Copy to new registration");
174         fSelectedMenu.add(fSelectedCopyToNewRegistration);
175         fSelectedCopyToNewRegistration.addActionListener(this);
176         fSelectedMenu.insertSeparator(12);
177         fSelectedUnregister = new JMenuItem("Unregister");
178         fSelectedMenu.add(fSelectedUnregister);
179         fSelectedUnregister.addActionListener(this);
180         fMenuBar.add(fSelectedMenu);
181 
182         fHelpMenu = new JMenu("Help");
183         fHelpAbout = new JMenuItem("About");
184         fHelpMenu.add(fHelpAbout);
185         fHelpAbout.addActionListener(this);
186         fMenuBar.add(fHelpMenu);
187 
188         JPanel servicePanel = new JPanel();
189         servicePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
190         JLabel serviceMachineLabel = new JLabel("Service Machine:");
191         serviceMachineLabel.setOpaque(true);
192         serviceMachineLabel.setForeground(Color.black);
193         servicePanel.add(serviceMachineLabel);
194 
195         servicePanel.add(fServiceMachineTF);
196         fServiceMachineTF.addKeyListener(this);
197 
198         JLabel serviceNameLabel = new JLabel("Service Name:");
199         serviceNameLabel.setOpaque(true);
200         serviceNameLabel.setForeground(Color.black);
201         servicePanel.add(serviceNameLabel);
202 
203         servicePanel.add(fServiceNameTF);
204         fServiceNameTF.addKeyListener(this);
205 
206         idPanel.add(BorderLayout.NORTH, servicePanel);
207 
208         this.setJMenuBar(fMenuBar);
209 
210         fColumnNames = new Vector<String>();
211         fColumnNames.add("ID");
212         fColumnNames.add("State");
213         fColumnNames.add("Description");
214         fColumnNames.add("Machine");
215         fColumnNames.add("Service");
216         fColumnNames.add("Request");
217 
218         RegisterModel regModel = new RegisterModel(idData, fColumnNames);
219         fIDTable = new JTable();
220         fIDTable.setModel(regModel);
221         fIDTable.setCellSelectionEnabled(false);
222         fIDTable.setRowSelectionAllowed(true);
223         fIDTable.addMouseListener(this);
224         fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
225 
226         fIDTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
227 
228         fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
229         fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
230         fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
231         fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
232         fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
233         fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
234 
235         fPopupMenu.add(fPopupMenuEdit);
236         fPopupMenuEdit.addActionListener(this);
237         fPopupMenu.addSeparator();
238         fPopupMenu.add(fPopupMenuEnable);
239         fPopupMenuEnable.addActionListener(this);
240         fPopupMenu.add(fPopupMenuDisable);
241         fPopupMenuDisable.addActionListener(this);
242         fPopupMenu.addSeparator();
243         fPopupMenu.add(fPopupMenuTrigger);
244         fPopupMenuTrigger.addActionListener(this);
245         fPopupMenu.add(fPopupMenuTriggerWithScript);
246         fPopupMenuTriggerWithScript.addActionListener(this);
247         fPopupMenu.addSeparator();
248         fPopupMenu.add(fPopupMenuCopyToNewRegistration);
249         fPopupMenuCopyToNewRegistration.addActionListener(this);
250         fPopupMenu.addSeparator();
251         fPopupMenu.add(fPopupMenuUnregister);
252         fPopupMenuUnregister.addActionListener(this);
253 
254         idPanel.add(BorderLayout.CENTER, new JScrollPane(fIDTable));
255 
256         fInstructionLabel = new JLabel();
257         setInstructionLabel(idData);
258         idPanel.add(BorderLayout.SOUTH, fInstructionLabel);
259 
260         getContentPane().add(idPanel);
261         setTitle("EventManagerUI");
262         pack();
263         setSize(new Dimension(750, 450));
264 
265         setVisible(true);
266 
267         addWindowListener(new WindowAdapter()
268         {
269             public void windowClosing(WindowEvent e)
270             {
271                 System.exit(0);
272             }
273         });
274     }
275 
setInstructionLabel(Vector idData)276     public void setInstructionLabel(Vector idData)
277     {
278         if (idData == null)
279         {
280             fInstructionLabel.setText("Enter a valid Service Machine" +
281                 " and Service Name");
282         }
283         else if (idData.size() == 0)
284         {
285             fInstructionLabel.setText("Click on File -> New Registration..." +
286                 " in the menu bar to register a new STAF command");
287         }
288         else
289         {
290             fInstructionLabel.setText("Double click on an existing " +
291                 "registration to edit");
292         }
293     }
294 
main(String argv[])295     public static void main(String argv[])
296     {
297         new EventManagerUI();
298     }
299 
actionPerformed(ActionEvent e)300     public void actionPerformed(ActionEvent e)
301     {
302         if (e.getSource() == fFileExit)
303         {
304             System.exit(0);
305         }
306         else if (e.getSource() == fFileNew)
307         {
308             displayfRegistrationDialog();
309             fRegistrationDialog.setVisible(true);
310         }
311         else if (e.getSource() == fHelpAbout)
312         {
313             STAFResult res = fHandle.submit2(
314                 fServiceMachine, fServiceName, "VERSION");
315 
316             if (res.rc == 0)
317             {
318                 JOptionPane.showMessageDialog(
319                     this, fServiceName.toUpperCase() + " version " +
320                     res.result, fServiceName.toUpperCase() + " VERSION " +
321                     res.result, JOptionPane.INFORMATION_MESSAGE);
322             }
323             else
324             {
325                 System.out.println(
326                     "Error service version " +
327                     "on machine " + fServiceMachine + ".  RC=" + res.rc +
328                     ", Result=" + res.result);
329             }
330         }
331         else if (e.getSource() == fViewRefresh)
332         {
333             Vector idData = getRegistrationTable();
334             setInstructionLabel(idData);
335 
336             ((RegisterModel)(fIDTable.getModel())).setDataVector(
337                 idData, fColumnNames);
338 
339             fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
340             fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
341             fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
342             fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
343             fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
344             fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
345             fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
346 
347             fSelectedMenu.setEnabled(false);
348         }
349         else if (e.getSource() == fViewServiceLogForID)
350         {
351             String id = JOptionPane.showInputDialog(this,
352                 "Enter the registration ID", "View Service log for ID",
353                 JOptionPane.QUESTION_MESSAGE);
354 
355             if (id == null) return;
356 
357             String queryRequest =
358                 "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
359                 fLogName + " CONTAINS " +
360                 STAFUtil.wrapData("[ID=" + id + "]") + " ALL";
361 
362             STAFLogViewer logViewer = new STAFLogViewer(
363                 this, fHandle, fServiceMachine, "LOG", queryRequest, "",
364                 "Monospaced");
365         }
366         else if (e.getSource() == fViewServiceLogLast100)
367         {
368             String queryRequest =
369                 "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
370                 fLogName + " LAST 100";
371 
372             STAFLogViewer logViewer = new STAFLogViewer(
373                 this, fHandle, fServiceMachine, "LOG", queryRequest, "",
374                 "Monospaced");
375         }
376         else if (e.getSource() == fViewServiceLogForSubmittedCommand)
377         {
378             String queryRequest =
379                 "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
380                 fLogName + " CONTAINS " +
381                 STAFUtil.wrapData("] Submitted a STAF command") + " ALL";
382 
383             STAFResult stafResult = fHandle.submit2(
384                 fServiceMachine, "LOG", queryRequest);
385 
386             if (stafResult.rc != 0)
387             {
388                 JOptionPane.showMessageDialog(
389                     this, "RC=" + stafResult.rc + ", Result=" +
390                     stafResult.result,
391                     "Error querying log " + fLogName + " on machine " +
392                     fServiceMachine, JOptionPane.INFORMATION_MESSAGE);
393 
394                 return;
395             }
396 
397             java.util.List outputList;
398 
399             try
400             {
401                 STAFMarshallingContext outputContext =
402                     STAFMarshallingContext.unmarshall(stafResult.result);
403 
404                 outputList = (java.util.List)outputContext.getRootObject();
405             }
406             catch (Exception ex)
407             {
408                 ex.printStackTrace();
409 
410                 JOptionPane.showMessageDialog(
411                     this, "Log " + fLogName + " on machine " +
412                     fServiceMachine + " has an invalid format",
413                     "Invalid Log Format",
414                     JOptionPane.INFORMATION_MESSAGE);
415 
416                 return;
417             }
418 
419             Iterator iter = outputList.iterator();
420             Vector<String> stafCommands = new Vector<String>();
421             int i = 0;
422 
423             try
424             {
425                 while (iter.hasNext())
426                 {
427                     i++;
428                     Map logRecord = (Map)iter.next();
429 
430                     String timestamp = (String)logRecord.get("timestamp");
431                     String logMessage = (String)logRecord.get("message");
432                     int firstBracketIndex = logMessage.indexOf("]");
433                     int secondBracketIndex = logMessage.indexOf("]",
434                         firstBracketIndex + 1);
435                     String idAndReqNum = logMessage.substring(0,
436                         secondBracketIndex + 1);
437                     String command = logMessage.substring(
438                         logMessage.indexOf("Submitted STAF command: ") + 24);
439                     stafCommands.add(0, idAndReqNum + " " + command);
440                 }
441             }
442             catch (Exception ex)
443             {
444                 ex.printStackTrace();
445 
446                 JOptionPane.showMessageDialog(
447                     this, "Log " + fLogName + " on machine " +
448                     fServiceName + " has an invalid format",
449                     "Invalid Log Format in record #" + i,
450                     JOptionPane.INFORMATION_MESSAGE);
451 
452                 return;
453             }
454 
455             fStafCommandsDialog = new JDialog(this,
456                 "Select submitted STAF command", true);
457             fStafCommandsDialog.setSize(600, 150);
458             JPanel stafCommandsPanel = new JPanel();
459             stafCommandsPanel.setLayout(new BorderLayout());
460             stafCommandsPanel.setBorder(new TitledBorder("Select STAF command"));
461             fStafCommandsDialog.getContentPane().add(stafCommandsPanel);
462 
463             fStafCommands = new JComboBox(stafCommands);
464             fStafCommands.setBackground(Color.white);
465 
466             stafCommandsPanel.add(BorderLayout.NORTH, fStafCommands);
467 
468             JPanel stafCommandsButtonPanel = new JPanel();
469             stafCommandsButtonPanel.setLayout(new
470                 FlowLayout(FlowLayout.CENTER, 0, 0));
471 
472             fStafCommandsOkButton = new JButton("OK");
473             fStafCommandsOkButton.addActionListener(this);
474             fStafCommandsCancelButton = new JButton("Cancel");
475             fStafCommandsCancelButton.addActionListener(this);
476             stafCommandsButtonPanel.add(fStafCommandsOkButton);
477             stafCommandsButtonPanel.add(Box.createHorizontalStrut(20));
478             stafCommandsButtonPanel.add(fStafCommandsCancelButton);
479 
480             stafCommandsPanel.add(BorderLayout.SOUTH, stafCommandsButtonPanel);
481 
482             fStafCommandsDialog.setLocationRelativeTo(this);
483 
484             fStafCommandsDialog.setVisible(true);
485         }
486         else if (e.getSource() == fStafCommandsCancelButton)
487         {
488             fStafCommandsDialog.dispose();
489         }
490         else if (e.getSource() == fStafCommandsOkButton)
491         {
492             String command = (String)fStafCommands.getSelectedItem();
493             int firstBracketIndex = command.indexOf("]");
494             int secondBracketIndex = command.indexOf("]",
495                 firstBracketIndex + 1);
496             String idAndReqNum = command.substring(0,
497                 secondBracketIndex + 1);
498 
499             fStafCommandsDialog.dispose();
500 
501             String queryRequest =
502                 "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
503                 fLogName + " CONTAINS " + STAFUtil.wrapData(idAndReqNum) +
504                 " ALL";
505 
506             STAFLogViewer logViewer = new STAFLogViewer(
507                 this, fHandle, fServiceMachine, "LOG", queryRequest, "",
508                 "Monospaced");
509         }
510         else if (e.getSource() == fViewEntireServiceLog)
511         {
512             String queryRequest =
513                 "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
514                 fLogName + " ALL";
515 
516             STAFLogViewer logViewer = new STAFLogViewer(
517                 this, fHandle, fServiceMachine, "LOG", queryRequest, "",
518                 "Monospaced");
519         }
520         else if (e.getSource() == fViewDeleteServiceLog)
521         {
522             int response = JOptionPane.showConfirmDialog(this,
523                 "Are you sure you want to delete the service log?");
524 
525             if (response != JOptionPane.YES_OPTION)
526             {
527                 return;
528             }
529 
530             STAFResult res = fHandle.submit2(
531                 fServiceMachine, "LOG",
532                 "DELETE MACHINE {STAF/Config/MachineNickname} LOGNAME " +
533                 fLogName + " CONFIRM");
534 
535             if (res.rc != 0)
536             {
537                 JOptionPane.showMessageDialog(
538                     this, "Error deleting the " + fLogName +
539                     " log on machine " + fServiceMachine + ".\n",
540                     "RC=" + res.rc + ", Result=" + res.result,
541                     JOptionPane.ERROR_MESSAGE);
542             }
543         }
544         else if (e.getSource() == fCancelButton)
545         {
546             fRegistrationDialog.dispose();
547 
548             Vector idData = getRegistrationTable();
549             setInstructionLabel(idData);
550 
551             if (idData == null)
552             {
553                 return;
554             }
555 
556             ((RegisterModel)(fIDTable.getModel())).setDataVector(
557                 idData, fColumnNames);
558 
559             fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
560             fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
561             fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
562             fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
563             fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
564             fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
565             fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
566 
567             fSelectedMenu.setEnabled(false);
568         }
569         else if (e.getSource() == fSelectedEdit ||
570                   e.getSource() == fPopupMenuEdit)
571         {
572             int selectedRow = fIDTable.getSelectedRow();
573 
574             if (selectedRow == -1)
575             {
576                 return;
577             }
578 
579             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
580 
581             String eventManagerId = "";
582 
583             Iterator idIter = fEntryList.iterator();
584 
585             while (idIter.hasNext() && !(eventManagerId.equals(selectedId)))
586             {
587                 Map registrationMap = (Map)idIter.next();
588                 eventManagerId = (String)registrationMap.get("eventManagerID");
589 
590                 if (eventManagerId.equals(selectedId))
591                 {
592                     String machine = (String)registrationMap.get("machine");
593                     String machineType =
594                         (String)registrationMap.get("machineType");
595                     String service = (String)registrationMap.get("service");
596                     String serviceType =
597                         (String)registrationMap.get("serviceType");
598                     String request = (String)registrationMap.get("request");
599                     String requestType =
600                         (String)registrationMap.get("requestType");
601                     String prepareScript =
602                         (String)registrationMap.get("prepareScript");
603                     String type = (String)registrationMap.get("type");
604                     String subtype = (String)registrationMap.get("subtype");
605                     String description =
606                         (String)registrationMap.get("description");
607                     String state =
608                         (String)registrationMap.get("state");
609 
610                     displayfRegistrationDialog();
611 
612                     fRegistrationIDLabel.setText(eventManagerId);
613 
614                     fMachineTF.setText(machine);
615                     fPythonMachine.setSelected(machineType.equals("Python"));
616                     fServiceTF.setText(service);
617                     fPythonService.setSelected(serviceType.equals("Python"));
618                     fRequestTF.setText(request);
619                     fPythonRequest.setSelected(requestType.equals("Python"));
620                     fPrepareTA.setText(prepareScript);
621                     fTypeTF.setText(type);
622                     fSubtypeTF.setText(subtype);
623                     fDescriptionTF.setText(description);
624 
625                     if (state.equals("Disabled"))
626                     {
627                         fEnabledCB.setSelected(false);
628                     }
629                     else
630                     {
631                         fEnabledCB.setSelected(true);
632                     }
633 
634                     fRegistrationDialog.setVisible(true);
635                 }
636             }
637         }
638         else if (e.getSource() == fSelectedTrigger ||
639                  e.getSource() == fPopupMenuTrigger)
640         {
641             int selectedRow = fIDTable.getSelectedRow();
642 
643             if (selectedRow == -1)
644             {
645                 return;
646             }
647 
648             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
649 
650             STAFResult result = fHandle.submit2(
651                 fServiceMachine, fServiceName, " TRIGGER ID " + selectedId);
652 
653             if (result.rc != 0)
654             {
655                 showErrorDialog(fRegistrationDialog,
656                                 "An error was encountered while "
657                                 + "attempting to trigger"
658                                 + " rc=" + result.rc
659                                 + " result=" + result.result);
660             }
661             else
662             {
663                 STAFMarshallingContext mc =
664                     STAFMarshallingContext.unmarshall(result.result);
665 
666                 Map triggerMap = (Map)mc.getRootObject();
667 
668                 String triggerMachine = (String)triggerMap.get("machine");
669                 String triggerRequestNumber =
670                     (String)triggerMap.get("requestNumber");
671 
672                 String logQueryContains = "[ID=" + selectedId + "] [" +
673                     triggerMachine + ":" + triggerRequestNumber + "]";
674 
675                 try
676                 {
677                     Thread.sleep(250);
678                 }
679                 catch(InterruptedException ex) {}
680 
681                 String queryRequest =
682                     "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
683                     fLogName + " CONTAINS " + logQueryContains + " ALL";
684 
685                 STAFLogViewer logViewer = new STAFLogViewer(
686                     this, fHandle, fServiceMachine, "LOG", queryRequest, "",
687                     "Monospaced");
688             }
689         }
690         else if (e.getSource() == fSelectedTriggerWithScript ||
691                  e.getSource() == fPopupMenuTriggerWithScript)
692         {
693             fScriptDialog = new JDialog(this, "Trigger Script", true);
694             fScriptDialog.setSize(new Dimension(400, 200));
695             JPanel scriptPanel = new JPanel();
696             scriptPanel.setLayout(new BorderLayout());
697             fScriptTextArea = new JTextArea(5, 15);
698             fScriptTextArea.setBorder(new TitledBorder("Enter script here"));
699             scriptPanel.add(BorderLayout.CENTER,
700                 new JScrollPane(fScriptTextArea));
701 
702             fScriptTriggerButton = new JButton("Trigger");
703             fScriptCancelButton = new JButton("Cancel");
704 
705             JPanel scriptButtonPanel = new JPanel();
706             scriptButtonPanel.setLayout(new
707                 FlowLayout(FlowLayout.CENTER, 0, 0));
708             scriptButtonPanel.add(fScriptTriggerButton);
709             scriptButtonPanel.add(Box.createHorizontalStrut(20));
710             scriptButtonPanel.add(fScriptCancelButton);
711 
712             scriptPanel.add(BorderLayout.SOUTH, scriptButtonPanel);
713 
714             fScriptTriggerButton.addActionListener(this);
715             fScriptCancelButton.addActionListener(this);
716 
717             fScriptDialog.getContentPane().add(scriptPanel);
718 
719             fScriptTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
720             fScriptDialog.setLocationRelativeTo(this);
721             fScriptDialog.setFont(new Font("Monospaced", Font.PLAIN, 12));
722             fScriptDialog.setVisible(true);
723         }
724         else if (e.getSource() == fScriptCancelButton)
725         {
726             fScriptDialog.dispose();
727         }
728         else if (e.getSource() == fScriptTriggerButton)
729         {
730             String triggerScript = fScriptTextArea.getText();
731 
732             fScriptDialog.dispose();
733 
734             int selectedRow = fIDTable.getSelectedRow();
735 
736             if (selectedRow == -1)
737             {
738                 return;
739             }
740 
741             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
742 
743             STAFResult result = fHandle.submit2(
744                 fServiceMachine, fServiceName,
745                 " TRIGGER ID " + selectedId + " SCRIPT " +
746                 STAFUtil.wrapData(triggerScript));
747 
748             if (result.rc != 0)
749             {
750                 showErrorDialog(fRegistrationDialog,
751                                 "An error was encountered while "
752                                 + "attempting to trigger"
753                                 + " rc=" + result.rc
754                                 + " result=" + result.result);
755             }
756             else
757             {
758                 STAFMarshallingContext mc =
759                     STAFMarshallingContext.unmarshall(result.result);
760 
761                 Map triggerMap = (Map)mc.getRootObject();
762 
763                 String triggerMachine = (String)triggerMap.get("machine");
764                 String triggerRequestNumber =
765                     (String)triggerMap.get("requestNumber");
766 
767                 String logQueryContains = "[ID=" + selectedId + "] [" +
768                     triggerMachine + ":" + triggerRequestNumber + "]";
769 
770                 try
771                 {
772                     Thread.sleep(250);
773                 }
774                 catch(InterruptedException ex) {}
775 
776                 String queryRequest =
777                     "QUERY MACHINE {STAF/Config/MachineNickname} LOGNAME " +
778                     fLogName + " CONTAINS " + logQueryContains + " ALL";
779 
780                 STAFLogViewer logViewer = new STAFLogViewer(
781                     this, fHandle, fServiceMachine, "LOG", queryRequest, "",
782                     "Monospaced");
783             }
784         }
785         else if (e.getSource() == fSelectedCopyToNewRegistration ||
786                  e.getSource() == fPopupMenuCopyToNewRegistration)
787         {
788             int selectedRow = fIDTable.getSelectedRow();
789 
790             if (selectedRow == -1)
791             {
792                 return;
793             }
794 
795             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
796 
797             String eventManagerId = "";
798 
799             Iterator idIter = fEntryList.iterator();
800 
801             while (idIter.hasNext() && !(eventManagerId.equals(selectedId)))
802             {
803                 Map registrationMap = (Map)idIter.next();
804                 eventManagerId = (String)registrationMap.get("eventManagerID");
805 
806                 if (eventManagerId.equals(selectedId))
807                 {
808                     String machine = (String)registrationMap.get("machine");
809                     String machineType =
810                         (String)registrationMap.get("machineType");
811                     String service = (String)registrationMap.get("service");
812                     String serviceType =
813                         (String)registrationMap.get("serviceType");
814                     String request = (String)registrationMap.get("request");
815                     String requestType =
816                         (String)registrationMap.get("requestType");
817                     String prepareScript =
818                         (String)registrationMap.get("prepareScript");
819                     String type = (String)registrationMap.get("type");
820                     String subtype = (String)registrationMap.get("subtype");
821                     String description =
822                         (String)registrationMap.get("description");
823                     String state =
824                         (String)registrationMap.get("state");
825 
826                     displayfRegistrationDialog();
827 
828                     fRegistrationIDLabel.setText("N/A");
829 
830                     fMachineTF.setText(machine);
831                     fPythonMachine.setSelected(machineType.equals("Python"));
832                     fServiceTF.setText(service);
833                     fPythonService.setSelected(serviceType.equals("Python"));
834                     fRequestTF.setText(request);
835                     fPythonRequest.setSelected(requestType.equals("Python"));
836                     fPrepareTA.setText(prepareScript);
837                     fTypeTF.setText(type);
838                     fSubtypeTF.setText(subtype);
839                     fDescriptionTF.setText(description);
840 
841                     if (state.equals("Disabled"))
842                     {
843                         fEnabledCB.setSelected(false);
844                     }
845                     else
846                     {
847                         fEnabledCB.setSelected(true);
848                     }
849 
850                     fRegistrationDialog.setVisible(true);
851                 }
852             }
853         }
854         else if (e.getSource() == fSelectedUnregister ||
855                  e.getSource() == fPopupMenuUnregister)
856         {
857             int selectedRow = fIDTable.getSelectedRow();
858 
859             if (selectedRow == -1)
860             {
861                 return;
862             }
863 
864             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
865 
866             int response = JOptionPane.showConfirmDialog(this,
867                 "Are you sure you want to unregister ID " +
868                 selectedId + "?");
869 
870             if (response != JOptionPane.YES_OPTION)
871             {
872                 return;
873             }
874 
875             STAFResult result = fHandle.submit2(
876                 fServiceMachine, fServiceName, "UNREGISTER ID " + selectedId);
877 
878             if (result.rc != 0)
879             {
880                 showErrorDialog(fRegistrationDialog,
881                                 "An error was encountered while "
882                                 + "attempting to unregister"
883                                 + " rc=" + result.rc
884                                 + " result=" + result.result);
885             }
886             else
887             {
888                 Vector idData = getRegistrationTable();
889                 setInstructionLabel(idData);
890 
891                 if (idData == null)
892                 {
893                     return;
894                 }
895 
896                 ((RegisterModel)(fIDTable.getModel())).setDataVector(
897                     idData, fColumnNames);
898 
899                 fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
900                 fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
901                 fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
902                 fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
903                 fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
904                 fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
905                 fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
906 
907                 JOptionPane.showMessageDialog(this,
908                     "Sucessfully unregistered.",
909                     "Sucessfully unregistered",
910                     JOptionPane.INFORMATION_MESSAGE);
911 
912                 fSelectedMenu.setEnabled(false);
913             }
914         }
915         else if (e.getSource() == fSelectedEnable ||
916                  e.getSource() == fPopupMenuEnable)
917         {
918             int selectedRow = fIDTable.getSelectedRow();
919 
920             if (selectedRow == -1)
921             {
922                 return;
923             }
924 
925             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
926 
927             STAFResult result = fHandle.submit2(
928                 fServiceMachine, fServiceName, "ENABLE ID " + selectedId);
929 
930             if (result.rc != 0)
931             {
932                 showErrorDialog(fRegistrationDialog,
933                                 "An error was encountered while "
934                                 + "attempting to enable"
935                                 + " rc=" + result.rc
936                                 + " result=" + result.result);
937             }
938             else
939             {
940                 Vector idData = getRegistrationTable();
941                 setInstructionLabel(idData);
942 
943                 if (idData == null)
944                 {
945                     return;
946                 }
947 
948                 ((RegisterModel)(fIDTable.getModel())).setDataVector(
949                     idData, fColumnNames);
950 
951                 fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
952                 fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
953                 fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
954                 fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
955                 fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
956                 fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
957                 fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
958 
959                 fSelectedMenu.setEnabled(false);
960             }
961         }
962         else if (e.getSource() == fSelectedDisable ||
963                  e.getSource() == fPopupMenuDisable)
964         {
965             int selectedRow = fIDTable.getSelectedRow();
966 
967             if (selectedRow == -1)
968             {
969                 return;
970             }
971 
972             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
973 
974             STAFResult result = fHandle.submit2(
975                 fServiceMachine, fServiceName, "DISABLE ID " + selectedId);
976 
977             if (result.rc != 0)
978             {
979                 showErrorDialog(fRegistrationDialog,
980                                 "An error was encountered while "
981                                 + "attempting to disable"
982                                 + " rc=" + result.rc
983                                 + " result=" + result.result);
984             }
985             else
986             {
987                 Vector idData = getRegistrationTable();
988                 setInstructionLabel(idData);
989 
990                 if (idData == null)
991                 {
992                     return;
993                 }
994 
995                 ((RegisterModel)(fIDTable.getModel())).setDataVector(
996                     idData, fColumnNames);
997 
998                 fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
999                 fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
1000                 fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
1001                 fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
1002                 fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
1003                 fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
1004                 fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
1005 
1006                 fSelectedMenu.setEnabled(false);
1007             }
1008         }
1009         else if (e.getSource() == fRegisterButton)
1010         {
1011             String request = "REGISTER";
1012 
1013             if (fMachineTF.getText().equals(""))
1014             {
1015                 JOptionPane.showMessageDialog(fRegistrationDialog,
1016                     "You must specify a value for Target Machine",
1017                     "Target Machine not specified", JOptionPane.ERROR_MESSAGE);
1018                 return;
1019             }
1020 
1021             if (fServiceTF.getText().equals(""))
1022             {
1023                 JOptionPane.showMessageDialog(fRegistrationDialog,
1024                     "You must specify a value for Target Service",
1025                     "Target Service not specified", JOptionPane.ERROR_MESSAGE);
1026                 return;
1027             }
1028 
1029             if (fRequestTF.getText().equals(""))
1030             {
1031                 JOptionPane.showMessageDialog(fRegistrationDialog,
1032                     "You must specify a value for Target Request",
1033                     "Target Request not specified", JOptionPane.ERROR_MESSAGE);
1034                 return;
1035             }
1036 
1037             if (fPythonMachine.isSelected())
1038             {
1039                 request += " PYTHONMACHINE " +
1040                     STAFUtil.wrapData(fMachineTF.getText());
1041             }
1042             else
1043             {
1044                 request += " MACHINE " +
1045                     STAFUtil.wrapData(fMachineTF.getText());
1046             }
1047 
1048             if (fPythonService.isSelected())
1049             {
1050                 request += " PYTHONSERVICE " +
1051                     STAFUtil.wrapData(fServiceTF.getText());
1052             }
1053             else
1054             {
1055                 request += " SERVICE " +
1056                     STAFUtil.wrapData(fServiceTF.getText());
1057             }
1058 
1059             if (fPythonRequest.isSelected())
1060             {
1061                 request += " PYTHONREQUEST " +
1062                     STAFUtil.wrapData(fRequestTF.getText());
1063             }
1064             else
1065             {
1066                 request += " REQUEST " +
1067                     STAFUtil.wrapData(fRequestTF.getText());
1068             }
1069 
1070             if (!(fPrepareTA.getText().equals("")))
1071             {
1072                 request += " PREPARE " + STAFUtil.wrapData(fPrepareTA.getText());
1073             }
1074 
1075             if (!(fTypeTF.getText().equals("")))
1076             {
1077                 request += " TYPE " + STAFUtil.wrapData(fTypeTF.getText());
1078             }
1079 
1080             if (!(fSubtypeTF.getText().equals("")))
1081             {
1082                 request += " SUBTYPE " + STAFUtil.wrapData(fSubtypeTF.getText());
1083             }
1084 
1085             if (!(fDescriptionTF.getText().equals("")))
1086             {
1087                 request += " DESCRIPTION " +
1088                     STAFUtil.wrapData(fDescriptionTF.getText());
1089             }
1090 
1091             if (!(fEnabledCB.isSelected()))
1092             {
1093                 request += " DISABLED";
1094             }
1095 
1096             boolean unregisterExistingID = false;
1097             String unregisterID = "";
1098 
1099             if (!(fRegistrationIDLabel.getText().equals("N/A")))
1100             {
1101                 int response = JOptionPane.showConfirmDialog(fRegistrationDialog,
1102                     "Do you want to unregister ID " +
1103                     fRegistrationIDLabel.getText() + " and re-register the " +
1104                     "STAF request?");
1105 
1106                 if (response != JOptionPane.YES_OPTION)
1107                 {
1108                     return;
1109                 }
1110 
1111                 unregisterExistingID = true;
1112                 unregisterID = fRegistrationIDLabel.getText();
1113             }
1114 
1115             // Submit the EventManager REGISTER request
1116 
1117             STAFResult result = fHandle.submit2(
1118                 fServiceMachine, fServiceName, request);
1119 
1120             if (result.rc != 0)
1121             {
1122                 showErrorDialog(fRegistrationDialog,
1123                                 "An error was encountered while "
1124                                 + "attempting to register"
1125                                 + " rc=" + result.rc
1126                                 + " result=" + result.result);
1127             }
1128             else
1129             {
1130                 if (unregisterExistingID)
1131                 {
1132                     STAFResult unregisterResult = fHandle.submit2(
1133                         fServiceMachine, fServiceName,
1134                         "UNREGISTER ID " + unregisterID);
1135 
1136                     if (unregisterResult.rc != 0)
1137                     {
1138                         showErrorDialog(fRegistrationDialog,
1139                                         "An error was encountered while "
1140                                         + "attempting to unregister ID"
1141                                         + unregisterID + " rc=" + result.rc
1142                                         + " result=" + result.result);
1143                     }
1144                 }
1145 
1146                 Vector idData = getRegistrationTable();
1147                 setInstructionLabel(idData);
1148 
1149                 if (idData == null)
1150                 {
1151                     return;
1152                 }
1153 
1154                 ((RegisterModel)(fIDTable.getModel())).setDataVector(
1155                     idData, fColumnNames);
1156 
1157                 fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
1158                 fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
1159                 fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
1160                 fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
1161                 fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
1162                 fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
1163                 fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
1164 
1165                 fRegistrationDialog.dispose();
1166 
1167                 JOptionPane.showMessageDialog(this,
1168                     "Sucessfully registered.  ID = " + result.result,
1169                     "Sucessfully registerd",
1170                     JOptionPane.INFORMATION_MESSAGE);
1171 
1172                 fSelectedMenu.setEnabled(false);
1173             }
1174         }
1175     }
1176 
mouseClicked(MouseEvent e)1177     public void mouseClicked(MouseEvent e)
1178     {
1179         int selectedRow = fIDTable.getSelectedRow();
1180 
1181         if (selectedRow != -1)
1182         {
1183             fSelectedMenu.setEnabled(true);
1184 
1185             String eventManagerId = "";
1186             String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
1187 
1188             Iterator idIter = fEntryList.iterator();
1189 
1190             while (idIter.hasNext() &&
1191                    !(eventManagerId.equals(selectedId)))
1192             {
1193                 Map registrationMap = (Map)idIter.next();
1194                 eventManagerId = (String)registrationMap.get("eventManagerID");
1195 
1196                 if (eventManagerId.equals(selectedId))
1197                 {
1198                     String state = (String)registrationMap.get("state");
1199 
1200                     if (state.equals("Enabled"))
1201                     {
1202                         fPopupMenuEnable.setEnabled(false);
1203                         fPopupMenuDisable.setEnabled(true);
1204                         fSelectedEnable.setEnabled(false);
1205                         fSelectedDisable.setEnabled(true);
1206                     }
1207                     else
1208                     {
1209                         fPopupMenuEnable.setEnabled(true);
1210                         fPopupMenuDisable.setEnabled(false);
1211                         fSelectedEnable.setEnabled(true);
1212                         fSelectedDisable.setEnabled(false);
1213                     }
1214                 }
1215             }
1216         }
1217 
1218         if ((e.getClickCount() != 2) ||
1219             (selectedRow == -1))
1220         {
1221             return;
1222         }
1223 
1224         String selectedId = (String) fIDTable.getValueAt(selectedRow, 0);
1225 
1226         String eventManagerId = "";
1227 
1228         Iterator idIter = fEntryList.iterator();
1229 
1230         while (idIter.hasNext() && !(eventManagerId.equals(selectedId)))
1231         {
1232             Map registrationMap = (Map)idIter.next();
1233             eventManagerId = (String)registrationMap.get("eventManagerID");
1234 
1235             if (eventManagerId.equals(selectedId))
1236             {
1237                 String machine = (String)registrationMap.get("machine");
1238                 String machineType = (String)registrationMap.get("machineType");
1239                 String service = (String)registrationMap.get("service");
1240                 String serviceType = (String)registrationMap.get("serviceType");
1241                 String request = (String)registrationMap.get("request");
1242                 String requestType = (String)registrationMap.get("requestType");
1243                 String prepareScript =
1244                     (String)registrationMap.get("prepareScript");
1245                 String type = (String)registrationMap.get("type");
1246                 String subtype = (String)registrationMap.get("subtype");
1247                 String dayOfMonth = (String)registrationMap.get("dayOfMonth");
1248                 String month = (String)registrationMap.get("month");
1249                 String dayOfWeek = (String)registrationMap.get("dayOfWeek");
1250                 String description = (String)registrationMap.get("description");
1251                 String state =
1252                     (String)registrationMap.get("state");
1253 
1254                 displayfRegistrationDialog();
1255 
1256                 fRegistrationIDLabel.setText(eventManagerId);
1257 
1258                 fMachineTF.setText(machine);
1259                 fPythonMachine.setSelected(machineType.equals("Python"));
1260                 fServiceTF.setText(service);
1261                 fPythonService.setSelected(serviceType.equals("Python"));
1262                 fRequestTF.setText(request);
1263                 fPythonRequest.setSelected(requestType.equals("Python"));
1264                 fPrepareTA.setText(prepareScript);
1265                 fTypeTF.setText(type);
1266                 fSubtypeTF.setText(subtype);
1267                 fDescriptionTF.setText(description);
1268 
1269                 if (state.equals("Disabled"))
1270                 {
1271                     fEnabledCB.setSelected(false);
1272                 }
1273                 else
1274                 {
1275                     fEnabledCB.setSelected(true);
1276                 }
1277 
1278                 fRegistrationDialog.setVisible(true);
1279             }
1280         }
1281     }
1282 
mouseEntered(MouseEvent e)1283     public void mouseEntered(MouseEvent e) {}
mouseExited(MouseEvent e)1284     public void mouseExited(MouseEvent e) {}
mousePressed(MouseEvent e)1285     public void mousePressed(MouseEvent e){}
1286 
mouseReleased(MouseEvent e)1287     public void mouseReleased(MouseEvent e)
1288     {
1289         displayPopup(e);
1290     }
1291 
displayPopup(MouseEvent e)1292     public void displayPopup(MouseEvent e)
1293     {
1294         if (e.isPopupTrigger())
1295         {
1296             int tableIndex = fIDTable.rowAtPoint(
1297                 new Point(e.getX(), e.getY()));
1298 
1299             if (tableIndex > -1)
1300             {
1301                 fIDTable.setRowSelectionInterval(tableIndex, tableIndex);
1302 
1303                 fPopupMenu.show(e.getComponent(), e.getX(), e.getY());
1304 
1305                 fSelectedMenu.setEnabled(true);
1306 
1307                 String eventManagerId = "";
1308                 String selectedId = (String) fIDTable.getValueAt(tableIndex, 0);
1309 
1310                 Iterator idIter = fEntryList.iterator();
1311 
1312                 while (idIter.hasNext() &&
1313                        !(eventManagerId.equals(selectedId)))
1314                 {
1315                     Map registrationMap = (Map)idIter.next();
1316                     eventManagerId =
1317                         (String)registrationMap.get("eventManagerID");
1318 
1319                     if (eventManagerId.equals(selectedId))
1320                     {
1321                         String state = (String)registrationMap.get("state");
1322 
1323                         if (state.equals("Enabled"))
1324                         {
1325                             fPopupMenuEnable.setEnabled(false);
1326                             fPopupMenuDisable.setEnabled(true);
1327                             fSelectedEnable.setEnabled(false);
1328                             fSelectedDisable.setEnabled(true);
1329                         }
1330                         else
1331                         {
1332                             fPopupMenuEnable.setEnabled(true);
1333                             fPopupMenuDisable.setEnabled(false);
1334                             fSelectedEnable.setEnabled(true);
1335                             fSelectedDisable.setEnabled(false);
1336                         }
1337                     }
1338                 }
1339             }
1340         }
1341     }
1342 
keyPressed(KeyEvent e)1343     public void keyPressed(KeyEvent e)
1344     {
1345         if ((e.getSource() == fServiceMachineTF) ||
1346             (e.getSource() == fServiceNameTF))
1347         {
1348             if (e.getKeyCode() == KeyEvent.VK_ENTER)
1349             {
1350                 // Check if service machine or service name was changed
1351 
1352                 boolean changed = false;
1353 
1354                 if (!fServiceMachine.equals(fServiceMachineTF.getText()))
1355                 {
1356                     changed = true;
1357                     fServiceMachine = fServiceMachineTF.getText();
1358                 }
1359 
1360                 if (!fServiceName.equals(fServiceNameTF.getText()))
1361                 {
1362                     changed = true;
1363                     fServiceName = fServiceNameTF.getText();
1364                 }
1365 
1366                 if (changed)
1367                 {
1368                     // Assign the log name for the service log.
1369                     // It must have the right case in order for a log query
1370                     // request to work on Unix machines.
1371 
1372                     assignLogName();
1373                 }
1374 
1375                 Vector idData = getRegistrationTable();
1376                 setInstructionLabel(idData);
1377 
1378                 ((RegisterModel)(fIDTable.getModel())).setDataVector(
1379                     idData, fColumnNames);
1380 
1381                 fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);
1382                 fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);
1383                 fIDTable.getColumnModel().getColumn(1).setPreferredWidth(20);
1384                 fIDTable.getColumnModel().getColumn(2).setPreferredWidth(150);
1385                 fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);
1386                 fIDTable.getColumnModel().getColumn(4).setPreferredWidth(30);
1387                 fIDTable.getColumnModel().getColumn(5).setPreferredWidth(265);
1388 
1389                 fSelectedMenu.setEnabled(false);
1390             }
1391         }
1392     }
1393 
keyReleased(KeyEvent e)1394     public void keyReleased(KeyEvent e) {}
1395 
keyTyped(KeyEvent e)1396     public void keyTyped(KeyEvent e) {}
1397 
displayfRegistrationDialog()1398     public void displayfRegistrationDialog()
1399     {
1400         fRegistrationDialog = new JDialog(
1401             this, "EventManager Registration", true);
1402 
1403         JPanel optionsPanel = new JPanel();
1404         GridBagLayout gbl = new GridBagLayout();
1405         GridBagConstraints gbc = new GridBagConstraints();
1406         optionsPanel.setLayout(gbl);
1407 
1408         JLabel registrationIDTitle = new JLabel("Registration ID:");
1409         registrationIDTitle.setOpaque(true);
1410         registrationIDTitle.setForeground(Color.black);
1411 
1412         gbc.anchor = GridBagConstraints.NORTHWEST;
1413         optionsPanel.add(registrationIDTitle, gbc);
1414         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1415 
1416         fRegistrationIDLabel = new JLabel("N/A");
1417         fRegistrationIDLabel.setForeground(Color.blue);
1418 
1419         gbc.gridwidth = GridBagConstraints.REMAINDER;
1420         gbc.weightx = 1.0;
1421         optionsPanel.add(fRegistrationIDLabel, gbc);
1422 
1423         gbc.weightx = 0;
1424         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1425 
1426         JLabel descriptionLabel = new JLabel("Description:");
1427         descriptionLabel.setOpaque(true);
1428         descriptionLabel.setForeground(Color.black);
1429 
1430         gbc.gridwidth = 1;
1431         optionsPanel.add(descriptionLabel, gbc);
1432         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1433 
1434         fDescriptionTF = new JTextField(20)
1435             {
1436                 public JToolTip createToolTip()
1437                 {
1438                     MultiLineToolTip tip = new MultiLineToolTip();
1439                     tip.setComponent(this);
1440                     return tip;
1441                 }
1442             };
1443 
1444         fDescriptionTF.setToolTipText(
1445             wrapText("Enter a description for the registration. This field " +
1446             "is optional.", 80));
1447 
1448         gbc.gridwidth = GridBagConstraints.REMAINDER;
1449         gbc.weightx = 1.0;
1450         optionsPanel.add(fDescriptionTF, gbc);
1451 
1452         gbc.weightx = 0;
1453         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1454 
1455         JLabel machineLabel = new JLabel("Target Machine:");
1456         machineLabel.setOpaque(true);
1457         machineLabel.setForeground(Color.black);
1458 
1459         gbc.gridwidth = 1;
1460         optionsPanel.add(machineLabel, gbc);
1461         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1462 
1463         fPythonMachine = new JCheckBox("Python", false)
1464             {
1465                 public JToolTip createToolTip()
1466                 {
1467                     MultiLineToolTip tip = new MultiLineToolTip();
1468                     tip.setComponent(this);
1469                     return tip;
1470                 }
1471             };
1472 
1473         fPythonMachine.setToolTipText(
1474            wrapText("Checking \"Python\" indicates that the text entered for " +
1475            "\"Target Machine\" contains Python code.", 80));
1476 
1477         gbc.gridwidth = 1;
1478         optionsPanel.add(fPythonMachine, gbc);
1479         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1480 
1481         fMachineTF = new JTextField(20)
1482             {
1483                 public JToolTip createToolTip()
1484                 {
1485                     MultiLineToolTip tip = new MultiLineToolTip();
1486                     tip.setComponent(this);
1487                     return tip;
1488                 }
1489             };
1490 
1491         fMachineTF.setToolTipText(
1492             wrapText("The machine where you wish to have the STAF command " +
1493             "executed. This field is required. If the text contains Python " +
1494             "code, then select \"Python\" next to the \"Target Machine\" " +
1495             "label.", 80));
1496 
1497         gbc.gridwidth = GridBagConstraints.REMAINDER;
1498         gbc.weightx = 1.0;
1499         optionsPanel.add(fMachineTF, gbc);
1500 
1501         gbc.weightx = 0;
1502         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1503 
1504         JLabel serviceLabel = new JLabel("Target Service:");
1505         serviceLabel.setOpaque(true);
1506         serviceLabel.setForeground(Color.black);
1507 
1508         gbc.gridwidth = 1;
1509         optionsPanel.add(serviceLabel, gbc);
1510         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1511 
1512         fPythonService = new JCheckBox("Python", false)
1513             {
1514                 public JToolTip createToolTip()
1515                 {
1516                     MultiLineToolTip tip = new MultiLineToolTip();
1517                     tip.setComponent(this);
1518                     return tip;
1519                 }
1520             };
1521 
1522         fPythonService.setToolTipText(
1523             wrapText("Checking \"Python\" indicates that the text entered " +
1524             "for \"Target Service\" contains Python code.", 80));
1525 
1526         gbc.gridwidth = 1;
1527         optionsPanel.add(fPythonService, gbc);
1528         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1529 
1530         fServiceTF = new JTextField(20)
1531             {
1532                 public JToolTip createToolTip()
1533                 {
1534                     MultiLineToolTip tip = new MultiLineToolTip();
1535                     tip.setComponent(this);
1536                     return tip;
1537                 }
1538             };
1539 
1540         fServiceTF.setToolTipText(
1541             wrapText("The service for the STAF command you wish to have " +
1542             "executed. This field is required. If the text contains Python " +
1543             "code, then select \"Python\" next to the \"Target Service\" " +
1544             "label.", 80));
1545 
1546         gbc.gridwidth = GridBagConstraints.REMAINDER;
1547         gbc.weightx = 1.0;
1548         optionsPanel.add(fServiceTF, gbc);
1549 
1550         gbc.weightx = 0;
1551         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1552 
1553         JLabel requestLabel = new JLabel("Target Request:");
1554         requestLabel.setOpaque(true);
1555         requestLabel.setForeground(Color.black);
1556 
1557         gbc.gridwidth = 1;
1558         optionsPanel.add(requestLabel, gbc);
1559         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1560 
1561         fPythonRequest = new JCheckBox("Python", false)
1562             {
1563                 public JToolTip createToolTip()
1564                 {
1565                     MultiLineToolTip tip = new MultiLineToolTip();
1566                     tip.setComponent(this);
1567                     return tip;
1568                 }
1569             };
1570 
1571         fPythonRequest.setToolTipText(
1572             wrapText("Checking \"Python\" indicates that the text entered " +
1573             "for \"Target Request\" contains Python code.", 80));
1574 
1575         gbc.gridwidth = 1;
1576         optionsPanel.add(fPythonRequest, gbc);
1577         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1578 
1579         fRequestTF = new JTextField(40)
1580             {
1581                 public JToolTip createToolTip()
1582                 {
1583                     MultiLineToolTip tip = new MultiLineToolTip();
1584                     tip.setComponent(this);
1585                     return tip;
1586                 }
1587             };
1588 
1589         fRequestTF.setToolTipText(
1590             wrapText("The STAF request you wish to have executed. This field " +
1591             "is required. If the text contains Python code, then select " +
1592             "\"Python\" next to the \"Target Request\" label.", 80));
1593 
1594         gbc.gridwidth = GridBagConstraints.REMAINDER;
1595         gbc.weightx = 1.0;
1596         optionsPanel.add(fRequestTF, gbc);
1597 
1598         gbc.weightx = 0;
1599         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1600 
1601         JLabel prepareLabel = new JLabel("Prepare Script:");
1602         prepareLabel.setOpaque(true);
1603         prepareLabel.setForeground(Color.black);
1604 
1605         gbc.gridwidth = 1;
1606         optionsPanel.add(prepareLabel, gbc);
1607         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1608 
1609         fPrepareTA = new JTextArea(5, 40)
1610             {
1611                 public JToolTip createToolTip()
1612                 {
1613                     MultiLineToolTip tip = new MultiLineToolTip();
1614                     tip.setComponent(this);
1615                     return tip;
1616                 }
1617             };
1618 
1619         fPrepareTA.setToolTipText(
1620             wrapText("Any Python code that you wish to have evaluated prior " +
1621             "to the evaluation of any PYTHONMACHINE, PYTHONSERVICE, or " +
1622             "PYTHONREQUEST options. This field is optional.", 80));
1623 
1624         fPrepareTA.setBorder(new BevelBorder(BevelBorder.LOWERED));
1625 
1626         gbc.gridwidth = GridBagConstraints.REMAINDER;
1627         gbc.weightx = 1.0;
1628         optionsPanel.add(fPrepareTA, gbc);
1629 
1630         gbc.weightx = 0;
1631         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1632 
1633         gbc.weightx = 0;
1634         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1635 
1636         JLabel typeLabel = new JLabel("Type:");
1637         typeLabel.setOpaque(true);
1638         typeLabel.setForeground(Color.black);
1639 
1640         gbc.gridwidth = 1;
1641         optionsPanel.add(typeLabel, gbc);
1642         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1643 
1644         fTypeTF = new JTextField(20)
1645             {
1646                 public JToolTip createToolTip()
1647                 {
1648                     MultiLineToolTip tip = new MultiLineToolTip();
1649                     tip.setComponent(this);
1650                     return tip;
1651                 }
1652             };
1653 
1654         fTypeTF.setToolTipText(
1655             wrapText("This specifies the Event Type for which this command " +
1656             "will be registered. This field is required.", 80));
1657 
1658         gbc.gridwidth = GridBagConstraints.REMAINDER;
1659         gbc.weightx = 1.0;
1660         optionsPanel.add(fTypeTF, gbc);
1661 
1662         gbc.weightx = 0;
1663         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1664 
1665         JLabel subtypeLabel = new JLabel("Subtype:");
1666         subtypeLabel.setOpaque(true);
1667         subtypeLabel.setForeground(Color.black);
1668 
1669         gbc.gridwidth = 1;
1670         optionsPanel.add(subtypeLabel, gbc);
1671         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1672 
1673         fSubtypeTF = new JTextField(20)
1674             {
1675                 public JToolTip createToolTip()
1676                 {
1677                     MultiLineToolTip tip = new MultiLineToolTip();
1678                     tip.setComponent(this);
1679                     return tip;
1680                 }
1681             };
1682 
1683         fSubtypeTF.setToolTipText(
1684             wrapText("This specifies the Event SubType for which this " +
1685             "command will be registered. This field is optional.", 80));
1686 
1687         gbc.gridwidth = GridBagConstraints.REMAINDER;
1688         gbc.weightx = 1.0;
1689         optionsPanel.add(fSubtypeTF, gbc);
1690 
1691         gbc.weightx = 0;
1692         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1693 
1694         JLabel enabledLabel = new JLabel("Enabled:");
1695         enabledLabel.setOpaque(true);
1696         enabledLabel.setForeground(Color.black);
1697 
1698         gbc.gridwidth = 1;
1699         optionsPanel.add(enabledLabel, gbc);
1700         optionsPanel.add(Box.createHorizontalStrut(10), gbc);
1701 
1702         fEnabledCB = new JCheckBox("", true)
1703             {
1704                 public JToolTip createToolTip()
1705                 {
1706                     MultiLineToolTip tip = new MultiLineToolTip();
1707                     tip.setComponent(this);
1708                     return tip;
1709                 }
1710             };
1711 
1712         fEnabledCB.setToolTipText(
1713             wrapText("Checking \"Enabled\" indicates that the STAF command " +
1714             "will be enabled when it is registered. If the STAF command is " +
1715             "disabled, it will not be submitted when its event type/subtype " +
1716             "is generated.", 80));
1717 
1718         gbc.gridwidth = GridBagConstraints.REMAINDER;
1719         gbc.weightx = 1.0;
1720         optionsPanel.add(fEnabledCB, gbc);
1721 
1722         gbc.weightx = 0;
1723         optionsPanel.add(Box.createVerticalStrut(3), gbc);
1724 
1725         JPanel outerPanel = new JPanel();
1726         outerPanel.setLayout(new BorderLayout());
1727         outerPanel.setBorder(new TitledBorder("EventManager Register options"));
1728         outerPanel.add(BorderLayout.CENTER, new JScrollPane(optionsPanel));
1729 
1730         JPanel buttonPanel = new JPanel();
1731         buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
1732 
1733         fRegisterButton = new JButton("Register");
1734         fRegisterButton.addActionListener(this);
1735         buttonPanel.add(fRegisterButton);
1736 
1737         fCancelButton = new JButton("Cancel");
1738         fCancelButton.addActionListener(this);
1739         buttonPanel.add(fCancelButton);
1740 
1741         outerPanel.add(BorderLayout.SOUTH, buttonPanel);
1742 
1743         fRegistrationDialog.getContentPane().add(outerPanel);
1744         fRegistrationDialog.setSize(new Dimension(650, 380));
1745         fRegistrationDialog.setLocationRelativeTo(this);
1746     }
1747 
showErrorDialog(Component comp, String message)1748     public void showErrorDialog(Component comp, String message)
1749     {
1750         JTextPane messagePane = new JTextPane();
1751         messagePane.setFont(new Font("Dialog", Font.BOLD, 12));
1752         messagePane.setEditable(false);
1753         messagePane.setText(message);
1754         messagePane.select(0,0);
1755         JScrollPane scrollPane = new JScrollPane(messagePane);
1756         scrollPane.setPreferredSize(new Dimension(400, 100));
1757         JOptionPane.showMessageDialog(comp, scrollPane,
1758                                       "EventManager Error",
1759                                       JOptionPane.ERROR_MESSAGE);
1760     }
1761 
assignLogName()1762     private void assignLogName()
1763     {
1764         // First try using the service name for the service log name
1765 
1766         fLogName = fServiceName;
1767 
1768         // Submit a LOG QUERY request to verify that a log name with the
1769         // specified service name exists.  We need to do this because the
1770         // service log name will have the case used when the service
1771         // was registered.  On Unix machines, the log name must be the same
1772         // case as the service name that was used when registering the
1773         // service.  So, if the "Service name" field on the UI doesn't
1774         // match the name used when registering the EventManager service,
1775         // the log query request will fail with RC 48 (Does Not Exist).
1776         // If this happens, we'll then list the machine logs to see if we
1777         // can find another log name that matches if we ignore the case.
1778         // If so, then we'll assign that as the log name.
1779 
1780         STAFResult result = fHandle.submit2(
1781             fServiceMachine, "LOG",
1782             "QUERY MACHINE {STAF/Config/MachineNickname} " +
1783             "LOGNAME " + fServiceName + " LAST 1");
1784 
1785         if (result.rc == STAFResult.DoesNotExist)
1786         {
1787             // List the machine logs on fServiceMachine and check if any of
1788             // the log names match fServiceName, case-insensitive
1789 
1790             result = fHandle.submit2(
1791                 fServiceMachine, "LOG",
1792                 "LIST MACHINE {STAF/Config/MachineNickname}");
1793 
1794             if (result.rc == STAFResult.Ok)
1795             {
1796                 // Iterate through list of logs
1797 
1798                 java.util.List log = (java.util.List)result.resultObj;
1799 
1800                 STAFMarshallingContext mc =
1801                     STAFMarshallingContext.unmarshall(
1802                         result.result);
1803 
1804                 java.util.List logList = (java.util.List)mc.getRootObject();
1805                 Iterator logIter = logList.iterator();
1806 
1807                 while (logIter.hasNext())
1808                 {
1809                     Map logMap = (HashMap)logIter.next();
1810                     String logName = (String)logMap.get("name");
1811 
1812                     if (fServiceName.equalsIgnoreCase(logName))
1813                     {
1814                         fLogName = logName;
1815                         break;
1816                     }
1817                 }
1818             }
1819         }
1820     }
1821 
getRegistrationTable()1822     public Vector getRegistrationTable()
1823     {
1824         String listRequest = "LIST LONG";
1825 
1826         STAFResult result = fHandle.submit2(
1827             fServiceMachine, fServiceName, listRequest);
1828 
1829         if (result.rc != STAFResult.Ok)
1830         {
1831             showErrorDialog(this, "Error listing the registrations.\nRC=" +
1832                 result.rc + " Result=" + result.result);
1833 
1834             return null;
1835         }
1836 
1837         STAFMarshallingContext mc =
1838             STAFMarshallingContext.unmarshall(result.result);
1839         STAFMapClassDefinition mcd = mc.getMapClassDefinition(
1840             "STAF/Service/EventManager/EventManagerID");
1841 
1842         fEntryList = (java.util.List)mc.getRootObject();
1843 
1844         Iterator idIter = fEntryList.iterator();
1845 
1846         Vector<Vector<String>> idData = new Vector<Vector<String>>();
1847 
1848         while (idIter.hasNext())
1849         {
1850             Map registrationMap = (Map)idIter.next();
1851             String id = (String)registrationMap.get("eventManagerID");
1852             String state = (String)registrationMap.get("state");
1853             String description = (String)registrationMap.get("description");
1854             String machine = (String)registrationMap.get("machine");
1855             String service = (String)registrationMap.get("service");
1856             String request = (String)registrationMap.get("request");
1857 
1858             Vector<String> row = new Vector<String>();
1859 
1860             row.add(id);
1861             row.add(state);
1862             row.add(description);
1863             row.add(machine);
1864             row.add(service);
1865             row.add(request);
1866 
1867             idData.add(row);
1868         }
1869 
1870         return idData;
1871     }
1872 
1873     // This method will wrap the input string at the specified column,
1874     // placing a newline character at the first whitespace character to the
1875     // left of the column position.  If the current section of the input string
1876     // contains no whitespace characters, then a newline character will be
1877     // placed at the next whitespace character to the right of the column
1878     // position.
1879 
wrapText(String inputString, int wrapColumn)1880     public static String wrapText(String inputString, int wrapColumn)
1881     {
1882         int i = wrapColumn;
1883         StringBuffer textBuffer = new StringBuffer(inputString);
1884         int lastWhitespaceIndex = 0;
1885 
1886         while (i < textBuffer.length())
1887         {
1888             if (Character.isWhitespace(textBuffer.charAt(i)))
1889             {
1890                 textBuffer.setCharAt(i, '\n');
1891                 lastWhitespaceIndex = i;
1892                 i = i + wrapColumn;
1893             }
1894             else
1895             {
1896                 i = i - 1;
1897 
1898                 if (i == lastWhitespaceIndex)
1899                 {
1900                     // No whitespace in the current block, so find the next
1901                     // whitespace character to the right of the current block
1902 
1903                     int j = i + wrapColumn;
1904 
1905                     while (j < textBuffer.length())
1906                     {
1907                         if (Character.isWhitespace(textBuffer.charAt(j)))
1908                         {
1909                             textBuffer.setCharAt(j, '\n');
1910                             lastWhitespaceIndex = j;
1911                             i = j + wrapColumn;
1912                             break;
1913                         }
1914 
1915                         j = j + 1;
1916                     }
1917 
1918                     if (j == textBuffer.length())
1919                     {
1920                         break;
1921                     }
1922                 }
1923             }
1924         }
1925 
1926         return textBuffer.toString();
1927     }
1928 
1929     class RegisterModel extends DefaultTableModel
1930     {
RegisterModel(Vector data, Vector columns)1931         public RegisterModel(Vector data, Vector columns)
1932         {
1933             super(data, columns);
1934         }
1935 
isCellEditable(int row, int col)1936         public boolean isCellEditable(int row, int col)
1937         {
1938             return false;
1939         }
1940     }
1941 
1942     class MultiLineToolTip extends JToolTip
1943     {
MultiLineToolTip()1944         public MultiLineToolTip()
1945         {
1946             setUI(new MultiLineToolTipUI());
1947         }
1948     }
1949 
1950     class MultiLineToolTipUI extends MetalToolTipUI
1951     {
1952         String[] lines;
1953         int maxWidth = 0;
1954 
paint(Graphics g, JComponent c)1955         public void paint(Graphics g, JComponent c)
1956         {
1957             FontMetrics metrics = g.getFontMetrics(g.getFont());
1958             Dimension size = c.getSize();
1959             g.setColor(c.getBackground());
1960             g.fillRect(0, 0, size.width, size.height);
1961             g.setColor(c.getForeground());
1962 
1963             if (lines != null)
1964             {
1965                 for (int i = 0; i < lines.length; i++)
1966                 {
1967                     g.drawString(lines[i], 3, (metrics.getHeight()) * ( i + 1));
1968                 }
1969             }
1970         }
1971 
getPreferredSize(JComponent c)1972         public Dimension getPreferredSize(JComponent c)
1973         {
1974             FontMetrics metrics = c.getFontMetrics(c.getFont());
1975             String tipText = ((JToolTip)c).getTipText();
1976 
1977             if (tipText == null)
1978             {
1979                 tipText = "";
1980             }
1981 
1982             BufferedReader br = new BufferedReader(new StringReader(tipText));
1983             String line;
1984             int maxWidth = 0;
1985             Vector<String> lineVector = new Vector<String>();
1986 
1987             try
1988             {
1989                 while ((line = br.readLine()) != null)
1990                 {
1991                     int width =
1992                         SwingUtilities.computeStringWidth(metrics,line);
1993 
1994                     if (maxWidth < width)
1995                     {
1996                         maxWidth = width;
1997                     }
1998 
1999                     lineVector.addElement(line);
2000                 }
2001             }
2002             catch (IOException ex)
2003             {
2004                 ex.printStackTrace();
2005             }
2006 
2007             int numberOfLines = lineVector.size();
2008 
2009             if (numberOfLines < 1)
2010             {
2011                 lines = null;
2012                 numberOfLines = 1;
2013             }
2014             else
2015             {
2016                 lines = new String[numberOfLines];
2017                 int i = 0;
2018 
2019                 for (Enumeration<String> e = lineVector.elements();
2020                      e.hasMoreElements(); i++)
2021                 {
2022                     lines[i] = e.nextElement();
2023                 }
2024             }
2025 
2026             int height = metrics.getHeight() * numberOfLines;
2027             this.maxWidth = maxWidth;
2028 
2029             return new Dimension(maxWidth + 8, height + 8);
2030         }
2031     }
2032 
2033 }