Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Scholz2017-11-27 19:34:40 -0500
committerSimon Scholz2017-11-28 08:38:25 -0500
commit40bf7f97e45fa3a2fb9419608d653b1d2d50c612 (patch)
tree7ea86b67645003cb3b7a0227314e694c0233276d
parent9eebfa376eeadd862a2ecd0ad941ef1a4dbda834 (diff)
downloadeclipse.platform.text-I20171128-2000.tar.gz
eclipse.platform.text-I20171128-2000.tar.xz
eclipse.platform.text-I20171128-2000.zip
Bug 527834 - [GenericEditor] hyperlinkDetector exampleI20171128-2000
Add a hyperlinkDetector to the generic editor examples project Change-Id: If88819b385cce2798a498cdc0ec280cb36de2e6e Signed-off-by: Simon Scholz <simon.scholz@vogella.com>
-rw-r--r--org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.ui.genericeditor.examples/plugin.xml11
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ProjectHyperlinkDetector.java45
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ShowInSystemExplorerHyperlink.java65
4 files changed, 124 insertions, 1 deletions
diff --git a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
index 17db4cef2..947e7ef78 100644
--- a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
@@ -11,5 +11,7 @@ Require-Bundle: org.eclipse.ui.genericeditor;bundle-version="1.0.0",
org.eclipse.core.resources;bundle-version="3.11.0",
org.eclipse.ui;bundle-version="3.108.0",
org.eclipse.core.runtime;bundle-version="3.11.0",
- org.eclipse.ui.workbench.texteditor;bundle-version="3.10.100"
+ org.eclipse.ui.workbench.texteditor;bundle-version="3.10.100",
+ org.eclipse.e4.core.commands;bundle-version="0.12.100",
+ org.eclipse.ui.ide
Export-Package: org.eclipse.ui.genericeditor.examples.dotproject
diff --git a/org.eclipse.ui.genericeditor.examples/plugin.xml b/org.eclipse.ui.genericeditor.examples/plugin.xml
index 97238a817..0073c9986 100644
--- a/org.eclipse.ui.genericeditor.examples/plugin.xml
+++ b/org.eclipse.ui.genericeditor.examples/plugin.xml
@@ -11,6 +11,7 @@
<!-- Sopot Cela & Mickael Istria (Red Hat Inc). -initial implementation -->
<!-- Lucas Bullen (Red Hat Inc.) - Bug 508829 custom reconciler support -->
<!-- - Bug 521382 default highlighter -->
+<!-- Simon Scholz <simon.scholz@vogella.com> - Bug 527834 -->
<!-- ====================================================================== -->
<plugin>
<extension
@@ -84,4 +85,14 @@
contentType="org.eclipse.ui.genericeditor.examples.dotproject">
</highlightReconciler>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ activate="true"
+ class="org.eclipse.ui.genericeditor.examples.dotproject.hyperlink.ProjectHyperlinkDetector"
+ id="org.eclipse.ui.genericeditor.examples.hyperlinkDetector"
+ name="Project Settings Hyperlink Detector"
+ targetId="org.eclipse.ui.genericeditor.GenericEditor">
+ </hyperlinkDetector>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ProjectHyperlinkDetector.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ProjectHyperlinkDetector.java
new file mode 100644
index 000000000..ba8dd56f3
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ProjectHyperlinkDetector.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2017 vogella GmbH 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:
+ * - Simon Scholz <simon.scholz@vogella.com> - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.examples.dotproject.hyperlink;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.hyperlink.URLHyperlink;
+import org.eclipse.osgi.util.TextProcessor;
+import org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+@SuppressWarnings("restriction")
+public class ProjectHyperlinkDetector extends AbstractHyperlinkDetector {
+
+ @Override
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+ ITextEditor textEditor = getAdapter(ITextEditor.class);
+
+ IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
+
+ String fileLocation = TextProcessor.process(IDEResourceInfoUtils.getLocationText(resource));
+
+ ShowInSystemExplorerHyperlink showInSystemExplorerHyperlink = new ShowInSystemExplorerHyperlink(fileLocation,
+ region);
+
+ URLHyperlink fileUrlHyperlink = new URLHyperlink(region, fileLocation);
+
+ URLHyperlink projectFileHelpLink = new URLHyperlink(region,
+ "https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fproject_description_file.html");
+
+ return new IHyperlink[] { showInSystemExplorerHyperlink, fileUrlHyperlink, projectFileHelpLink };
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ShowInSystemExplorerHyperlink.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ShowInSystemExplorerHyperlink.java
new file mode 100644
index 000000000..507145bbf
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/hyperlink/ShowInSystemExplorerHyperlink.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2017 vogella GmbH 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:
+ * - Simon Scholz <simon.scholz@vogella.com> - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.examples.dotproject.hyperlink;
+
+import java.util.Collections;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.commands.EHandlerService;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.ide.handlers.ShowInSystemExplorerHandler;
+
+@SuppressWarnings("restriction")
+public class ShowInSystemExplorerHyperlink implements IHyperlink {
+
+ private String fileLocation;
+ private IRegion region;
+
+ public ShowInSystemExplorerHyperlink(String fileLocation, IRegion region) {
+ this.fileLocation = fileLocation;
+ this.region = region;
+ }
+
+ @Override
+ public IRegion getHyperlinkRegion() {
+ return region;
+ }
+
+ @Override
+ public String getTypeLabel() {
+ return null;
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ return "Show in System Explorer";
+ }
+
+ @Override
+ public void open() {
+ ECommandService commandService = PlatformUI.getWorkbench().getService(ECommandService.class);
+ EHandlerService handlerService = PlatformUI.getWorkbench().getService(EHandlerService.class);
+
+ Command command = commandService.getCommand(ShowInSystemExplorerHandler.ID);
+ if (command.isDefined()) {
+ ParameterizedCommand parameterizedCommand = commandService.createCommand(ShowInSystemExplorerHandler.ID,
+ Collections.singletonMap(ShowInSystemExplorerHandler.RESOURCE_PATH_PARAMETER, fileLocation));
+ if (handlerService.canExecute(parameterizedCommand)) {
+ handlerService.executeHandler(parameterizedCommand);
+ }
+ }
+ }
+
+}

Back to the top