use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class XMLFoldingStrategy method calcNewFoldPosition.
/**
* @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#calcNewFoldPosition(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
*/
protected Position calcNewFoldPosition(IndexedRegion indexedRegion) {
Position retPos = null;
// only want to fold regions of the valid type and with a valid range
if (indexedRegion.getStartOffset() >= 0 && indexedRegion.getLength() >= 0) {
IDOMNode node = (IDOMNode) indexedRegion;
IStructuredDocumentRegion startRegion = node.getStartStructuredDocumentRegion();
IStructuredDocumentRegion endRegion = node.getEndStructuredDocumentRegion();
// else if the region is only an open tag or an open/close tag then don't fold it
if (startRegion != null && endRegion != null) {
if (endRegion.getEndOffset() >= startRegion.getStartOffset())
retPos = new XMLElementFoldingPosition(startRegion, endRegion);
} else if (startRegion != null && indexedRegion instanceof CommentImpl) {
retPos = new XMLCommentFoldingPosition(startRegion);
}
}
return retPos;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method formatChild.
public static void formatChild(Node child) {
if (child instanceof IDOMNode) {
IDOMModel model = ((IDOMNode) child).getModel();
try {
// tell the model that we are about to make a big model change
model.aboutToChangeModel();
IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
formatProcessor.formatNode(child);
} finally {
// tell the model that we are done with the big model change
model.changedModel();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractModelTest method calculateErrorsAndWarnings.
private Map<Integer, String> calculateErrorsAndWarnings(IFile file) throws XPathExpressionException, IOException, CoreException {
Map<Integer, String> expectedErrors = new HashMap<Integer, String>();
IStructuredModel smodel = null;
try {
smodel = StructuredModelManager.getModelManager().getModelForRead(file);
if (smodel != null && smodel instanceof IDOMModel) {
IDOMModel model = (IDOMModel) smodel;
XPathExpression xp = XPathFactory.newInstance().newXPath().compile("//comment()");
NodeList nodeSet = (NodeList) xp.evaluate(model.getDocument(), XPathConstants.NODESET);
for (int i = 0; i < nodeSet.getLength(); i++) {
Node commentNode = nodeSet.item(i);
String comment = commentNode.getNodeValue().trim();
if (comment.startsWith("ERROR") || comment.startsWith("WARN")) {
IDOMNode parent = (IDOMNode) commentNode.getParentNode();
int line = model.getStructuredDocument().getLineOfOffset(parent.getStartOffset()) + 1;
expectedErrors.put(line, comment);
}
}
}
} finally {
if (smodel != null)
smodel.releaseFromRead();
}
return expectedErrors;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class AbstractXSLContentAssistProcessor method getCompletionRegion.
/**
* Return the region whose content's require completion. This is something
* of a misnomer as sometimes the user wants to be prompted for contents of
* a non-existent ITextRegion, such as for enumerated attribute values
* following an '=' sign.
*
* Copied from AbstractContentAssist Processor.
*/
protected ITextRegion getCompletionRegion(int documentPosition, Node domnode) {
if (domnode == null) {
return null;
}
ITextRegion region = null;
int offset = documentPosition;
IStructuredDocumentRegion flatNode = null;
IDOMNode node = (IDOMNode) domnode;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
if (node.getStructuredDocument().getLength() == 0) {
return null;
}
ITextRegion result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
while (result == null) {
offset--;
result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
}
return result;
}
IStructuredDocumentRegion startTag = node.getStartStructuredDocumentRegion();
IStructuredDocumentRegion endTag = node.getEndStructuredDocumentRegion();
if ((startTag != null) && (startTag.getStartOffset() <= offset) && (offset < startTag.getStartOffset() + startTag.getLength())) {
flatNode = startTag;
} else if ((endTag != null) && (endTag.getStartOffset() <= offset) && (offset < endTag.getStartOffset() + endTag.getLength())) {
flatNode = endTag;
}
if (flatNode != null) {
region = getCompletionRegion(offset, flatNode);
} else {
flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(offset);
if ((flatNode.getStartOffset() <= documentPosition) && (flatNode.getEndOffset() >= documentPosition)) {
if ((offset == flatNode.getStartOffset()) && (flatNode.getPrevious() != null) && (((flatNode.getRegionAtCharacterOffset(documentPosition) != null) && (flatNode.getRegionAtCharacterOffset(documentPosition).getType() != DOMRegionContext.XML_CONTENT)) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_TAG_OPEN) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN))) {
region = flatNode.getPrevious().getLastRegion();
} else if (flatNode.getEndOffset() == documentPosition) {
region = flatNode.getLastRegion();
} else {
region = flatNode.getFirstRegion();
}
} else {
region = flatNode.getLastRegion();
}
}
return region;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class XMLTableTreeContentProvider method inputChanged.
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// remove our listeners to the old state
if (oldInput != null) {
Document domDoc = (Document) oldInput;
ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
if (mq != null) {
documentManager = mq.getCMDocumentManager();
if (documentManager != null) {
documentManager.removeListener(this);
}
}
}
if ((oldInput != null) && (oldInput instanceof IDOMNode)) {
IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) oldInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
if (factory != null) {
factory.removeListener(viewer);
}
}
if (viewer instanceof StructuredViewer) {
fViewer = null;
} else {
fViewer = (StructuredViewer) viewer;
}
if ((newInput != null) && (newInput instanceof IDOMNode)) {
IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) newInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
if (factory != null) {
factory.addListener(viewer);
}
}
if (newInput != null) {
Document domDoc = (Document) newInput;
ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
if (mq != null) {
documentManager = mq.getCMDocumentManager();
if (documentManager != null) {
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
documentManager.addListener(this);
}
}
}
}
Aggregations