Search in sources :

Example 21 with CustomCompletionProposal

use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method addPCDATAProposal.

protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
    CustomCompletionProposal proposal = new // $NON-NLS-1$
    CustomCompletionProposal(// $NON-NLS-1$
    "<![CDATA[]]>", // $NON-NLS-1$
    contentAssistRequest.getReplacementBeginPosition(), // $NON-NLS-1$
    contentAssistRequest.getReplacementLength(), // $NON-NLS-1$
    9, // $NON-NLS-1$
    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CDATASECTION), // $NON-NLS-1$
    "CDATA Section", null, null, XMLRelevanceConstants.R_CDATA);
    contentAssistRequest.addProposal(proposal);
    proposal = new // $NON-NLS-1$
    CustomCompletionProposal(// $NON-NLS-1$
    nodeName, // $NON-NLS-1$
    contentAssistRequest.getReplacementBeginPosition(), // $NON-NLS-1$
    contentAssistRequest.getReplacementLength(), // $NON-NLS-1$
    nodeName.length(), // $NON-NLS-1$
    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT), // $NON-NLS-1$
    "#PCDATA", null, null, XMLRelevanceConstants.R_CDATA);
    contentAssistRequest.addProposal(proposal);
}
Also used : CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)

Example 22 with CustomCompletionProposal

use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method addXMLProposal.

/**
 * @deprecated XML proposal is added via xml declaration template instead
 */
protected void addXMLProposal(ContentAssistRequest contentAssistRequest) {
    // $NON-NLS-2$//$NON-NLS-1$
    String proposedText = "<?xml version=\"1.0\" encoding=\"" + ContentTypeEncodingPreferences.getUserPreferredCharsetName(ContentTypeIdForXML.ContentTypeID_XML) + "\"?>";
    ICompletionProposal proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION), proposedText, null, null, XMLRelevanceConstants.R_XML_DECLARATION);
    // TODO add special XML proposal info
    contentAssistRequest.addProposal(proposal);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)

Example 23 with CustomCompletionProposal

use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method addDocTypeProposal.

protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) {
    // 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();
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    String proposedText = "<!DOCTYPE " + rootname + " PUBLIC \"//UNKNOWN/\" \"unknown.dtd\">";
    ICompletionProposal proposal = new // $NON-NLS-1$
    CustomCompletionProposal(// $NON-NLS-1$
    proposedText, // $NON-NLS-1$
    contentAssistRequest.getReplacementBeginPosition(), // $NON-NLS-1$
    contentAssistRequest.getReplacementLength(), // $NON-NLS-1$
    10, // $NON-NLS-1$
    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DOCTYPE), // $NON-NLS-1$
    "<!DOCTYPE ... >", null, null, XMLRelevanceConstants.R_DOCTYPE);
    // TODO provide special documentation on doc type
    contentAssistRequest.addProposal(proposal);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)

Example 24 with CustomCompletionProposal

use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method addPCDATAProposal.

protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) {
    CustomCompletionProposal proposal = new // $NON-NLS-1$
    CustomCompletionProposal(// $NON-NLS-1$
    "<![CDATA[]]>", // $NON-NLS-1$
    contentAssistRequest.getReplacementBeginPosition(), // $NON-NLS-1$
    contentAssistRequest.getReplacementLength(), // $NON-NLS-1$
    9, // $NON-NLS-1$
    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_CDATASECTION), // $NON-NLS-1$
    "CDATA Section", null, null, XMLRelevanceConstants.R_CDATA);
    contentAssistRequest.addProposal(proposal);
    proposal = new // $NON-NLS-1$
    CustomCompletionProposal(// $NON-NLS-1$
    nodeName, // $NON-NLS-1$
    contentAssistRequest.getReplacementBeginPosition(), // $NON-NLS-1$
    contentAssistRequest.getReplacementLength(), // $NON-NLS-1$
    nodeName.length(), // $NON-NLS-1$
    XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TXTEXT), // $NON-NLS-1$
    "#PCDATA", null, null, XMLRelevanceConstants.R_CDATA);
    contentAssistRequest.addProposal(proposal);
}
Also used : CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)

Example 25 with CustomCompletionProposal

use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method addAttributeNameProposals.

protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) {
    IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
    IStructuredDocumentRegion sdRegion = contentAssistRequest.getDocumentRegion();
    // retrieve the list of attributes
    CMElementDeclaration elementDecl = getCMElementDeclaration(node);
    if (elementDecl != null) {
        CMNamedNodeMap attributes = elementDecl.getAttributes();
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
            for (int k = 0; k < nodes.size(); k++) {
                CMNode cmnode = (CMNode) nodes.get(k);
                if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                    allAttributes.put(cmnode);
                }
            }
        }
        attributes = allAttributes;
        String matchString = contentAssistRequest.getMatchString();
        // check whether an attribute really exists for the replacement
        // offsets AND if it possesses a value
        boolean attrAtLocationHasValue = false;
        NamedNodeMap attrs = node.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
            AttrImpl existingAttr = (AttrImpl) attrs.item(i);
            ITextRegion name = existingAttr.getNameRegion();
            if ((sdRegion.getStartOffset(name) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(name) + name.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength()) && (existingAttr.getValueRegion() != null)) {
                attrAtLocationHasValue = true;
                break;
            }
        }
        // the matchstring
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) attributes.item(i);
                int isRequired = 0;
                if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
                    isRequired = XMLRelevanceConstants.R_REQUIRED;
                }
                boolean showAttribute = true;
                showAttribute = showAttribute && beginsWith(getRequiredName(node, attrDecl), matchString.trim());
                AttrImpl attr = (AttrImpl) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
                ITextRegion nameRegion = attr != null ? attr.getNameRegion() : null;
                // nameRegion.getEndOffset() + 1 is required to allow for
                // matches against the full name of an existing Attr
                showAttribute = showAttribute && (attr == null || nameRegion == null || (nameRegion != null && (sdRegion.getStartOffset(nameRegion) <= contentAssistRequest.getReplacementBeginPosition()) && (sdRegion.getStartOffset(nameRegion) + nameRegion.getLength() >= contentAssistRequest.getReplacementBeginPosition() + contentAssistRequest.getReplacementLength())));
                if (showAttribute) {
                    Image attrImage = CMImageUtil.getImage(attrDecl);
                    if (attrImage == null) {
                        if (isRequired > 0) {
                            attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATT_REQ_OBJ);
                        } else {
                            attrImage = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                        }
                    }
                    String proposedText = null;
                    String proposedInfo = getAdditionalInfo(elementDecl, attrDecl);
                    CustomCompletionProposal proposal = null;
                    // attribute is at this location and already exists
                    if (attrAtLocationHasValue) {
                        // only propose the name
                        proposedText = getRequiredName(node, attrDecl);
                        proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), proposedText.length(), attrImage, proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired, true);
                    } else // no attribute exists or is elsewhere, generate
                    // minimally
                    {
                        Attr existingAttrNode = (Attr) node.getAttributes().getNamedItem(getRequiredName(node, attrDecl));
                        String value = null;
                        if (existingAttrNode != null && existingAttrNode.getSpecified()) {
                            value = existingAttrNode.getNodeValue();
                        }
                        if ((value != null) && (value.length() > 0)) {
                            proposedText = getRequiredName(node, attrDecl);
                        } else {
                            proposedText = getRequiredText(node, attrDecl);
                        }
                        proposal = new CustomCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), attrDecl.getNodeName().length() + 2, attrImage, // and there is no single quote that may be encasing a double quote
                        (showValues && (proposedText.lastIndexOf('\"') - proposedText.indexOf('\"') == 1 && proposedText.indexOf('\'') == -1)) ? getRequiredName(node, attrDecl) : proposedText, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_NAME + isRequired);
                    }
                    contentAssistRequest.addProposal(proposal);
                }
            }
        }
    } else {
        setErrorMessage(NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[] { node.getNodeName() })));
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) AttrImpl(org.eclipse.wst.xml.core.internal.document.AttrImpl) Image(org.eclipse.swt.graphics.Image) Attr(org.w3c.dom.Attr) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Aggregations

CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)48 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)22 Image (org.eclipse.swt.graphics.Image)20 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)17 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)17 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)14 ArrayList (java.util.ArrayList)13 Iterator (java.util.Iterator)13 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)13 List (java.util.List)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)12 Node (org.w3c.dom.Node)11 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)9 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)9 NodeList (org.w3c.dom.NodeList)8 Document (org.w3c.dom.Document)7 Element (org.w3c.dom.Element)7 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)6 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)6