[logback-dev] svn commit: r1361 - in logbackPDE/trunk/plugins/ConsolePlugin: . META-INF src/main/java/ch/qos/logback/eclipse/views

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Feb 27 16:31:20 CET 2007


Author: seb
Date: Tue Feb 27 16:31:20 2007
New Revision: 1361

Added:
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java
Modified:
   logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF
   logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/LogbackView.java
   logbackPDE/trunk/plugins/ConsolePlugin/todo.txt

Log:
Added a first version of link support

Modified: logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/META-INF/MANIFEST.MF	Tue Feb 27 16:31:20 2007
@@ -13,6 +13,6 @@
 Require-Bundle: org.eclipse.ui,
  org.eclipse.core.runtime,
  org.eclipse.jface.text,
- org.eclipse.jdt.core,
- org.eclipse.ui.console
+ org.eclipse.ui.console,
+ org.eclipse.ui.ide
 Eclipse-LazyStart: true

Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaFileHyperLink.java	Tue Feb 27 16:31:20 2007
@@ -0,0 +1,35 @@
+package ch.qos.logback.eclipse.views;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+
+class JavaFileHyperLink implements IHyperlink {
+
+  private String className;
+  private String method;
+  private int lineNumber;
+  private IRegion region;
+  
+  public JavaFileHyperLink(String className, String method, int lineNumber, IRegion region) {
+    this.lineNumber = lineNumber;
+    this.region = region;
+    this.className = className;
+    this.method = method;
+  }
+
+  public IRegion getHyperlinkRegion() {
+    return region;
+  }
+
+  public String getHyperlinkText() {
+    return null;
+  }
+
+  public String getTypeLabel() {
+    return null;
+  }
+
+  public void open() {
+    System.out.println("Link to: " + className + "/" + method + " line: " + lineNumber);
+  }
+}

Added: logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java
==============================================================================
--- (empty file)
+++ logbackPDE/trunk/plugins/ConsolePlugin/src/main/java/ch/qos/logback/eclipse/views/JavaLinkDetector.java	Tue Feb 27 16:31:20 2007
@@ -0,0 +1,91 @@
+package ch.qos.logback.eclipse.views;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+
+public class JavaLinkDetector implements IHyperlinkDetector {
+
+  public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
+      boolean canShowMultipleHyperlinks) {
+
+    if (region == null || textViewer == null) {
+      return null;
+    }
+
+    IDocument document = textViewer.getDocument();
+
+    int offset = region.getOffset();
+
+    if (document == null) {
+      return null;
+    }
+
+    IRegion lineInfo;
+    String text;
+    try {
+      lineInfo = document.getLineInformationOfOffset(offset);
+      text = document.get(lineInfo.getOffset(), lineInfo.getLength());
+    } 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));
+    if (indexEndOfLineNumber > 0) {
+      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 className = text.substring(0, indexOfLastPoint);
+    
+    if (lineNumber != -1) {
+      JavaFileHyperLink link = new JavaFileHyperLink(className, method, lineNumber, region);
+      return new IHyperlink[] { link };
+    }
+
+    return null;
+  }
+  
+  private int indexOfNextNonDigit(String text) {
+    char zero = '0';
+    
+    int length = text.length();
+    for (int i = 0; i < length; i++) {
+      char c = text.charAt(i);
+      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	Tue Feb 27 16:31:20 2007
@@ -3,7 +3,14 @@
 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.ISharedImages;
 import org.eclipse.ui.PlatformUI;
@@ -51,11 +58,17 @@
 
     viewer = new TextConsoleViewer(parent, myConsole);
     viewer.setEditable(false);
-//    Display disp = Display.getCurrent();
-//    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()}, 0);
+    
+    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.setHyperlinkDetectors(new IHyperlinkDetector[]{new URLHyperlinkDetector(),
+//      new JavaLinkDetector()}, SWT.NONE);
 
     provider = new LoggingEventContentProvider(myConsole, viewer);
     labelProvider = new LoggingEventLabelProvider();

Modified: logbackPDE/trunk/plugins/ConsolePlugin/todo.txt
==============================================================================
--- logbackPDE/trunk/plugins/ConsolePlugin/todo.txt	(original)
+++ logbackPDE/trunk/plugins/ConsolePlugin/todo.txt	Tue Feb 27 16:31:20 2007
@@ -12,7 +12,8 @@
 
 Save Preferences between sessions
 
+Autoscroll use with double-buffer and stop the filling of the console when auto scroll = off
+
 DONE:
 Allow the user to change the socket's port
 Make the viewer always display the latest lines added
-Autoscroll
\ No newline at end of file



More information about the logback-dev mailing list