[jbosstools-commits] JBoss Tools SVN: r17796 - in trunk/common/plugins/org.jboss.tools.common.model.ui: schema and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Sep 29 11:11:15 EDT 2009


Author: scabanovich
Date: 2009-09-29 11:11:15 -0400 (Tue, 29 Sep 2009)
New Revision: 17796

Added:
   trunk/common/plugins/org.jboss.tools.common.model.ui/schema/propertiesFileContentAssist.exsd
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/AbstractPropertiesContentAssistProcessor.java
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesSourceViewerConfiguration.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
   trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesTextEditorStub.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4916

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml	2009-09-29 14:50:14 UTC (rev 17795)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml	2009-09-29 15:11:15 UTC (rev 17796)
@@ -10,6 +10,7 @@
    <extension-point id="InsertTagWizard" name="%ExtensionName_InsertTagWizard" schema="schema/InsertTagWizard.exsd"/>
    <extension-point id="labelDecorator" name="%ExtensionName_labelDecorator" schema="schema/labelDecorator.exsd"/>
    <extension-point id="attributeContentProposalProviders" name="%ExtensionName_attributeContentProposalProviders" schema="schema/attributeContentProposalProviders.exsd"/>
+   <extension-point id="propertiesFileContentAssist" name="Properties File Content Assist" schema="schema/propertiesFileContentAssist.exsd"/>
 
    <extension point="org.eclipse.ui.elementFactories">
       <factory class="org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory" id="org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory">

Added: trunk/common/plugins/org.jboss.tools.common.model.ui/schema/propertiesFileContentAssist.exsd
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/schema/propertiesFileContentAssist.exsd	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/schema/propertiesFileContentAssist.exsd	2009-09-29 15:11:15 UTC (rev 17796)
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.common.model.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appInfo>
+         <meta.schema plugin="org.jboss.tools.common.model.ui" id="propertiesFileContentAssist" name="Properties File Content Assist"/>
+      </appInfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appInfo>
+            <meta.element />
+         </appInfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="propertiesFileContentAssist" minOccurs="1" maxOccurs="unbounded"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute translatable="true"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="propertiesFileContentAssist">
+      <complexType>
+         <attribute name="processor" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute kind="java"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+         <attribute name="fileName" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="since"/>
+      </appInfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="examples"/>
+      </appInfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="apiinfo"/>
+      </appInfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="implementation"/>
+      </appInfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>


Property changes on: trunk/common/plugins/org.jboss.tools.common.model.ui/schema/propertiesFileContentAssist.exsd
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/AbstractPropertiesContentAssistProcessor.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/AbstractPropertiesContentAssistProcessor.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/AbstractPropertiesContentAssistProcessor.java	2009-09-29 15:11:15 UTC (rev 17796)
@@ -0,0 +1,162 @@
+package org.jboss.tools.common.model.ui.texteditors.propertyeditor;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jface.text.ITextViewer;
+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;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelObjectConstants;
+import org.jboss.tools.common.model.loaders.impl.PropertiesLoader;
+
+public class AbstractPropertiesContentAssistProcessor implements IContentAssistProcessor {
+	protected XModelObject object;
+	
+	public AbstractPropertiesContentAssistProcessor() {}
+
+	public void setModelObject(XModelObject object) {
+		this.object = object;
+	}
+
+	public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
+			int offset) {
+		return null;
+	}
+
+	public IContextInformation[] computeContextInformation(ITextViewer viewer,
+			int offset) {
+		return null;
+	}
+
+	public char[] getCompletionProposalAutoActivationCharacters() {
+		return null;
+	}
+
+	public char[] getContextInformationAutoActivationCharacters() {
+		return null;
+	}
+
+	public IContextInformationValidator getContextInformationValidator() {
+		return null;
+	}
+
+	public String getErrorMessage() {
+		return null;
+	}
+
+	protected class Context {
+		boolean inComment = false;
+		int offset;
+		int nameOffset;
+		int nameLength;
+		boolean inPropertyName = false;
+		String propertyName;
+
+		int valueOffset;
+		int valueLength;
+		String propertyValue;
+		Set<String> allProperties = new HashSet<String>();
+	
+		public boolean isInComment() {
+			return inComment;
+		}
+
+		public boolean isInPropertyName() {
+			return inPropertyName;
+		}
+
+		public int getNameOffset() {
+			return nameOffset;
+		}
+
+		public int getNameLength() {
+			return nameLength;
+		}
+
+		public int getValueOffset() {
+			return valueOffset;
+		}
+
+		public int getValueLength() {
+			return valueLength;
+		}
+
+		public String getPropertyName() {
+			return propertyName;
+		}
+
+		public boolean hasProperty(String property) {
+			return allProperties.contains(property) && !property.equals(propertyName);
+		}
+
+		public boolean isInValue() {
+			return !isInPropertyName() && offset >= valueOffset;
+		}
+	}
+
+	public Context getContext(ITextViewer viewer, int offset) {
+		Context context = new Context();
+		context.offset = offset;
+		XModelObject[] ps = object.getChildren();
+		for (int i = 0; i < ps.length; i++) {
+			String name = ps[i].getAttributeValue(XModelObjectConstants.ATTR_NAME);
+			context.allProperties.add(name);
+		}
+		int lineOffset = getNameOffset(viewer, offset);
+		context.nameOffset = lineOffset;
+		int valueEnd = getValueEnd(viewer, offset);
+		String line = viewer.getDocument().get().substring(context.nameOffset, valueEnd);
+		if(line.trim().startsWith("#")) {
+			context.inComment = true;
+			return context;
+		}
+		int si = PropertiesLoader.getSeparatorIndex(line);
+		if(si < 0) si = line.length();
+		if(si == line.length()) {
+			context.inPropertyName = true;
+		}
+		String name = line.substring(0, si).trim();
+		context.propertyName = name;
+		context.nameLength = name.length();
+		if(name.length() > 0) {
+			int b = line.indexOf(name);
+			if(b >= 0) {
+				context.nameOffset += b;
+			}
+		}
+		if(offset >= context.nameOffset && offset <= context.nameOffset + context.nameLength) {
+			context.inPropertyName = true;
+		}
+		String value = (si >= line.length()) ? "" : line.substring(si + 1, line.length());
+		context.valueLength = value.length();
+		context.propertyValue = value;
+		if(si < line.length()) {
+			context.valueOffset = lineOffset + si + 1;
+			int b = line.indexOf(value, si + 1);
+			if(b > 0) {
+				context.valueOffset = lineOffset + b;
+			}
+		}
+		return context;
+	}
+
+	int getNameOffset(ITextViewer viewer, int offset) {
+		String body = viewer.getDocument().get();
+		for (int i = offset - 1; i >= 0; i--) {
+			char c = body.charAt(i);
+			if(c == '\n' || c == '\r') return i + 1;
+		}
+		return 0;
+	}
+	int getValueEnd(ITextViewer viewer, int offset) {
+		String body = viewer.getDocument().get();
+		for (int i = offset; i < body.length(); i++) {
+			char c = body.charAt(i);
+			if(c == '\n' || c == '\r') return i;
+		}
+		return body.length();
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/AbstractPropertiesContentAssistProcessor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesSourceViewerConfiguration.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesSourceViewerConfiguration.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesSourceViewerConfiguration.java	2009-09-29 15:11:15 UTC (rev 17796)
@@ -0,0 +1,82 @@
+package org.jboss.tools.common.model.ui.texteditors.propertyeditor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions;
+import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileSourceViewerConfiguration;
+import org.eclipse.jdt.ui.text.IColorManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.editor.IModelObjectEditorInput;
+
+public class PropertiesSourceViewerConfiguration extends PropertiesFileSourceViewerConfiguration {
+
+	ContentAssistant fContentAssistant;
+
+	public PropertiesSourceViewerConfiguration(IColorManager colorManager,
+			IPreferenceStore preferenceStore, ITextEditor editor,
+			String partitioning) {
+		super(colorManager, preferenceStore, editor, partitioning);
+
+	}
+
+	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+		if(fContentAssistant == null) {
+			fContentAssistant = new ContentAssistant();
+			IEditorInput input = getEditor().getEditorInput();
+			if(input instanceof IFileEditorInput && input instanceof IModelObjectEditorInput) {
+				IFile f = ((IFileEditorInput)input).getFile();
+				String name = f.getName();
+				AbstractPropertiesContentAssistProcessor p = createProcessorByFileName(name);
+				if(p != null) {
+					XModelObject o = ((IModelObjectEditorInput)input).getXModelObject();
+					p.setModelObject(o);
+					fContentAssistant.setContentAssistProcessor(p, "__dftl_partition_content_type");
+				}
+				fContentAssistant.setInformationControlCreator(new IInformationControlCreator() {
+					public IInformationControl createInformationControl(Shell parent) {
+						return new DefaultInformationControl(parent, JavaPlugin.getAdditionalInfoAffordanceString());
+					}
+				});
+			}
+		}
+		return fContentAssistant;
+	}
+
+	static String EXTENSION_POINT = "org.jboss.tools.common.model.ui.propertiesFileContentAssist";
+	
+	private AbstractPropertiesContentAssistProcessor createProcessorByFileName(String fileName) {
+		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT);
+		if(point == null) return null;
+		IConfigurationElement[] cs = point.getConfigurationElements();
+		for (IConfigurationElement c: cs) {
+			if(fileName.equals(c.getAttribute("fileName"))) {
+				try {
+					AbstractPropertiesContentAssistProcessor p = (AbstractPropertiesContentAssistProcessor)c.createExecutableExtension("processor");
+					return p;
+				} catch (CoreException e) {
+					ModelUIPlugin.getPluginLog().logError(e);
+				} catch (ClassCastException e2) {
+					ModelUIPlugin.getPluginLog().logError(e2);
+				}
+			}			
+		}
+
+		return null;
+	}
+}


Property changes on: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesSourceViewerConfiguration.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesTextEditorStub.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesTextEditorStub.java	2009-09-29 14:50:14 UTC (rev 17795)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/texteditors/propertyeditor/PropertiesTextEditorStub.java	2009-09-29 15:11:15 UTC (rev 17796)
@@ -18,7 +18,12 @@
 import org.eclipse.core.resources.IResource;
 import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDrop;
 import org.jboss.tools.common.model.ui.texteditors.dnd.TextEditorDropProvider;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions;
 import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditor;
+import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileSourceViewerConfiguration;
+import org.eclipse.jdt.ui.text.JavaTextTools;
+import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.DocumentEvent;
 import org.eclipse.jface.text.IDocumentListener;
 import org.eclipse.jface.text.source.ISourceViewer;
@@ -92,4 +97,11 @@
 		}
 		
 	}
+
+	protected void initializeEditor() {
+		super.initializeEditor();
+		IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
+		JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
+		setSourceViewerConfiguration(new PropertiesSourceViewerConfiguration(textTools.getColorManager(), store, this, IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING));
+	}
 }



More information about the jbosstools-commits mailing list