### Eclipse Workspace Patch 1.0
#P org.eclipse.ecf.provider.irc.ui
Index: plugin.xml
===================================================================
RCS file: /cvsroot/technology/org.eclipse.ecf/plugins/org.eclipse.ecf.provider.irc.ui/plugin.xml,v
retrieving revision 1.6
diff -u -r1.6 plugin.xml
--- plugin.xml 24 Jul 2007 15:25:19 -0000 1.6
+++ plugin.xml 27 Jul 2007 20:57:31 -0000
@@ -19,6 +19,13 @@
name="%IRCHyperlinkDetector"
targetId="org.eclipse.ui.DefaultTextEditor">
+
+
Index: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java
===================================================================
RCS file: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java
diff -N src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlinkDetector.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,98 @@
+package org.eclipse.ecf.internal.irc.ui.hyperlink;
+
+import java.util.StringTokenizer;
+
+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.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+
+public class BugHyperlinkDetector extends
+ org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector {
+
+ public static final String DEFAULT_PREFIX = "bug "; //$NON-NLS-1$
+ public static final String DEFAULT_ENDDELIMITERS = " \t\n\r\f<>"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer,
+ * org.eclipse.jface.text.IRegion, boolean)
+ */
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+ if (region == null || textViewer == null)
+ return null;
+
+ IDocument document = textViewer.getDocument();
+ if (document == null)
+ return null;
+
+ int offset = region.getOffset();
+
+ IRegion lineInfo;
+ String line;
+ try {
+ lineInfo = document.getLineInformationOfOffset(offset);
+ line = document.get(lineInfo.getOffset(), lineInfo.getLength());
+ } catch (BadLocationException ex) {
+ return null;
+ }
+
+ String detectedSubstring = detectSubstring(line, offset
+ - lineInfo.getOffset());
+ String bugNumber = detectedSubstring.substring(DEFAULT_PREFIX.length());
+
+ if (detectedSubstring != null && isBugNumber(bugNumber))
+ return createHyperLinksForBug(bugNumber, new Region(
+ lineInfo.getOffset() + line.indexOf(detectedSubstring),
+ detectedSubstring.length()));
+
+ return null;
+ }
+
+ private boolean isBugNumber(String bug) {
+ try {
+ Integer.parseInt(bug);
+ return true;
+ } catch (NumberFormatException e) {
+ }
+
+ return false;
+ }
+
+ private IHyperlink[] createHyperLinksForBug(String bugNumber, Region region) {
+ return new IHyperlink[] { new BugHyperlink(bugNumber, region) };
+ }
+
+ private String detectSubstring(String fromLine, int offsetInLine) {
+ int resultLength = 0;
+
+ int separatorOffset = fromLine.indexOf(DEFAULT_PREFIX);
+ while (separatorOffset >= 0) {
+ StringTokenizer tokenizer = new StringTokenizer(fromLine
+ .substring(separatorOffset + DEFAULT_PREFIX.length()),
+ DEFAULT_ENDDELIMITERS, false);
+ if (!tokenizer.hasMoreTokens())
+ return null;
+
+ resultLength = tokenizer.nextToken().length()
+ + DEFAULT_PREFIX.length();
+ if (offsetInLine >= separatorOffset
+ && offsetInLine <= separatorOffset + resultLength)
+ break;
+
+ separatorOffset = fromLine.indexOf(DEFAULT_PREFIX,
+ separatorOffset + 1);
+ }
+
+ if (separatorOffset < 0)
+ return null;
+
+ return fromLine.substring(separatorOffset, separatorOffset
+ + resultLength);
+ }
+
+}
Index: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java
===================================================================
RCS file: src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java
diff -N src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ecf/internal/irc/ui/hyperlink/BugHyperlink.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,71 @@
+package org.eclipse.ecf.internal.irc.ui.hyperlink;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
+
+public class BugHyperlink implements IHyperlink {
+ public static final String ECLIPSE_BUGZILLA_URL = "https://bugs.eclipse.org/bugs/show_bug.cgi?id=";
+
+ public static final String BROWSER_BUG_TITLE = "Bug #";
+
+ private Region region;
+
+ private String bugNumber;
+
+ private String typeLabel;
+
+ private String hyperlinkText;
+
+ public BugHyperlink(Region region) {
+ }
+
+ public BugHyperlink(String bugNumber, Region region) {
+ this.region = region;
+ this.bugNumber = bugNumber;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return this.region;
+ }
+
+ public String getHyperlinkText() {
+ return this.hyperlinkText;
+ }
+
+ public String getTypeLabel() {
+ return this.typeLabel;
+ }
+
+ public void open() {
+ IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench()
+ .getBrowserSupport();
+
+ URL webUrl;
+
+ try {
+ webUrl = new URL(ECLIPSE_BUGZILLA_URL + bugNumber);
+ } catch (MalformedURLException e) {
+ return;
+ }
+
+ IWebBrowser browser;
+ try {
+ browser = browserSupport.createBrowser(
+ IWorkbenchBrowserSupport.AS_EDITOR, BROWSER_BUG_TITLE+bugNumber, BROWSER_BUG_TITLE+bugNumber,
+ BROWSER_BUG_TITLE+bugNumber);
+ browser.openURL(webUrl);
+ } catch (PartInitException e) {
+ return;
+ }
+
+ }
+
+}