use of org.eclipse.wst.xsl.ui.provisional.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class CommonSelectContentAssistRequest method addNodeSetProposal.
private void addNodeSetProposal() {
String nodeset = "";
if (prefix != null) {
nodeset = prefix + ":" + NODE_SET;
} else {
nodeset = NODE_SET;
}
CustomCompletionProposal proposal = new CustomCompletionProposal(nodeset, getStartOffset() + 1, 0, nodeset.length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_XPATH_FUNCTION), nodeset, null, null, 0);
proposals.add((ICompletionProposal) proposal);
}
use of org.eclipse.wst.xsl.ui.provisional.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class SelectAttributeContentAssist method addVariablesProposals.
/**
* Adds Parameter and Variables as proposals. This information is selected
* based on the XPath statement that is sent to it and the input Node
* passed. It uses a custom composer to XSL Variable proposal.
*
* @param xpath
* @param xpathnode
* @param contentAssistRequest
* @param offset
*/
private void addVariablesProposals(String xpath, Node xpathnode, int offset) {
synchronized (XPATH_LOCK) {
try {
NodeList nodes = XSLTXPathHelper.selectNodeList(xpathnode, xpath);
if (!hasNodes(nodes)) {
return;
}
int startLength = getCursorPosition() - offset;
for (int nodecnt = 0; nodecnt < nodes.getLength(); nodecnt++) {
Node node = nodes.item(nodecnt);
// $NON-NLS-1$
Node nameItem = node.getAttributes().getNamedItem("name");
if (nameItem == null)
continue;
// $NON-NLS-1$
String variableName = "$" + nameItem.getNodeValue();
CustomCompletionProposal proposal = new CustomCompletionProposal(variableName, offset, 0, startLength + variableName.length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_VARIABLES), variableName, null, null, 0);
if (matchString.length() > 0) {
if (proposal.getDisplayString().startsWith(matchString)) {
addProposal(proposal);
}
} else {
addProposal(proposal);
}
}
} catch (TransformerException ex) {
XSLUIPlugin.log(ex);
}
}
}
use of org.eclipse.wst.xsl.ui.provisional.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class XSLTemplatesPage method insertTemplate.
// This code based on the JavaTemplatesPage code. Modified to work with
// SSE
@Override
protected void insertTemplate(Template template, IDocument document) {
ISourceViewer contextViewer = fTextEditor.getTextViewer();
ITextSelection textSelection = (ITextSelection) contextViewer.getSelectionProvider().getSelection();
if (!isValidTemplate(document, template, textSelection.getOffset(), textSelection.getLength()))
return;
beginCompoundChange(contextViewer);
/*
* The Editor checks whether a completion for a word exists before it
* allows for the template to be applied. We pickup the current text at
* the selection position and replace it with the first char of the
* template name for this to succeed. Another advantage by this method
* is that the template replaces the selected text provided the
* selection by itself is not used in the template pattern.
*/
String savedText;
try {
savedText = document.get(textSelection.getOffset(), textSelection.getLength());
if (savedText.length() == 0) {
String prefix = getIdentifierPart(document, template, textSelection.getOffset(), textSelection.getLength());
if (prefix.length() > 0 && !template.getName().startsWith(prefix)) {
return;
}
if (prefix.length() > 0) {
contextViewer.setSelectedRange(textSelection.getOffset() - prefix.length(), prefix.length());
textSelection = (ITextSelection) contextViewer.getSelectionProvider().getSelection();
}
}
document.replace(textSelection.getOffset(), textSelection.getLength(), template.getName().substring(0, 1));
} catch (BadLocationException e) {
endCompoundChange(contextViewer);
return;
}
Region region = new Region(textSelection.getOffset() + 1, 0);
contextViewer.getSelectionProvider().setSelection(new TextSelection(textSelection.getOffset(), 1));
DocumentTemplateContext context = getContext(document, template, textSelection.getOffset(), textSelection.getLength());
// $NON-NLS-1$
context.setVariable("selection", savedText);
if (context.getKey().length() == 0) {
try {
document.replace(textSelection.getOffset(), 1, savedText);
} catch (BadLocationException e) {
endCompoundChange(contextViewer);
return;
}
}
ITextViewer viewer = fTextEditor.getTextViewer();
int offset = viewer.getTextWidget().getCaretOffset();
int startLength = offset - region.getOffset();
// $NON-NLS-1$ //$NON-NLS-2$
String pattern = template.getPattern().replace("${cursor}", "");
CustomCompletionProposal proposal = new CustomCompletionProposal(pattern, offset, 0, startLength + pattern.length(), getImage(template), template.getName(), null, null, 0);
fTextEditor.getSite().getPage().activate(fTextEditor);
proposal.apply(fTextEditor.getTextViewer(), ' ', 0, offset);
viewer.getTextWidget().setCaretOffset(offset + pattern.length() - 1);
endCompoundChange(contextViewer);
}
use of org.eclipse.wst.xsl.ui.provisional.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class CommonSelectContentAssistRequest method addObjectTypeProposal.
private void addObjectTypeProposal() {
String nodeset = "";
if (prefix != null) {
nodeset = prefix + ":" + OBJECT_TYPE;
} else {
nodeset = OBJECT_TYPE;
}
CustomCompletionProposal proposal = new CustomCompletionProposal(nodeset, getStartOffset() + 1, 0, nodeset.length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_XPATH_FUNCTION), nodeset, null, null, 0);
proposals.add((ICompletionProposal) proposal);
}
Aggregations