use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class JSONModelImpl method nodesReplaced.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.core.internal.provisional.events.
* IStructuredDocumentListener
* #nodesReplaced(org.eclipse.wst.sse.core.internal
* .provisional.events.StructuredDocumentRegionsReplacedEvent)
*/
@Override
public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) {
if (event == null)
return;
IStructuredDocumentRegionList oldStructuredDocumentRegions = event.getOldStructuredDocumentRegions();
IStructuredDocumentRegionList newStructuredDocumentRegions = event.getNewStructuredDocumentRegions();
JSONModelUpdater updater = getActiveUpdater();
if (updater != null) {
// being updated
try {
updater.replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
}
// checkForReinit();
return;
}
JSONModelNotifier notifier = getModelNotifier();
boolean isChanging = notifier.isChanging();
if (!isChanging)
notifier.beginChanging();
JSONModelParser parser = getModelParser();
setActive(parser);
try {
/* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=486860 */
// this.refresh = true;
// handleRefresh();
boolean reloadModel = false;
// the model is reloaded completely.
if (newStructuredDocumentRegions != null) {
int newCount = newStructuredDocumentRegions.getLength();
for (int i = 0; i < newCount - 1; i++) {
if (newStructuredDocumentRegions.item(i).getType().equals(JSONRegionContexts.JSON_COMMA)) {
IStructuredDocumentRegion nextNode = newStructuredDocumentRegions.item(i).getNext();
while (nextNode != null) {
if (nextNode.getType().equals(JSONRegionContexts.JSON_OBJECT_KEY) || nextNode.getType().equals(JSONRegionContexts.JSON_OBJECT_OPEN) || nextNode.getType().equals(JSONRegionContexts.JSON_ARRAY_OPEN)) {
reloadModel = true;
break;
}
nextNode = nextNode.getNext();
}
}
}
}
if (!reloadModel && oldStructuredDocumentRegions != null && oldStructuredDocumentRegions.getLength() > 0) {
if (oldStructuredDocumentRegions.getLength() > 3 || oldStructuredDocumentRegions.item(0).getType().equals(JSONRegionContexts.JSON_OBJECT_OPEN)) {
// Reload all the model when the first region that will be
// replaced is a JSONObject or if more than 3 regions are
// replaced in the model (a JSONPair is composed by 3 regions,
// this means more that one JSON Pair are replaced in the model)
reloadModel = true;
} else {
// also, always reload the model in case of removing at least one UNDEFINED region
for (int i = 0; !reloadModel && i < oldStructuredDocumentRegions.getLength(); i++) {
if (oldStructuredDocumentRegions.item(i).getType().equals(JSONRegionContexts.UNDEFINED)) {
reloadModel = true;
}
}
}
}
if (reloadModel) {
this.refresh = true;
handleRefresh();
} else {
parser.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);
if (!isChanging) {
notifier.endChanging();
handleRefresh();
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class JSONModelImpl method internalSetNewDocument.
private void internalSetNewDocument(IStructuredDocument structuredDocument) {
if (structuredDocument == null)
return;
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if ((flatNodes == null) || (flatNodes.getLength() == 0)) {
return;
}
if (this.document == null)
// being constructed
return;
JSONModelUpdater updater = getActiveUpdater();
if (updater != null) {
// being updated
try {
updater.replaceStructuredDocumentRegions(flatNodes, null);
} catch (Exception ex) {
Logger.logException(ex);
this.refresh = true;
handleRefresh();
} finally {
setActive(null);
}
// checkForReinit();
return;
}
JSONModelNotifier notifier = getModelNotifier();
boolean isChanging = notifier.isChanging();
// call even if changing to notify doing new model
getModelNotifier().beginChanging(true);
JSONModelParser parser = getModelParser();
setActive(parser);
this.document.removeChildNodes();
try {
parser.replaceStructuredDocumentRegions(flatNodes, null);
} catch (Exception ex) {
Logger.logException(ex);
// meaningless to refresh, because the result might be the same
} finally {
setActive(null);
if (!isChanging) {
getModelNotifier().endChanging();
}
// ignore refresh
this.refresh = false;
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class CSSModelImpl method nodesReplaced.
public void nodesReplaced(StructuredDocumentRegionsReplacedEvent structuredDocumentEvent) {
if (structuredDocumentEvent == null) {
return;
}
IStructuredDocumentRegionList oldStructuredDocumentRegions = structuredDocumentEvent.getOldStructuredDocumentRegions();
IStructuredDocumentRegionList newStructuredDocumentRegions = structuredDocumentEvent.getNewStructuredDocumentRegions();
if (oldStructuredDocumentRegions == null && newStructuredDocumentRegions == null) {
return;
}
fStructuredDocumentUpdate = true;
CSSModelParser parser = getParser();
parser.setStructuredDocumentEvent(structuredDocumentEvent);
if (structuredDocumentEvent.isEntireDocumentReplaced())
parser.replaceDocument(newStructuredDocumentRegions);
else
parser.replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
fStructuredDocumentUpdate = false;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class CSSModelImpl method newModel.
public void newModel(NewDocumentEvent structuredDocumentEvent) {
if (structuredDocumentEvent == null)
return;
IStructuredDocument structuredDocument = structuredDocumentEvent.getStructuredDocument();
if (structuredDocument == null)
return;
// this should not happen, but for the case
if (structuredDocument != getStructuredDocument())
setStructuredDocument(structuredDocument);
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if (flatNodes == null)
return;
if (getDocument() == null)
return;
fStructuredDocumentUpdate = true;
((CSSStructuredDocumentRegionContainer) getDocument()).removeChildNodes();
CSSModelParser parser = getParser();
parser.setStructuredDocumentEvent(structuredDocumentEvent);
parser.replaceStructuredDocumentRegions(flatNodes, null);
fStructuredDocumentUpdate = false;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.
the class TestStructuredDocument method testGetRegionList.
public void testGetRegionList() throws IOException, CoreException {
IStructuredModel model = getTestModel();
try {
IStructuredDocument sDoc = model.getStructuredDocument();
IStructuredDocumentRegionList regions = sDoc.getRegionList();
assertNotNull("couldn't get region list", regions);
assertEquals(17, regions.getLength());
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
Aggregations