Author: vrubezhny
Date: 2007-07-04 08:21:41 -0400 (Wed, 04 Jul 2007)
New Revision: 2278
Added:
trunk/common/plugins/org.jboss.tools.common.text.ext/schema/contentAssistProcessor.exsd
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/contentassist/
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/contentassist/ContentAssistProcessorBuilder.java
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml
Log:
http://jira.jboss.org/jira/browse/EXIN-330
The schema added due to allow the xml-editor configuration to load and use custom content
assist processors dependig on the partition type.
Modified: trunk/common/plugins/org.jboss.tools.common.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.ext/META-INF/MANIFEST.MF 2007-07-04
10:12:06 UTC (rev 2277)
+++ trunk/common/plugins/org.jboss.tools.common.text.ext/META-INF/MANIFEST.MF 2007-07-04
12:21:41 UTC (rev 2278)
@@ -2,6 +2,7 @@
Eclipse-LazyStart: true
Bundle-Activator: org.jboss.tools.common.text.ext.ExtensionsPlugin
Export-Package: org.jboss.tools.common.text.ext,
+ org.jboss.tools.common.text.ext.contentassist,
org.jboss.tools.common.text.ext.hyperlink,
org.jboss.tools.common.text.ext.hyperlink.jsp,
org.jboss.tools.common.text.ext.hyperlink.xml,
Modified: trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml 2007-07-04 10:12:06
UTC (rev 2277)
+++ trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml 2007-07-04 12:21:41
UTC (rev 2278)
@@ -4,6 +4,7 @@
<extension-point id="hyperlink" name="Hyperlink Extension Point
Extension" schema="schema/hyperlink.exsd"/>
<extension-point id="hyperlinkPartitioner" name="Hyperlink
Partitioner Extension Point Extension"
schema="schema/hyperlinkPartitioner.exsd"/>
+ <extension-point id="contentAssistProcessor" name="Content Assist
Processor Extension Point Extension"
schema="schema/contentAssistProcessor.exsd"/>
<extension
point="org.jboss.tools.common.text.ext.hyperlinkPartitioner"
Added:
trunk/common/plugins/org.jboss.tools.common.text.ext/schema/contentAssistProcessor.exsd
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/schema/contentAssistProcessor.exsd
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/schema/contentAssistProcessor.exsd 2007-07-04
12:21:41 UTC (rev 2278)
@@ -0,0 +1,153 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.common.text.ext">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.jboss.tools.common.text.ext"
id="contentAssistProcessor" name="Content Assist Processor Extension Point
Extension"/>
+ </appInfo>
+ <documentation>
+ Content Assist Processor
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <documentation>
+ Defines an extension point for the Content Assist Processor definitions.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="contentAssistProcessor" minOccurs="1"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string"
use="required">
+ <annotation>
+ <documentation>
+ A unique ID for this extension point. It is recommended that the plugin
ID be used to prefix any extensions.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ A unique ID for this extension. It is recommended that the plugin ID
be used to prefix any extensions.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ A brief name to show to the user.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="contentAssistProcessor">
+ <annotation>
+ <documentation>
+ Defines a Content Assist Processor item. Contains information on a class to
be used to perform content assist depending on the content and partition types.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="partitiontype" minOccurs="1"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="id" type="string"
use="required">
+ <annotation>
+ <documentation>
+ A unique ID for this Content Assist Processor.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string"
use="required">
+ <annotation>
+ <documentation>
+ An implementor of
org.eclipse.jface.text.contentassist.IContentAssistProcessor, it controls the content
assist within text editor.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="partitiontype">
+ <annotation>
+ <documentation>
+ Defined the editor's partition type to be assotiated with the
Content Assist Processor. The value is either one of the WTP structured model partition
type ID or any other structured text partition ID
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="id" type="string"
use="required">
+ <annotation>
+ <documentation>
+ A unique ID for this partitiontype. The value is either one of the WTP
structured model partition type ID or any other structured text partition ID.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ V3.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ <pre>
+ <extension-point id="contentAssistProcessor"
name="Content Assist Processor Extension Point Extension"/>
+
+ <extension
+ point="org.jboss.tools.common.text.ext.contentAssistProcesor"
+ id="org.jboss.tools.common.text.ext.contentAssistProcessor"
+
name="org.jboss.tools.common.text.ext.contentAssistProcessor">
+
+ <contentAssistProcessor
+
class="org.jboss.tools.common.text.xml.contentassist.MyContentAssistProcessor"
+
id="org.jboss.tools.common.text.xml.contentassist.MyContentAssistProcessorID">
+ <partitiontype
id="org.jboss.tools.common.text.xml.XML_DOCTYPE" />
+ </contentAssistProcessor>
+ </extension>
+</pre>
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ The baseline for API and extension point stability is RedHat Developer Studio
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ The supplied implementation of the contentAssistProcessor functionality requires
the WTP components.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ RedHat
+ </documentation>
+ </annotation>
+
+</schema>
Added:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/contentassist/ContentAssistProcessorBuilder.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/contentassist/ContentAssistProcessorBuilder.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/contentassist/ContentAssistProcessorBuilder.java 2007-07-04
12:21:41 UTC (rev 2278)
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.text.ext.contentassist;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.text.ext.ExtensionsPlugin;
+import org.jboss.tools.common.text.ext.util.xpl.RegistryReader;
+
+public class ContentAssistProcessorBuilder extends RegistryReader{
+ // extension point ID
+ public static final String PL_CONTENTASSISTPROCESSOR =
"contentAssistProcessor"; //$NON-NLS-1$
+
+ public static final String TAG_CONTENTASSISTPROCESSOR =
"contentAssistProcessor"; //$NON-NLS-1$
+ public static final String TAG_PARTITION_TYPE = "partitiontype";
//$NON-NLS-1$
+
+ public static final String ATT_ID = "id"; //$NON-NLS-1$
+ public static final String ATT_CLASS = "class"; //$NON-NLS-1$
+
+ protected String targetContributionTag;
+
+ private static ContentAssistProcessorBuilder fInstance;
+
+ private List<ContentAssistProcessorDefinition> fContentAssistProcessorDefs =
null;
+ private ContentAssistProcessorDefinition fCurrentDefinition = null;
+
+ /**
+ * returns singleton instance of ContentAssistProcessorBuilder
+ *
+ * @return ContentAssistProcessorBuilder
+ */
+ public synchronized static ContentAssistProcessorBuilder getInstance() {
+ if (fInstance == null) {
+ fInstance = new ContentAssistProcessorBuilder();
+ }
+ return fInstance;
+ }
+
+ /**
+ * Returns the name of the part ID attribute that is expected
+ * in the target extension.
+ *
+ * @param element
+ * @return String
+ */
+ protected String getId(IConfigurationElement element) {
+ String value = element.getAttribute(ATT_ID);
+ return value;
+ }
+
+ protected String getContentAssistProcessorClass(IConfigurationElement element) {
+ String value = element.getAttribute(ATT_CLASS);
+ return value;
+ }
+
+ /**
+ * Processes element which should be a configuration element specifying an
+ * open on object. Creates a new ContentAssistProcessor definitio object and adds it to
the
+ * list of ContentAssistProcessor definition objects
+ *
+ * @param element ContentAssistProcessor configuration element
+ */
+ private void processContentAssistProcessorTag(IConfigurationElement element) {
+ String theId = getId(element);
+ String theClass = getContentAssistProcessorClass(element);
+
+ if (theId != null && theClass != null) {
+ // start building new HyperlinkDefinition
+ fCurrentDefinition = new ContentAssistProcessorDefinition(theId, theClass, element);
+
+ // create a new list of open on definitions if it hasn't been created yet
+ if (fContentAssistProcessorDefs == null) {
+ fContentAssistProcessorDefs = new
ArrayList<ContentAssistProcessorDefinition>();
+ }
+ fContentAssistProcessorDefs.add(fCurrentDefinition);
+ }
+ else {
+ fCurrentDefinition = null;
+ }
+ }
+
+ /**
+ * Processes element which should be a configuration element specifying a partition
+ * type for the current contentAssistProcessor tag. Assumes that there is a valid
+ * current contentAssistProcessor tag.
+ *
+ * @param element partitiontype configuration element
+ */
+ private void processPartitionTypeTag(IConfigurationElement element) {
+ // add to current HyperlinkDefinition/contentType
+ String theId = getId(element);
+
+ if (theId != null) {
+ fCurrentDefinition.addPartitionType(theId);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
com.ibm.sse.editor.internal.extension.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ protected boolean readElement(IConfigurationElement element) {
+ String tag = element.getName();
+
+ if (tag.equals(targetContributionTag)) {
+ processContentAssistProcessorTag(element);
+
+ if (fCurrentDefinition != null) {
+ readElementChildren(element);
+ }
+ return true;
+ }
+ else if (tag.equals(TAG_PARTITION_TYPE)) {
+ processPartitionTypeTag(element);
+ return true;
+ }
+
+ return false;
+ }
+
+ private void initCache() {
+ if (fContentAssistProcessorDefs == null) {
+ readContributions(TAG_CONTENTASSISTPROCESSOR, PL_CONTENTASSISTPROCESSOR);
+ }
+ }
+
+ /**
+ * Returns all the ContentAssistProcessor definition objects
+ * @return
+ */
+ public ContentAssistProcessorDefinition[] getContentAssistProcessorDefinitions() {
+ initCache();
+ return (fContentAssistProcessorDefs == null ? new ContentAssistProcessorDefinition[0] :
+ (ContentAssistProcessorDefinition[])fContentAssistProcessorDefs.toArray(new
ContentAssistProcessorDefinition[fContentAssistProcessorDefs.size()]));
+ }
+
+ /**
+ * Returns all the ContentAssistProcessor definition objects valid for partitionType
+ *
+ * @param partitionType
+ * @return if partitionType is null, null is returned
+ */
+ public ContentAssistProcessorDefinition[] getContentAssistProcessorDefinitions(String
partitionType) {
+ if (partitionType == null) {
+ return null;
+ }
+
+ ContentAssistProcessorDefinition[] allDefs = getContentAssistProcessorDefinitions();
+ List defs = new ArrayList();
+ List lastDefs = new ArrayList();
+
+ for (int i = 0; i < allDefs.length; ++i) {
+ List partitions = (List) allDefs[i].getPartitionTypes();
+ if (partitions != null) {
+ if (partitions.isEmpty()) {
+ lastDefs.add(allDefs[i]);
+ }
+ else {
+ int j = 0;
+ boolean added = false;
+ while (j < partitions.size() && !added) {
+ if (partitionType.equals(partitions.get(j))) {
+ defs.add(allDefs[i]);
+ added = true;
+ }
+ else {
+ ++j;
+ }
+ }
+ }
+ }
+ }
+ defs.addAll(lastDefs);
+
+ return (ContentAssistProcessorDefinition[]) defs.toArray(new
ContentAssistProcessorDefinition[defs.size()]);
+ }
+
+ /**
+ * @param tag
+ * @param extensionPoint
+ */
+ protected void readContributions(String tag, String extensionPoint) {
+ targetContributionTag = tag;
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ readRegistry(registry, ExtensionsPlugin.PLUGIN_ID, extensionPoint);
+ }
+
+}