Author: scabanovich
Date: 2009-10-01 11:14:35 -0400 (Thu, 01 Oct 2009)
New Revision: 17845
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/plugin.xml
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentAssistProcessor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentProposalProvider.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4916
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/plugin.xml 2009-10-01
15:11:15 UTC (rev 17844)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/plugin.xml 2009-10-01
15:14:35 UTC (rev 17845)
@@ -68,6 +68,7 @@
processor="org.jboss.tools.hibernate.ui.xml.editor.HibernatePropertiesContentAssistProcessor"
attributeProcessor="org.jboss.tools.hibernate.ui.xml.editor.HibernatePropertiesContentProposalProvider"
fileName="hibernate.properties"
+ entity="HibConfig3Property"
/>
</extension>
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentAssistProcessor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentAssistProcessor.java 2009-10-01
15:11:15 UTC (rev 17844)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentAssistProcessor.java 2009-10-01
15:14:35 UTC (rev 17845)
@@ -31,6 +31,7 @@
import org.jboss.tools.common.meta.constraint.XAttributeConstraint;
import org.jboss.tools.common.meta.constraint.impl.XAttributeConstraintAList;
import org.jboss.tools.common.meta.key.WizardKeys;
+import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.ui.attribute.adapter.JavaClassContentAssistProvider;
import
org.jboss.tools.common.model.ui.texteditors.propertyeditor.AbstractPropertiesContentAssistProcessor;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -54,7 +55,7 @@
List<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
- Map<String, XAttribute> attributes = getAttributes();
+ Map<String, XAttribute> attributes = getAttributes(object);
if(context.isInComment()) {
return new ICompletionProposal[0];
@@ -146,7 +147,7 @@
static Map<String, XAttribute> attributes = null;
- public Map<String, XAttribute> getAttributes() {
+ public static Map<String, XAttribute> getAttributes(XModelObject object) {
if(attributes == null) {
attributes = new TreeMap<String, XAttribute>();
XModelEntity entity =
object.getModel().getMetaData().getEntity("HibConfig3PropertiesFolder");
//$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentProposalProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentProposalProvider.java 2009-10-01
15:11:15 UTC (rev 17844)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.xml.ui/src/org/jboss/tools/hibernate/ui/xml/editor/HibernatePropertiesContentProposalProvider.java 2009-10-01
15:14:35 UTC (rev 17845)
@@ -10,8 +10,23 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.xml.editor;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.meta.constraint.XAttributeConstraint;
+import org.jboss.tools.common.meta.constraint.impl.XAttributeConstraintAList;
+import org.jboss.tools.common.model.XModelObjectConstants;
+import org.jboss.tools.common.model.loaders.impl.PropertiesLoader;
+import
org.jboss.tools.common.model.ui.attribute.AttributeContentProposalProviderFactory;
+import org.jboss.tools.common.model.ui.attribute.adapter.JavaClassContentAssistProvider;
import
org.jboss.tools.common.model.ui.attribute.adapter.PropertiesContentProposalProvider;
+import org.jboss.tools.hibernate.xml.model.impl.HibConfigComplexPropertyImpl;
/**
*
@@ -20,8 +35,77 @@
*/
public class HibernatePropertiesContentProposalProvider extends
PropertiesContentProposalProvider {
+ public HibernatePropertiesContentProposalProvider() {}
+
public IContentProposal[] getProposals(String contents, int position) {
- return null;
+ Map<String, XAttribute> attributes =
HibernatePropertiesContentAssistProcessor.getAttributes(object);
+
+ List<IContentProposal> result = new ArrayList<IContentProposal>();
+
+ if(isNameAttribute()) {
+ String[] ps = attributes.keySet().toArray(new String[0]);
+ Set<String> unique = new HashSet<String>();
+ String prefix = contents.substring(0, position);
+ for (int i = 0; i < ps.length; i++) {
+ if(ps[i].startsWith(prefix)) {
+ int dot = ps[i].indexOf('.', prefix.length());
+ String prop = (dot < 0) ? ps[i] : ps[i].substring(0, dot + 1);
+ if(unique.contains(prop)) continue;
+ unique.add(prop);
+ IContentProposal cp =
AttributeContentProposalProviderFactory.makeContentProposal(prop, prop);
+ result.add(cp);
+ }
+ }
+ } else {
+ String valuePrefix = contents.substring(0, position);
+ String propertyName = getPropertyName();
+ if(attributes.containsKey(propertyName)) {
+ XAttribute attr = attributes.get(propertyName);
+ if(attr == null) {
+ return new IContentProposal[0];
+ }
+ XAttributeConstraint c = attr.getConstraint();
+ if(c instanceof XAttributeConstraintAList) {
+ String[] vs = ((XAttributeConstraintAList)c).getValues();
+ for (int i = 0; i < vs.length; i++) {
+ if(vs[i].length() == 0) continue;
+ if(vs[i].startsWith(valuePrefix)) {
+ IContentProposal cp =
AttributeContentProposalProviderFactory.makeContentProposal(vs[i], vs[i]);
+ result.add(cp);
+ }
+ }
+ } else if("AccessibleJava".equals(attr.getEditor().getName())) {
//$NON-NLS-1$
+ JavaClassContentAssistProvider p = new JavaClassContentAssistProvider();
+ p.init(object, null, attr);
+ IContentProposalProvider pp = p.getContentProposalProvider();
+ IContentProposal[] ps = pp.getProposals(valuePrefix, valuePrefix.length());
+ return ps;
+ } else {
+ //TODO
+ }
+ }
+ }
+
+ return result.toArray(new IContentProposal[0]);
}
+ boolean isNameAttribute() {
+ return attribute.getName().equals(XModelObjectConstants.ATTR_NAME);
+ }
+
+ String getPropertyName() {
+ String value = null;
+ if(data != null) {
+ value = data.getValue(XModelObjectConstants.ATTR_NAME);
+
+ } else if(object != null
+ && (object.getModelEntity().getName().equals(PropertiesLoader.ENT_PROPERTY)
+ ||
object.getModelEntity().getName().equals(HibConfigComplexPropertyImpl.ENT_PROPERTY))) {
+ value = object.getAttributeValue(XModelObjectConstants.ATTR_NAME);
+
+ }
+ return value;
+
+ }
+
}