use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class LibraryTagsCompletionProposalComputer method addAttributeValueProposals.
/**
* @see org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
*/
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
if (!this.isXHTML) {
IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
if (mq != null) {
CMDocument doc = mq.getCorrespondingCMDocument(node);
// this shouldn't have to have the prefix coded in
if (doc instanceof JSPCMDocument || doc instanceof CMNodeWrapper || node.getNodeName().startsWith("jsp:")) {
// $NON-NLS-1$
return;
}
}
// Find the attribute name for which this position should have a value
IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
ITextRegionList openRegions = open.getRegions();
int i = openRegions.indexOf(contentAssistRequest.getRegion());
if (i < 0) {
return;
}
ITextRegion nameRegion = null;
while (i >= 0) {
nameRegion = openRegions.get(i--);
if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
break;
}
}
// on an empty value, add all the JSP and taglib tags
CMElementDeclaration elementDecl = AbstractXMLModelQueryCompletionProposalComputer.getCMElementDeclaration(node);
if (nameRegion != null && elementDecl != null) {
String attributeName = open.getText(nameRegion);
if (attributeName != null) {
Node parent = contentAssistRequest.getParent();
// ignore start quote in match string
String matchString = contentAssistRequest.getMatchString().trim();
if (matchString.startsWith("'") || matchString.startsWith("\"")) {
// $NON-NLS-1$ //$NON-NLS-2$
matchString = matchString.substring(1);
}
// get all the proposals
List additionalElements = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ALL);
Iterator nodeIterator = additionalElements.iterator();
// check each suggestion
while (nodeIterator.hasNext()) {
CMNode additionalElementDecl = (CMNode) nodeIterator.next();
if (additionalElementDecl != null && additionalElementDecl instanceof CMElementDeclaration && validModelQueryNode(additionalElementDecl)) {
CMElementDeclaration ed = (CMElementDeclaration) additionalElementDecl;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
StringBuffer sb = new StringBuffer();
getContentGenerator().generateTag(parent, ed, sb);
String proposedText = sb.toString();
// filter out any proposals that dont match matchString
if (beginsWith(proposedText, matchString)) {
// wrap with ' because JSP attributes are warped with "
// $NON-NLS-1$
proposedText = "'" + proposedText;
// don't want to risk injecting an extra
if (!(contentAssistRequest.getRegion() instanceof ITextRegionContainer)) {
// $NON-NLS-1$
proposedText += "'";
}
// get the image
Image image = CMImageUtil.getImage(elementDecl);
if (image == null) {
image = this.getGenericTagImage();
}
// create the proposal
int cursorAdjustment = getCursorPositionForProposedText(proposedText);
String proposedInfo = AbstractXMLModelQueryCompletionProposalComputer.getAdditionalInfo(AbstractXMLModelQueryCompletionProposalComputer.getCMElementDeclaration(parent), elementDecl);
String tagname = getContentGenerator().getRequiredName(node, ed);
CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, image, tagname, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
contentAssistRequest.addProposal(proposal);
}
}
}
}
}
}
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class HTMLTagsCompletionProposalComputer method addHTMLTagProposal.
/**
* <p>adds HTML tag proposal for empty document</p>
*
* @param contentAssistRequest request to add proposal too
* @param context context of the completion request
*/
private void addHTMLTagProposal(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
IStructuredModel model = null;
try {
if (context.getDocument() instanceof IStructuredDocument) {
model = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument) context.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);
IStructuredDocumentRegion region = contentAssistRequest.getDocumentRegion();
if (region != null) {
if (region.getFirstRegion() != null && region.getFirstRegion().getType().equals(DOMRegionContext.XML_TAG_OPEN)) {
// in order to differentiate between content assist on
// completely empty document and the one with xml open tag
proposedText = proposedText.substring(1);
}
}
if (!beginsWith(proposedText, contentAssistRequest.getMatchString())) {
return;
}
int cursorAdjustment = getCursorPositionForProposedText(proposedText);
CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), cursorAdjustment, HTMLEditorPluginImageHelper.getInstance().getImage(HTMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), requiredName, null, null, XMLRelevanceConstants.R_TAG_NAME);
contentAssistRequest.addProposal(proposal);
}
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class HTMLTagsCompletionProposalComputer method addDocTypeProposal.
/**
* @param contentAssistRequest
* @param isXHTML
*/
private void addDocTypeProposal(ContentAssistRequest contentAssistRequest, boolean isXHTML) {
// if a DocumentElement exists, use that for the root Element name
// $NON-NLS-1$
String rootname = "unspecified";
if (contentAssistRequest.getNode().getOwnerDocument().getDocumentElement() != null) {
rootname = contentAssistRequest.getNode().getOwnerDocument().getDocumentElement().getNodeName();
}
// decide which entry to use
HTMLDocumentTypeEntry entry;
if (isXHTML) {
entry = HTMLDocumentTypeRegistry.getInstance().getXHTMLDefaultEntry();
} else {
entry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry();
}
// create the content assist string and proposal
String proposedText = // $NON-NLS-1$ //$NON-NLS-2$
"<!DOCTYPE " + rootname + " PUBLIC \"" + entry.getPublicId() + "\" \"" + entry.getSystemId() + // $NON-NLS-1$ //$NON-NLS-2$
"\">";
ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 10, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DOCTYPE), // $NON-NLS-1$
entry.getDisplayName() + " " + HTMLUIMessages.Expandable_label_document_type, null, null, XMLRelevanceConstants.R_DOCTYPE);
contentAssistRequest.addProposal(proposal);
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class TemplateNameAttributeContentAssist method getCompletionProposals.
/* (non-Javadoc)
* @see org.eclipse.wst.xsl.ui.internal.contentassist.AbstractXSLContentAssistRequest#getCompletionProposals()
*/
@Override
public ArrayList<ICompletionProposal> getCompletionProposals() {
proposals.clear();
StylesheetModel model = getStylesheetModel();
List<CallTemplate> templates = model.getCallTemplates();
for (CallTemplate template : templates) {
CustomCompletionProposal proposal = createProposal(template);
addUniqueProposal(proposal);
}
return getAllCompletionProposals();
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPJavaCompletionProposalComputer method computeCompletionProposals.
/**
* <p>Return a list of proposed code completions based on the specified
* location within the document that corresponds to the current cursor
* position within the text-editor control.</p>
*
* @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
List results = new ArrayList(0);
if (isValidContext(context)) {
ITextViewer viewer = context.getViewer();
int documentPosition = context.getInvocationOffset();
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, documentPosition);
// get results from JSP completion processor
results = computeJavaCompletionProposals(viewer, documentPosition, 0);
IDOMNode xNode = null;
IStructuredDocumentRegion flat = null;
if (treeNode instanceof IDOMNode) {
xNode = (IDOMNode) treeNode;
flat = xNode.getFirstStructuredDocumentRegion();
if (flat != null && flat.getType() == DOMJSPRegionContexts.JSP_CONTENT) {
flat = flat.getPrevious();
}
}
// this is in case it's a <%@, it will be a region container...
ITextRegion openRegion = null;
if (flat != null && flat instanceof ITextRegionContainer) {
ITextRegionList v = ((ITextRegionContainer) flat).getRegions();
if (v.size() > 0)
openRegion = v.get(0);
}
// ADD CDATA PROPOSAL IF IT'S AN XML-JSP TAG
if (flat != null && flat.getType() != DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_DECLARATION_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_EXPRESSION_OPEN && flat.getType() != DOMRegionContext.BLOCK_TEXT && (openRegion != null && openRegion.getType() != DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) && !inAttributeRegion(flat, documentPosition)) {
// determine if cursor is before or after selected range
int adjustedDocPosition = documentPosition;
int realCaretPosition = viewer.getTextWidget().getCaretOffset();
int selectionLength = viewer.getSelectedRange().y;
if (documentPosition > realCaretPosition) {
adjustedDocPosition -= selectionLength;
}
CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);
results.add(cdataProposal);
}
}
return results;
}
Aggregations