diff options
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 00000000000..eca7bdba8f0 --- /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 00000000000..7671970d772 --- /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 00000000000..0c68a61dca8 --- /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 00000000000..a7f228ca721 --- /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 00000000000..e9863e281ea --- /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 00000000000..2b809c171c7 --- /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 00000000000..bb92f5afa1f --- /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 00000000000..fd2400544dc --- /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 00000000000..e6fd01b94d2 --- /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 00000000000..37509080b2c --- /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 @@ -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> |