Refactor content assist request class for easier implementation and maintenance.
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXSLContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXSLContentAssistRequest.java
index 5dd2485..8636199 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXSLContentAssistRequest.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/AbstractXSLContentAssistRequest.java
@@ -1,15 +1,21 @@
package org.eclipse.wst.xsl.ui.internal.contentassist;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection;
+import org.eclipse.wst.sse.core.utils.StringUtils;
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
+import org.eclipse.wst.xml.ui.internal.contentassist.ProposalComparator;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -21,27 +27,17 @@
* @author dcarver
*
*/
-public abstract class AbstractXSLContentAssistRequest extends
- ContentAssistRequest {
-
+public abstract class AbstractXSLContentAssistRequest implements IContentAssistProposalRequest {
+ protected IStructuredDocumentRegion documentRegion = null;
+ protected List<ICompletionProposal> macros = new ArrayList<ICompletionProposal>();
+ protected String matchString;
+ protected Node node = null;
+ protected List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+ protected ITextRegion region = null;
+ protected int replacementBeginPosition;
+ protected int replacementLength;
protected ITextViewer textViewer = null;
- /**
- * @param node
- * @param parent
- * @param documentRegion
- * @param completionRegion
- * @param begin
- * @param length
- * @param filter
- * @deprecated
- */
- public AbstractXSLContentAssistRequest(Node node, Node parent,
- IStructuredDocumentRegion documentRegion,
- ITextRegion completionRegion, int begin, int length, String filter) {
- super(node, parent, documentRegion, completionRegion, begin, length, filter);
- // TODO Auto-generated constructor stub
- }
/**
* Handles Content Assistance requests for Select Attributes. This is called an instantiated
@@ -58,15 +54,45 @@
* @param textViewer
*/
- public AbstractXSLContentAssistRequest(Node node, Node parent,
+ public AbstractXSLContentAssistRequest(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length, filter);
+ setNode(node);
+ setDocumentRegion(documentRegion);
+ setRegion(completionRegion);
+ setMatchString(filter);
+ setReplacementBeginPosition(begin);
+ setReplacementLength(length);
this.textViewer = textViewer;
}
/**
+ * Returns a list of proposals. Implementations are to provide the appropriate
+ * implementation for the proposals they would like to return. Use of the getAllCompletionProposals
+ * should be used to return the actual proposals from this method.
+ * @return
+ */
+ public abstract ICompletionProposal[] getCompletionProposals();
+
+ protected ICompletionProposal[] getAllCompletionProposals() {
+ ICompletionProposal results[] = null;
+ if ((getProposals().size() > 0) || (getMacros().size() > 0)) {
+ List<ICompletionProposal> allProposals = new ArrayList<ICompletionProposal>();
+ allProposals.addAll(getProposals());
+ allProposals.addAll(getMacros());
+ allProposals = sortProposals(allProposals);
+
+ results = new ICompletionProposal[allProposals.size()];
+ for (int i = 0; i < allProposals.size(); i++) {
+ results[i] = (ICompletionProposal) allProposals.get(i);
+ }
+ }
+ return results;
+ }
+
+
+ /**
* Checks to make sure that the NodeList has data
* @param nodes A NodeList object
* @return True if has data, false if empty
@@ -102,5 +128,119 @@
return document.getModel().getBaseLocation();
}
+ /**
+ * @param newProposal
+ */
+ protected void addMacro(ICompletionProposal newProposal) {
+ macros.add(newProposal);
+ }
+
+ protected void addProposal(ICompletionProposal newProposal) {
+ proposals.add(newProposal);
+ }
+
+ protected IStructuredDocumentRegion getDocumentRegion() {
+ return documentRegion;
+ }
+
+ protected List<ICompletionProposal> getMacros() {
+ return macros;
+ }
+
+ protected java.lang.String getMatchString() {
+ return matchString;
+ }
+
+ protected org.w3c.dom.Node getNode() {
+ return node;
+ }
+
+ protected org.w3c.dom.Node getParent() {
+ return node.getParentNode();
+ }
+
+ protected List<ICompletionProposal> getProposals() {
+ return proposals;
+ }
+
+ protected ITextRegion getRegion() {
+ return region;
+ }
+
+ protected int getReplacementBeginPosition() {
+ return replacementBeginPosition;
+ }
+
+ protected int getReplacementLength() {
+ return replacementLength;
+ }
+
+ protected int getStartOffset() {
+ if ((getDocumentRegion() != null) && (getRegion() != null)) {
+ return ((ITextRegionCollection) getDocumentRegion()).getStartOffset(getRegion());
+ }
+ return -1;
+ }
+
+ protected String getText() {
+ if ((getDocumentRegion() != null) && (getRegion() != null)) {
+ return ((ITextRegionCollection) getDocumentRegion()).getText(getRegion());
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ protected int getTextEndOffset() {
+ if ((getDocumentRegion() != null) && (getRegion() != null)) {
+ return ((ITextRegionCollection) getDocumentRegion()).getTextEndOffset(getRegion());
+ }
+ return -1;
+ }
+
+ protected void setDocumentRegion(IStructuredDocumentRegion region) {
+ documentRegion = region;
+ }
+
+ protected void setMatchString(java.lang.String newMatchString) {
+ matchString = newMatchString;
+ }
+
+
+ protected void setNode(org.w3c.dom.Node newNode) {
+ node = newNode;
+ }
+
+
+ protected void setRegion(ITextRegion newRegion) {
+ region = newRegion;
+ }
+
+ protected void setReplacementBeginPosition(int newReplacementBeginPosition) {
+ replacementBeginPosition = newReplacementBeginPosition;
+ }
+
+
+ protected void setReplacementLength(int newReplacementLength) {
+ replacementLength = newReplacementLength;
+ }
+
+ protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposalsIn) {
+ Collections.sort(proposalsIn, new ProposalComparator());
+ return proposalsIn;
+
+ }
+
+ /**
+ *
+ * @return java.lang.String
+ */
+ public java.lang.String toString() {
+ return "Node: " + getNode() //$NON-NLS-1$
+ + "\nParent: " + getParent() //$NON-NLS-1$
+ + "\nStructuredDocumentRegion: " + StringUtils.escape(getDocumentRegion().toString()) //$NON-NLS-1$
+ + "\nRegion: " + getRegion() //$NON-NLS-1$
+ + "\nMatch string: '" + StringUtils.escape(getMatchString()) + "'" //$NON-NLS-2$//$NON-NLS-1$
+ + "\nOffsets: [" + getReplacementBeginPosition() + "-" + (getReplacementBeginPosition() + getReplacementLength()) + "]\n"; //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
+ }
+
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CallTemplateContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CallTemplateContentAssistRequest.java
index d08345f..e73b441 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CallTemplateContentAssistRequest.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CallTemplateContentAssistRequest.java
@@ -52,11 +52,10 @@
* @param filter
* @param textViewer
*/
- public CallTemplateContentAssistRequest(Node node, Node parent,
- IStructuredDocumentRegion documentRegion,
+ public CallTemplateContentAssistRequest(Node node, IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length,
+ super(node, documentRegion, completionRegion, begin, length,
filter, textViewer);
// TODO Auto-generated constructor stub
}
@@ -88,7 +87,7 @@
addProposal(proposal);
}
}
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
protected String getAdditionalInfo(Template template) {
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CustomCompletionProposal.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CustomCompletionProposal.java
index f423884..37a5e8a 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CustomCompletionProposal.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/CustomCompletionProposal.java
@@ -27,7 +27,6 @@
super(replacementString, replacementOffset, replacementLength,
cursorPosition, image, displayString, contextInformation,
additionalProposalInfo, relevance);
- // TODO Auto-generated constructor stub
}
/**
@@ -52,7 +51,6 @@
cursorPosition, image, displayString, contextInformation,
additionalProposalInfo, relevance,
updateReplacementLengthOnValidate);
- // TODO Auto-generated constructor stub
}
/**
@@ -62,5 +60,4 @@
public boolean isAutoInsertable() {
return true;
}
-
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java
index 5d3003a..294c68c 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ElementContentAssistRequest.java
@@ -67,11 +67,11 @@
* @param filter
* @param textViewer
*/
- public ElementContentAssistRequest(Node node, Node parent,
+ public ElementContentAssistRequest(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length,
+ super(node, documentRegion, completionRegion, begin, length,
filter, textViewer);
contentModel = new XSLContentModelGenerator();
}
@@ -88,7 +88,7 @@
} else if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
computeTagNameProposals();
}
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
/**
@@ -213,11 +213,11 @@
XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
}
String proposedInfo = getAdditionalInfo(
- getCMElementDeclaration(parent), elementDecl);
+ getCMElementDeclaration(getParent()), elementDecl);
CustomCompletionProposal proposal = new CustomCompletionProposal(
proposedText, getReplacementBeginPosition(),
getReplacementLength(), cursorAdjustment,
- image, contentModel.getRequiredName(parent,
+ image, contentModel.getRequiredName(getParent(),
elementDecl), null, proposedInfo,
XMLRelevanceConstants.R_TAG_NAME);
addProposal(proposal);
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ExcludeResultPrefixesContentAssist.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ExcludeResultPrefixesContentAssist.java
index fb47272..841b445 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ExcludeResultPrefixesContentAssist.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/ExcludeResultPrefixesContentAssist.java
@@ -38,19 +38,13 @@
*
*/
public class ExcludeResultPrefixesContentAssist extends AbstractXSLContentAssistRequest {
-
private static final String EXCLUDE_RESULT_PREFIXES = "exclude-result-prefixes"; //$NON-NLS-1$
private static final String DEFAULT = "#all"; //$NON-NLS-1$
private static final String ADDITIONAL_INFO = Messages.getString("ExcludeResultPrefixesContentAssist.2"); //$NON-NLS-1$
protected String[] tokens = null;
-
+
/**
- * Handles Content Assistance requests for Select Attributes. This is called an instantiated
- * through the use of the computeProposals method from the XSLContentAssistProcessor. It will
- * calculate the available proposals that are available for the XSL select attribute.
- *
* @param node
- * @param parent
* @param documentRegion
* @param completionRegion
* @param begin
@@ -58,14 +52,11 @@
* @param filter
* @param textViewer
*/
-
- @SuppressWarnings("deprecation")
- public ExcludeResultPrefixesContentAssist(Node node, Node parent,
+ public ExcludeResultPrefixesContentAssist(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length, filter);
- this.textViewer = textViewer;
+ super(node, documentRegion, completionRegion, begin, length, filter, textViewer);
}
/**
@@ -81,10 +72,9 @@
int offset = getCursorPosition();
if (excludeResultPrefixes == null || excludeResultPrefixes.equals(DEFAULT)) {
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
-
tokens = excludeResultPrefixes.split("\\s"); //$NON-NLS-1$
if (tokens[0].equals("")) { //$NON-NLS-1$
CustomCompletionProposal proposal = new CustomCompletionProposal(
@@ -105,7 +95,7 @@
}
}
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
protected boolean includePrefix(NamespaceInfo namespace) {
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/HrefContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/HrefContentAssistRequest.java
index 93b4401..f8755d5 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/HrefContentAssistRequest.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/HrefContentAssistRequest.java
@@ -113,9 +113,9 @@
* @param filter
* @param textViewer
*/
- public HrefContentAssistRequest(Node node, Node parent, IStructuredDocumentRegion documentRegion, ITextRegion completionRegion, int begin, int length, String filter, ITextViewer textViewer)
+ public HrefContentAssistRequest(Node node, IStructuredDocumentRegion documentRegion, ITextRegion completionRegion, int begin, int length, String filter, ITextViewer textViewer)
{
- super(node, parent, documentRegion, completionRegion, begin, length, filter, textViewer);
+ super(node, documentRegion, completionRegion, begin, length, filter, textViewer);
}
/**
@@ -167,7 +167,7 @@
XSLUIPlugin.log(e);
}
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
/**
@@ -175,8 +175,7 @@
*
* @return the same list, in the same order
*/
- @SuppressWarnings("unchecked")
- protected List sortProposals(List proposalsIn) {
+ protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposalsIn) {
return proposalsIn;
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/IContentAssistProposalRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/IContentAssistProposalRequest.java
new file mode 100644
index 0000000..975dcaa
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/IContentAssistProposalRequest.java
@@ -0,0 +1,18 @@
+package org.eclipse.wst.xsl.ui.internal.contentassist;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+
+/**
+ * Provides content assistance ICompletionProposals.
+ *
+ * @author David Carver
+ *
+ */
+public interface IContentAssistProposalRequest {
+
+ /**
+ * Completion Proposals for a Content Assist Request.
+ * @return
+ */
+ public ICompletionProposal[] getCompletionProposals();
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/NullContentAssistRequest.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/NullContentAssistRequest.java
index a96fe24..7f8de8b 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/NullContentAssistRequest.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/NullContentAssistRequest.java
@@ -16,13 +16,28 @@
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.w3c.dom.Node;
+/**
+ *
+ * @author dcarver
+ *
+ */
public class NullContentAssistRequest extends AbstractXSLContentAssistRequest {
- public NullContentAssistRequest(Node node, Node parent,
+ /**
+ * A NULL ContentAssistRequest has no proposals.
+ * @param node
+ * @param documentRegion
+ * @param completionRegion
+ * @param begin
+ * @param length
+ * @param filter
+ * @param textViewer
+ */
+ public NullContentAssistRequest(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length,
+ super(node, documentRegion, completionRegion, begin, length,
filter, textViewer);
// TODO Auto-generated constructor stub
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java
index 9e2f325..4bc05a1 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/SelectAttributeContentAssist.java
@@ -62,27 +62,6 @@
private XPathTemplateCompletionProcessor fTemplateProcessor = null;
private List<String> fTemplateContexts = new ArrayList<String>();
private static final byte[] XPATH_LOCK = new byte[0];
-
- /**
- * Handles Content Assistance requests for Select Attributes. This is called an instantiated
- * through the use of the computeProposals method from the XSLContentAssistProcessor. It will
- * calculate the available proposals that are available for the XSL select attribute.
- *
- * @param node
- * @param parent
- * @param documentRegion
- * @param completionRegion
- * @param begin
- * @param length
- * @param filter
- * @deprecated Don't use this constructor for XSL.
- */
- public SelectAttributeContentAssist(Node node, Node parent,
- IStructuredDocumentRegion documentRegion,
- ITextRegion completionRegion, int begin, int length, String filter) {
- super(node, parent, documentRegion, completionRegion, begin, length, filter);
- // TODO Auto-generated constructor stub
- }
/**
* Handles Content Assistance requests for Select Attributes. This is called an instantiated
@@ -90,7 +69,6 @@
* calculate the available proposals that are available for the XSL select attribute.
*
* @param node
- * @param parent
* @param documentRegion
* @param completionRegion
* @param begin
@@ -98,15 +76,14 @@
* @param filter
* @param textViewer
*/
-
- public SelectAttributeContentAssist(Node node, Node parent,
+ public SelectAttributeContentAssist(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length, filter);
- this.textViewer = textViewer;
+ super(node, documentRegion, completionRegion, begin, length, filter, textViewer);
+ // TODO Auto-generated constructor stub
}
-
+
/**
* (non-Javadoc)
@@ -125,7 +102,7 @@
addSelectProposals((Element)getNode().getParentNode(), offset);
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TemplateModeAttributeContentAssist.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TemplateModeAttributeContentAssist.java
index 688aa1b..42c2f59 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TemplateModeAttributeContentAssist.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TemplateModeAttributeContentAssist.java
@@ -16,25 +16,16 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
import org.eclipse.wst.xsl.core.XSLCore;
import org.eclipse.wst.xsl.core.model.StylesheetModel;
import org.eclipse.wst.xsl.core.model.Template;
import org.eclipse.wst.xsl.core.model.XSLAttribute;
-import org.eclipse.wst.xsl.ui.internal.XSLUIPlugin;
import org.eclipse.wst.xsl.ui.internal.util.XSLPluginImageHelper;
import org.eclipse.wst.xsl.ui.internal.util.XSLPluginImages;
import org.w3c.dom.Node;
@@ -61,11 +52,11 @@
* @param filter
* @param textViewer
*/
- public TemplateModeAttributeContentAssist(Node node, Node parent,
+ public TemplateModeAttributeContentAssist(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length,
+ super(node, documentRegion, completionRegion, begin, length,
filter, textViewer);
}
@@ -81,11 +72,18 @@
proposals.clear();
IFile editorFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getLocation()));
-
StylesheetModel model = XSLCore.getInstance().getStylesheet(editorFile);
+ addModeProposals(model);
+ return getAllCompletionProposals();
+ }
+
+ /**
+ * @param model
+ */
+ protected void addModeProposals(StylesheetModel model) {
List<Template> templates = model.getTemplates();
- ArrayList<String> modes = new ArrayList();
+ ArrayList<String> modes = new ArrayList<String>();
for (Template template : templates) {
XSLAttribute attribute = template.getAttribute("mode");
@@ -105,7 +103,6 @@
}
}
modes.clear();
- return super.getCompletionProposals();
}
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TestAttributeContentAssist.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TestAttributeContentAssist.java
index cd82824..bba0044 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TestAttributeContentAssist.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/TestAttributeContentAssist.java
@@ -33,7 +33,6 @@
* Constructor for the XSL content assistance for the test attribute.
*
* @param node
- * @param parent
* @param documentRegion
* @param completionRegion
* @param begin
@@ -41,13 +40,12 @@
* @param filter
* @param textViewer
*/
- public TestAttributeContentAssist(Node node, Node parent,
+ public TestAttributeContentAssist(Node node,
IStructuredDocumentRegion documentRegion,
ITextRegion completionRegion, int begin, int length, String filter,
ITextViewer textViewer) {
- super(node, parent, documentRegion, completionRegion, begin, length, filter,
+ super(node, documentRegion, completionRegion, begin, length, filter,
textViewer);
- // TODO Auto-generated constructor stub
}
/**
@@ -62,11 +60,11 @@
int offset = getReplacementBeginPosition();
IDOMAttr attrNode = (IDOMAttr)((IDOMElement)getNode()).getAttributeNode("test");
- this.matchString = extractXPathMatchString(attrNode, getRegion(), getReplacementBeginPosition());
+ matchString = extractXPathMatchString(attrNode, getRegion(), getReplacementBeginPosition());
addSelectProposals((Element)getNode().getParentNode(), offset);
- return super.getCompletionProposals();
+ return getAllCompletionProposals();
}
/**
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java
index 48689b0..e6920ab 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistProcessor.java
@@ -22,7 +22,6 @@
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
@@ -32,7 +31,6 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor;
-import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor;
import org.eclipse.wst.xsl.core.XSLCore;
import org.w3c.dom.NamedNodeMap;
@@ -55,7 +53,6 @@
private String errorMessage = "";
private ITextViewer textViewer = null;
-
/**
* The XSL Content Assist Processor handles XSL specific functionality for
@@ -83,49 +80,126 @@
public ICompletionProposal[] computeCompletionProposals(
ITextViewer textViewer, int documentPosition) {
setErrorMessage(null);
-
+ ICompletionProposal[] additionalProposals = null;
this.textViewer = textViewer;
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer,
documentPosition);
- Node node = (Node) treeNode;
- while ((node != null) && (node.getNodeType() == Node.TEXT_NODE)
- && (node.getParentNode() != null)) {
- node = node.getParentNode();
- }
+ Node node = getActualDOMNode((Node) treeNode);
+
IDOMNode xmlNode = (IDOMNode) node;
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
ITextRegion completionRegion = getCompletionRegion(documentPosition,
node);
+ ICompletionProposal[] xmlProposals = getXMLProposals(textViewer,
+ documentPosition);
+
+ String matchString = getXPathMatchString(sdRegion, completionRegion,
+ documentPosition);
+
+ additionalProposals = getAdditionalXSLElementProposals(textViewer,
+ documentPosition, additionalProposals, xmlNode, sdRegion,
+ completionRegion, matchString);
+
+ ICompletionProposal[] xslNamespaceProposals = getXSLNamespaceProposals(
+ textViewer, documentPosition, xmlNode, sdRegion,
+ completionRegion, matchString);
+
+ ArrayList<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
+ addProposals(xmlProposals, proposalList);
+ addProposals(additionalProposals, proposalList);
+ addProposals(xslNamespaceProposals, proposalList);
+
+ ICompletionProposal[] combinedProposals = combineProposals(proposalList);
+
+ if (combinedProposals == null || combinedProposals.length == 0) {
+ setErrorMessage(Messages.getString("NoContentAssistance"));
+ }
+
+ return combinedProposals;
+ }
+
+ /**
+ * @param textViewer
+ * @param documentPosition
+ * @param xmlNode
+ * @param sdRegion
+ * @param completionRegion
+ * @param matchString
+ * @return
+ */
+ private ICompletionProposal[] getXSLNamespaceProposals(
+ ITextViewer textViewer, int documentPosition, IDOMNode xmlNode,
+ IStructuredDocumentRegion sdRegion, ITextRegion completionRegion,
+ String matchString) {
+ ICompletionProposal[] xslProposals = null;
+ if (XSLCore.isXSLNamespace(xmlNode)) {
+ xslProposals = getXSLProposals(textViewer, documentPosition,
+ xmlNode, sdRegion, completionRegion, matchString);
+ }
+ return xslProposals;
+ }
+
+ /**
+ * @param textViewer
+ * @param documentPosition
+ * @param additionalProposals
+ * @param xmlNode
+ * @param sdRegion
+ * @param completionRegion
+ * @param matchString
+ * @return
+ */
+ private ICompletionProposal[] getAdditionalXSLElementProposals(
+ ITextViewer textViewer, int documentPosition,
+ ICompletionProposal[] additionalProposals, IDOMNode xmlNode,
+ IStructuredDocumentRegion sdRegion, ITextRegion completionRegion,
+ String matchString) {
+ if (!XSLCore.isXSLNamespace(xmlNode)) {
+ additionalProposals = new ElementContentAssistRequest(xmlNode,
+ sdRegion, completionRegion, documentPosition, 0,
+ matchString, textViewer).getCompletionProposals();
+ }
+ return additionalProposals;
+ }
+
+ /**
+ * @param node
+ * @return
+ */
+ private Node getActualDOMNode(Node node) {
+ while ((node != null) && (node.getNodeType() == Node.TEXT_NODE)
+ && (node.getParentNode() != null)) {
+ node = node.getParentNode();
+ }
+ return node;
+ }
+
+ /**
+ * @param textViewer
+ * @param documentPosition
+ * @return
+ */
+ private ICompletionProposal[] getXMLProposals(ITextViewer textViewer,
+ int documentPosition) {
AbstractContentAssistProcessor processor = new XMLContentAssistProcessor();
ICompletionProposal proposals[] = processor.computeCompletionProposals(
textViewer, documentPosition);
+ return proposals;
+ }
- String matchString = getXPathMatchString(sdRegion, completionRegion,
- documentPosition);
-
- ICompletionProposal[] additionalProposals = null;
- if (!XSLCore.isXSLNamespace(xmlNode)) {
- additionalProposals = new ElementContentAssistRequest(xmlNode, xmlNode.getParentNode(), sdRegion, completionRegion, documentPosition, 0, matchString, textViewer).getCompletionProposals();
- }
-
- ICompletionProposal[] xslProposals = null;
- if (XSLCore.isXSLNamespace(xmlNode)) {
- xslProposals = getXSLProposals(textViewer, documentPosition, xmlNode,
- sdRegion, completionRegion, proposals, matchString);
- }
-
- ArrayList<ICompletionProposal> proposalList = new ArrayList();
- addProposals(proposals, proposalList);
- addProposals(additionalProposals, proposalList);
- addProposals(xslProposals, proposalList);
-
- ICompletionProposal[] combinedProposals = new ICompletionProposal[proposalList.size()];
- proposalList.toArray(combinedProposals);
-
+ /**
+ * @param proposalList
+ * @return
+ */
+ private ICompletionProposal[] combineProposals(
+ ArrayList<ICompletionProposal> proposalList) {
+ ICompletionProposal[] combinedProposals = new ICompletionProposal[proposalList
+ .size()];
+ proposalList.toArray(combinedProposals);
return combinedProposals;
}
@@ -137,24 +211,22 @@
}
}
}
-
protected ICompletionProposal[] getXSLProposals(ITextViewer textViewer,
int documentPosition, IDOMNode xmlNode,
IStructuredDocumentRegion sdRegion, ITextRegion completionRegion,
- ICompletionProposal[] proposals, String matchString) {
+ String matchString) {
XSLContentAssistRequestFactory requestFactory = new XSLContentAssistRequestFactory();
ICompletionProposal[] xslProposals = null;
- ContentAssistRequest contentAssistRequest = requestFactory
+ IContentAssistProposalRequest contentAssistRequest = requestFactory
.getContentAssistRequest(textViewer, documentPosition, xmlNode,
- sdRegion, completionRegion, proposals, matchString);
+ sdRegion, completionRegion, matchString);
- xslProposals = contentAssistRequest.getCompletionProposals();
+ xslProposals = contentAssistRequest.getCompletionProposals();
return xslProposals;
}
-
/**
* StructuredTextViewer must be set before using this.
*
@@ -165,7 +237,6 @@
return ContentAssistUtils.getStructuredDocumentRegion(textViewer, pos);
}
-
/**
* Return the region whose content's require completion. This is something
* of a misnomer as sometimes the user wants to be prompted for contents of
@@ -361,6 +432,7 @@
*
* the auto activation characters for completion proposal or
* <code>null</code> if no auto activation is desired
+ *
* @return an array of activation characters
*/
public char[] getCompletionProposalAutoActivationCharacters() {
@@ -376,7 +448,6 @@
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
*/
public char[] getContextInformationAutoActivationCharacters() {
- // TODO Auto-generated method stub
return null;
}
@@ -408,16 +479,6 @@
}
/**
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- // TODO Auto-generated method stub
-
- }
-
- /**
* Sets the error message for why content assistance didn't complete.
*
* @param errorMessage
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistRequestFactory.java b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistRequestFactory.java
index 5dfa44b..00e977b 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistRequestFactory.java
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/XSLContentAssistRequestFactory.java
@@ -20,8 +20,8 @@
import org.w3c.dom.NamedNodeMap;
/**
- * A Factory that determines which Content Assist Request class is
- * needed and returns the appropriate class.
+ * A Factory that determines which Content Assist Request class is needed and
+ * returns the appropriate class.
*
* @author David Carver
* @since 1.0
@@ -32,15 +32,16 @@
private static final String ATTR_MATCH = "match"; //$NON-NLS-1$
private static final String ATTR_EXCLUDE_RESULT_PREFIXES = "exclude-result-prefixes"; //$NON-NLS-1$
private static final String ATTR_MODE = "mode"; //$NON-NLS-1$
- private static final String ELEM_TEMPLATE = "template"; //$NON-NLS-1$
+ private static final String ELEM_TEMPLATE = "template"; //$NON-NLS-1$
private static final String ELEM_APPLYTEMPLATES = "apply-templates"; //$NON-NLS-1$
private static final String ELEM_APPLY_IMPORTS = "apply-imports"; //$NON-NLS-1$
private static final String ATTR_HREF = "href"; //$NON-NLS-1$
private static final String ELEM_CALLTEMPLATE = "call-template"; //$NON-NLS-1$
private static final String ATTR_NAME = "name"; //$NON-NLS-1$
-
+
/**
* Get the appropriate content assist request class for the XSL request.
+ *
* @param textViewer
* @param documentPosition
* @param xmlNode
@@ -50,80 +51,80 @@
* @param matchString
* @return
*/
- public AbstractXSLContentAssistRequest getContentAssistRequest(ITextViewer textViewer,
- int documentPosition, IDOMNode xmlNode,
+ public AbstractXSLContentAssistRequest getContentAssistRequest(
+ ITextViewer textViewer, int documentPosition, IDOMNode xmlNode,
IStructuredDocumentRegion sdRegion, ITextRegion completionRegion,
- ICompletionProposal[] proposals, String matchString) {
+ String matchString) {
NamedNodeMap nodeMap = xmlNode.getAttributes();
IDOMElement element = (IDOMElement) xmlNode;
+ if (this.hasAttributeAtTextRegion(ATTR_SELECT, nodeMap,
+ completionRegion)) {
+ return new SelectAttributeContentAssist(xmlNode, sdRegion,
+ completionRegion, documentPosition, 0, matchString,
+ textViewer);
+ }
- if (this.hasAttributeAtTextRegion(ATTR_SELECT, nodeMap, completionRegion)) {
- return new SelectAttributeContentAssist(
- xmlNode, xmlNode.getParentNode(), sdRegion,
+ if (this
+ .hasAttributeAtTextRegion(ATTR_MATCH, nodeMap, completionRegion)) {
+ return new SelectAttributeContentAssist(xmlNode, sdRegion,
completionRegion, documentPosition, 0, matchString,
textViewer);
}
-
- if (this.hasAttributeAtTextRegion(ATTR_MATCH, nodeMap, completionRegion)) {
- return new SelectAttributeContentAssist(
- xmlNode, xmlNode.getParentNode(), sdRegion,
- completionRegion, documentPosition, 0, matchString,
- textViewer);
- }
-
-
+
if (this.hasAttributeAtTextRegion(ATTR_TEST, nodeMap, completionRegion)) {
- return new TestAttributeContentAssist(
- xmlNode, xmlNode.getParentNode(), sdRegion,
+ return new TestAttributeContentAssist(xmlNode, sdRegion,
completionRegion, documentPosition, 0, matchString,
textViewer);
}
- if (this.hasAttributeAtTextRegion(ATTR_EXCLUDE_RESULT_PREFIXES, nodeMap, completionRegion)) {
- return new ExcludeResultPrefixesContentAssist(
- xmlNode, xmlNode.getParentNode(), sdRegion,
+ if (this.hasAttributeAtTextRegion(ATTR_EXCLUDE_RESULT_PREFIXES,
+ nodeMap, completionRegion)) {
+ return new ExcludeResultPrefixesContentAssist(xmlNode, sdRegion,
completionRegion, documentPosition, 0, matchString,
textViewer);
}
-
+
if (hasAttributeAtTextRegion(ATTR_HREF, nodeMap, completionRegion)) {
- return new HrefContentAssistRequest(
- xmlNode, xmlNode.getParentNode(), sdRegion, completionRegion,
- documentPosition, 0, matchString, textViewer);
- }
-
-
+ return new HrefContentAssistRequest(xmlNode, sdRegion,
+ completionRegion, documentPosition, 0, matchString,
+ textViewer);
+ }
+
if (element.getLocalName().equals(ELEM_TEMPLATE)) {
if (hasAttributeAtTextRegion(ATTR_MODE, nodeMap, completionRegion)) {
- return new TemplateModeAttributeContentAssist(
- xmlNode, xmlNode.getParentNode(), sdRegion, completionRegion,
- documentPosition, 0, matchString, textViewer);
+ return new TemplateModeAttributeContentAssist(xmlNode,
+ sdRegion, completionRegion, documentPosition, 0,
+ matchString, textViewer);
}
}
-
- if (element.getLocalName().equals(ELEM_APPLYTEMPLATES) || element.getLocalName().equals(ELEM_APPLY_IMPORTS)) {
+
+ if (element.getLocalName().equals(ELEM_APPLYTEMPLATES)
+ || element.getLocalName().equals(ELEM_APPLY_IMPORTS)) {
if (hasAttributeAtTextRegion(ATTR_MODE, nodeMap, completionRegion)) {
- return new TemplateModeAttributeContentAssist(
- xmlNode, xmlNode.getParentNode(), sdRegion, completionRegion,
- documentPosition, 0, matchString, textViewer);
+ return new TemplateModeAttributeContentAssist(xmlNode,
+ sdRegion, completionRegion, documentPosition, 0,
+ matchString, textViewer);
}
-
+
}
-
+
if (element.getLocalName().equals(ELEM_CALLTEMPLATE)) {
if (hasAttributeAtTextRegion(ATTR_NAME, nodeMap, completionRegion)) {
- return new CallTemplateContentAssistRequest(xmlNode, xmlNode.getParentNode(), sdRegion, completionRegion,
- documentPosition, 0, matchString, textViewer);
+ return new CallTemplateContentAssistRequest(xmlNode, sdRegion,
+ completionRegion, documentPosition, 0, matchString,
+ textViewer);
}
}
-
- return new NullContentAssistRequest(xmlNode, xmlNode.getParentNode(), sdRegion, completionRegion,
- documentPosition, 0, matchString, textViewer);
+
+ return new NullContentAssistRequest(xmlNode, sdRegion,
+ completionRegion, documentPosition, 0, matchString, textViewer);
}
- protected boolean hasAttributeAtTextRegion(String attrName, NamedNodeMap nodeMap, ITextRegion aRegion) {
+ protected boolean hasAttributeAtTextRegion(String attrName,
+ NamedNodeMap nodeMap, ITextRegion aRegion) {
IDOMAttr attrNode = (IDOMAttr) nodeMap.getNamedItem(attrName);
- return attrNode != null && attrNode.getValueRegion() != null && attrNode.getValueRegion().getStart() == aRegion.getStart();
- }
+ return attrNode != null && attrNode.getValueRegion() != null
+ && attrNode.getValueRegion().getStart() == aRegion.getStart();
+ }
}
diff --git a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/messages.properties b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/messages.properties
index ecbe244..7dc90a6 100644
--- a/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/messages.properties
+++ b/bundles/org.eclipse.wst.xsl.ui/src/org/eclipse/wst/xsl/ui/internal/contentassist/messages.properties
@@ -1,2 +1,3 @@
ExcludeResultPrefixesContentAssist.2=XML Namespace:
XPathCustomTemplateProposal.1=Description:\r\n
+NoContentAssistance=No Content Assistance Proposals Available.