diff options
Diffstat (limited to 'plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css')
7 files changed, 333 insertions, 16 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF index bf7ebbcc105..472718fa1a9 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Export-Package: org.eclipse.papyrus.infra.gmfdiag.css, org.eclipse.papyrus.infra.gmfdiag.css.spi, org.eclipse.papyrus.infra.gmfdiag.css.style, org.eclipse.papyrus.infra.gmfdiag.css.style.impl, - org.eclipse.papyrus.infra.gmfdiag.css.theme + org.eclipse.papyrus.infra.gmfdiag.css.theme, + org.eclipse.papyrus.internal.infra.gmfdiag.css.xml.engine;x-internal:=true Require-Bundle: org.eclipse.e4.ui.css.core;bundle-version="[0.11.0,1.0.0)", org.w3c.css.sac;bundle-version="[1.3.0,2.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf.appearance;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, @@ -32,7 +33,7 @@ Require-Bundle: org.eclipse.e4.ui.css.core;bundle-version="[0.11.0,1.0.0)", org.eclipse.papyrus.infra.architecture.representation;bundle-version="[2.0.0,3.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy -Bundle-Version: 2.2.1.qualifier +Bundle-Version: 2.3.0.qualifier Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.css.Activator diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/pom.xml b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/pom.xml index 0faaee1c716..787f390379d 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/pom.xml +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.infra.gmfdiag.css</artifactId> - <version>2.2.1-SNAPSHOT</version> + <version>2.3.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project>
\ No newline at end of file diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/CssSvgPostProcessor.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/CssSvgPostProcessor.java index e979ddbc6ab..cde4b9e5dd4 100755 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/CssSvgPostProcessor.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/CssSvgPostProcessor.java @@ -26,7 +26,6 @@ import java.util.WeakHashMap; import org.eclipse.e4.ui.css.core.engine.CSSEngine; import org.eclipse.e4.ui.css.core.impl.dom.CSSStyleRuleImpl; import org.eclipse.e4.ui.css.core.impl.sac.ExtendedSelector; -import org.eclipse.e4.ui.css.xml.engine.CSSXMLEngineImpl; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -37,6 +36,7 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart; import org.eclipse.papyrus.infra.gmfdiag.common.handler.RefreshHandler; import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.SVGPostProcessor; +import org.eclipse.papyrus.internal.infra.gmfdiag.css.xml.engine.CSSXMLEngineImpl; import org.eclipse.ui.IEditorPart; import org.w3c.css.sac.SelectorList; import org.w3c.dom.Element; @@ -97,11 +97,11 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar * Initializes this processor */ public CssSvgPostProcessor() { - engine = new CSSXMLEngineImpl(); - relativePaths = new WeakHashMap<Resource, Map<String, URI>>(); - loadedSheets = new ArrayList<URI>(); - failedSheets = new ArrayList<URI>(); - styledDocuments = new HashMap<SVGDocument, Map<Element, Map<String, String>>>(); + engine = new CSSXMLEngineImpl(); // FIXME this has been cloned from the Platform_UI repository to fix a problem introduced by Bug 534764 + relativePaths = new WeakHashMap<>(); + loadedSheets = new ArrayList<>(); + failedSheets = new ArrayList<>(); + styledDocuments = new HashMap<>(); RefreshHandler.register(this); } @@ -202,7 +202,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar Map<String, URI> resMap = relativePaths.get(model.eResource()); if (resMap == null) { - resMap = new HashMap<String, URI>(); + resMap = new HashMap<>(); relativePaths.put(model.eResource(), resMap); } URI canonical = resMap.get(uri); @@ -237,7 +237,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar List<CSSStyleRule> rules = getAllRulesIn(engine.getDocumentCSS()); Map<Element, Map<String, String>> originals = styledDocuments.get(document); if (originals == null) { - originals = new HashMap<Element, Map<String, String>>(); + originals = new HashMap<>(); styledDocuments.put(document, originals); } applyStyles(document.getDocumentElement(), rules, originals); @@ -268,7 +268,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar style = getBaseStyle(element); originals.put(element, style); } - style = new HashMap<String, String>(style); + style = new HashMap<>(style); // get the applicable CSS rules List<CSSStyleRule> applicable = getApplicableRules(element, rules); @@ -300,7 +300,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar * @return The CSS style rules */ private List<CSSStyleRule> getAllRulesIn(DocumentCSS css) { - List<CSSStyleRule> result = new ArrayList<CSSStyleRule>(); + List<CSSStyleRule> result = new ArrayList<>(); for (int i = 0; i != css.getStyleSheets().getLength(); i++) { StyleSheet ss = css.getStyleSheets().item(i); if (ss instanceof CSSStyleSheet) { @@ -326,7 +326,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar * @return The matching rules */ private List<CSSStyleRule> getApplicableRules(Element svgElement, List<CSSStyleRule> rules) { - List<CSSStyleRule> matching = new ArrayList<CSSStyleRule>(); + List<CSSStyleRule> matching = new ArrayList<>(); // Matches the rules using the selectors for (CSSStyleRule rule : rules) { @@ -363,7 +363,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar } } } - List<CSSStyleRule> result = new ArrayList<CSSStyleRule>(); + List<CSSStyleRule> result = new ArrayList<>(); for (int i = 0; i != matching.size(); i++) { if (available[i]) { result.add(matching.get(i)); @@ -380,7 +380,7 @@ public class CssSvgPostProcessor implements SVGPostProcessor, IRefreshHandlerPar * @return The styling properties in the DOM */ private Map<String, String> getBaseStyle(Element element) { - HashMap<String, String> result = new HashMap<String, String>(); + HashMap<String, String> result = new HashMap<>(); String styleValue = element.getAttribute("style"); if (styleValue != null && !styleValue.isEmpty()) { String[] props = styleValue.split(";"); diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyBackgroundXMLHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyBackgroundXMLHandler.java new file mode 100755 index 00000000000..90b6735b00a --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyBackgroundXMLHandler.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2008 -2014 Angelo Zerr and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 422702 + *******************************************************************************/ +package org.eclipse.papyrus.internal.infra.gmfdiag.css.xml.engine; + +import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyBackgroundHandler; +import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyBackgroundHandler; +import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.w3c.dom.Element; +import org.w3c.dom.css.CSSValue; + +/** + * + * @since 2.3.0 + */ +// FIXME this has been cloned from the Platform_UI repository to fix a problem introduced by Bug 534764 +public class CSSPropertyBackgroundXMLHandler extends + AbstractCSSPropertyBackgroundHandler { + + public final static ICSSPropertyBackgroundHandler INSTANCE = new CSSPropertyBackgroundXMLHandler(); + + @Override + public boolean applyCSSProperty(Object node, String property, + CSSValue value, String pseudo, CSSEngine engine) throws Exception { + if (node instanceof Element) { + super.applyCSSProperty(node, property, value, pseudo, + engine); + return true; + } + return false; + } + + @Override + public String retrieveCSSPropertyBackgroundAttachment(Object element, + String pseudo, CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyBackgroundColor(Object element, + String pseudo, CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyBackgroundImage(Object element, + String pseudo, CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyBackgroundPosition(Object element, + String pseudo, CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyBackgroundRepeat(Object element, + String pseudo, CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + +}
\ No newline at end of file diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyFontXMLHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyFontXMLHandler.java new file mode 100755 index 00000000000..f64ba6c5b34 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyFontXMLHandler.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2014 Angelo Zerr and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 422702 + *******************************************************************************/ +package org.eclipse.papyrus.internal.infra.gmfdiag.css.xml.engine; + +import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyFontHandler; +import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyFontHandler; +import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.css.CSSPrimitiveValue; +import org.w3c.dom.css.CSSValue; + +/** + * + * @since 2.3.0 + */ +// FIXME this has been cloned from the Platform_UI repository to fix a problem introduced by Bug 534764 +public class CSSPropertyFontXMLHandler extends AbstractCSSPropertyFontHandler { + + public final static ICSSPropertyFontHandler INSTANCE = new CSSPropertyFontXMLHandler(); + + @Override + public boolean applyCSSProperty(Object node, String property, + CSSValue value, String pseudo, CSSEngine engine) throws Exception { + if (node instanceof Element && ((Node) node).getOwnerDocument() != null) { + super.applyCSSProperty(node, property, value, pseudo, + engine); + return true; + } + return false; + } + + @Override + public void applyCSSPropertyFontSize(Object node, CSSValue value, + String pseudo, CSSEngine engine) throws Exception { + if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + Element element = (Element) node; + // Add size attribute + int size = (int) ((CSSPrimitiveValue) value) + .getFloatValue(CSSPrimitiveValue.CSS_PT); + element.setAttribute("size", size + ""); + } + } + + @Override + public void applyCSSPropertyFontWeight(Object node, CSSValue value, + String pseudo, CSSEngine engine) throws Exception { + if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + Element element = (Element) node; + String weight = ((CSSPrimitiveValue) value).getStringValue(); + if ("bold".equals(weight.toLowerCase())) { + insertElement(element, "b"); + } + } + } + + @Override + public void applyCSSPropertyFontStyle(Object node, CSSValue value, + String pseudo, CSSEngine engine) throws Exception { + if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + Element element = (Element) node; + String style = ((CSSPrimitiveValue) value).getStringValue(); + if ("italic".equals(style)) { + insertElement(element, "i"); + } + } + } + + @Override + public String retrieveCSSPropertyFontAdjust(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyFontFamily(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyFontSize(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyFontStretch(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyFontStyle(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyFontVariant(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public String retrieveCSSPropertyFontWeight(Object element, String pseudo, + CSSEngine engine) throws Exception { + // TODO Auto-generated method stub + return null; + } + + private void insertElement(Element element, String elementName) { + Element b = element.getOwnerDocument().createElement(elementName); + NodeList nodes = element.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + b.appendChild(node.cloneNode(true)); + node.getParentNode().removeChild(node); + } + element.appendChild(b); + } + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyTextXMLHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyTextXMLHandler.java new file mode 100755 index 00000000000..8604871fa9e --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSPropertyTextXMLHandler.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2013 Angelo Zerr and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 422702 + *******************************************************************************/ +package org.eclipse.papyrus.internal.infra.gmfdiag.css.xml.engine; + +import org.eclipse.e4.ui.css.core.dom.properties.css2.AbstractCSSPropertyTextHandler; +import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyTextHandler; +import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.w3c.dom.Element; +import org.w3c.dom.css.CSSPrimitiveValue; +import org.w3c.dom.css.CSSValue; + +/** + * + * @since 2.3.0 + */ +// FIXME this has been cloned from the Platform_UI repository to fix a problem introduced by Bug 534764 +public class CSSPropertyTextXMLHandler extends AbstractCSSPropertyTextHandler { + + public final static ICSSPropertyTextHandler INSTANCE = new CSSPropertyTextXMLHandler(); + + @Override + public boolean applyCSSProperty(Object node, String property, + CSSValue value, String pseudo, CSSEngine engine) throws Exception { + if (node instanceof Element) { + super.applyCSSProperty(node, property, value, pseudo, + engine); + return true; + } + return false; + } + + @Override + public void applyCSSPropertyColor(Object node, CSSValue value, + String pseudo, CSSEngine engine) throws Exception { + if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { + // Add color attribute + Element element = (Element) node; + CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value; + element.setAttribute("color", primitiveValue.getStringValue()); + } + } + + public String retrieveCSSPropertyColor(Object node, CSSEngine engine) + throws Exception { + Element element = (Element) node; + return element.getAttribute("color"); + } + +} diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSXMLEngineImpl.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSXMLEngineImpl.java new file mode 100755 index 00000000000..f60b6a90f46 --- /dev/null +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/internal/infra/gmfdiag/css/xml/engine/CSSXMLEngineImpl.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008, 2014 Angelo Zerr and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.papyrus.internal.infra.gmfdiag.css.xml.engine; + +import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyBackgroundHandler; +import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyFontHandler; +import org.eclipse.e4.ui.css.core.dom.properties.css2.ICSSPropertyTextHandler; +import org.eclipse.e4.ui.css.core.engine.CSSEngine; +import org.eclipse.e4.ui.css.core.impl.engine.CSSEngineImpl; + +/** + * {@link CSSEngine} implementation to apply style sheet to XML DOM. + * + * @since 2.3.0 + */ +// FIXME this has been cloned from the Platform_UI repository to fix a problem introduced by Bug 534764 +public class CSSXMLEngineImpl extends CSSEngineImpl { + + public CSSXMLEngineImpl() { + // Register XML CSS Property Background Handler + super.registerCSSPropertyHandler(ICSSPropertyBackgroundHandler.class, + CSSPropertyBackgroundXMLHandler.INSTANCE); + // Register XML CSS Property Text Handler + super.registerCSSPropertyHandler(ICSSPropertyTextHandler.class, + CSSPropertyTextXMLHandler.INSTANCE); + // Register XML CSS Property Font Handler + super.registerCSSPropertyHandler(ICSSPropertyFontHandler.class, + CSSPropertyFontXMLHandler.INSTANCE); + } + + @Override + public void reapply() { + // TODO Auto-generated method stub + } +}
\ No newline at end of file |