Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Niewrzal2016-12-16 05:13:24 -0500
committerMichal Niewrzal2017-06-29 09:54:38 -0400
commita960a556bb97303083f87165350bdc44c55d701e (patch)
tree6d554619adc4d97945f2910be0c13350e477946a
parent2da5c4c44f32c6db2c1b5c27c49a93846ee7eefb (diff)
downloadeclipse.platform.text-a960a556bb97303083f87165350bdc44c55d701e.tar.gz
eclipse.platform.text-a960a556bb97303083f87165350bdc44c55d701e.tar.xz
eclipse.platform.text-a960a556bb97303083f87165350bdc44c55d701e.zip
Bug 508677 - [Generic Editor] Extension point for auto edit strategies
Change-Id: I275a82c443e6a9e612ea8e3297b2c78f6cae8ac0 Signed-off-by: Michal Niewrzal <michal.n@zend.com>
-rw-r--r--org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.genericeditor.examples/plugin.xml8
-rw-r--r--org.eclipse.ui.genericeditor.examples/pom.xml2
-rw-r--r--org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagAutoEditStrategy.java39
-rw-r--r--org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.genericeditor.tests/plugin.xml15
-rw-r--r--org.eclipse.ui.genericeditor.tests/pom.xml2
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java31
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java3
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyFirst.java24
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategySecond.java24
-rw-r--r--org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyThird.java24
-rw-r--r--org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.genericeditor/plugin.properties1
-rw-r--r--org.eclipse.ui.genericeditor/plugin.xml1
-rw-r--r--org.eclipse.ui.genericeditor/pom.xml2
-rw-r--r--org.eclipse.ui.genericeditor/schema/autoEditStrategies.exsd116
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AutoEditStrategyRegistry.java130
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java12
-rw-r--r--org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java12
20 files changed, 444 insertions, 8 deletions
diff --git a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
index a7dd0efc5..0f084dc6f 100644
--- a/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.examples/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ 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-Version: 1.1.0.qualifier
Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.ui.genericeditor;bundle-version="1.0.0",
diff --git a/org.eclipse.ui.genericeditor.examples/plugin.xml b/org.eclipse.ui.genericeditor.examples/plugin.xml
index d4552620e..60f20e05b 100644
--- a/org.eclipse.ui.genericeditor.examples/plugin.xml
+++ b/org.eclipse.ui.genericeditor.examples/plugin.xml
@@ -57,5 +57,11 @@
contentTypeId="org.eclipse.ui.genericeditor.examples.dotproject">
</participant>
</extension>
-
+ <extension
+ point="org.eclipse.ui.genericeditor.autoEditStrategies">
+ <autoEditStrategy
+ class="org.eclipse.ui.genericeditor.examples.dotproject.TagAutoEditStrategy"
+ contentType="org.eclipse.ui.genericeditor.examples.dotproject">
+ </autoEditStrategy>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor.examples/pom.xml b/org.eclipse.ui.genericeditor.examples/pom.xml
index 788a2a2f1..4097fb89f 100644
--- a/org.eclipse.ui.genericeditor.examples/pom.xml
+++ b/org.eclipse.ui.genericeditor.examples/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.genericeditor.examples</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagAutoEditStrategy.java b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagAutoEditStrategy.java
new file mode 100644
index 000000000..c997bae69
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.examples/src/org/eclipse/ui/genericeditor/examples/dotproject/TagAutoEditStrategy.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Rogue Wave Software 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:
+ * Michał Niewrzał (Rogue Wave Software Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.examples.dotproject;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public class TagAutoEditStrategy implements IAutoEditStrategy {
+
+ @Override
+ public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
+ if (!">".equals(command.text)) { //$NON-NLS-1$
+ return;
+ }
+ try {
+ IRegion region = document.getLineInformationOfOffset(command.offset);
+ String line = document.get(region.getOffset(), command.offset - region.getOffset());
+ int index = line.lastIndexOf('<');
+ if (index != -1 && (index != line.length() - 1) && line.charAt(index + 1) != '/') {
+ String tag = line.substring(index + 1);
+ command.text += "</" + tag + command.text; //$NON-NLS-1$
+ }
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
index eda150653..813cb18ad 100644
--- a/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.genericeditor.tests;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.ui.genericeditor.tests,
diff --git a/org.eclipse.ui.genericeditor.tests/plugin.xml b/org.eclipse.ui.genericeditor.tests/plugin.xml
index e9a65d19e..4f199ed08 100644
--- a/org.eclipse.ui.genericeditor.tests/plugin.xml
+++ b/org.eclipse.ui.genericeditor.tests/plugin.xml
@@ -53,5 +53,20 @@
priority="normal">
</content-type>
</extension>
+ <extension
+ point="org.eclipse.ui.genericeditor.autoEditStrategies">
+ <autoEditStrategy
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheAutoEditStrategyFirst"
+ contentType="org.eclipse.core.runtime.text">
+ </autoEditStrategy>
+ <autoEditStrategy
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheAutoEditStrategySecond"
+ contentType="org.eclipse.core.runtime.text">
+ </autoEditStrategy>
+ <autoEditStrategy
+ class="org.eclipse.ui.genericeditor.tests.contributions.TheAutoEditStrategyThird"
+ contentType="org.eclipse.core.runtime.text">
+ </autoEditStrategy>
+ </extension>
</plugin>
diff --git a/org.eclipse.ui.genericeditor.tests/pom.xml b/org.eclipse.ui.genericeditor.tests/pom.xml
index e16cc5a1f..8dce90bc2 100644
--- a/org.eclipse.ui.genericeditor.tests/pom.xml
+++ b/org.eclipse.ui.genericeditor.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.genericeditor.tests</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java
new file mode 100644
index 000000000..8a30f57a7
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/AutoEditTest.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Rogue Wave Software 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:
+ * Michał Niewrzał (Rogue Wave Software Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.jface.text.IDocument;
+
+public class AutoEditTest extends AbstratGenericEditorTest {
+
+ @Test
+ public void testAutoEdit() throws Exception {
+ IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ StyledText control= (StyledText) editor.getAdapter(Control.class);
+ control.setText("");
+ Assert.assertEquals("AutoAddedFirst! AutoAddedSecond! AutoAddedThird!", document.get());
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java
index e349652f2..96361db40 100644
--- a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/GenericEditorTestSuite.java
@@ -19,7 +19,8 @@ import org.junit.runners.Suite.SuiteClasses;
CompletionTest.class,
StylingTest.class,
HoverTest.class,
- EditorTest.class
+ EditorTest.class,
+ AutoEditTest.class
})
public class GenericEditorTestSuite {
// see @SuiteClasses
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyFirst.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyFirst.java
new file mode 100644
index 000000000..8a36c3963
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyFirst.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Rogue Wave Software 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:
+ * Michał Niewrzał (Rogue Wave Software Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+
+public class TheAutoEditStrategyFirst implements IAutoEditStrategy {
+
+ @Override
+ public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
+ command.text = command.text + "AutoAddedFirst!";
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategySecond.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategySecond.java
new file mode 100644
index 000000000..37e2587d8
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategySecond.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Rogue Wave Software 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:
+ * Michał Niewrzał (Rogue Wave Software Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+
+public class TheAutoEditStrategySecond implements IAutoEditStrategy {
+
+ @Override
+ public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
+ command.text = command.text + " AutoAddedSecond!";
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyThird.java b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyThird.java
new file mode 100644
index 000000000..c7882aaf4
--- /dev/null
+++ b/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/TheAutoEditStrategyThird.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Rogue Wave Software 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:
+ * Michał Niewrzał (Rogue Wave Software Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.genericeditor.tests.contributions;
+
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+
+public class TheAutoEditStrategyThird implements IAutoEditStrategy {
+
+ @Override
+ public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
+ command.text = command.text + " AutoAddedThird!";
+ }
+
+}
diff --git a/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF b/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF
index 083e27187..4dc991ae2 100644
--- a/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.genericeditor/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Generic and Extensible Text Editor
Bundle-SymbolicName: org.eclipse.ui.genericeditor;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.ui.workbench.texteditor;bundle-version="3.10.0",
diff --git a/org.eclipse.ui.genericeditor/plugin.properties b/org.eclipse.ui.genericeditor/plugin.properties
index e7204f733..1405cc2e3 100644
--- a/org.eclipse.ui.genericeditor/plugin.properties
+++ b/org.eclipse.ui.genericeditor/plugin.properties
@@ -12,6 +12,7 @@ genericEditor_name=Generic Text Editor
ExtPoint.presentationReconciliers=Presentation Reconciliers
ExtPoint.hoverProviders= Hover Providers
ExtPoint.contentAssistProcessors=Content Assist Providers
+ExtPoint.autoEditStrategies=Auto Edit Strategies
openDeclarationCommand_name=Open Declaration
context_name=in Generic Code Editor
context_description=When editing in the Generic Code Editor
diff --git a/org.eclipse.ui.genericeditor/plugin.xml b/org.eclipse.ui.genericeditor/plugin.xml
index 06b6de70d..c58bfc082 100644
--- a/org.eclipse.ui.genericeditor/plugin.xml
+++ b/org.eclipse.ui.genericeditor/plugin.xml
@@ -14,6 +14,7 @@
<extension-point id="presentationReconcilers" name="%ExtPoint.presentationReconciliers" schema="schema/presentationReconcilers.exsd"/>
<extension-point id="contentAssistProcessors" name="%ExtPoint.contentAssistProcessors" schema="schema/contentAssistProcessors.exsd"/>
<extension-point id="hoverProviders" name="%ExtPoint.hoverProviders" schema="schema/hoverProviders.exsd"/>
+ <extension-point id="autoEditStrategies" name="%ExtPoint.autoEditStrategies" schema="schema/autoEditStrategies.exsd"/>
<extension
point="org.eclipse.ui.editors">
<editor
diff --git a/org.eclipse.ui.genericeditor/pom.xml b/org.eclipse.ui.genericeditor/pom.xml
index 312f3d798..321c4f2ea 100644
--- a/org.eclipse.ui.genericeditor/pom.xml
+++ b/org.eclipse.ui.genericeditor/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.genericeditor</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.ui.genericeditor/schema/autoEditStrategies.exsd b/org.eclipse.ui.genericeditor/schema/autoEditStrategies.exsd
new file mode 100644
index 000000000..6e9cc9404
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/schema/autoEditStrategies.exsd
@@ -0,0 +1,116 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.ui.genericeditor" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.ui.genericeditor" id="autoEditStrategies" name="Auto edit strategies"/>
+ </appinfo>
+ <documentation>
+ This extension point is used to contribute auto edit strategies for a given content type.
+ </documentation>
+ </annotation>
+
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="autoEditStrategy"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+ a fully qualified identifier of the target extension point
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ an optional identifier of the extension instance
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ an optional name of the extension instance
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="autoEditStrategy">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.IAutoEditStrategy&lt;/code&gt;
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.jface.text.IAutoEditStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="contentType" type="string" use="required">
+ <annotation>
+ <documentation>
+ The target content-type for this extension. Content-types are defined as extension to the org.eclipse.core.contenttype.contentTypes extension point.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 1.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ This is an example of a strategy being registered for a target definition file type:
+
+&lt;pre&gt;
+&lt;extension point=&quot;org.eclipse.ui.genericeditor.autoEditStrategies&quot;&gt;
+ &lt;autoEditStrategy
+ class=&quot;org.eclipse.ui.genericeditor.examples.TargedDefinitionAutoEditStrategy&quot;
+ contentType=&quot;org.eclipse.pde.targetFile&quot;&gt;
+ &lt;/autoEditStrategy&gt;
+&lt;/extension&gt;
+&lt;/pre&gt;
+ </documentation>
+ </annotation>
+
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2017 Rogue Wave Software 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 &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AutoEditStrategyRegistry.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AutoEditStrategyRegistry.java
new file mode 100644
index 000000000..40769998a
--- /dev/null
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/AutoEditStrategyRegistry.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Rogue Wave Software 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:
+ * Michał Niewrzał (Rogue Wave Software Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal.genericeditor;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * A registry of auto edit strategies provided by extension
+ * <code>org.eclipse.ui.genericeditor.autoEditStrategy</code>. Those extensions
+ * are specific to a given {@link IContentType}.
+ *
+ * @since 1.1
+ */
+public class AutoEditStrategyRegistry {
+
+ private static final String EXTENSION_POINT_ID = GenericEditorPlugin.BUNDLE_ID + ".autoEditStrategies"; //$NON-NLS-1$
+
+ private Map<IConfigurationElement, AutoEditStrategyExtension> extensions = new LinkedHashMap<>();
+ private boolean outOfSync = true;
+
+ static class AutoEditStrategyExtension {
+ private static final String CONTENT_TYPE_ATTRIBUTE = "contentType"; //$NON-NLS-1$
+ private static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$
+
+ private IConfigurationElement extension;
+ private IContentType targetContentType;
+ private IAutoEditStrategy strategy;
+
+ public AutoEditStrategyExtension(IConfigurationElement extension) throws Exception {
+ this.extension = extension;
+ this.targetContentType = Platform.getContentTypeManager()
+ .getContentType(extension.getAttribute(CONTENT_TYPE_ATTRIBUTE));
+ }
+
+ public IAutoEditStrategy getStrategy() {
+ if (this.strategy == null) {
+ try {
+ this.strategy = (IAutoEditStrategy) extension.createExecutableExtension(CLASS_ATTRIBUTE);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ return strategy;
+ }
+
+ IConfigurationElement getConfigurationElement() {
+ return this.extension;
+ }
+ }
+
+ /**
+ * Creates the registry and binds it to the extension point.
+ */
+ public AutoEditStrategyRegistry() {
+ Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() {
+ @Override
+ public void registryChanged(IRegistryChangeEvent event) {
+ outOfSync = true;
+ }
+ }, EXTENSION_POINT_ID);
+ }
+
+ /**
+ * Get the contributed {@link IAutoEditStrategy}s that are relevant to hook
+ * on source viewer according to document content types.
+ *
+ * @param sourceViewer
+ * the source viewer we're hooking completion to.
+ * @param contentTypes
+ * the content types of the document we're editing.
+ * @return the list of {@link IAutoEditStrategy} contributed for at least
+ * one of the content types.
+ */
+ public List<IAutoEditStrategy> getAutoEditStrategies(ISourceViewer sourceViewer, Set<IContentType> contentTypes) {
+ if (this.outOfSync) {
+ sync();
+ }
+ List<IAutoEditStrategy> res = new ArrayList<>();
+ for (AutoEditStrategyExtension ext : this.extensions.values()) {
+ if (contentTypes.contains(ext.targetContentType)) {
+ res.add(ext.getStrategy());
+ }
+ }
+ return res;
+ }
+
+ private void sync() {
+ Set<IConfigurationElement> toRemoveExtensions = new HashSet<>(this.extensions.keySet());
+ for (IConfigurationElement extension : Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(EXTENSION_POINT_ID)) {
+ toRemoveExtensions.remove(extension);
+ if (!this.extensions.containsKey(extension)) {
+ try {
+ this.extensions.put(extension, new AutoEditStrategyExtension(extension));
+ } catch (Exception ex) {
+ GenericEditorPlugin.getDefault().getLog()
+ .log(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, ex.getMessage(), ex));
+ }
+ }
+ }
+ for (IConfigurationElement toRemove : toRemoveExtensions) {
+ this.extensions.remove(toRemove);
+ }
+ this.outOfSync = false;
+ }
+}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
index 0992d1460..d6a0facb4 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/ExtensionBasedTextViewerConfiguration.java
@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.AbstractReusableInformationControlCreator;
import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioningListener;
import org.eclipse.jface.text.IInformationControl;
@@ -188,4 +189,15 @@ public final class ExtensionBasedTextViewerConfiguration extends TextSourceViewe
public IReconciler getReconciler(ISourceViewer sourceViewer) {
return null; // to disable spell-checker
}
+
+ @Override
+ public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
+ AutoEditStrategyRegistry registry = GenericEditorPlugin.getDefault().getAutoEditStrategyRegistry();
+ List<IAutoEditStrategy> editStrategies = registry.getAutoEditStrategies(sourceViewer, getContentTypes());
+ if (!editStrategies.isEmpty()) {
+ return editStrategies.toArray(new IAutoEditStrategy[editStrategies.size()]);
+ }
+ return super.getAutoEditStrategies(sourceViewer, contentType);
+ }
+
}
diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java
index e5f33d470..ef8a0145c 100644
--- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java
+++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/GenericEditorPlugin.java
@@ -30,6 +30,7 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
private TextHoverRegistry textHoversRegistry;
private ContentAssistProcessorRegistry contentAssistProcessorsRegistry;
private PresentationReconcilerRegistry presentationReconcilierRegistry;
+ private AutoEditStrategyRegistry autoEditStrategyRegistry;
@Override
public void start(BundleContext context) throws Exception{
@@ -79,4 +80,15 @@ public class GenericEditorPlugin extends AbstractUIPlugin {
}
return this.presentationReconcilierRegistry;
}
+
+ /**
+ * @return the registry allowing to access contributed {@link IAutoEditStrategy}s.
+ * @since 1.1
+ */
+ public synchronized AutoEditStrategyRegistry getAutoEditStrategyRegistry() {
+ if (this.autoEditStrategyRegistry == null) {
+ this.autoEditStrategyRegistry = new AutoEditStrategyRegistry();
+ }
+ return this.autoEditStrategyRegistry;
+ }
}

Back to the top