[logback-dev] svn commit: r1340 - in logbackRCP/trunk/plugins/LogbackPlugin: . META-INF src/main/java/ch/qos/logback/eclipse src/main/java/ch/qos/logback/eclipse/model src/main/java/ch/qos/logback/eclipse/reciever src/main/java/ch/qos/logback/eclipse/views

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Feb 22 14:34:46 CET 2007


Author: seb
Date: Thu Feb 22 14:34:45 2007
New Revision: 1340

Added:
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/LogbackPlugin.java
Modified:
   logbackRCP/trunk/plugins/LogbackPlugin/   (props changed)
   logbackRCP/trunk/plugins/LogbackPlugin/META-INF/MANIFEST.MF
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
   logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java

Log:
Colored warn and error messages
First version of buffered console

Modified: logbackRCP/trunk/plugins/LogbackPlugin/META-INF/MANIFEST.MF
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/META-INF/MANIFEST.MF	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/META-INF/MANIFEST.MF	Thu Feb 22 14:34:45 2007
@@ -11,5 +11,8 @@
 Bundle-Vendor: QOS.ch
 Bundle-Localization: plugin
 Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text,
+ org.eclipse.jdt.core,
+ org.eclipse.ui.console
 Eclipse-LazyStart: true

Added: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/LogbackPlugin.java
==============================================================================
--- (empty file)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/LogbackPlugin.java	Thu Feb 22 14:34:45 2007
@@ -0,0 +1,64 @@
+package ch.qos.logback.eclipse;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class LogbackPlugin extends AbstractUIPlugin {
+
+  // The plug-in ID
+  public static final String PLUGIN_ID = "ch.qos.logback.eclipse";
+
+  // The shared instance
+  private static LogbackPlugin plugin;
+
+  /**
+   * The constructor
+   */
+  public LogbackPlugin() {
+    plugin = this;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+   */
+  public void start(BundleContext context) throws Exception {
+    super.start(context);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+   */
+  public void stop(BundleContext context) throws Exception {
+    plugin = null;
+    super.stop(context);
+  }
+
+  /**
+   * Returns the shared instance
+   * 
+   * @return the shared instance
+   */
+  public static LogbackPlugin getDefault() {
+    return plugin;
+  }
+
+  /**
+   * Returns an image descriptor for the image file at the given plug-in
+   * relative path
+   * 
+   * @param path
+   *          the path
+   * @return the image descriptor
+   */
+  public static ImageDescriptor getImageDescriptor(String path) {
+    return imageDescriptorFromPlugin(PLUGIN_ID, path);
+  }
+}

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	Thu Feb 22 14:34:45 2007
@@ -17,9 +17,9 @@
   static LoggingEvent[] NONE = new LoggingEvent[] {};
 
   private static LoggingEventManager manager;
-
-  private Collection loggingEventCollection = new ArrayList();
-  private List listeners = new ArrayList();
+  
+  private Collection<LoggingEvent> loggingEventCollection = new ArrayList<LoggingEvent>();
+  private List<LoggingEventManagerListener> listeners = new ArrayList<LoggingEventManagerListener>();
 
   public static LoggingEventManager getManager() {
     if (manager == null)

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/reciever/SimpleSocketServer.java	Thu Feb 22 14:34:45 2007
@@ -19,7 +19,7 @@
   public void run() {
     try {
       ServerSocket serverSocket = new ServerSocket(port);
-      PluginLogger.logInfo("Listening on port: " + port);
+      //PluginLogger.logInfo("Listening on port: " + port);
       while (true) {
         Socket socket = serverSocket.accept();
         new Thread(new SocketNode(socket)).start();

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	Thu Feb 22 14:34:45 2007
@@ -3,13 +3,12 @@
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.DecoratingLabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.TextConsoleViewer;
 import org.eclipse.ui.part.ViewPart;
 
 import ch.qos.logback.eclipse.model.LoggingEventManager;
@@ -23,21 +22,28 @@
  */
 
 public class LogbackView extends ViewPart {
-  private TableViewer viewer;
+
+  private TextConsoleViewer viewer;
+  private MessageConsole myConsole;
   private Action action1;
   private Action action2;
-
+  
   public LogbackView() {
     launchSocketServer();
   }
-
+  
   public void createPartControl(Composite parent) {
-    viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
-
-    viewer.setContentProvider(new LoggingEventContentProvider());
-    viewer.setLabelProvider(new DecoratingLabelProvider(new LoggingEventLabelProvider(), null));
-    viewer.setInput(LoggingEventManager.getManager());
-
+    
+    myConsole = new MessageConsole("My Console", null); 
+    myConsole.setWaterMarks(100000, 40000);
+    viewer = new TextConsoleViewer(parent, myConsole);
+    
+    LoggingEventContentProvider pro = new LoggingEventContentProvider();
+    pro.setLabelProvider(new LoggingEventLabelProvider());
+    pro.setConsole(myConsole);
+    
+    LoggingEventManager.getManager().addLoggingEventManagerListener(pro);
+    
     makeActions();
     contributeToActionBars();
   }
@@ -75,18 +81,16 @@
   }
 
   private void showMessage(String message) {
-    MessageDialog.openInformation(viewer.getControl().getShell(), "Logback View", message);
+    MessageDialog.openInformation(getSite().getShell(), "Logback View", message);
   }
 
-  /**
-   * Passing the focus request to the viewer's control.
-   */
-  public void setFocus() {
-    viewer.getControl().setFocus();
-  }
-  
   private void launchSocketServer() {
     new Thread(new SimpleSocketServer()).start();
   }
-  
+
+  @Override
+  public void setFocus() {
+    viewer.getControl().setFocus();
+  }
+
 }
\ No newline at end of file

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java	Thu Feb 22 14:34:45 2007
@@ -1,48 +1,39 @@
 package ch.qos.logback.eclipse.views;
 
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
+import java.io.IOException;
+
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
 
-import ch.qos.logback.eclipse.model.LoggingEventManager;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.eclipse.model.LoggingEventManagerEvent;
 import ch.qos.logback.eclipse.model.LoggingEventManagerListener;
 
 /**
- * The content provider class is responsible for providing objects to the
- * view.
+ * The content provider class is responsible for providing objects to the view.
  * 
  * @author S&eacute;bastien Pennec
  */
-public class LoggingEventContentProvider implements IStructuredContentProvider,
-    LoggingEventManagerListener {
-
-  private TableViewer viewer;
-  private LoggingEventManager manager;
+public class LoggingEventContentProvider implements LoggingEventManagerListener {
 
-  public Object[] getElements(Object inputElement) {
-    return manager.getLoggingEvents();
+  private MessageConsole console;
+  
+  private Color cachedRed;
+  private LabelProvider labelProvider;
+  
+  public LoggingEventContentProvider() {
+    Display display = Display.getCurrent();
+    cachedRed = new Color(display, 255, 0,0);
   }
 
   public void dispose() {
-    // do nothing
-  }
-
-  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-    this.viewer = (TableViewer) viewer;
-    if (manager != null) {
-      manager.removeLoggingEventManagerListener(this);
-    }
-    manager = (LoggingEventManager) newInput;
-    if (manager != null) {
-      manager.addLoggingEventManagerListener(this);
-    }
+    cachedRed.dispose();
   }
 
-  /**
-   * Called when one or more favorites items have been added and/or removed.
-   */
   public void loggingEventsChanged(final LoggingEventManagerEvent event) {
 
     // If this is the UI thread, then make the change
@@ -59,16 +50,25 @@
     });
   }
 
-  private void updateViewer(final LoggingEventManagerEvent event) {
-    // Use the setRedraw method to reduce flicker
-    // when adding or removing multiple items in a table.
-    viewer.getTable().setRedraw(false);
+  private void updateViewer(final LoggingEventManagerEvent event) {    
+    LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
+    MessageConsoleStream stream = console.newMessageStream();
+    if (le.getLevel().isGreaterOrEqual(Level.WARN)) {
+      stream.setColor(cachedRed);
+    }
+    stream.println(labelProvider.getText(le));
     try {
-      viewer.remove(event.getItemsRemoved());
-      viewer.add(event.getItemsAdded());
-    } finally {
-      viewer.getTable().setRedraw(true);
+      stream.close();
+    } catch (IOException e) {
+      //do nothing for now
     }
   }
-
+  
+  public void setLabelProvider(LabelProvider provider) {
+    this.labelProvider = provider;
+  }
+  
+  public void setConsole(MessageConsole console) {
+    this.console = console;
+  }
 }

Modified: logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java
==============================================================================
--- logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java	(original)
+++ logbackRCP/trunk/plugins/LogbackPlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventLabelProvider.java	Thu Feb 22 14:34:45 2007
@@ -1,13 +1,8 @@
 package ch.qos.logback.eclipse.views;
 
-import org.eclipse.jface.viewers.IColorProvider;
 import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
 
-import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.PatternLayout;
 import ch.qos.logback.classic.spi.LoggingEvent;
@@ -18,16 +13,12 @@
  * 
  * @author S&eacute;bastien Pennec
  */
-class LoggingEventLabelProvider extends LabelProvider implements IColorProvider {
+class LoggingEventLabelProvider extends LabelProvider {
 
   private static String DEFAULT_PATTERN = "%date %level [%thread] %message";
   private LoggerContext context;
   private PatternLayout patternLayout;
 
-  private Color red;
-  private Color gray;
-  private int count;
-  
   public LoggingEventLabelProvider() {
     context = new LoggerContext();
     context.setName("Logback Plugin Context");
@@ -35,10 +26,6 @@
     patternLayout.setContext(context);
     patternLayout.setPattern(DEFAULT_PATTERN);
     patternLayout.start();
-    
-    Display display = PlatformUI.getWorkbench().getDisplay();
-    red = new Color(display, 255, 0, 0);
-    gray = new Color(display, 240, 240, 240);
   }
 
   public String getText(Object element) {
@@ -54,29 +41,8 @@
   public Image getImage(Object element) {
     return null;
   }
-  
-  public Color getBackground(Object element) {
-    if (count++ % 2 == 0) {
-      return gray;
-    } else {
-      return null;
-    }
-  }
 
-  public Color getForeground(Object element) {
-    if (!(element instanceof LoggingEvent)) {
-      return null;
-    }
-    
-    LoggingEvent event = (LoggingEvent)element;
-    if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
-      return red;
-    }
-    
-    return null;
-  }
 
   public void dispose() {
-    red.dispose();
   }
 }
\ No newline at end of file



More information about the logback-dev mailing list