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);
}
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);
}
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);
}
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);
}
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() })));
}
}
Aggregations