use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class HTMLContentAssistProcessor method getHTMLTagProposal.
/**
* @return ICompletionProposal
*/
private ICompletionProposal getHTMLTagProposal(ITextViewer viewer, int documentPosition) {
IModelManager mm = StructuredModelManager.getModelManager();
IStructuredModel model = null;
ICompletionProposal result = null;
try {
if (mm != null) {
model = mm.getExistingModelForRead(viewer.getDocument());
if (model != null) {
IDOMDocument doc = ((IDOMModel) model).getDocument();
ModelQuery mq = ModelQueryUtil.getModelQuery(doc);
if (mq != null) {
// XHTML requires lowercase tagname for lookup
CMDocument correspondingCMDocument = mq.getCorrespondingCMDocument(doc);
if (correspondingCMDocument != null) {
CMElementDeclaration htmlDecl = (CMElementDeclaration) correspondingCMDocument.getElements().getNamedItem(HTML40Namespace.ElementName.HTML.toLowerCase());
if (htmlDecl != null) {
StringBuffer proposedTextBuffer = new StringBuffer();
getContentGenerator().generateTag(doc, htmlDecl, proposedTextBuffer);
String proposedText = proposedTextBuffer.toString();
String requiredName = getContentGenerator().getRequiredName(doc, htmlDecl);
CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, documentPosition, /* start pos */
0, /* replace length */
requiredName.length() + 2, /*
* cursor position
* after
* (relavtive to
* start)
*/
HTMLEditorPluginImageHelper.getInstance().getImage(HTMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), requiredName, null, null, XMLRelevanceConstants.R_TAG_NAME);
result = proposal;
}
}
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
return result;
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class AbstractXMLElementContentAssistRequest method addTagNameProposals.
/**
* Adds proposals for the XML_TAG_NAME region.
* @param position
*/
protected void addTagNameProposals(int position) {
Node ancestorNode = null;
try {
ancestorNode = XSLTXPathHelper.selectSingleNode(getNode(), XPATH_FIRST_XSLANCESTOR_NODE);
} catch (TransformerException ex) {
}
if (ancestorNode == null) {
return;
}
List<CMNode> cmnodes = null;
if (ancestorNode.getNodeType() == Node.ELEMENT_NODE) {
cmnodes = getAvailableChildElementDeclarations((Element) ancestorNode, 0);
Iterator<CMNode> nodeIterator = cmnodes.iterator();
// chop off any leading <'s and whitespace from the matchstring
while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) {
// $NON-NLS-1$
// $NON-NLS-1$
matchString = matchString.substring(1);
}
if (!nodeIterator.hasNext()) {
return;
}
while (nodeIterator.hasNext()) {
CMNode elementDecl = nodeIterator.next();
if (elementDecl != null) {
// only add proposals for the child element's that begin
// with the matchstring
String proposedText = null;
proposedText = contentModel.getRequiredName(ancestorNode, elementDecl);
int cursorAdjustment = proposedText.length();
if (elementDecl instanceof CMElementDeclaration) {
CMElementDeclaration ed = (CMElementDeclaration) elementDecl;
if (ed.getContentType() == CMElementDeclaration.EMPTY) {
proposedText += contentModel.getStartTagClose(ancestorNode, ed);
cursorAdjustment = proposedText.length();
} else {
StringBuffer sb = new StringBuffer();
contentModel.generateTag(ancestorNode, ed, sb);
// since it's a name proposal, assume '<' is
// already there
// only return the rest of the tag
proposedText = sb.toString().substring(1);
cursorAdjustment = getCursorPositionForProposedText(proposedText);
}
}
if (beginsWith(proposedText, matchString)) {
Image image = CMImageUtil.getImage(elementDecl);
if (image == null) {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
}
String proposedInfo = getAdditionalInfo(getCMElementDeclaration(getParent()), elementDecl);
CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, getReplacementBeginPosition(), getReplacementLength(), cursorAdjustment, image, contentModel.getRequiredName(getParent(), elementDecl), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
addProposal(proposal);
}
}
}
}
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class HrefContentAssistRequest method getCompletionProposals.
/**
* The main method that returns an array of proposals. Returns relative paths to files in the current project.
*
* @return ICompletionProposal[]
* @see org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest#getCompletionProposals()
*/
@Override
public ArrayList<ICompletionProposal> getCompletionProposals() {
pathList.clear();
proposals.clear();
try {
String text = getText();
String precedingText;
int length = getCursorPosition() - getStartOffset();
if (length > 0 && text.length() > length + 1)
precedingText = text.substring(1, length);
else
// $NON-NLS-1$
precedingText = "";
IFile editorFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(getLocation()));
editorFile.getProject().accept(new XSLFileResourceVisitor(editorFile, precedingText));
Collections.sort(pathList, new PathComparator());
for (IPath path : pathList) {
String pathString = path.toString();
CustomCompletionProposal proposal = new CustomCompletionProposal(pathString, getStartOffset() + 1, text.length() - 2, pathString.length(), XSLPluginImageHelper.getInstance().getImage(XSLPluginImages.IMG_XSL_FILE), pathString, null, null, 0, true);
proposals.add(proposal);
}
} catch (CoreException e) {
XSLUIPlugin.log(e);
}
return proposals;
}
Aggregations