1 package org.coach.tracing.server.viewer; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 import javax.swing.table.*; 7 import javax.swing.tree.*; 8 import javax.swing.event.*; 9 import java.util.*; 10 import org.coach.idltree.*; 11 12 import java.text.DateFormat ; 13 import java.text.SimpleDateFormat ; 14 import org.coach.tracing.server.EventRecord; 15 16 public class EventBrowser extends JFrame { 17 JTabbedPane propertyBrowser = new JTabbedPane(); 18 JPanel params_panel = new JPanel(); 19 BorderLayout borderLayout1 = new BorderLayout(); 20 DefaultTableColumnModel dtcm = new DefaultTableColumnModel(); 21 PropertyTableModel dataModel; 22 TableColumn tc1 = new TableColumn(0); 23 TableColumn tc2 = new TableColumn(1); 24 JScrollPane property_scroll = new JScrollPane(); 25 JScrollPane params_scroll = new JScrollPane(); 26 JTable property_table = null; 27 EventRecord er; 28 29 public EventBrowser(EventRecord r) { 30 er = r; 31 dataModel = new PropertyTableModel(r); 32 33 try { 34 jbInit(); 35 } catch (Exception e) { 36 e.printStackTrace(); 37 } 38 } 39 40 private void jbInit() throws Exception { 41 property_table = new JTable(dataModel); 42 dtcm.addColumn(tc1); 43 dtcm.addColumn(tc2); 44 tc1.setHeaderValue("Name"); 45 tc2.setHeaderValue("Value"); 46 tc1.setMaxWidth(120); 47 property_table.setColumnModel(dtcm); 48 PropertyTableRenderer mtr = new PropertyTableRenderer(dataModel); 49 property_table.setDefaultRenderer(property_table.getColumnClass(1), mtr); 50 property_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 51 property_table.getSelectionModel().setSelectionInterval(0, 0); 52 this.getContentPane().add(propertyBrowser, BorderLayout.CENTER); 53 propertyBrowser.addTab("Properties", property_scroll); 54 55 try { 56 JTree typeTree = new JTree(); 57 IdlNode params = er.getParameters(); 58 if (params != null) { 59 final IdlModel model = new IdlModel(params); 60 typeTree.setModel(model); 61 typeTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 62 typeTree.addTreeSelectionListener(new TreeSelectionListener() { 63 public void valueChanged(TreeSelectionEvent e) { 64 TreePath selection = e.getNewLeadSelectionPath(); 65 model.setSelection(selection); 66 } 67 }); 68 params_scroll.getViewport().add(typeTree, null); 69 } 70 } catch (Exception ex) { 71 ex.printStackTrace(); 72 } 73 propertyBrowser.addTab("Parameters, Results, Exceptions", params_scroll); 74 property_scroll.getViewport().add(property_table, null); 75 propertyBrowser.setSelectedComponent(property_scroll); 76 } 77 } 78 79 class PropertyTableModel extends AbstractTableModel { 80 private static String [] fields = { 81 "EventCounter", 82 "TrailLabel", 83 "MessageId", 84 "ObjectName", 85 "ObjectType", 86 "ComponentName", 87 "ComponentType", 88 "ContainerName", 89 "ContainerType", 90 "ProcessId", 91 "HostName", 92 "IpAddress", 93 "ThreadId", 94 "TrailId", 95 "Operation", 96 "InteractionPoint", 97 "TimeStamp" 98 }; 99 private Object [] values = new Object [fields.length]; 100 101 public PropertyTableModel(EventRecord me) { 102 int i = 0; 103 Long key = me.getIdentityKey(); 104 values[i++] = "" + me.getEventCounter(); 105 values[i++] = me.getTrailLabel(); 106 values[i++] = me.getMessageId(); 107 values[i++] = IdentityNode.getObjectName(key); 108 values[i++] = IdentityNode.getObjectType(key); 109 values[i++] = IdentityNode.getCmpName(key); 110 values[i++] = IdentityNode.getCmpType(key); 111 values[i++] = IdentityNode.getCntName(key); 112 values[i++] = IdentityNode.getCntType(key); 113 values[i++] = IdentityNode.getProcessId(key); 114 values[i++] = IdentityNode.getNodeName(key); 115 values[i++] = IdentityNode.getNodeIp(key); 116 values[i++] = me.getThreadId(); 117 values[i++] = me.getTrailId(); 118 values[i++] = me.getOpName(); 119 values[i++] = me.getInteractionPointName(); 120 values[i++] = me.getTimeStamp(); 121 } 122 123 public int getColumnCount() { 124 return 2; 125 } 126 127 public int getRowCount() { 128 return fields.length; 129 } 130 131 public Object getValueAt(int x, int y) { 132 if (y == 0) { 133 return fields[x]; 134 } else { 135 return values[x]; 136 } 137 } 138 139 public Class getColumnClass(int columnIndex) { 140 if (columnIndex == 1) { 141 return Object .class; 142 } else { 143 return String .class; 144 } 145 } 146 } 147 148 class PropertyTableRenderer extends DefaultTableCellRenderer { 149 PropertyTableModel model = null; 150 151 public PropertyTableRenderer(PropertyTableModel tm) { 152 super(); 153 model = tm; 154 } 155 156 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 157 Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 158 ToolTipManager.sharedInstance().registerComponent((JComponent)comp); 159 return comp; 160 } 161 } 162 163 | Popular Tags |