[logback-dev] svn commit: r1409 - in logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse: model views

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Mar 7 10:06:03 CET 2007


Author: seb
Date: Wed Mar  7 10:06:02 2007
New Revision: 1409

Added:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackViewerConfiguration.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/MyHyperlinkPresenter.java
Modified:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java

Log:
Working cyclic buffer :)

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/model/LoggingEventManager.java	Wed Mar  7 10:06:02 2007
@@ -1,11 +1,14 @@
 package ch.qos.logback.eclipse.model;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.helpers.CyclicBuffer;
 
 /**
  * This class manages the logging events that are recieved by the plugin.
@@ -18,9 +21,16 @@
 
   private static LoggingEventManager manager;
   
-  private Collection<LoggingEvent> loggingEventCollection = new ArrayList<LoggingEvent>();
+  private CyclicBuffer<LoggingEvent> cyclicBuffer;
+  private boolean sendingEvents = true;
+  ScheduledExecutorService scheduledExecutorService;
+
   private List<LoggingEventManagerListener> listeners = new ArrayList<LoggingEventManagerListener>();
 
+  private LoggingEventManager() {
+    cyclicBuffer = new CyclicBuffer<LoggingEvent>(5000);
+  }
+  
   public static LoggingEventManager getManager() {
     if (manager == null)
       manager = new LoggingEventManager();
@@ -33,14 +43,12 @@
     }
   }
 
-  public LoggingEvent[] getLoggingEvents() {
-    return (LoggingEvent[]) loggingEventCollection.toArray(new LoggingEvent[loggingEventCollection
-        .size()]);
-  }
-
   public void addLoggingEvent(LoggingEvent event) {
-    loggingEventCollection.add(event);
-    fireFavoritesChanged(new LoggingEvent[] { event }, NONE);
+    if (sendingEvents) {
+      fireFavoritesChanged(new LoggingEvent[] { event }, NONE);
+    } else {
+      cyclicBuffer.add(event);
+    }
   }
 
   /**
@@ -57,7 +65,38 @@
 
   private void fireFavoritesChanged(LoggingEvent[] itemsAdded, LoggingEvent[] itemsRemoved) {
     LoggingEventManagerEvent event = new LoggingEventManagerEvent(this, itemsAdded, itemsRemoved);
-    for (Iterator iter = listeners.iterator(); iter.hasNext();)
-      ((LoggingEventManagerListener) iter.next()).loggingEventsChanged(event);
+    Iterator<LoggingEventManagerListener> it = listeners.iterator();
+    while(it.hasNext()) {
+      (it.next()).loggingEventsChanged(event);
+    }
+  }
+  
+  public boolean isSendingEvents() {
+    return sendingEvents;
+  }
+  
+  public void toggleSendEvents() {
+    sendingEvents = !sendingEvents;
+    emptyBuffer();
+  }
+  
+  private void emptyBuffer() {
+    if (cyclicBuffer.length() == 0) {
+      return;
+    }
+    
+    scheduledExecutorService = Executors.newScheduledThreadPool(2);
+    
+    Runnable runnnable = new Runnable() {
+
+      public void run() {
+        LoggingEvent event = cyclicBuffer.get();
+        addLoggingEvent(event);
+      }
+    };
+    
+    scheduledExecutorService.scheduleAtFixedRate(runnnable,
+        0, 1, TimeUnit.MILLISECONDS);
+
   }
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java	Wed Mar  7 10:06:02 2007
@@ -4,6 +4,7 @@
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.IRegion;
 import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
 import org.eclipse.jface.text.hyperlink.IHyperlink;
 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
 
@@ -32,47 +33,49 @@
     } catch (BadLocationException ex) {
       return null;
     }
-    
+
     text = text.trim();
-    
+
     if (text.startsWith("at ")) {
       text = text.substring(3);
     }
-    
+
     int indexSeparator = text.indexOf(':');
     if (indexSeparator == -1) {
       return null;
     }
 
     int lineNumber = -1;
-    int indexEndOfLineNumber = indexOfNextNonDigit(text.substring(indexSeparator+1));
+    int indexEndOfLineNumber = indexOfNextNonDigit(text.substring(indexSeparator + 1));
     if (indexEndOfLineNumber > 0) {
-      String lineNumberStr = text.substring(indexSeparator+1, indexSeparator+indexEndOfLineNumber+1);
+      String lineNumberStr = text.substring(indexSeparator + 1, indexSeparator
+          + indexEndOfLineNumber + 1);
       lineNumber = Integer.parseInt(lineNumberStr);
     } else {
       return null;
     }
-    
-    
+
     int indexOfParenthesis = text.indexOf("(");
-    
+
     if (indexOfParenthesis == -1) {
       return null;
     }
-    
+
     text = text.substring(0, indexOfParenthesis);
     int indexOfLastPoint = text.lastIndexOf(".");
-    String method = text.substring(indexOfLastPoint+1, indexOfParenthesis);
+    String method = text.substring(indexOfLastPoint + 1, indexOfParenthesis);
     String className = text.substring(0, indexOfLastPoint);
-    
+
     if (lineNumber != -1) {
-      JavaFileHyperLink link = new JavaFileHyperLink(className, method, lineNumber, region);
+      Region subRegion = new Region(lineInfo.getOffset() + indexOfParenthesis, indexSeparator
+          - indexOfParenthesis);
+      JavaFileHyperLink link = new JavaFileHyperLink(className, method, lineNumber, subRegion);
       return new IHyperlink[] { link };
     }
 
     return null;
   }
-  
+
   private int indexOfNextNonDigit(String text) {
     int length = text.length();
     for (int i = 0; i < length; i++) {
@@ -80,8 +83,7 @@
       if (!Character.isDigit(c)) {
         return i;
       }
-    }  
+    }
     return -1;
   }
-
 }

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java	Wed Mar  7 10:06:02 2007
@@ -3,14 +3,7 @@
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter;
-import org.eclipse.jface.text.hyperlink.HyperlinkManager;
-import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
-import org.eclipse.jface.text.hyperlink.URLHyperlinkDetector;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.ISharedImages;
@@ -65,18 +58,12 @@
 
     viewer = new TextConsoleViewer(parent, myConsole);
     viewer.setEditable(false);
+
     
-    Display disp = Display.getDefault();
-    Color blue = new Color(disp, new RGB(0,0,255) );
-    DefaultHyperlinkPresenter presenter = new DefaultHyperlinkPresenter(blue);
-    HyperlinkManager manager = new HyperlinkManager(HyperlinkManager.FIRST);
-    manager.install(viewer, presenter, new IHyperlinkDetector[]{new URLHyperlinkDetector(),
-        new JavaLinkDetector()}, 0);
+    viewer.configure(new LogbackViewerConfiguration());
+    viewer.setDocument(viewer.getDocument());
     
     
-//    viewer.setHyperlinkDetectors(new IHyperlinkDetector[]{new URLHyperlinkDetector(),
-//      new JavaLinkDetector()}, SWT.NONE);
-
     provider = new LoggingEventContentProvider(myConsole, viewer);
     
     labelProvider = new LoggingEventLabelProvider();
@@ -87,7 +74,6 @@
     
     provider.setLabelProvider(labelProvider);
    
-   
     LoggingEventManager.getManager().addLoggingEventManagerListener(provider);
 
     makeActions();
@@ -126,12 +112,13 @@
       @Override
       public void run() {
         super.run();
-        provider.toggleAutoScroll();
+        //provider.toggleAutoScroll();
+        LoggingEventManager.getManager().toggleSendEvents();
         updateText();
       }
       
       private void updateText() {
-        if (provider.isAutoScroll()) {
+        if (/*provider.isAutoScroll()*/ LoggingEventManager.getManager().isSendingEvents()) {
           this.setText("Turn off auto scroll");
           this.setToolTipText("Turn off auto scroll");
         } else {

Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackViewerConfiguration.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackViewerConfiguration.java	Wed Mar  7 10:06:02 2007
@@ -0,0 +1,39 @@
+package ch.qos.logback.eclipse.views;
+
+import org.eclipse.jface.text.hyperlink.DefaultHyperlinkPresenter;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
+import org.eclipse.jface.text.hyperlink.URLHyperlinkDetector;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.RGB;
+
+public class LogbackViewerConfiguration extends SourceViewerConfiguration {
+
+  PresentationReconciler recon = new PresentationReconciler();
+  DefaultHyperlinkPresenter pres = new DefaultHyperlinkPresenter(new RGB(0, 0, 255));
+  
+  @Override
+  public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+    return new IHyperlinkDetector[] { new URLHyperlinkDetector(), new JavaLinkDetector() };
+  }
+
+  @Override
+  public IHyperlinkPresenter getHyperlinkPresenter(ISourceViewer sourceViewer) {
+    return pres;
+  }
+
+  @Override
+  public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
+    return SWT.NONE;
+  }
+
+  @Override
+  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+    return recon;
+  }
+
+}

Modified: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LoggingEventContentProvider.java	Wed Mar  7 10:06:02 2007
@@ -14,7 +14,6 @@
 
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.helpers.CyclicBuffer;
 import ch.qos.logback.eclipse.PluginLogger;
 import ch.qos.logback.eclipse.model.EventFilter;
 import ch.qos.logback.eclipse.model.LoggingEventManagerEvent;
@@ -30,21 +29,19 @@
   private MessageConsoleStream redStream;
   private MessageConsoleStream blackStream;
   private TextConsoleViewer viewer;
-
-  private CyclicBuffer<LoggingEvent> cyclicBuffer;
+  //private MessageConsole console;
 
   private Color cachedRed;
   private Color cachedBlack;
   private LabelProvider labelProvider;
 
-  private boolean autoScroll = true;
 
   public LoggingEventContentProvider(MessageConsole console, TextConsoleViewer viewer) {
     Display display = Display.getCurrent();
     cachedRed = new Color(display, 255, 0, 0);
     cachedBlack = new Color(display, 0, 0, 0);
     this.viewer = viewer;
-    this.cyclicBuffer = new CyclicBuffer<LoggingEvent>(4000);
+    //this.console = console;
 
     redStream = console.newMessageStream();
     redStream.setColor(cachedRed);
@@ -52,7 +49,7 @@
     blackStream.setColor(cachedBlack);
   }
 
-   WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") {
+  WorkbenchJob revealJob = new WorkbenchJob("Reveal End of Document") {
     public IStatus runInUIThread(IProgressMonitor monitor) {
       StyledText textWidget = viewer.getTextWidget();
       if (textWidget != null) {
@@ -75,28 +72,25 @@
   }
 
   public void loggingEventsChanged(final LoggingEventManagerEvent event) {
-
-    if (autoScroll) {
-      updateViewer(event);
-    } else {
-      LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
-      cyclicBuffer.add(le);
-    }
+    updateViewer(event);
   }
 
   private void updateViewer(final LoggingEventManagerEvent event) {
     LoggingEvent le = (LoggingEvent) event.getItemsAdded()[0];
+    if (le == null) {
+      return;
+    }
+    
     try {
       flushStreams();
-      
+
       writeEvent(le);
 
     } catch (Exception e) {
       PluginLogger.logError(e);
     }
-    if (autoScroll) {
-      revealJob.schedule(50);
-    }
+    
+    revealJob.schedule(50);
   }
 
   private void flushStreams() {
@@ -108,37 +102,11 @@
     }
   }
 
-  public void emptyCyclicBuffer() {
-
-    int max = 100;
-
-    int i = 0;
-    
-    LoggingEvent le = (LoggingEvent) cyclicBuffer.get();
-    while (le != null) {
-      if (i++ >= max) {
-        try {
-          if (i % 100 == 0) {
-//            IOConsolePartitioner idp = (IOConsolePartitioner)redStream.getConsole().getDocument().getDocumentPartitioner();
-//            idp.clearBuffer();
-            System.out.println("100 more done: " + i);
-          }
-        } catch (Exception e) {
-
-        }
-      }
-      
-      writeEvent(le);
-      
-      le = (LoggingEvent) cyclicBuffer.get();
-    }
-  }
-  
   private void writeEvent(LoggingEvent le) {
     if (!EventFilter.filter(le)) {
       return;
     }
-    
+
     if (le.getLevel().isGreaterOrEqual(Level.WARN)) {
       redStream.println(labelProvider.getText(le));
     } else {
@@ -149,26 +117,4 @@
   public void setLabelProvider(LabelProvider provider) {
     this.labelProvider = provider;
   }
-
-  public void setAutoScroll(boolean autoScroll) {
-    this.autoScroll = autoScroll;
-  }
-
-  public boolean isAutoScroll() {
-    return autoScroll;
-  }
-
-  public void toggleAutoScroll() {
-    autoScroll = !autoScroll;
-
-    if (!autoScroll) {
-      // if autoScroll is turned off
-      // we clear the buffer first.
-      cyclicBuffer.clear();
-    } else {
-      // if it is turned on
-      // we empty the buffer
-      emptyCyclicBuffer();
-    }
-  }
 }

Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/MyHyperlinkPresenter.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/MyHyperlinkPresenter.java	Wed Mar  7 10:06:02 2007
@@ -0,0 +1,38 @@
+package ch.qos.logback.eclipse.views;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
+
+public class MyHyperlinkPresenter implements IHyperlinkPresenter {
+
+  private ITextViewer viewer;
+  
+  public boolean canShowMultipleHyperlinks() {
+    return false;
+  }
+
+  public void hideHyperlinks() {
+  }
+
+  public void install(ITextViewer textViewer) {
+    this.viewer = textViewer;
+  }
+
+  public void showHyperlinks(IHyperlink[] hyperlinks) throws IllegalArgumentException {
+    if (hyperlinks == null || hyperlinks.length == 0) {
+      return;
+    }
+    
+    for (int i = 0; i < hyperlinks.length; i++) {
+      showLink(hyperlinks[i]);
+    }
+  }
+
+  private void showLink(IHyperlink link) {
+  }
+  
+  public void uninstall() {
+  }
+
+}



More information about the logback-dev mailing list