Search in sources :

Example 76 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class StyleElementAdapter method createModel.

/**
 */
protected ICSSModel createModel(boolean addListener) {
    if (!isValidAttribute()) {
        return null;
    }
    ICSSModel model = super.createModel(addListener);
    if (!addListener)
        return model;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (structuredDocument == null)
        return null;
    structuredDocument.addDocumentChangedListener(this);
    return model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 77 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class StyleElementAdapter method getModel.

/**
 */
public ICSSModel getModel() {
    ICSSModel model = getExistingModel();
    if (this.replaceModel) {
        ICSSModel oldModel = model;
        model = createModel(false);
        // need to set before contentChanged()
        setModel(model, false);
        contentChanged();
        // from super.createModel()
        // get ModelProvideAdapter
        IModelProvideAdapter modelProvideAdapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
        // notify adapter
        if (modelProvideAdapter != null)
            modelProvideAdapter.modelProvided(model);
        // from createModel()
        IStructuredDocument structuredDocument = null;
        if (model != null)
            structuredDocument = model.getStructuredDocument();
        if (structuredDocument == null)
            return null;
        structuredDocument.addDocumentChangedListener(this);
        // from setModel()
        if (oldModel != null)
            oldModel.removeStyleListener(this);
        if (model != null)
            model.addStyleListener(this);
        if (oldModel != null) {
            // get ModelProvideAdapter
            IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
            if (adapter != null) {
                adapter.modelRemoved(oldModel);
            }
        }
        this.replaceModel = false;
    }
    return model;
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 78 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel 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 79 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class AbstractStyleSheetAdapter method released.

/**
 */
public void released() {
    ICSSModel currentModel = getModel();
    // get ModelProvideAdapter
    IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
    setElement(null);
    setModel(null);
    if (adapter != null)
        adapter.modelReleased(currentModel);
    if (currentModel != null)
        currentModel.releaseFromRead();
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)

Example 80 with ICSSModel

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.

the class EmbeddedCSSFormatter method getCSSContent.

/**
 */
private String getCSSContent(IDOMNode text) {
    ICSSModel model = getCSSModel(text);
    if (model == null)
        return null;
    ICSSNode document = model.getDocument();
    if (document == null)
        return null;
    INodeNotifier notifier = (INodeNotifier) document;
    CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
    // try another way to get formatter
    if (formatter == null)
        formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
    if (formatter == null)
        return null;
    StringBuffer buffer = formatter.format(document);
    if (buffer == null)
        return null;
    return buffer.toString();
}
Also used : CSSSourceFormatter(org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Aggregations

ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)82 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)41 CSSRule (org.w3c.dom.css.CSSRule)21 CSSRuleList (org.w3c.dom.css.CSSRuleList)20 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)14 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)14 CSSValue (org.w3c.dom.css.CSSValue)14 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IModelProvideAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter)8 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)7 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)7 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)7 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Element (org.w3c.dom.Element)6