Search in sources :

Example 66 with IStructuredDocumentRegionList

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);
}
Also used : IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 67 with IStructuredDocumentRegionList

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);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) Element(org.w3c.dom.Element) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 68 with IStructuredDocumentRegionList

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();
        }
    }
}
Also used : IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) DOMException(org.w3c.dom.DOMException)

Aggregations

IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)68 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)11 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)3 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)3 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 DOMException (org.w3c.dom.DOMException)2 Element (org.w3c.dom.Element)2 NodesEvent (org.eclipse.wst.dtd.core.internal.event.NodesEvent)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 NewDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent)1 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)1 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)1 RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)1 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)1 CoreNodeList (org.eclipse.wst.sse.core.internal.text.CoreNodeList)1