001: /*
002: * <copyright>
003: *
004: * Copyright 2000-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.tools.csmart.ui.console;
028:
029: import org.cougaar.tools.csmart.ui.viewer.CSMART;
030: import org.cougaar.tools.server.RemoteProcess;
031: import org.cougaar.tools.server.system.ProcessStatus;
032: import org.cougaar.util.log.Logger;
033:
034: import javax.swing.*;
035: import javax.swing.event.InternalFrameListener;
036: import javax.swing.event.ListSelectionEvent;
037: import javax.swing.event.ListSelectionListener;
038: import javax.swing.table.DefaultTableModel;
039: import java.awt.*;
040: import java.awt.event.ActionEvent;
041: import java.awt.event.KeyEvent;
042: import java.io.IOException;
043: import java.io.ObjectInputStream;
044: import java.net.InetAddress;
045: import java.net.UnknownHostException;
046: import java.util.ArrayList;
047: import java.util.Enumeration;
048: import java.util.Observable;
049: import java.util.Observer;
050: import java.util.Properties;
051: import java.util.Vector;
052:
053: /**
054: * org.cougaar.tools.csmart.ui.console
055: *
056: */
057: // This is essentially ConsoleInternalFrame, but
058: // created from the new CSMARTConsoleModel code
059: public class NodeView extends JInternalFrame implements Observer {
060: private static final String NODE_MENU = "Node";
061: private static final String INFO_ACTION = "Info";
062: private static final String CPU_USAGE_ACTION = "Machine CPU Usage";
063: private static final String NODE_CPU_USAGE_ACTION = "Node CPU Usage";
064:
065: private static final String EDIT_MENU = "Edit";
066: private static final String CUT_ACTION = "Cut";
067: private static final String COPY_ACTION = "Copy";
068: private static final String PASTE_ACTION = "Paste";
069: private static final String SELECT_ALL_ACTION = "Select All";
070: private static final String FIND_ACTION = "Find...";
071: private static final String FIND_NEXT_ACTION = "Find Next";
072:
073: private static final String VIEW_MENU = "View";
074: private static final String SET_VIEW_SIZE_ACTION = "Set View Size...";
075: private static final String FILTER_ACTION = "Filter...";
076:
077: private static final String CONTROL_MENU = "Control";
078: private static final String START_ACTION = "Restart";
079: private static final String STOP_ACTION = "Kill";
080: private static final String STACK_TRACE_ACTION = "Stack Trace";
081:
082: private static final String NOTIFY_MENU = "Notify";
083: private static final String SET_NOTIFY_ACTION = "Set Notification...";
084: private static final String REMOVE_NOTIFY_ACTION = "Remove Notification";
085: private static final String NOTIFY_NEXT_ACTION = "Find Next Notification";
086: private static final String RESET_NOTIFY_ACTION = "Reset Notification";
087:
088: private ConsoleTextPane consoleTextPane;
089: private Action findAction;
090: private Action findNextAction;
091: private Action notifyAction;
092: private Action notifyNextAction;
093: private Action startAction;
094: private Action stopAction;
095: private Action traceAction;
096:
097: private transient Logger log;
098:
099: private NodeModel model;
100: private JScrollPane scrollPane;
101:
102: private String nodeName;
103: private String hostName;
104: private Properties properties;
105: private java.util.List args;
106: private ConsoleNodeListener listener;
107: private NodeStatusButton statusButton;
108: private String logFileName;
109: private RemoteProcess remoteNode;
110:
111: public NodeView(NodeModel model) {
112: super ("", // title
113: true, //resizable
114: false, //not closable, because they can't be recreated
115: true, //maximizable
116: true);//iconifiable
117:
118: this .model = model;
119: initGui();
120: }
121:
122: private void initGui() {
123: scrollPane = new JScrollPane(model.getTextPane());
124: nodeName = model.getNodeName();
125: NodeInfo info = model.getInfo();
126: hostName = info.getHostName();
127: properties = info.getProperties();
128: args = info.getArgs();
129: listener = model.getListener();
130: statusButton = model.getStatusButton();
131: logFileName = model.getLogFileName();
132: remoteNode = null;
133: try {
134: remoteNode = info.getAppServer().getRemoteProcess(nodeName);
135: } catch (Exception e) {
136: if (log.isErrorEnabled()) {
137: log.error("Trying to get remote process:", e);
138: }
139: }
140: createLogger();
141: consoleTextPane = (ConsoleTextPane) scrollPane.getViewport()
142: .getView();
143: setTitle("Node " + nodeName + " (" + hostName + ")");
144: JMenuBar menuBar = new JMenuBar();
145:
146: // Node menu
147: JMenu nodeMenu = new JMenu(NODE_MENU);
148: Action infoAction = new AbstractAction(INFO_ACTION) {
149: public void actionPerformed(ActionEvent e) {
150: displayAbout();
151: }
152: };
153: nodeMenu.add(infoAction);
154: Action cpuUsageAction = new AbstractAction(CPU_USAGE_ACTION) {
155: public void actionPerformed(ActionEvent e) {
156: totalCPUUsage_actionPerformed();
157: }
158: };
159: nodeMenu.add(cpuUsageAction);
160: Action nodeCPUUsageAction = new AbstractAction(
161: NODE_CPU_USAGE_ACTION) {
162: public void actionPerformed(ActionEvent e) {
163: nodeCPUUsage_actionPerformed();
164: }
165: };
166: nodeMenu.add(nodeCPUUsageAction);
167: // Edit menu
168: JMenu editMenu = new JMenu(EDIT_MENU);
169: Action cutAction = new AbstractAction(CUT_ACTION) {
170: public void actionPerformed(ActionEvent e) {
171: cut_actionPerformed();
172: }
173: };
174: JMenuItem mi = editMenu.add(cutAction);
175: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
176: Event.CTRL_MASK));
177: Action copyAction = new AbstractAction(COPY_ACTION) {
178: public void actionPerformed(ActionEvent e) {
179: copy_actionPerformed();
180: }
181: };
182: mi = editMenu.add(copyAction);
183: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
184: Event.CTRL_MASK));
185: Action pasteAction = new AbstractAction(PASTE_ACTION) {
186: public void actionPerformed(ActionEvent e) {
187: paste_actionPerformed();
188: }
189: };
190: mi = editMenu.add(pasteAction);
191: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
192: Event.CTRL_MASK));
193: editMenu.addSeparator();
194: Action selectAllAction = new AbstractAction(SELECT_ALL_ACTION) {
195: public void actionPerformed(ActionEvent e) {
196: selectAll_actionPerformed();
197: }
198: };
199: mi = editMenu.add(selectAllAction);
200: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
201: Event.CTRL_MASK));
202: editMenu.addSeparator();
203: findAction = new AbstractAction(FIND_ACTION) {
204: public void actionPerformed(ActionEvent e) {
205: find_actionPerformed();
206: }
207: };
208: mi = editMenu.add(findAction);
209: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
210: Event.CTRL_MASK));
211: findNextAction = new AbstractAction(FIND_NEXT_ACTION) {
212: public void actionPerformed(ActionEvent e) {
213: findNext_actionPerformed();
214: }
215: };
216: mi = editMenu.add(findNextAction);
217: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
218: Event.CTRL_MASK));
219: // view menu
220: JMenu viewMenu = new JMenu(VIEW_MENU);
221: Action setViewSizeAction = new AbstractAction(
222: SET_VIEW_SIZE_ACTION) {
223: public void actionPerformed(ActionEvent e) {
224: setViewSize_actionPerformed();
225: }
226: };
227: viewMenu.add(setViewSizeAction);
228: Action filterAction = new AbstractAction(FILTER_ACTION) {
229: public void actionPerformed(ActionEvent e) {
230: filter_actionPerformed();
231: }
232: };
233: viewMenu.add(filterAction);
234:
235: // control menu
236: JMenu controlMenu = new JMenu(CONTROL_MENU);
237: startAction = new AbstractAction(START_ACTION) {
238: public void actionPerformed(ActionEvent e) {
239: model.restart();
240: }
241: };
242: startAction.setEnabled(false);
243: controlMenu.add(startAction);
244:
245: stopAction = new AbstractAction(STOP_ACTION) {
246: public void actionPerformed(ActionEvent e) {
247: model.stop();
248: }
249: };
250: stopAction.setEnabled(false);
251: controlMenu.add(stopAction);
252:
253: traceAction = new AbstractAction(STACK_TRACE_ACTION) {
254: public void actionPerformed(ActionEvent e) {
255: trace_actionPerformed();
256: }
257: };
258: traceAction.setEnabled(false);
259: controlMenu.add(traceAction);
260:
261: // notify menu
262: JMenu notifyMenu = new JMenu(NOTIFY_MENU);
263: notifyAction = new AbstractAction(SET_NOTIFY_ACTION) {
264: public void actionPerformed(ActionEvent e) {
265: notify_actionPerformed();
266: }
267: };
268: notifyMenu.add(notifyAction);
269: Action removeNotifyAction = new AbstractAction(
270: REMOVE_NOTIFY_ACTION) {
271: public void actionPerformed(ActionEvent e) {
272: removeNotify_actionPerformed();
273: }
274: };
275: notifyMenu.add(removeNotifyAction);
276: notifyNextAction = new AbstractAction(NOTIFY_NEXT_ACTION) {
277: public void actionPerformed(ActionEvent e) {
278: notifyNext_actionPerformed();
279: }
280: };
281: mi = notifyMenu.add(notifyNextAction);
282: mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
283: Event.CTRL_MASK));
284: Action resetNotifyAction = new AbstractAction(
285: RESET_NOTIFY_ACTION) {
286: public void actionPerformed(ActionEvent e) {
287: resetNotify();
288: }
289: };
290: notifyMenu.add(resetNotifyAction);
291:
292: menuBar.add(nodeMenu);
293: menuBar.add(editMenu);
294: menuBar.add(viewMenu);
295: menuBar.add(controlMenu);
296: menuBar.add(notifyMenu);
297: getRootPane().setJMenuBar(menuBar);
298: initKeyMap(consoleTextPane);
299: getContentPane().add(scrollPane);
300: setSize(300, 300);
301: updateMenuItems(model.getState()); // get the menu items initted
302: model.addObserver(this );
303: }
304:
305: private void createLogger() {
306: log = CSMART.createLogger(this .getClass().getName());
307: }
308:
309: /**
310: * Set up a keymap:
311: * ctrl-f find (find)
312: * ctrl-g find next
313: * ctrl-n notify
314: * ctrl-o notify next
315: */
316: private void initKeyMap(ConsoleTextPane pane) {
317: InputMap im = pane
318: .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
319: ActionMap am = pane.getActionMap();
320: im.put(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK),
321: FIND_ACTION);
322: am.put(FIND_ACTION, findAction);
323: im.put(KeyStroke.getKeyStroke(KeyEvent.VK_G, Event.CTRL_MASK),
324: FIND_NEXT_ACTION);
325: am.put(FIND_NEXT_ACTION, findNextAction);
326: im.put(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK),
327: NOTIFY_NEXT_ACTION);
328: am.put(NOTIFY_NEXT_ACTION, notifyNextAction);
329: }
330:
331: public String getNodeName() {
332: return nodeName;
333: }
334:
335: /**
336: * Display information about node in pop-up dialog.
337: * Colloquially the "Node Info" window.
338: */
339: public void displayAbout() {
340: ArrayList agentNames = (ArrayList) model.getNodePropertyValue(
341: nodeName, "AgentNames");
342:
343: // If got no Agent Names, that probably means
344: // we have no configuration info for the Node,
345: // so we won't display that portion of
346: // the info window
347: if (agentNames != null) {
348: // clone the agent names so we don't modify them when we add the NodeAgent
349: agentNames = (ArrayList) agentNames.clone();
350: agentNames.add(0, nodeName);
351: }
352:
353: JPanel aboutPanel = new JPanel();
354: aboutPanel.setLayout(new GridBagLayout());
355: int x = 0;
356: int y = 0;
357:
358: // insets are top, left, bottom, right
359: aboutPanel
360: .add(new JLabel("Status:"), new GridBagConstraints(x++,
361: y, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
362: GridBagConstraints.NONE,
363: new Insets(10, 0, 5, 5), 0, 0));
364: String status = (statusButton).getMyModel()
365: .getStatusDescription();
366: aboutPanel.add(new JLabel(status), new GridBagConstraints(x,
367: y++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
368: GridBagConstraints.HORIZONTAL, new Insets(10, 0, 5, 0),
369: 0, 0));
370: x = 0;
371: aboutPanel.add(new JLabel("Notifications:"),
372: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
373: GridBagConstraints.WEST,
374: GridBagConstraints.NONE,
375: new Insets(0, 0, 5, 5), 0, 0));
376: int notifyCount = consoleTextPane.getNotifyCount();
377: aboutPanel.add(new JLabel(Integer.toString(notifyCount)),
378: new GridBagConstraints(x, y++, 1, 1, 1.0, 0.0,
379: GridBagConstraints.WEST,
380: GridBagConstraints.HORIZONTAL, new Insets(0, 0,
381: 5, 0), 0, 0));
382: x = 0;
383: aboutPanel.add(new JLabel("Log File:"), new GridBagConstraints(
384: x++, y, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
385: GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
386: aboutPanel.add(new JTextField(logFileName),
387: new GridBagConstraints(x, y++, 1, 1, 1.0, 0.0,
388: GridBagConstraints.WEST,
389: GridBagConstraints.HORIZONTAL, new Insets(0, 0,
390: 5, 0), 0, 0));
391: x = 0;
392: aboutPanel.add(new JLabel("Host Name:"),
393: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
394: GridBagConstraints.WEST,
395: GridBagConstraints.NONE,
396: new Insets(0, 0, 5, 5), 0, 0));
397: aboutPanel.add(new JLabel(hostName), new GridBagConstraints(x,
398: y++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
399: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0),
400: 0, 0));
401: x = 0;
402: aboutPanel.add(new JLabel("Host Address:"),
403: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
404: GridBagConstraints.WEST,
405: GridBagConstraints.NONE,
406: new Insets(0, 0, 5, 5), 0, 0));
407: String hostAddress = "";
408: try {
409: InetAddress host = InetAddress.getByName(hostName);
410: hostAddress = host.toString();
411: } catch (UnknownHostException uhe) {
412: }
413: aboutPanel.add(new JLabel(hostAddress), new GridBagConstraints(
414: x, y++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
415: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0),
416: 0, 0));
417: x = 0;
418: aboutPanel.add(new JLabel("Host Type:"),
419: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
420: GridBagConstraints.WEST,
421: GridBagConstraints.NONE,
422: new Insets(0, 0, 5, 5), 0, 0));
423: aboutPanel.add(new JLabel((String) model.getHostPropertyValue(
424: hostName, "MachineType")), new GridBagConstraints(x,
425: y++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
426: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0),
427: 0, 0));
428: x = 0;
429: aboutPanel.add(new JLabel("Host Location:"),
430: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
431: GridBagConstraints.WEST,
432: GridBagConstraints.NONE,
433: new Insets(0, 0, 5, 5), 0, 0));
434: aboutPanel.add(new JLabel((String) model.getHostPropertyValue(
435: hostName, "Location")), new GridBagConstraints(x, y++,
436: 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
437: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0),
438: 0, 0));
439: x = 0;
440: aboutPanel.add(new JLabel("Host Description:"),
441: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
442: GridBagConstraints.WEST,
443: GridBagConstraints.NONE,
444: new Insets(0, 0, 5, 5), 0, 0));
445: aboutPanel.add(new JLabel((String) model.getHostPropertyValue(
446: hostName, "Description")), new GridBagConstraints(x,
447: y++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
448: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0),
449: 0, 0));
450: x = 0;
451: aboutPanel.add(new JLabel("Node Description: "),
452: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
453: GridBagConstraints.WEST,
454: GridBagConstraints.NONE,
455: new Insets(0, 0, 5, 5), 0, 0));
456: aboutPanel.add(new JLabel((String) model.getNodePropertyValue(
457: nodeName, "Description")), new GridBagConstraints(x,
458: y++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
459: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0),
460: 0, 0));
461: x = 0;
462:
463: // display -D options
464: aboutPanel.add(new JLabel("-D Options (in CSMART):"),
465: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
466: GridBagConstraints.WEST,
467: GridBagConstraints.NONE,
468: new Insets(0, 0, 5, 5), 0, 0));
469: Vector data = new Vector();
470: Enumeration propertyNames = properties.propertyNames();
471: while (propertyNames.hasMoreElements()) {
472: String name = (String) propertyNames.nextElement();
473: Vector row = new Vector(2);
474: row.add(name);
475: row.add(properties.getProperty(name));
476: data.add(row);
477: }
478: Vector columnNames = new Vector(2);
479: columnNames.add("Name");
480: columnNames.add("Value");
481: // Bug 1874: Disable editing here
482: JTable argTable = new JTable(new DefaultTableModel(data,
483: columnNames)) {
484: public boolean isCellEditable(int row, int column) {
485: return false;
486: }
487: };
488: argTable.getTableHeader().setReorderingAllowed(false);
489: argTable.setColumnSelectionAllowed(false);
490: argTable.getSelectionModel().setSelectionMode(
491: ListSelectionModel.SINGLE_SELECTION);
492: argTable.setPreferredScrollableViewportSize(new Dimension(50,
493: 100));
494: JScrollPane jspArgTable = new JScrollPane(argTable);
495: // ensure the layout leaves space for the scrollbar
496: jspArgTable.setMinimumSize(new Dimension(50, 50));
497: aboutPanel.add(jspArgTable, new GridBagConstraints(x, y++, 1,
498: 1, 1.0, 1.0, GridBagConstraints.WEST,
499: GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
500: x = 0;
501: aboutPanel.add(new JLabel("Command Line Arguments:"),
502: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
503: GridBagConstraints.WEST,
504: GridBagConstraints.NONE,
505: new Insets(0, 0, 5, 5), 0, 0));
506: JScrollPane jspArgs = new JScrollPane(new JList(args.toArray()));
507: jspArgs.setMinimumSize(new Dimension(50, 50));
508: aboutPanel.add(jspArgs, new GridBagConstraints(x, y++, 1, 1,
509: 1.0, 1.0, GridBagConstraints.WEST,
510: GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0));
511:
512: x = 0;
513:
514: // Only show initial configuration info if we had some
515: if (agentNames != null) {
516: // Now the contents of the Node
517: aboutPanel.add(
518: new JLabel("Agents (initial configuration):"),
519: new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,
520: GridBagConstraints.WEST,
521: GridBagConstraints.NONE, new Insets(0, 0,
522: 5, 5), 0, 0));
523: aboutPanel.add(new JLabel("(select for more information)"),
524: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
525: GridBagConstraints.WEST,
526: GridBagConstraints.NONE, new Insets(0, 0,
527: 5, 5), 0, 0));
528:
529: // Put together the list of Agents in the Node
530: JList agentsList = null;
531: agentsList = new JList(agentNames.toArray());
532: agentsList.setBackground(aboutPanel.getBackground());
533:
534: // Allow user to select an Agent in the list and get the detailed
535: // contents of that Agent in a pop-up window
536: agentsList
537: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
538: agentsList
539: .addListSelectionListener(new ListSelectionListener() {
540: public void valueChanged(ListSelectionEvent e) {
541: if (e.getValueIsAdjusting())
542: return;
543: JList myagentsList = (JList) e.getSource();
544: String agentName = (String) myagentsList
545: .getSelectedValue();
546: if (agentName != null)
547: displayPlugins(agentName);
548: }
549: });
550:
551: JScrollPane jspAgents = new JScrollPane(agentsList);
552: jspAgents.setMinimumSize(new Dimension(50, 50));
553: aboutPanel.add(jspAgents, new GridBagConstraints(x, y++, 1,
554: 1, 1.0, 1.0, GridBagConstraints.WEST,
555: GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0,
556: 0));
557: } // end of block to show configuration info
558:
559: JOptionPane pane = new JOptionPane(aboutPanel,
560: JOptionPane.PLAIN_MESSAGE);
561: JInternalFrame infoFrame = pane.createInternalFrame(this ,
562: "Information: " + nodeName + " (" + hostName + ")");
563: infoFrame.setSize(new Dimension(500, 500));
564: infoFrame.setResizable(true);
565: infoFrame.show();
566: }
567:
568: // Implementations for the action items from the menu
569:
570: private void totalCPUUsage_actionPerformed() {
571: try {
572: displayProcessInfo(remoteNode.listProcesses(true));
573: } catch (Exception e) {
574: JOptionPane.showConfirmDialog(this ,
575: "This information is not available for this node.",
576: "Information Not Available",
577: JOptionPane.PLAIN_MESSAGE);
578: }
579: }
580:
581: private void nodeCPUUsage_actionPerformed() {
582: try {
583: displayProcessInfo(remoteNode.listProcesses(false));
584: } catch (Exception e) {
585: JOptionPane.showConfirmDialog(this ,
586: "This information is not available for this node.",
587: "Information Not Available",
588: JOptionPane.PLAIN_MESSAGE);
589: }
590: }
591:
592: private void displayProcessInfo(ProcessStatus[] ps) {
593: String[][] psInfo = new String[ps.length][];
594: for (int i = 0; i < ps.length; i++) {
595: String[] singlePSInfo = new String[5];
596: singlePSInfo[0] = String.valueOf(ps[i]
597: .getProcessIdentifier());
598: singlePSInfo[1] = String.valueOf(ps[i].getStartTime());
599: singlePSInfo[2] = String.valueOf(ps[i]
600: .getParentProcessIdentifier());
601: singlePSInfo[3] = ps[i].getUserName();
602: singlePSInfo[4] = ps[i].getCommand();
603: psInfo[i] = singlePSInfo;
604: }
605: String[] columnNames = { "PID", "Start Time", "Parent PID",
606: "User Name", "Command" };
607: JTable table = new JTable(psInfo, columnNames);
608: JScrollPane jsp = new JScrollPane(table);
609: table
610: .setPreferredScrollableViewportSize(new Dimension(400,
611: 100));
612: JOptionPane.showConfirmDialog(this , jsp, "Process Status",
613: JOptionPane.PLAIN_MESSAGE);
614: }
615:
616: /**
617: * Query user for search string and search for it.
618: */
619:
620: private void find_actionPerformed() {
621: // get string to search for
622: String s = (String) JOptionPane.showInputDialog(this ,
623: "Search string:", "Search",
624: JOptionPane.QUESTION_MESSAGE, null, null,
625: consoleTextPane.getSearchString());
626: if (s == null || s.length() == 0) {
627: return;
628: }
629: // find and highlight
630: boolean found = consoleTextPane.search(s);
631: findNextAction.setEnabled(found);
632: }
633:
634: /**
635: * Search for next instance of string.
636: */
637:
638: private void findNext_actionPerformed() {
639: // search and highlight
640: boolean found = consoleTextPane.searchNext();
641: findNextAction.setEnabled(found);
642: consoleTextPane.revalidate();
643: consoleTextPane.repaint();
644: }
645:
646: private void cut_actionPerformed() {
647: consoleTextPane.requestFocus();
648: consoleTextPane.cut();
649: }
650:
651: private void copy_actionPerformed() {
652: consoleTextPane.requestFocus();
653: consoleTextPane.copy();
654: }
655:
656: private void paste_actionPerformed() {
657: consoleTextPane.requestFocus();
658: consoleTextPane.paste();
659: }
660:
661: /**
662: * Select everything in the node's output pane.
663: * Note that the focus must be requested before the select action will work.
664: */
665:
666: private void selectAll_actionPerformed() {
667: consoleTextPane.requestFocus();
668: consoleTextPane.selectAll();
669: }
670:
671: private void setViewSize_actionPerformed() {
672: ConsoleStyledDocument doc = (ConsoleStyledDocument) consoleTextPane
673: .getStyledDocument();
674: int viewSize = CSMARTConsoleView.displayViewSizeDialog(doc
675: .getBufferSize());
676: if (viewSize == -2)
677: return; // ignore, user cancelled
678: setViewSize(viewSize);
679: }
680:
681: public void setViewSize(int size) {
682: ConsoleStyledDocument doc = (ConsoleStyledDocument) consoleTextPane
683: .getStyledDocument();
684: doc.setBufferSize(size);
685: }
686:
687: /**
688: * Get the values from any existing filter and use those to
689: * initialize the new filter.
690: */
691: private void filter_actionPerformed() {
692: boolean[] filterValues = null;
693: boolean isAllSelected = true;
694: ConsoleNodeOutputFilter currentFilter = listener.getFilter();
695: if (currentFilter != null) {
696: filterValues = currentFilter.getValues();
697: isAllSelected = currentFilter.isAllSelected();
698: }
699: ConsoleNodeOutputFilter filter = new ConsoleNodeOutputFilter(
700: filterValues, isAllSelected);
701: model.setFilter(filter);
702: }
703:
704: private void trace_actionPerformed() {
705: try {
706: remoteNode.dumpThreads();
707: } catch (Exception e) {
708: JOptionPane.showConfirmDialog(this ,
709: "This operation is not available for this node.",
710: "Operation Not Available",
711: JOptionPane.PLAIN_MESSAGE);
712:
713: }
714: }
715:
716: /**
717: * Notify (by coloring status button) when the specified
718: * output is received on this node.
719: */
720:
721: private void notify_actionPerformed() {
722: JPanel notifyPanel = new JPanel(new GridBagLayout());
723: int x = 0;
724: int y = 0;
725: notifyPanel.add(new JLabel("Search string:"),
726: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
727: GridBagConstraints.WEST,
728: GridBagConstraints.NONE,
729: new Insets(10, 0, 5, 5), 0, 0));
730: JTextField notifyField = new JTextField(20);
731: notifyField.setText(consoleTextPane.getNotifyCondition());
732: notifyPanel.add(notifyField, new GridBagConstraints(x, y++, 1,
733: 1, 1.0, 0.0, GridBagConstraints.WEST,
734: GridBagConstraints.HORIZONTAL, new Insets(10, 0, 5, 0),
735: 0, 0));
736: x = 0;
737: JCheckBox stdErrorCB = new JCheckBox(
738: "Notify on Standard Error", (statusButton).getMyModel()
739: .getNotifyOnStandardError());
740: notifyPanel
741: .add(stdErrorCB, new GridBagConstraints(x++, y, 1, 1,
742: 0.0, 0.0, GridBagConstraints.WEST,
743: GridBagConstraints.NONE,
744: new Insets(10, 0, 5, 5), 0, 0));
745: int result = JOptionPane.showConfirmDialog(this , notifyPanel,
746: "Notification", JOptionPane.OK_CANCEL_OPTION);
747: if (result != JOptionPane.OK_OPTION)
748: return;
749: setNotification(notifyField.getText());
750: (statusButton).getMyModel().setNotifyOnStandardError(
751: stdErrorCB.isSelected());
752: }
753:
754: private void setNotification(String s) {
755: String notifyCondition = null;
756: if (s != null && s.length() != 0)
757: notifyCondition = s;
758: consoleTextPane.setNotifyCondition(notifyCondition);
759: (statusButton).getMyModel().clearError();
760: }
761:
762: private void removeNotify_actionPerformed() {
763: setNotification(null);
764: (statusButton).getMyModel().setNotifyOnStandardError(false);
765: (statusButton).getMyModel().clearError();
766: }
767:
768: private void notifyNext_actionPerformed() {
769: boolean found = consoleTextPane.notifyNext();
770: notifyNextAction.setEnabled(found);
771: consoleTextPane.revalidate();
772: consoleTextPane.repaint();
773: }
774:
775: public void resetNotify() {
776: consoleTextPane.clearNotify();
777: (statusButton).getMyModel().clearError();
778: }
779:
780: // Display pop-up with the INI style contents of an Agent listed
781: // invoked from window displayed by displayAbout method
782: private void displayPlugins(String agentName) {
783: ArrayList entries = model.getAgentComponentDescriptions(
784: nodeName, agentName);
785: if (entries == null)
786: return;
787: JList plugInsList = new JList(entries.toArray());
788: JScrollPane jsp = new JScrollPane(plugInsList,
789: ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
790: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
791: jsp.setPreferredSize(new Dimension(550, 200));
792: JPanel agentInfoPanel = new JPanel();
793: agentInfoPanel.setLayout(new GridBagLayout());
794: plugInsList.setBackground(agentInfoPanel.getBackground());
795: int x = 0;
796: int y = 0;
797: agentInfoPanel.add(new JLabel("SubComponents:"),
798: new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,
799: GridBagConstraints.WEST,
800: GridBagConstraints.NONE,
801: new Insets(10, 0, 5, 5), 0, 0));
802: agentInfoPanel.add(jsp, new GridBagConstraints(x, y++, 1, 1,
803: 0.0, 0.0, GridBagConstraints.WEST,
804: GridBagConstraints.NONE, new Insets(0, 0, 5, 0), 0, 0));
805: JOptionPane.showMessageDialog(this , agentInfoPanel,
806: "Information: " + agentName, JOptionPane.PLAIN_MESSAGE);
807:
808: }
809:
810: /**
811: * Over-ride standard dispose to ensure everything cleaned up.
812: * In particular, clean up the ConsoleNodeListener,
813: * and recurse to the TextPane and from there to the document
814: **/
815: // TODO: Determine if this is being called and handled correctly
816: public void dispose() {
817: // FIXME: Do this first? Will it complain if called twice?
818: super .dispose();
819: // Clean up the listener (and log file)
820: // before the text pane (which handles the document)
821: if (listener != null) {
822: // FIXME: Do this?
823: // if (log.isDebugEnabled())
824: // log.debug("CInternal.dipose had non-null listener to cleanUp");
825: listener.cleanUp();
826: listener = null;
827: }
828: if (consoleTextPane != null) {
829: // if (log.isDebugEnabled())
830: // log.debug("CInternal had non-null pane to dispose");
831: // recurse to the text pane
832: // this also recurses to the document
833: // which means the ConsoleNodeListener should be gone too
834: // but rely on someone else to do this?
835: consoleTextPane.cleanUp();
836: consoleTextPane = null;
837: }
838: remoteNode = null;
839:
840: // Remove listeners
841: InternalFrameListener[] lists = getInternalFrameListeners();
842: for (int i = 0; i < lists.length; i++)
843: removeInternalFrameListener(lists[i]);
844:
845: // FIXME
846: // Ancestor listener? ContainerListener? FocusListener? ComponentListener?
847:
848: removeAll();
849: // if (log.isDebugEnabled()) {
850: // log.debug("In CInternal.dispose");
851: // }
852: }
853:
854: private void readObject(ObjectInputStream ois) throws IOException,
855: ClassNotFoundException {
856: ois.defaultReadObject();
857: createLogger();
858: }
859:
860: public void update(Observable o, Object arg) {
861: if (arg instanceof String
862: && ((String) arg).startsWith("NODE_STATE"))
863: updateMenuItems((String) arg);
864: }
865:
866: private void updateMenuItems(String state) {
867: if (state.startsWith("NODE_STATE")) {
868: if (state.equals(model.STATE_RUNNING)) {
869: stopAction.setEnabled(true);
870: traceAction.setEnabled(true);
871: } else {
872: stopAction.setEnabled(false);
873: }
874: if (state.equals(NodeModel.STATE_STOPPED)) {
875: startAction.setEnabled(true);
876: traceAction.setEnabled(false);
877: } else {
878: startAction.setEnabled(false);
879: }
880: }
881: }
882:
883: }
|