Search in sources :

Example 71 with ICSSModel

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

Example 72 with ICSSModel

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

the class JSPedCSSSourceParserTest method readModelOpen.

private ICSSModel readModelOpen(String filename) throws IOException {
    String source = createString(FILES_DIR, filename);
    // $NON-NLS-1$
    ICSSModel model = createModel(filename.endsWith("jspf"));
    IStructuredDocument document = model.getStructuredDocument();
    document.replaceText(null, 0, 0, source);
    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 73 with ICSSModel

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

the class JSPedCSSSourceParserTest method readModelInsert.

private ICSSModel readModelInsert(String filename) throws IOException {
    String source = createString(FILES_DIR, filename);
    // $NON-NLS-1$
    ICSSModel model = createModel(filename.endsWith("jspf"));
    IStructuredDocument document = model.getStructuredDocument();
    for (int i = 0; i < source.length(); i++) {
        int textIndex = source.length() - i - 1;
        document.replaceText(null, 0, 0, source.substring(textIndex, textIndex + 1));
    }
    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 74 with ICSSModel

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

the class JSPedCSSSourceParserTest method sourceParserTest.

private void sourceParserTest(String filename, String mode) throws IOException {
    ICSSModel model = null;
    if (mode.equals(MODE_OPEN)) {
        model = readModelOpen(filename);
    } else if (mode.equals(MODE_APPEND)) {
        model = readModelAppend(filename);
    } else if (mode.equals(MODE_INSERT)) {
        model = readModelInsert(filename);
    }
    String result = dumpRegions(model.getStructuredDocument());
    // $NON-NLS-1$
    compareResult(result, "JSPedCSSSourceParserTest-" + filename);
    closeModel(model);
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)

Example 75 with ICSSModel

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

the class JSPedCSSSourceParserTest method readModelAppend.

private ICSSModel readModelAppend(String filename) throws IOException {
    String source = createString(FILES_DIR, filename);
    // $NON-NLS-1$
    ICSSModel model = createModel(filename.endsWith("jspf"));
    IStructuredDocument document = model.getStructuredDocument();
    for (int i = 0; i < source.length(); i++) {
        document.replaceText(null, i, 0, source.substring(i, i + 1));
    }
    return model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

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