Search in sources :

Example 1 with IModelProvideAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter in project webtools.sourceediting by eclipse.

the class AbstractStyleSheetAdapter method removed.

/**
 */
public void removed() {
    ICSSModel currentModel = getModel();
    setModel(null);
    // get ModelProvideAdapter
    IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
    if (adapter != null)
        adapter.modelRemoved(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 2 with IModelProvideAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter in project webtools.sourceediting by eclipse.

the class LinkElementAdapter method getModel.

/**
 */
public ICSSModel getModel() {
    ICSSModel model = getExistingModel();
    if (this.replaceModel) {
        ICSSModel oldModel = model;
        try {
            model = retrieveModel();
            setModel(model);
            // release old model
            if (oldModel != null) {
                // get ModelProvideAdapter
                IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
                if (adapter != null)
                    adapter.modelRemoved(oldModel);
            }
        } finally {
            if (oldModel != null)
                oldModel.releaseFromRead();
        }
        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)

Example 3 with IModelProvideAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter in project webtools.sourceediting by eclipse.

the class LinkElementAdapter method removed.

/**
 */
public void removed() {
    ICSSModel model = getExistingModel();
    if (model != null) {
        try {
            setModel(null);
            // get ModelProvideAdapter
            IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
            if (adapter != null)
                adapter.modelRemoved(model);
        } finally {
            model.releaseFromRead();
        }
    }
    this.replaceModel = false;
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)

Example 4 with IModelProvideAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter in project webtools.sourceediting by eclipse.

the class LinkElementAdapter method retrieveModel.

/**
 */
private ICSSModel retrieveModel() {
    if (!isValidAttribute()) {
        return null;
    }
    // null,attr check is done in isValidAttribute()
    Element element = getElement();
    // $NON-NLS-1$
    String href = element.getAttribute("href");
    IDOMModel baseModel = ((IDOMNode) element).getModel();
    if (baseModel == null)
        return null;
    Object id = baseModel.getId();
    if (!(id instanceof String))
        return null;
    // String base = (String)id;
    // get ModelProvideAdapter
    IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(ModelProvideAdapterClass);
    URLModelProvider provider = new URLModelProvider();
    try {
        IStructuredModel newModel = provider.getModelForRead(baseModel, href);
        if (newModel == null)
            return null;
        if (!(newModel instanceof ICSSModel)) {
            newModel.releaseFromRead();
            return null;
        }
        // notify adapter
        if (adapter != null)
            adapter.modelProvided(newModel);
        return (ICSSModel) newModel;
    } catch (UnsupportedEncodingException e) {
    } catch (IOException e) {
    }
    return null;
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 5 with IModelProvideAdapter

use of org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter in project webtools.sourceediting by eclipse.

the class CSSImportRuleImpl method getStyleSheet.

/**
 * The style sheet referred to by this rule, if it has been loaded. The
 * value of this attribute is <code>null</code> if the style sheet has
 * not yet been loaded or if it will not be loaded (e.g. if the style
 * sheet is for a media type not supported by the user agent).
 */
public CSSStyleSheet getStyleSheet() {
    if (fDirty) {
        // NOTE: try/catch block is a TEMP fix to avoid compile errors:
        try {
            closeStyleSheet();
            if (getHref() == null || getHref().length() <= 0) {
                fDirty = false;
                return null;
            }
            IStructuredModel baseModel = getOwnerDocument().getModel();
            if (getOwnerDocument().getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
                // case
                // STYLE
                // tag
                baseModel = ((IDOMNode) getOwnerDocument().getModel().getOwnerDOMNode()).getModel();
            }
            // get ModelProvideAdapter
            IModelProvideAdapter adapter = (IModelProvideAdapter) getAdapterFor(IModelProvideAdapter.class);
            // if (getOwnerDocument().getModel().getStyleSheetType() ==
            // ICSSModel.EMBEDDED) { // case STYLE tag
            // adapter = (ModelProvideAdapter)
            // ((INodeNotifier)getOwnerDocument().getModel().getOwnerDOMNode()).getAdapterFor(ModelProvideAdapter.class);
            // }
            // load model from IModelManager
            URLModelProviderCSS provider = new URLModelProviderCSS();
            IStructuredModel newModel = provider.getModelForRead(baseModel, getHref());
            fDirty = false;
            if (newModel == null)
                return null;
            if (!(newModel instanceof ICSSModel)) {
                newModel.releaseFromRead();
                return null;
            }
            // notify adapter
            if (adapter != null)
                adapter.modelProvided(newModel);
            fStyleSheet = (ICSSStyleSheet) ((ICSSModel) newModel).getDocument();
            if (fStyleSheet != null)
                fStyleSheet.getModel().addStyleListener(getOwnerDocument().getModel());
        } catch (java.io.IOException e) {
            Logger.logException(e);
        }
    }
    return fStyleSheet;
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) URLModelProviderCSS(org.eclipse.wst.css.core.internal.util.URLModelProviderCSS) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IModelProvideAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter)10 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)8 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URLModelProviderCSS (org.eclipse.wst.css.core.internal.util.URLModelProviderCSS)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1 Element (org.w3c.dom.Element)1