use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method newModel.
/**
* Implementing IStructuredDocumentListener's method
* Event from CSS Flat Model
*/
public void newModel(NewDocumentEvent event) {
if (event == null)
return;
if (event.getOriginalRequester() == getRequesterH2C())
return;
IStructuredDocument structuredDocument = event.getStructuredDocument();
if (structuredDocument == null)
return;
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if (flatNodes == null)
return;
replaceStructuredDocumentRegions(flatNodes, null);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method changeStructuredDocumentRegion.
/**
* Preparation of applying changes from CSS sub-model to HTML model
*/
private void changeStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
if (flatNode == null)
return;
Element element = getElement();
if (element == null)
return;
ICSSModel model = getExistingModel();
if (model == null)
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return;
// get old content length
Node child = element.getFirstChild();
if (child == null || child.getNodeType() != Node.TEXT_NODE)
return;
IDOMNode content = (IDOMNode) child;
int oldLength = content.getEndOffset() - content.getStartOffset();
// get new content length
int newLength = 0;
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if (flatNodes != null) {
int count = flatNodes.getLength();
if (count > 0) {
IStructuredDocumentRegion last = flatNodes.item(count - 1);
if (last != null)
newLength = last.getEnd();
}
}
int offset = flatNode.getStart();
int end = flatNode.getEnd();
int diff = oldLength - newLength;
int length = end - offset + diff;
String data = flatNode.getText();
replaceData(offset, length, data);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class DOMModelImpl method nodesReplaced.
/**
* nodesReplaced method
*/
public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) {
if (event == null)
return;
IStructuredDocumentRegionList oldStructuredDocumentRegions = event.getOldStructuredDocumentRegions();
IStructuredDocumentRegionList newStructuredDocumentRegions = event.getNewStructuredDocumentRegions();
XMLModelUpdater updater = getActiveUpdater();
if (updater != null) {
// being updated
try {
updater.replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
} catch (Exception ex) {
if (ex.getClass().equals(StructuredDocumentRegionManagementException.class)) {
Logger.traceException(TRACE_PARSER_MANAGEMENT_EXCEPTION, ex);
} else {
Logger.logException(ex);
}
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
}
// checkForReinit();
return;
}
XMLModelNotifier notifier = getModelNotifier();
boolean isChanging = notifier.isChanging();
if (!isChanging)
notifier.beginChanging();
XMLModelParser parser = getModelParser();
setActive(parser);
try {
parser.replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
if (!isChanging) {
notifier.endChanging();
handleRefresh();
}
}
}
Aggregations