use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method computeEntityReferenceProposals.
/**
* return all possible EntityReferenceProposals (according to current
* position in doc)
*/
protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
// only handle XML content for now
// ICompletionProposals
Vector proposals = new Vector();
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) {
int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion);
String regionText = sdRegion.getFullText(completionRegion);
// the previous region...there might be a better way to do this
if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) {
// $NON-NLS-1$
IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1);
if ((prev != null) && prev.getText().equals("&")) {
// $NON-NLS-1$
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680
// examine previous region
sdRegion = prev;
completionRegion = prev.getLastRegion();
regionText = prev.getFullText();
nodeOffset = 1;
}
}
// string must start w/ &
if ((regionText != null) && regionText.startsWith("&")) {
// $NON-NLS-1$
// $NON-NLS-1$
String key = (nodeOffset > 0) ? regionText.substring(1, nodeOffset) : "";
// get entity proposals, passing in the appropriate start
// string
ModelQuery mq = ModelQueryUtil.getModelQuery(((Node) treeNode).getOwnerDocument());
if (mq != null) {
CMDocument xmlDoc = mq.getCorrespondingCMDocument(treeNode);
CMNamedNodeMap cmmap = null;
Properties entities = null;
if (xmlDoc != null) {
cmmap = xmlDoc.getEntities();
}
if (cmmap != null) {
entities = mapToProperties(cmmap);
} else // 224787 in absence of content model, just use
// minimal 5 entities
{
entities = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("quot", "\"");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("apos", "'");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("amp", "&");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("lt", "<");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("gt", ">");
// $NON-NLS-1$ //$NON-NLS-2$
entities.put("nbsp", " ");
}
addEntityProposals(proposals, entities, key, nodeOffset, sdRegion, completionRegion);
}
}
}
return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLTableTreePropertyDescriptorFactory method createTextPropertyDescriptor.
public IPropertyDescriptor createTextPropertyDescriptor(Text text) {
IPropertyDescriptor result = null;
Node parentNode = text.getParentNode();
if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) {
Element parentElement = (Element) parentNode;
ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument());
CMElementDeclaration ed = null;
if (mq != null) {
ed = mq.getCMElementDeclaration(parentElement);
}
if (ed != null) {
result = createPropertyDescriptorHelper(HACK, parentElement, ed);
} else {
result = createDefaultPropertyDescriptor(parentElement.getNodeName());
}
}
if (result == null) {
result = new TextPropertyDescriptor(HACK, HACK);
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLTreeExtension method getElementValueHelper.
public String getElementValueHelper(Element element) {
String result = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if ((result == null) && (mq != null)) {
CMElementDeclaration ed = mq.getCMElementDeclaration(element);
if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
// $NON-NLS-1$
result = decriptionBuilder.buildDescription(ed);
}
}
// $NON-NLS-1$
return result != null ? result : "";
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class DOMObserver method invokeCMDocumentLoad.
public void invokeCMDocumentLoad() {
if (fIsDisabled)
return;
try {
fIsLoading = true;
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fDocument);
if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) {
CMDocumentLoader loader = isGrammarInferenceEnabled ? new InferredGrammarBuildingCMDocumentLoader(fDocument, modelQuery) : new CMDocumentLoader(fDocument, modelQuery);
loader.loadCMDocuments();
}
} finally {
fIsLoading = false;
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLTableTreeContentProvider method getElementValueHelper.
private String getElementValueHelper(Element element) {
String result = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if ((result == null) && (mq != null)) {
CMElementDeclaration ed = mq.getCMElementDeclaration(element);
if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
// $NON-NLS-1$
result = descriptionBuilder.buildDescription(ed);
}
}
// $NON-NLS-1$
return result != null ? result : "";
}
Aggregations