View Javadoc
1 package net.sf.panoptes.module.jmx; 2 3 import java.util.HashMap; 4 5 import javax.management.Attribute; 6 import javax.management.MBeanParameterInfo; 7 8 import net.sf.panoptes.controller.MainController; 9 import net.sf.panoptes.model.node.Node; 10 import net.sf.panoptes.model.node.NodeUpdateEvent; 11 import net.sf.panoptes.view.configurator.NodeConfigurator; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.custom.SashForm; 17 import org.eclipse.swt.layout.FillLayout; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Event; 23 import org.eclipse.swt.widgets.Label; 24 import org.eclipse.swt.widgets.Listener; 25 import org.eclipse.swt.widgets.Table; 26 import org.eclipse.swt.widgets.TableColumn; 27 import org.eclipse.swt.widgets.TableItem; 28 //import com.sun.org.omg.CORBA.OperationDescription; 29 30 /*** 31 * IntrospectorPanel.java 32 * 33 * Simple NodeConfigurator for MBeanComponent introspection. 34 * 35 * @see net.sf.panoptes.module.jmx.MBeanComponent 36 * @author Dag Liodden 37 * @version 0.1 38 */ 39 public class IntrospectorPanel extends NodeConfigurator { 40 41 private MBeanComponent mBean = null; 42 Table opTable; 43 Table propTable; 44 Label beanDescriptionLabel; 45 46 private Log log = LogFactory.getLog(getClass()); 47 48 /*** 49 * Constructor for IntrospectorPanel. 50 * @param parent 51 * @param style 52 */ 53 public IntrospectorPanel( 54 MainController controller, 55 Composite parent, 56 int style, 57 HashMap attributes) { 58 super(controller, parent, style, attributes); 59 60 this.setLayout(new FillLayout()); 61 62 SashForm sash = new SashForm(this, SWT.VERTICAL); 63 64 Composite top = new Composite(sash, SWT.NULL); 65 top.setLayout(new GridLayout()); 66 beanDescriptionLabel = new Label(top, SWT.NULL); 67 beanDescriptionLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 68 69 Button btnRefresh = new Button(top, SWT.NULL); 70 // btnRefresh.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 71 btnRefresh.setText("Refresh"); 72 btnRefresh.addListener(SWT.Selection, new Listener() { 73 public void handleEvent(Event arg0) { 74 mBean.refresh(); 75 setBean(mBean); 76 } 77 }); 78 79 Label l = new Label(top, SWT.NULL); 80 l.setText("Properties:"); 81 l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 82 83 propTable = new Table(top, SWT.BORDER | SWT.FULL_SELECTION); 84 propTable.setLinesVisible(true); 85 propTable.setHeaderVisible(true); 86 propTable.setLayoutData(new GridData(GridData.FILL_BOTH)); 87 88 TableColumn tc; 89 tc = new TableColumn(propTable, SWT.NULL); 90 tc.setText("Name"); 91 tc.setWidth(150); 92 93 tc = new TableColumn(propTable, SWT.NULL); 94 tc.setText("Value"); 95 tc.setWidth(200); 96 97 final Composite bottom = new Composite(sash, SWT.NULL); 98 bottom.setLayout(new GridLayout()); 99 l = new Label(bottom, SWT.NULL); 100 l.setText("Operations:"); 101 l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 102 103 Table t; 104 105 opTable = new Table(bottom, SWT.BORDER | SWT.FULL_SELECTION); 106 opTable.setLinesVisible(true); 107 opTable.setHeaderVisible(true); 108 opTable.setLayoutData(new GridData(GridData.FILL_BOTH)); 109 110 tc = new TableColumn(opTable, SWT.NULL); 111 tc.setText("Name"); 112 tc.setWidth(150); 113 114 tc = new TableColumn(opTable, SWT.NULL); 115 tc.setText("Parameters"); 116 tc.setWidth(200); 117 118 tc = new TableColumn(opTable, SWT.NULL); 119 tc.setText("Returntype"); 120 tc.setWidth(100); 121 122 tc = new TableColumn(opTable, SWT.NULL); 123 tc.setText(""); 124 tc.setWidth(100); 125 126 } 127 128 public void setNode(Node component) { 129 setBean((MBeanComponent) component); 130 } 131 132 public void setBean(MBeanComponent mBean) { 133 this.mBean = mBean; 134 opTable.removeAll(); 135 propTable.removeAll(); 136 137 try { 138 beanDescriptionLabel.setText(mBean.getObjectName().toString()); 139 140 Attribute[] atts = mBean.getAttributes(); 141 for (int i = 0; i < atts.length; i++) { 142 Attribute a = atts[i]; 143 TableItem ti = new TableItem(propTable, SWT.NULL); 144 ti.setText(0, a.getName()); 145 146 Object value = mBean.getAttributeValue(a.getName()); 147 String strValue = value == null ? "null" : value.toString(); 148 ti.setText(1, strValue); 149 } 150 151 Operation[] ops = mBean.getOperations(); 152 for (int i = 0; i < ops.length; i++) { 153 TableItem ti = new TableItem(opTable, SWT.NULL); 154 ti.setData(ops[i]); 155 Operation op = ops[i]; 156 ti.setText(0, op.getName()); 157 ti.setText(2, op.getReturnType()); 158 159 MBeanParameterInfo[] params = op.getParameterInfo(); 160 StringBuffer s = new StringBuffer(); 161 if (params.length == 0) 162 s = new StringBuffer("void"); 163 else 164 for (int j = 0; j < params.length; j++) { 165 s.append(params[j].getType() + ", "); 166 } 167 ti.setText(1, s.toString()); 168 } 169 170 } catch (RuntimeException e) { 171 e.printStackTrace(); 172 } 173 } 174 175 /* (non-Javadoc) 176 * @see net.sf.panoptes.view.configurator.NodeConfigurator#refresh() 177 */ 178 public void refresh() { 179 if (mBean != null) 180 setNode(mBean); 181 } 182 183 /* (non-Javadoc) 184 * @see net.sf.panoptes.model.node.NodeUpdateListener#nodeUpdated(net.sf.panoptes.model.node.NodeUpdateEvent) 185 */ 186 public void nodeUpdated(NodeUpdateEvent event) { 187 refresh(); 188 } 189 190 }

This page was automatically generated by Maven