Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-06-22 13:25:11 +0000
committerDani Megert2016-09-26 10:33:12 +0000
commitae146da17062d199167360e47eae3fab596e31f0 (patch)
treeaeded078a5854d06145edd6b6f561e74f36d3abe
parent5bcb7ac5045743f9ec17895a9a12318dd90ea4cb (diff)
downloadeclipse.platform.text-ae146da17062d199167360e47eae3fab596e31f0.tar.gz
eclipse.platform.text-ae146da17062d199167360e47eae3fab596e31f0.tar.xz
eclipse.platform.text-ae146da17062d199167360e47eae3fab596e31f0.zip
Bug 499811 - .project edition contributing to Generic Editor
This is an example of a usable and feature rich editor for .project files which contributes to the Generic Editor proposal. Bug: 499811 Bug: 497871 Signed-off-by: Mickael Istria <mistria@redhat.com> Signed-off-by: Sopot Cela <scela@redhat.com> Change-Id: I131e00cbca566e3dc2413c7b5db8c9d724b46bfb
-rw-r--r--org.eclipse.ui.genericeditor.examples/.classpath7
-rw-r--r--org.eclipse.ui.genericeditor.examples/.project28
-rw-r--r--org.eclipse.ui.genericeditor.examples/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF13
-rw-r--r--org.eclipse.ui.genericeditor.examples/build.properties5
-rw-r--r--org.eclipse.ui.genericeditor.examples/plugin.xml37
-rw-r--r--org.eclipse.ui.genericeditor.examples/pom.xml23
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/BlueTagsPresentationReconciler.java41
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NatureLabelHoverProvider.java49
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NaturesAndProjectsContentAssistProcessor.java79
-rw-r--r--pom.xml1
11 files changed, 290 insertions, 0 deletions
diff --git a/org.eclipse.ui.genericeditor.examples/.classpath b/org.eclipse.ui.genericeditor.examples/.classpath
new file mode 100644
index 000000000..eca7bdba8
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.ui.genericeditor.examples/.project b/org.eclipse.ui.genericeditor.examples/.project
new file mode 100644
index 000000000..7671970d7
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ui.genericeditor.examples</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.ui.genericeditor.examples/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.ui.genericeditor.examples/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..0c68a61dc
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..a7f228ca7
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Examples for Generic Editor
+Bundle-SymbolicName: org.eclipse.ui.genericeditor.examples;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Eclipse.org
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Require-Bundle: org.eclipse.ui.genericeditor;bundle-version="1.0.0",
+ org.eclipse.ui.editors;bundle-version="3.10.0",
+ org.eclipse.jface.text;bundle-version="3.11.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"
diff --git a/org.eclipse.ui.genericeditor.examples/build.properties b/org.eclipse.ui.genericeditor.examples/build.properties
new file mode 100644
index 000000000..e9863e281
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/org.eclipse.ui.genericeditor.examples/plugin.xml b/org.eclipse.ui.genericeditor.examples/plugin.xml
new file mode 100644
index 000000000..2b809c171
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/plugin.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.core.contenttype.contentTypes">
+ <content-type
+ base-type="org.eclipse.core.runtime.text"
+ file-names=".project"
+ id="dotproject"
+ name="Eclipse .project"
+ priority="normal">
+ </content-type>
+ </extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.contentAssistProcessors">
+ <contentAssistProcessor
+ class="org.eclipse.ui.genericeditor.examples.dotproject.NaturesAndProjectsContentAssistProcessor"
+ contentType="org.eclipse.ui.genericeditor.examples.dotproject">
+ </contentAssistProcessor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.hoverProviders">
+ <hoverProvider
+ class="org.eclipse.ui.genericeditor.examples.dotproject.NatureLabelHoverProvider"
+ contentType="org.eclipse.ui.genericeditor.examples.dotproject"
+ id="natureLabelHoverProvider">
+ </hoverProvider>
+ </extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.presentationReconcilers">
+ <presentationReconciler
+ class="org.eclipse.ui.genericeditor.examples.dotproject.BlueTagsPresentationReconciler"
+ contentType="org.eclipse.ui.genericeditor.examples.dotproject">
+ </presentationReconciler>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.ui.genericeditor.examples/pom.xml b/org.eclipse.ui.genericeditor.examples/pom.xml
new file mode 100644
index 000000000..bb92f5afa
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/pom.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2016 Red Hat Inc. and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Distribution License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/org/documents/edl-v10.php
+
+ Contributors:
+ Mickael Istria (Red Hat Inc.) - initial implementation
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>eclipse.platform.text</artifactId>
+ <groupId>eclipse.platform.text</groupId>
+ <version>4.7.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.eclipse.ui</groupId>
+ <artifactId>org.eclipse.ui.genericeditor.examples</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+</project>
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/BlueTagsPresentationReconciler.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/BlueTagsPresentationReconciler.java
new file mode 100644
index 000000000..fd2400544
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/BlueTagsPresentationReconciler.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat 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:
+ * Mickael Istria, Sopot Cela (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.examples.dotproject;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+
+public class BlueTagsPresentationReconciler extends PresentationReconciler {
+
+ private final TextAttribute tagAttribute = new TextAttribute(new Color(Display.getCurrent(), new RGB(0,0, 255)));
+ private final TextAttribute headerAttribute = new TextAttribute(new Color(Display.getCurrent(), new RGB(128,128,128)));
+
+ public BlueTagsPresentationReconciler() {
+ RuleBasedScanner scanner= new RuleBasedScanner();
+ IRule[] rules = new IRule[2];
+ rules[1]= new SingleLineRule("<", ">", new Token(tagAttribute));
+ rules[0]= new SingleLineRule("<?", "?>", new Token(headerAttribute));
+ scanner.setRules(rules);
+ DefaultDamagerRepairer dr= new DefaultDamagerRepairer(scanner);
+ this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NatureLabelHoverProvider.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NatureLabelHoverProvider.java
new file mode 100644
index 000000000..e6fd01b94
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NatureLabelHoverProvider.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat 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:
+ * Mickael Istria, Sopot Cela (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.examples.dotproject;
+
+import org.eclipse.core.resources.IProjectNatureDescriptor;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+public class NatureLabelHoverProvider implements ITextHover {
+
+ public NatureLabelHoverProvider() {
+ }
+
+ @Override
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+
+ String contents= textViewer.getDocument().get();
+ int offset= hoverRegion.getOffset();
+ int endIndex= contents.indexOf("</nature>", offset);
+ if (endIndex==-1) return "";
+ int startIndex= contents.substring(0, offset).lastIndexOf("<nature>");
+ if (startIndex==-1) return "";
+ String selection = contents.substring(startIndex+"<nature>".length(), endIndex);
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors();
+ for (int i= 0; i < natureDescriptors.length; i++) {
+ if (natureDescriptors[i].getNatureId().equals(selection))
+ return natureDescriptors[i].getLabel();
+ }
+ return "";
+ }
+
+ @Override
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ return new Region(offset, 0);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NaturesAndProjectsContentAssistProcessor.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NaturesAndProjectsContentAssistProcessor.java
new file mode 100644
index 000000000..37509080b
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/NaturesAndProjectsContentAssistProcessor.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat 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:
+ * - Mickael Istria, Sopot Cela (Red Hat Inc.)
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.examples.dotproject;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectNatureDescriptor;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+public class NaturesAndProjectsContentAssistProcessor implements IContentAssistProcessor {
+
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ String text = viewer.getTextWidget().getText();
+ String natureTag= "<nature>";
+ String projectReferenceTag="<project>";
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (text.length() >= natureTag.length() && text.substring(offset - natureTag.length(), offset).equals(natureTag)) {
+ IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors();
+ ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
+ for (int i= 0; i < natureDescriptors.length; i++) {
+ IProjectNatureDescriptor descriptor= natureDescriptors[i];
+ proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0, descriptor.getNatureId().length());
+ }
+ return proposals;
+ }
+ if (text.length() >= projectReferenceTag.length() && text.substring(offset - projectReferenceTag.length(), offset).equals(projectReferenceTag)) {
+ IProject[] projects= workspace.getRoot().getProjects();
+ //TODO - filter out the project this file is in
+ ICompletionProposal[] proposals = new ICompletionProposal[projects.length];
+ for (int i= 0; i < projects.length; i++) {
+ proposals[i]=new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length());
+ }
+ return proposals;
+ }
+ return new ICompletionProposal[0];
+ }
+
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ return null;
+ }
+
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index fa14d0f9d..0b1b8552e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
<!-- Generic editor -->
<module>org.eclipse.ui.genericeditor</module>
<module>org.eclipse.ui.genericeditor.tests</module>
+ <module>org.eclipse.ui.genericeditor.examples</module>
</modules>
</project>

Back to the top