Author: scabanovich
Date: 2008-11-14 10:13:23 -0500 (Fri, 14 Nov 2008)
New Revision: 11789
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionContentAssistProvider.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/attribute/AttributeContentProposalProviderFactory.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionAdapter.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/StringButtonFieldEditorEx.java
Log:
JBIDE-2575
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-11-14 14:25:13
UTC (rev 11788)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-11-14 15:13:23
UTC (rev 11789)
@@ -494,4 +494,9 @@
pattern="org\.jboss\.tools\.jst\.web\.ui/.*SaveProjectAsTemplateActionDelegate"/>
</extension>
+ <extension
+
point="org.jboss.tools.common.model.ui.attributeContentProposalProviders">
+ <provider
class="org.jboss.tools.common.model.ui.attribute.adapter.DefaultTreeSelectionContentAssistProvider"/>
+ </extension>
+
</plugin>
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/AttributeContentProposalProviderFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/AttributeContentProposalProviderFactory.java 2008-11-14
14:25:13 UTC (rev 11788)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/AttributeContentProposalProviderFactory.java 2008-11-14
15:13:23 UTC (rev 11789)
@@ -129,6 +129,27 @@
return result;
}
+
+ public static IContentProposal makeContentProposal(final String proposal, final String
label) {
+ return new IContentProposal() {
+ public String getContent() {
+ return proposal;
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public int getCursorPosition() {
+ return proposal.length();
+ }
+ };
+ }
+
}
/**
@@ -153,7 +174,7 @@
ArrayList<IContentProposal> ps = new ArrayList<IContentProposal>();
if(position <= contents.length() && position > 3 &&
"test".equals(contents.substring(position - 4, position))) {
- ps.add(makeContentProposal("aaa", ".aaa"));
+ ps.add(AttributeContentProposalProviderFactory.makeContentProposal("aaa",
".aaa"));
}
return ps.toArray(new IContentProposal[0]);
@@ -170,25 +191,4 @@
public void dispose() {
}
- private IContentProposal makeContentProposal(final String proposal, final String label)
{
- return new IContentProposal() {
- public String getContent() {
- return proposal;
- }
-
- public String getDescription() {
- return null;
- }
-
- public String getLabel() {
- return label;
- }
-
- public int getCursorPosition() {
- return proposal.length();
- }
- };
- }
-
-
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionAdapter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionAdapter.java 2008-11-14
14:25:13 UTC (rev 11788)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionAdapter.java 2008-11-14
15:13:23 UTC (rev 11789)
@@ -87,7 +87,9 @@
if (adapter == IActionProvider.class) {
return getActionProvider();
}
+
if(adapter == IContentAssistProcessor.class) {
+ //deprecated, replaced by AttributeContentProposalProviderFactory
DefaultTreeSelectionContentAssistProcessor processor = new
DefaultTreeSelectionContentAssistProcessor();
ITreeContentProvider tree = getTreeContentProvider();
if(tree instanceof DefaultXAttributeTreeContentProvider) {
@@ -97,6 +99,7 @@
return null;
}
}
+
Assert.isTrue(true, "DefaultTreeSelectionAdapter instance itself cannot provide
adapter for "+adapter.getName());
return null;
}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionContentAssistProvider.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionContentAssistProvider.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultTreeSelectionContentAssistProvider.java 2008-11-14
15:13:23 UTC (rev 11789)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.attribute.adapter;
+
+import java.util.*;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.model.*;
+import
org.jboss.tools.common.model.ui.attribute.AttributeContentProposalProviderFactory;
+import org.jboss.tools.common.model.ui.attribute.IAttributeContentProposalProvider;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+
+public class DefaultTreeSelectionContentAssistProvider implements
IAttributeContentProposalProvider {
+ XModelObject object;
+ XAttribute attribute;
+
+ DefaultXAttributeTreeContentProvider treeProvider;
+
+ public DefaultTreeSelectionContentAssistProvider() {}
+
+ public boolean isRelevant(XModelObject object, XAttribute attribute) {
+ if(object == null) {
+ //TODO it looks like we need to pass model, if we do not have object
+ return false;
+ }
+ String editor = attribute.getEditor().getName();
+ return editor != null && editor.startsWith("Tree");
+ }
+
+ void addAttributeValueProposals(List<IContentProposal> proposalsList, String text,
int offset) {
+ if(treeProvider == null) return;
+ XFilteredTree tree = treeProvider.getFilteredTree();
+ if(tree == null) {
+ treeProvider.getElements(null);
+ tree = treeProvider.getFilteredTree();
+ }
+ if(tree == null) return;
+ XModelObject root = tree.getRoot();
+ if(root == null) return;
+ String startText = text.substring(0, offset);
+ Map<String,Image> pathsMap = new TreeMap<String,Image>();
+ collectPaths(startText, root, tree, pathsMap);
+ String[] paths = pathsMap.keySet().toArray(new String[0]);
+ if(paths.length == 1 && text.startsWith(paths[0])) {
+ pathsMap = new TreeMap<String,Image>();
+ collectPaths(paths[0], root, tree, pathsMap);
+ paths = (String[])pathsMap.keySet().toArray(new String[0]);
+ }
+ for (int i = 0; i < paths.length; i++) {
+ String label = paths[i];
+ String replacementString = paths[i];
+ if(text.startsWith(replacementString)) {
+// replacementString = "";
+ }
+
+ IContentProposal proposal =
AttributeContentProposalProviderFactory.makeContentProposal(replacementString,
replacementString);
+
+ proposalsList.add(proposal);
+ }
+ }
+
+ void collectPaths(String startText, XModelObject object, XFilteredTree tree,
Map<String,Image> map) {
+ String value = tree.getValue(object);
+ if(value != null && value.startsWith(startText)) {
+ if(value.length() > 0) {
+ if(value.equals(startText) && value.endsWith("/")) {
+ //skip this value
+ } else {
+ map.put(value, EclipseResourceUtil.getImage(object));
+ }
+ }
+ if(value.length() > startText.length()) return;
+ } else if(value != null && !startText.startsWith(value)) {
+ return;
+ }
+ XModelObject[] cs = tree.getChildren(object);
+ for (int i = 0; i < cs.length; i++) collectPaths(startText, cs[i], tree, map);
+ }
+
+ public IContentProposalProvider getContentProposalProvider() {
+ return new ContentProposalProvider();
+ }
+
+ public int getProposalAcceptanceStyle() {
+ return ContentProposalAdapter.PROPOSAL_REPLACE;
+ }
+
+ public void init(XModelObject object, XAttribute attribute) {
+ this.object = object;
+ this.attribute = attribute;
+ treeProvider = new DefaultXAttributeTreeContentProvider(attribute, object.getModel(),
object);
+ }
+
+ public void dispose() {
+ object = null;
+ attribute = null;
+ treeProvider = null;
+ }
+
+ class ContentProposalProvider implements IContentProposalProvider {
+
+ public IContentProposal[] getProposals(String contents, int position) {
+ List<IContentProposal> proposalsList = new ArrayList<IContentProposal>();
+ addAttributeValueProposals(proposalsList, contents, position);
+ return proposalsList.toArray(new IContentProposal[0]);
+ }
+
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/StringButtonFieldEditorEx.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/StringButtonFieldEditorEx.java 2008-11-14
14:25:13 UTC (rev 11788)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/StringButtonFieldEditorEx.java 2008-11-14
15:13:23 UTC (rev 11789)
@@ -285,12 +285,13 @@
getLabelAction().setEnabled((value!=null && value.length()>0));
}
}
+
+// deprecated - now addContentAssist works
+// IContentAssistProcessor processor =
(IContentAssistProcessor)propertyEditor.getAdapter(IContentAssistProcessor.class);
+// if(processor != null) {
+// ControlContentAssistHelper.createTextContentAssistant(getTextField(), processor);
+// }
- IContentAssistProcessor processor =
(IContentAssistProcessor)propertyEditor.getAdapter(IContentAssistProcessor.class);
- if(processor != null) {
- ControlContentAssistHelper.createTextContentAssistant(getTextField(), processor);
- }
-
return composite;
}