Search in sources :

Example 1 with CSSPropertyContext

use of org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testInsertPropertyInExistingRule.

/**
 * To test https://bugs.eclipse.org/298111
 */
public void testInsertPropertyInExistingRule() {
    ICSSModel model = FileUtil.createModel();
    try {
        String originalDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "}";
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(originalDocument);
        IndexedRegion indexedRegion = model.getIndexedRegion(28);
        assertTrue("Indexed region should be an ICSSStyleRule", indexedRegion instanceof ICSSStyleRule);
        ICSSStyleRule rule = (ICSSStyleRule) indexedRegion;
        ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) rule.getStyle();
        declaration.setProperty("color", "#008040", null);
        CSSPropertyContext context = new CSSPropertyContext(declaration);
        context.applyModified(declaration);
        String newDocument = structuredDocument.get();
        String expectedNewDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "\tcolor: #008040\r\n" + "}";
        assertEquals("The updated CSS document does not equal the expected", expectedNewDocument, newDocument);
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule) CSSPropertyContext(org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)

Example 2 with CSSPropertyContext

use of org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext in project webtools.sourceediting by eclipse.

the class TestCSSDecl method testStandaloneCSSDecl.

// commenting out this test because decl.setCssText() is not an implemented method
// public void testDecl() {
// CSSPropertyContext context = new CSSPropertyContext();
// ICSSStyleDeclaration decl = CSSStyleDeclarationFactory.getInstance().createStyleDeclaration();
// context.initialize(decl);
// decl.setCssText(getString() != null ? getString() : "");//$NON-NLS-1$
// }
// private String getString() {
// return "body {}";
// }
public void testStandaloneCSSDecl() {
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=202615
    CSSPropertyContext context = new CSSPropertyContext();
    ICSSStyleDeclaration decl = CSSStyleDeclarationFactory.getInstance().createStyleDeclaration();
    context.initialize(decl);
    String cssText = decl.getCssText();
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("standalone css node was not initialized", "", cssText);
    // $NON-NLS-1$
    context.setMargin("auto");
    // $NON-NLS-1$
    context.setColor("red");
    // $NON-NLS-1$
    context.setBorder("thick");
    context.applyFull(decl);
    cssText = decl.getCssText();
    // $NON-NLS-1$
    String expected = "color: red; border: thick; margin: auto";
    // $NON-NLS-1$
    assertEquals("standalone css node's properties were not set as expected", expected, cssText);
}
Also used : ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) CSSPropertyContext(org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)

Aggregations

ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)2 CSSPropertyContext (org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)2 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1