View Javadoc
1 package net.sf.panoptes.view.configurator; 2 3 import java.util.Date; 4 5 import net.sf.panoptes.model.component.log4j.LoggerComponent; 6 import net.sf.panoptes.model.node.*; 7 import net.sf.panoptes.model.node.log4j.LoggerRepository; 8 9 import org.apache.log4j.Level; 10 import org.apache.log4j.spi.LoggingEvent; 11 import org.eclipse.jface.viewers.ILabelProviderListener; 12 import org.eclipse.jface.viewers.ISelectionChangedListener; 13 import org.eclipse.jface.viewers.IStructuredContentProvider; 14 import org.eclipse.jface.viewers.IStructuredSelection; 15 import org.eclipse.jface.viewers.ITableLabelProvider; 16 import org.eclipse.jface.viewers.SelectionChangedEvent; 17 import org.eclipse.jface.viewers.TableViewer; 18 import org.eclipse.jface.viewers.Viewer; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.custom.SashForm; 21 import org.eclipse.swt.events.DisposeEvent; 22 import org.eclipse.swt.events.DisposeListener; 23 import org.eclipse.swt.graphics.Image; 24 import org.eclipse.swt.layout.FillLayout; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.layout.GridLayout; 27 import org.eclipse.swt.widgets.Combo; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Display; 30 import org.eclipse.swt.widgets.Event; 31 import org.eclipse.swt.widgets.Label; 32 import org.eclipse.swt.widgets.Listener; 33 import org.eclipse.swt.widgets.TableColumn; 34 import org.eclipse.swt.widgets.Text; 35 36 /*** 37 * LoggerPanel.java 38 * 39 * NodeConfigurator for <code>LoggerComponent</code>s. 40 * 41 * @author Dag Liodden 42 * @version 0.1 43 */ 44 public class LoggerPanel extends NodeConfigurator { 45 46 TableViewer table; 47 Combo comboLevel; 48 Level level; 49 Text details; 50 LoggerRepository repository; 51 private LoggerComponent loggerLocation = null; 52 53 /*** 54 * Constructor for LoggerPanel. 55 * @param parent 56 * @param style 57 */ 58 public LoggerPanel( 59 Composite parent, 60 int style, 61 final LoggerRepository repository) { 62 super(parent, style); 63 64 this.repository = repository; 65 66 setLayout(new FillLayout()); 67 68 SashForm sash = new SashForm(this, SWT.VERTICAL); 69 70 Composite top = new Composite(sash, SWT.NULL); 71 top.setLayout(new GridLayout(2, false)); 72 73 new Label(top, SWT.NULL).setText("Threshold:"); 74 comboLevel = new Combo(top, SWT.DROP_DOWN | SWT.READ_ONLY); 75 76 comboLevel.add(Level.ERROR.toString()); 77 comboLevel.add(Level.WARN.toString()); 78 comboLevel.add(Level.INFO.toString()); 79 comboLevel.add(Level.DEBUG.toString()); 80 81 comboLevel.addListener(SWT.Selection, new Listener() { 82 public void handleEvent(Event arg0) { 83 Level l = Level.toLevel(comboLevel.getText()); 84 setLevel(l); 85 } 86 }); 87 88 table = new TableViewer(top, SWT.FULL_SELECTION | SWT.BORDER); 89 GridData gd = new GridData(GridData.FILL_BOTH); 90 gd.horizontalSpan = 2; 91 table.getTable().setLayoutData(gd); 92 table.getTable().setHeaderVisible(true); 93 table.getTable().setLinesVisible(true); 94 95 Composite bottom = new Composite(sash, SWT.NULL); 96 bottom.setLayout(new GridLayout()); 97 98 Label tmp = new Label(bottom, SWT.NULL); 99 tmp.setText("Details:"); 100 tmp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 101 102 details = new Text(bottom, SWT.BORDER | SWT.WRAP); 103 details.setLayoutData(new GridData(GridData.FILL_BOTH)); 104 details.setEditable(false); 105 106 table.setContentProvider(new IStructuredContentProvider() { 107 public Object[] getElements(Object inputElement) { 108 109 Object[] kids = null; 110 if (loggerLocation != null) 111 kids = loggerLocation.listEvents(level); 112 return kids == null ? new Object[0] : kids; 113 } 114 115 public void dispose() { 116 } 117 118 public void inputChanged( 119 Viewer viewer, 120 Object oldInput, 121 Object newInput) { 122 } 123 }); 124 125 table.setLabelProvider(new ITableLabelProvider() { 126 public Image getColumnImage(Object element, int columnIndex) { 127 if (columnIndex == 0) { 128 LoggingEvent m = (LoggingEvent) element; 129 String icon; 130 131 switch (m.getLevel().toInt()) { 132 case Level.ERROR_INT : 133 { 134 icon = INode.ICON_ERROR; 135 break; 136 } 137 case Level.WARN_INT : 138 { 139 icon = INode.ICON_WARNING; 140 break; 141 } 142 case Level.INFO_INT : 143 case Level.DEBUG_INT : 144 { 145 icon = INode.ICON_INFO; 146 break; 147 } 148 default : 149 { 150 icon = null; 151 } 152 } 153 return icon == null 154 ? null 155 : new Image( 156 Display.getCurrent(), 157 ClassLoader.getSystemResourceAsStream(icon)); 158 } else 159 return null; 160 } 161 162 public String getColumnText(Object element, int columnIndex) { 163 LoggingEvent m = (LoggingEvent) element; 164 switch (columnIndex) { 165 case 0 : 166 { 167 return ""; 168 } 169 case 1 : 170 { 171 return (new Date(m.timeStamp)).toString(); 172 } 173 case 2 : 174 { 175 return m.getRenderedMessage() == null 176 ? "-" 177 : m.getRenderedMessage().toString(); 178 } 179 case 3 : 180 { 181 return m.getLocationInformation().fullInfo == null 182 ? "-" 183 : m.getLocationInformation().fullInfo; 184 } 185 case 4 : 186 { 187 return m.getNDC() == null ? "-" : m.getNDC(); 188 } 189 default : 190 { 191 return "Unknown"; 192 } 193 } 194 } 195 196 public void addListener(ILabelProviderListener listener) { 197 } 198 199 public void dispose() { 200 } 201 202 public boolean isLabelProperty(Object element, String property) { 203 return false; 204 } 205 206 public void removeListener(ILabelProviderListener listener) { 207 } 208 }); 209 210 table.addSelectionChangedListener(new ISelectionChangedListener() { 211 public void selectionChanged(SelectionChangedEvent event) { 212 IStructuredSelection selection = 213 (IStructuredSelection) event.getSelection(); 214 LoggingEvent m = (LoggingEvent) selection.getFirstElement(); 215 String message = m.getMessage().toString(); 216 String cause = "No stacktrace available"; 217 218 if (m.getThrowableInformation() != null) { 219 String[] trace = m.getThrowableInformation().getThrowableStrRep(); 220 StringBuffer b = new StringBuffer(); 221 for (int i = 0; i < trace.length; i++) { 222 b.append(trace[i] + "\n"); 223 } 224 cause = b.toString(); 225 } 226 details.setText( 227 "Message:\n" 228 + message 229 + "\n\nLocation:\n" 230 + m.getLocationInformation().fullInfo 231 + "\n\nNDC:\n" 232 + m.getNDC() 233 + "\n\nCause:\n" 234 + cause); 235 } 236 }); 237 238 TableColumn tc; 239 240 tc = new TableColumn(table.getTable(), SWT.NULL); 241 tc.setWidth(20); 242 tc.setText("!"); 243 244 tc = new TableColumn(table.getTable(), SWT.NULL); 245 tc.setWidth(200); 246 tc.setText("Time"); 247 248 tc = new TableColumn(table.getTable(), SWT.NULL); 249 tc.setWidth(200); 250 tc.setText("Message"); 251 252 tc = new TableColumn(table.getTable(), SWT.NULL); 253 tc.setWidth(200); 254 tc.setText("Location"); 255 256 tc = new TableColumn(table.getTable(), SWT.NULL); 257 tc.setWidth(200); 258 tc.setText("NDC"); 259 260 comboLevel.select(0); 261 setLevel(Level.ERROR); 262 table.setInput(""); 263 264 addDisposeListener(new DisposeListener() { 265 public void widgetDisposed(DisposeEvent e) { 266 } 267 }); 268 } 269 270 public void refresh() { 271 table.refresh(true); 272 } 273 274 /*** 275 * Method setLocation. 276 * @param location 277 */ 278 public void setLocation(LoggerComponent location) { 279 loggerLocation = location; 280 if (location == null) 281 return; 282 refresh(); 283 } 284 285 public void setNode(INode configurable) { 286 setLocation((LoggerComponent) configurable); 287 } 288 289 protected void setLevel(Level level) { 290 this.level = level; 291 refresh(); 292 } 293 294 /*** 295 * Method getLoggerLocation. 296 */ 297 public LoggerComponent getLoggerLocation() { 298 return loggerLocation; 299 } 300 301 }

This page was automatically generated by Maven