Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-04-26 00:10:48 +0000
committerslewis2007-04-26 00:10:48 +0000
commit9ca6bef0e757fdd75d1e6d3b0cd4a05120c80af8 (patch)
tree5de056daa8e6a2bed734c50f98ef990f3b8f7412 /providers/bundles/org.eclipse.ecf.provider.irc.ui
parent7afe72cb3b05970b64b04050ddd85c4319c534c9 (diff)
downloadorg.eclipse.ecf-9ca6bef0e757fdd75d1e6d3b0cd4a05120c80af8.tar.gz
org.eclipse.ecf-9ca6bef0e757fdd75d1e6d3b0cd4a05120c80af8.tar.xz
org.eclipse.ecf-9ca6bef0e757fdd75d1e6d3b0cd4a05120c80af8.zip
Added support for irc hyperlink detector for text editors
Diffstat (limited to 'providers/bundles/org.eclipse.ecf.provider.irc.ui')
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF4
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.properties2
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml20
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlink.java104
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlinkDetector.java115
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizard.java12
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizardPage.java15
7 files changed, 268 insertions, 4 deletions
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF b/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF
index c4200ac14..55341ed69 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/META-INF/MANIFEST.MF
@@ -10,7 +10,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ecf,
org.eclipse.ui,
org.eclipse.ecf.presence,
- org.eclipse.ecf.presence.ui
+ org.eclipse.ecf.presence.ui,
+ org.eclipse.jface.text,
+ org.eclipse.ui.workbench.texteditor
Eclipse-LazyStart: true
Export-Package: org.eclipse.ecf.internal.irc.ui;x-internal:=true,
org.eclipse.ecf.internal.irc.ui.wizards;x-internal:=true
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.properties b/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.properties
index d6da34431..2ac21add8 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.properties
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.properties
@@ -11,3 +11,5 @@
plugin.name=ECF IRC UI
plugin.provider=Eclipse.org
+TextEditorHyperlinkTarget= Textual Editors
+IRCHyperlinkDetector= IRC
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml b/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml
index cb9834bc8..d71e7dde2 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/plugin.xml
@@ -9,4 +9,24 @@
id="org.eclipse.ecf.provider.ui.irc.connectWizard"
name="IRC"/>
</extension>
+
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
+ <target
+ id="org.eclipse.ui.DefaultTextEditor"
+ name="%TextEditorHyperlinkTarget">
+ </target>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ activate="true"
+ class="org.eclipse.ecf.internal.irc.hyperlink.IRCHyperlinkDetector"
+ id="org.eclipse.ecf.internal.irc.hyperlink.IRCHyperlinkDetector"
+ name="%IRCHyperlinkDetector"
+ targetId="org.eclipse.ui.DefaultTextEditor">
+ </hyperlinkDetector>
+ </extension>
+
</plugin>
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlink.java b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlink.java
new file mode 100644
index 000000000..20208c42e
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlink.java
@@ -0,0 +1,104 @@
+/****************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.internal.irc.hyperlink;
+
+import java.net.URI;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.internal.irc.ui.wizards.IRCConnectWizard;
+import org.eclipse.ecf.ui.IConnectWizard;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ *
+ */
+public class IRCHyperlink implements IHyperlink {
+
+ private static final String ECF_IRC_CONTAINER_NAME = "ecf.irc.irclib";
+ private URI fURI;
+ private IRegion fRegion;
+
+ /**
+ * Creates a new URL hyperlink.
+ *
+ * @param region
+ * @param urlString
+ */
+ public IRCHyperlink(IRegion region, URI uri) {
+ Assert.isNotNull(uri);
+ Assert.isNotNull(region);
+
+ fRegion= region;
+ fURI= uri;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkRegion()
+ */
+ public IRegion getHyperlinkRegion() {
+ return fRegion;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#open()
+ */
+ public void open() {
+ openConnectWizard(fURI.toString());
+ }
+
+ private void openConnectWizard(String uri) {
+ try {
+ IContainer container = ContainerFactory.getDefault()
+ .createContainer(ECF_IRC_CONTAINER_NAME);
+ IConnectWizard icw = (IConnectWizard) new IRCConnectWizard(uri);
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ icw.init(workbench, container);
+ WizardDialog dialog = new WizardDialog(window.getShell(), icw);
+ dialog.open();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getTypeLabel()
+ */
+ public String getTypeLabel() {
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkText()
+ */
+ public String getHyperlinkText() {
+ return null;
+ }
+
+ /**
+ * Returns the URL string of this hyperlink.
+ *
+ * @return the URL string
+ * @since 3.2
+ */
+ public String getURLString() {
+ return fURI.toString();
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlinkDetector.java b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlinkDetector.java
new file mode 100644
index 000000000..067ef5131
--- /dev/null
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/hyperlink/IRCHyperlinkDetector.java
@@ -0,0 +1,115 @@
+package org.eclipse.ecf.internal.irc.hyperlink;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+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;
+import org.eclipse.jface.text.hyperlink.URLHyperlinkDetector;
+
+public class IRCHyperlinkDetector extends URLHyperlinkDetector {
+
+ public static final String IRC_PROTOCOL = "irc";
+
+ public IRCHyperlinkDetector() {
+ }
+
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+ if (region == null || textViewer == null)
+ return null;
+
+ IDocument document = textViewer.getDocument();
+
+ int offset = region.getOffset();
+
+ String urlString = null;
+ if (document == null)
+ return null;
+
+ IRegion lineInfo;
+ String line;
+ try {
+ lineInfo = document.getLineInformationOfOffset(offset);
+ line = document.get(lineInfo.getOffset(), lineInfo.getLength());
+ } catch (BadLocationException ex) {
+ return null;
+ }
+
+ int offsetInLine = offset - lineInfo.getOffset();
+
+ boolean startDoubleQuote = false;
+ int urlOffsetInLine = 0;
+ int urlLength = 0;
+
+ int urlSeparatorOffset = line.indexOf("://"); //$NON-NLS-1$
+ while (urlSeparatorOffset >= 0) {
+
+ // URL protocol (left to "://")
+ urlOffsetInLine = urlSeparatorOffset;
+ char ch;
+ do {
+ urlOffsetInLine--;
+ ch = ' ';
+ if (urlOffsetInLine > -1)
+ ch = line.charAt(urlOffsetInLine);
+ startDoubleQuote = ch == '"';
+ } while (Character.isUnicodeIdentifierStart(ch));
+ urlOffsetInLine++;
+
+ // Right to "://"
+ StringTokenizer tokenizer = new StringTokenizer(line
+ .substring(urlSeparatorOffset + 3), " \t\n\r\f<>", false); //$NON-NLS-1$
+ if (!tokenizer.hasMoreTokens())
+ return null;
+
+ urlLength = tokenizer.nextToken().length() + 3 + urlSeparatorOffset
+ - urlOffsetInLine;
+ if (offsetInLine >= urlOffsetInLine
+ && offsetInLine <= urlOffsetInLine + urlLength)
+ break;
+
+ urlSeparatorOffset = line.indexOf("://", urlSeparatorOffset + 1); //$NON-NLS-1$
+ }
+
+ if (urlSeparatorOffset < 0)
+ return null;
+
+ if (startDoubleQuote) {
+ int endOffset = -1;
+ int nextDoubleQuote = line.indexOf('"', urlOffsetInLine);
+ int nextWhitespace = line.indexOf(' ', urlOffsetInLine);
+ if (nextDoubleQuote != -1 && nextWhitespace != -1)
+ endOffset = Math.min(nextDoubleQuote, nextWhitespace);
+ else if (nextDoubleQuote != -1)
+ endOffset = nextDoubleQuote;
+ else if (nextWhitespace != -1)
+ endOffset = nextWhitespace;
+ if (endOffset != -1)
+ urlLength = endOffset - urlOffsetInLine;
+ }
+
+ // Set and validate URL string
+ URI uri = null;
+ try {
+ urlString = line.substring(urlOffsetInLine, urlOffsetInLine
+ + urlLength);
+ uri = new URI(urlString);
+ String protocol = uri.getScheme();
+ if (protocol == null || !protocol.equals(IRC_PROTOCOL))
+ return null;
+ } catch (URISyntaxException e) {
+ return null;
+ }
+
+ IRegion urlRegion = new Region(lineInfo.getOffset() + urlOffsetInLine,
+ urlLength);
+ return new IHyperlink[] { new IRCHyperlink(urlRegion, uri) };
+ }
+
+}
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizard.java b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizard.java
index 992d54661..6f1b44ff1 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizard.java
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizard.java
@@ -43,6 +43,8 @@ public final class IRCConnectWizard extends Wizard implements IConnectWizard {
private IConnectContext connectContext;
+ private String uriString = null;
+
private IExceptionHandler exceptionHandler = new IExceptionHandler() {
public IStatus handleException(final Throwable exception) {
if (exception != null) {
@@ -59,8 +61,16 @@ public final class IRCConnectWizard extends Wizard implements IConnectWizard {
}
};
+ public IRCConnectWizard() {
+ super();
+ }
+
+ public IRCConnectWizard(String uri) {
+ super();
+ uriString = uri;
+ }
public void addPages() {
- page = new IRCConnectWizardPage();
+ page = new IRCConnectWizardPage(uriString);
addPage(page);
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizardPage.java b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizardPage.java
index 9a797b684..0024bc521 100644
--- a/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizardPage.java
+++ b/providers/bundles/org.eclipse.ecf.provider.irc.ui/src/org/eclipse/ecf/internal/irc/ui/wizards/IRCConnectWizardPage.java
@@ -26,12 +26,19 @@ final class IRCConnectWizardPage extends WizardPage {
private Text passwordText;
+ private String uriString;
+
IRCConnectWizardPage() {
super("");
setTitle("IRC Connection Wizard");
setDescription("Specify a nickname and IRC server to connect to.");
setPageComplete(false);
}
+
+ IRCConnectWizardPage(String uri) {
+ this();
+ uriString = uri;
+ }
public void createControl(Composite parent) {
parent.setLayout(new GridLayout());
@@ -48,11 +55,10 @@ final class IRCConnectWizardPage extends WizardPage {
if (!connectText.getText().equals("")) { //$NON-NLS-1$
updateStatus(null);
} else {
- updateStatus("An connect ID must be specified.");
+ updateStatus("A connect ID must be specified.");
}
}
});
-
label = new Label(parent, SWT.RIGHT);
label.setText("irc://<user>@<ircserver>[/<#channel>]");
label.setLayoutData(endData);
@@ -65,6 +71,11 @@ final class IRCConnectWizardPage extends WizardPage {
label.setText("This password is for password-protected IRC servers.");
label.setLayoutData(endData);
+ if (uriString != null) {
+ connectText.setText(uriString);
+ passwordText.setFocus();
+ }
+
setControl(parent);
}

Back to the top