Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFanch BONNABESSE2016-11-10 13:23:54 +0000
committerGerrit Code Review @ Eclipse.org2016-11-30 14:58:22 +0000
commit083ab686c404441775a727abe08b12451dbd33f1 (patch)
treea2350c7320bd521bfbe5186af5e569f138d5fe4c /plugins/infra
parenta3ea7ef9891a5d83d0de788df4bafcfcfb50b453 (diff)
downloadorg.eclipse.papyrus-083ab686c404441775a727abe08b12451dbd33f1.tar.gz
org.eclipse.papyrus-083ab686c404441775a727abe08b12451dbd33f1.tar.xz
org.eclipse.papyrus-083ab686c404441775a727abe08b12451dbd33f1.zip
Bug 502531: [CSS] Have a support to insert images in the compartment
symbol Add the property 'imagePath' on the CSS to show all type of image. Change-Id: I098a3a224c93da85e997991fbcf23dc3d7e2fd01 Signed-off-by: Fanch BONNABESSE <fanch.bonnabesse@all4tec.net> Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java750
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/provider/CSSCustomStyleDelegate.java8
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css3.xtext.ui/src/org/eclipse/papyrus/infra/gmfdiag/css3/ui/contentassist/CustomCSSProposalProvider.java7
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ShapeDisplayCompartmentEditPart.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java13
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecorator.java2
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/StyleBasedShapeProvider.java76
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java18
8 files changed, 466 insertions, 410 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java
index 0abd6087113..216898a3a0a 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java
@@ -1,375 +1,375 @@
-/*****************************************************************************
- * Copyright (c) 2012, 2015 CEA LIST, Christian W. Damus, 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 461629
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.css.configuration.handler;
-
-import static org.eclipse.papyrus.infra.gmfdiag.css.configuration.helper.DiagramTypeHelper.getDiagramType;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.emf.common.util.Enumerator;
-import org.eclipse.emf.ecore.EDataType;
-import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.NamedStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.Style;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.gmf.runtime.notation.datatype.GradientData;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
-import org.eclipse.papyrus.infra.gmfdiag.css.configuration.Activator;
-import org.eclipse.papyrus.infra.gmfdiag.css.engine.BaseCSSEngine;
-import org.eclipse.papyrus.infra.gmfdiag.css.provider.CustomStyle;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.AttributeSelector;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.CSSFactory;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ClassSelector;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.CssSelector;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.CssTok;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ElementSelector;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.charset;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.css_declaration;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.css_property;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ruleset;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.selector;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.simple_selector;
-import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.stylesheet;
-import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Shell;
-
-
-public abstract class AbstractStyleHandler extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) {
- ISelection selection;
- try {
- selection = ServiceUtilsForHandlers.getInstance().getNestedActiveIEditorPart(event).getSite().getSelectionProvider().getSelection();
- if (selection.isEmpty()) {
- return null;
- }
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return null;
- }
-
- if (!(selection instanceof IStructuredSelection)) {
- return null;
- }
-
- IStructuredSelection sSelection = (IStructuredSelection) selection;
- Object element = sSelection.getFirstElement();
-
- View view = NotationHelper.findView(element);
- if (view == null) {
- Activator.log.warn("Cannot create a Style from the selected element ; the element is not a View");
- return null;
- }
-
- Shell parentShell = ((Event) event.getTrigger()).widget.getDisplay().getActiveShell();
-
- if (view.getElement() == null || view instanceof Diagram) {
- MessageDialog.open(MessageDialog.WARNING, parentShell, "Style error", "The selected element's style cannot be exported", SWT.NONE);
- return null;
- }
-
- Map<css_declaration, Boolean> declarations = handleStyles(view);
- Map<AttributeSelector, Boolean> conditions = handleSemantic(view);
-
- String selectorName = view.getElement().eClass().getName();
-
- AbstractStyleDialog dialog = createStyleDialog(parentShell, declarations, conditions, selectorName, view);
-
- if (dialog.open() != Window.OK) {
- return null;
- }
-
- ruleset ruleset = getRuleset(dialog);
- selector baseSelector = CSSFactory.eINSTANCE.createselector();
- simple_selector simple_selector = createSimpleElementSelector(selectorName, !dialog.useSelectorName());
-
- baseSelector.getSimpleselectors().add(simple_selector);
-
- if (dialog.getDiagramRestriction()) {
- String diagramType = getDiagramType(view.getDiagram());
- selector compositeSelector = CSSFactory.eINSTANCE.createselector();
- compositeSelector.setSelector(baseSelector);
-
-
- simple_selector diagramSelector = createSimpleElementSelector(diagramType, false);
-
- compositeSelector.getSimpleselectors().add(diagramSelector);
-
- ruleset.getSelectors().add(compositeSelector);
- } else {
- ruleset.getSelectors().add(baseSelector);
- }
-
- if (dialog.getCSSClass() != null) {
- String cssClass = dialog.getCSSClass();
- ClassSelector classCondition = CSSFactory.eINSTANCE.createClassSelector();
- classCondition.setName(cssClass);
- simple_selector.getSubSelectors().add(classCondition);
- }
-
- for (CssSelector condition : conditions.keySet()) {
- if (conditions.get(condition)) {
- simple_selector.getSubSelectors().add(condition);
- }
- }
-
- for (css_declaration declaration : declarations.keySet()) {
- if (declarations.get(declaration)) {
- ruleset.getDeclarations().add(declaration);
- }
- }
-
- stylesheet xtextStylesheet = getStyleSheet(dialog, view);
-
- if (xtextStylesheet == null) {
- return null;
- }
-
- Resource resource = xtextStylesheet.eResource();
-
- if (!xtextStylesheet.getRuleset().contains(ruleset)) {
- xtextStylesheet.getRuleset().add(ruleset);
- }
-
- try {
- resource.save(new HashMap<>());
- BaseCSSEngine.INSTANCE.reset();
- DiagramHelper.forceRefresh();
- } catch (IOException ex) {
- Activator.log.error(ex);
- MessageDialog.open(MessageDialog.ERROR, parentShell, "Style error", "An unexpected error occured while trying to save the Stylesheet", SWT.NONE);
- } catch (Exception ex) {
- Activator.log.error(ex);
- MessageDialog.open(MessageDialog.ERROR, parentShell, "Style error", "An unexpected error occured while trying to save the Stylesheet", SWT.NONE);
- }
-
- return null;
- }
-
- protected simple_selector createSimpleElementSelector(String elementName, boolean universal) {
- simple_selector simple_selector = CSSFactory.eINSTANCE.createsimple_selector();
-
- if (universal) {
- simple_selector.setUniversal(CSSFactory.eINSTANCE.createUniversalSelector());
- } else {
- ElementSelector elementSelector = CSSFactory.eINSTANCE.createElementSelector();
- elementSelector.setName(elementName);
- simple_selector.setElement(elementSelector);
- }
-
- return simple_selector;
- }
-
- protected abstract AbstractStyleDialog createStyleDialog(Shell shell, Map<css_declaration, Boolean> declarations, Map<AttributeSelector, Boolean> conditions, String selectorName, View context);
-
- protected abstract ruleset getRuleset(AbstractStyleDialog dialog);
-
- protected abstract stylesheet getStyleSheet(AbstractStyleDialog dialog, View contextView);
-
- protected Map<css_declaration, Boolean> handleStyles(View view) {
- Map<css_declaration, Boolean> declarations = new LinkedHashMap<>();
-
- for (Object styleObject : view.getStyles()) {
- Style style = (Style) styleObject;
- declarations.putAll(handleStyle(style));
- }
-
- if (view instanceof Style) {
- declarations.putAll(handleStyle((Style) view));
- }
-
- if (view instanceof CustomStyle) {
- declarations.putAll(handleCustomStyle((CustomStyle) view, view));
- }
-
- return declarations;
- }
-
- protected Map<AttributeSelector, Boolean> handleSemantic(View view) {
- Map<AttributeSelector, Boolean> result = new LinkedHashMap<>();
-
- EObject semanticElement = view.getElement();
-
- for (EStructuralFeature feature : semanticElement.eClass().getEAllStructuralFeatures()) {
- if (isBoolean(feature) || isInteger(feature) || feature.getEType() instanceof EEnum) {
- AttributeSelector attributeCondition = CSSFactory.eINSTANCE.createAttributeSelector();
-
- attributeCondition.setName(feature.getName());
- attributeCondition.setOp("=");
- attributeCondition.setValue(semanticElement.eGet(feature).toString());
-
- boolean check = semanticElement.eGet(feature) != feature.getDefaultValue();
-
- result.put(attributeCondition, check);
- }
- }
-
- return result;
- }
-
- protected boolean isBoolean(EStructuralFeature feature) {
- if (feature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || feature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
- return true;
- }
-
- if (feature.getEType() instanceof EDataType) {
- EDataType datatype = (EDataType) feature.getEType();
- return datatype.getName().equals("Boolean");
- }
-
- return false;
- }
-
- protected boolean isString(EStructuralFeature feature) {
- return feature.getEType() == EcorePackage.eINSTANCE.getEString();
- }
-
- protected boolean isInteger(EStructuralFeature feature) {
- if (feature.getEType() == EcorePackage.eINSTANCE.getEInt() || feature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
- return true;
- }
-
- if (feature.getEType() instanceof EDataType) {
- EDataType datatype = (EDataType) feature.getEType();
- return datatype.getName().equals("Integer");
- }
-
- return false;
- }
-
- protected Map<css_declaration, Boolean> handleStyle(Style style) {
- if (style instanceof NamedStyle) {
- return Collections.emptyMap();
- }
-
- Map<css_declaration, Boolean> declarations = new LinkedHashMap<>();
-
- for (EStructuralFeature feature : style.eClass().getEAllStructuralFeatures()) {
- if (NotationPackage.eINSTANCE.getStyle().isSuperTypeOf(feature.getEContainingClass())) {
- Object currentValue = style.eGet(feature);
- Object defaultValue = feature.getDefaultValue();
- boolean check = currentValue == null ? currentValue != defaultValue : !currentValue.equals(defaultValue);
-
- css_declaration declaration = handleStyleFeature(style, feature);
- if (!declaration.getValueTokens().isEmpty()) { // If expression is null, the type of this property is not supported
- declarations.put(declaration, check);
- }
- }
- }
-
- return declarations;
- }
-
- // FIXME: Use constants for the CSS Properties names
- // FIXME: Use a helper to determine whether the custom styles are computed or forced
- protected Map<css_declaration, Boolean> handleCustomStyle(CustomStyle customStyle, View view) {
- Map<css_declaration, Boolean> declarations = new LinkedHashMap<>();
-
- GMFToCSSConverter converter = GMFToCSSConverter.instance;
-
- handleCustomStyle(view, "elementIcon", VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON, declarations, converter.convert(customStyle.showElementIcon()));
- handleCustomStyle(view, "shadow", VisualInformationPapyrusConstants.SHADOWFIGURE, declarations, converter.convert(customStyle.showShadow()));
- handleCustomStyle(view, "qualifiedNameDepth", VisualInformationPapyrusConstants.QUALIFIED_NAME, declarations, converter.convert(customStyle.getQualifiedNameDepth()));
-
- return declarations;
- }
-
- protected void handleCustomStyle(View view, String cssProperty, String eAnnotationName, Map<css_declaration, Boolean> result, List<CssTok> expression) {
- css_declaration cssDeclaration = CSSFactory.eINSTANCE.createcss_declaration();
-
- setProperty(cssDeclaration, cssProperty);
-
- setValueTokens(cssDeclaration, expression);
-
- boolean check = view.getEAnnotation(eAnnotationName) != null;
- result.put(cssDeclaration, check);
- }
-
- protected css_declaration handleStyleFeature(Style style, EStructuralFeature feature) {
- css_declaration declaration = CSSFactory.eINSTANCE.createcss_declaration();
-
- setProperty(declaration, feature.getName());
-
- GMFToCSSConverter converter = GMFToCSSConverter.instance;
-
- if (isString(feature)) {
- setValueTokens(declaration, converter.convert((String) style.eGet(feature)));
- }
-
- if (isInteger(feature)) {
- if (feature.getName().endsWith("Color")) {
- Color color = FigureUtilities.integerToColor((Integer) style.eGet(feature));
- setValueTokens(declaration, converter.convert(color));
- color.dispose();
- } else {
- setValueTokens(declaration, converter.convert((Integer) style.eGet(feature)));
- }
- }
-
- if (feature.getEType() == NotationPackage.eINSTANCE.getGradientData()) {
- setValueTokens(declaration, converter.convert((GradientData) style.eGet(feature)));
- }
-
- if (feature.getEType() instanceof EEnum) {
- setValueTokens(declaration, converter.convert((Enumerator) style.eGet(feature)));
- }
-
- if (isBoolean(feature)) {
- setValueTokens(declaration, converter.convert((Boolean) style.eGet(feature)));
- }
-
- return declaration;
- }
-
- protected final void setProperty(css_declaration declaration, String property) {
- css_property cssProperty = CSSFactory.eINSTANCE.createcss_property();
- cssProperty.setName(property);
- declaration.setProperty(cssProperty);
- }
-
- protected final void setValueTokens(css_declaration declaration, List<CssTok> tokens) {
- declaration.getValueTokens().clear();
- declaration.getValueTokens().addAll(tokens);
- }
-
- protected final void setCharset(stylesheet stylesheet, String charset) {
- charset cssCharset = CSSFactory.eINSTANCE.createcharset();
- cssCharset.setCharset(charset);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2015 CEA LIST, Christian W. Damus, 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 461629
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.configuration.handler;
+
+import static org.eclipse.papyrus.infra.gmfdiag.css.configuration.helper.DiagramTypeHelper.getDiagramType;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.Style;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.runtime.notation.datatype.GradientData;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.NamedStyleProperties;
+import org.eclipse.papyrus.infra.gmfdiag.css.configuration.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.css.engine.BaseCSSEngine;
+import org.eclipse.papyrus.infra.gmfdiag.css.provider.CustomStyle;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.AttributeSelector;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.CSSFactory;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ClassSelector;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.CssSelector;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.CssTok;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ElementSelector;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.charset;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.css_declaration;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.css_property;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.ruleset;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.selector;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.simple_selector;
+import org.eclipse.papyrus.infra.gmfdiag.css3.cSS.stylesheet;
+import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+
+
+public abstract class AbstractStyleHandler extends AbstractHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) {
+ ISelection selection;
+ try {
+ selection = ServiceUtilsForHandlers.getInstance().getNestedActiveIEditorPart(event).getSite().getSelectionProvider().getSelection();
+ if (selection.isEmpty()) {
+ return null;
+ }
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return null;
+ }
+
+ if (!(selection instanceof IStructuredSelection)) {
+ return null;
+ }
+
+ IStructuredSelection sSelection = (IStructuredSelection) selection;
+ Object element = sSelection.getFirstElement();
+
+ View view = NotationHelper.findView(element);
+ if (view == null) {
+ Activator.log.warn("Cannot create a Style from the selected element ; the element is not a View");
+ return null;
+ }
+
+ Shell parentShell = ((Event) event.getTrigger()).widget.getDisplay().getActiveShell();
+
+ if (view.getElement() == null || view instanceof Diagram) {
+ MessageDialog.open(MessageDialog.WARNING, parentShell, "Style error", "The selected element's style cannot be exported", SWT.NONE);
+ return null;
+ }
+
+ Map<css_declaration, Boolean> declarations = handleStyles(view);
+ Map<AttributeSelector, Boolean> conditions = handleSemantic(view);
+
+ String selectorName = view.getElement().eClass().getName();
+
+ AbstractStyleDialog dialog = createStyleDialog(parentShell, declarations, conditions, selectorName, view);
+
+ if (dialog.open() != Window.OK) {
+ return null;
+ }
+
+ ruleset ruleset = getRuleset(dialog);
+ selector baseSelector = CSSFactory.eINSTANCE.createselector();
+ simple_selector simple_selector = createSimpleElementSelector(selectorName, !dialog.useSelectorName());
+
+ baseSelector.getSimpleselectors().add(simple_selector);
+
+ if (dialog.getDiagramRestriction()) {
+ String diagramType = getDiagramType(view.getDiagram());
+ selector compositeSelector = CSSFactory.eINSTANCE.createselector();
+ compositeSelector.setSelector(baseSelector);
+
+
+ simple_selector diagramSelector = createSimpleElementSelector(diagramType, false);
+
+ compositeSelector.getSimpleselectors().add(diagramSelector);
+
+ ruleset.getSelectors().add(compositeSelector);
+ } else {
+ ruleset.getSelectors().add(baseSelector);
+ }
+
+ if (dialog.getCSSClass() != null) {
+ String cssClass = dialog.getCSSClass();
+ ClassSelector classCondition = CSSFactory.eINSTANCE.createClassSelector();
+ classCondition.setName(cssClass);
+ simple_selector.getSubSelectors().add(classCondition);
+ }
+
+ for (CssSelector condition : conditions.keySet()) {
+ if (conditions.get(condition)) {
+ simple_selector.getSubSelectors().add(condition);
+ }
+ }
+
+ for (css_declaration declaration : declarations.keySet()) {
+ if (declarations.get(declaration)) {
+ ruleset.getDeclarations().add(declaration);
+ }
+ }
+
+ stylesheet xtextStylesheet = getStyleSheet(dialog, view);
+
+ if (xtextStylesheet == null) {
+ return null;
+ }
+
+ Resource resource = xtextStylesheet.eResource();
+
+ if (!xtextStylesheet.getRuleset().contains(ruleset)) {
+ xtextStylesheet.getRuleset().add(ruleset);
+ }
+
+ try {
+ resource.save(new HashMap<>());
+ BaseCSSEngine.INSTANCE.reset();
+ DiagramHelper.forceRefresh();
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ MessageDialog.open(MessageDialog.ERROR, parentShell, "Style error", "An unexpected error occured while trying to save the Stylesheet", SWT.NONE);
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ MessageDialog.open(MessageDialog.ERROR, parentShell, "Style error", "An unexpected error occured while trying to save the Stylesheet", SWT.NONE);
+ }
+
+ return null;
+ }
+
+ protected simple_selector createSimpleElementSelector(String elementName, boolean universal) {
+ simple_selector simple_selector = CSSFactory.eINSTANCE.createsimple_selector();
+
+ if (universal) {
+ simple_selector.setUniversal(CSSFactory.eINSTANCE.createUniversalSelector());
+ } else {
+ ElementSelector elementSelector = CSSFactory.eINSTANCE.createElementSelector();
+ elementSelector.setName(elementName);
+ simple_selector.setElement(elementSelector);
+ }
+
+ return simple_selector;
+ }
+
+ protected abstract AbstractStyleDialog createStyleDialog(Shell shell, Map<css_declaration, Boolean> declarations, Map<AttributeSelector, Boolean> conditions, String selectorName, View context);
+
+ protected abstract ruleset getRuleset(AbstractStyleDialog dialog);
+
+ protected abstract stylesheet getStyleSheet(AbstractStyleDialog dialog, View contextView);
+
+ protected Map<css_declaration, Boolean> handleStyles(View view) {
+ Map<css_declaration, Boolean> declarations = new LinkedHashMap<>();
+
+ for (Object styleObject : view.getStyles()) {
+ Style style = (Style) styleObject;
+ declarations.putAll(handleStyle(style));
+ }
+
+ if (view instanceof Style) {
+ declarations.putAll(handleStyle((Style) view));
+ }
+
+ if (view instanceof CustomStyle) {
+ declarations.putAll(handleCustomStyle((CustomStyle) view, view));
+ }
+
+ return declarations;
+ }
+
+ protected Map<AttributeSelector, Boolean> handleSemantic(View view) {
+ Map<AttributeSelector, Boolean> result = new LinkedHashMap<>();
+
+ EObject semanticElement = view.getElement();
+
+ for (EStructuralFeature feature : semanticElement.eClass().getEAllStructuralFeatures()) {
+ if (isBoolean(feature) || isInteger(feature) || feature.getEType() instanceof EEnum) {
+ AttributeSelector attributeCondition = CSSFactory.eINSTANCE.createAttributeSelector();
+
+ attributeCondition.setName(feature.getName());
+ attributeCondition.setOp("=");
+ attributeCondition.setValue(semanticElement.eGet(feature).toString());
+
+ boolean check = semanticElement.eGet(feature) != feature.getDefaultValue();
+
+ result.put(attributeCondition, check);
+ }
+ }
+
+ return result;
+ }
+
+ protected boolean isBoolean(EStructuralFeature feature) {
+ if (feature.getEType() == EcorePackage.eINSTANCE.getEBoolean() || feature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
+ return true;
+ }
+
+ if (feature.getEType() instanceof EDataType) {
+ EDataType datatype = (EDataType) feature.getEType();
+ return datatype.getName().equals("Boolean");
+ }
+
+ return false;
+ }
+
+ protected boolean isString(EStructuralFeature feature) {
+ return feature.getEType() == EcorePackage.eINSTANCE.getEString();
+ }
+
+ protected boolean isInteger(EStructuralFeature feature) {
+ if (feature.getEType() == EcorePackage.eINSTANCE.getEInt() || feature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
+ return true;
+ }
+
+ if (feature.getEType() instanceof EDataType) {
+ EDataType datatype = (EDataType) feature.getEType();
+ return datatype.getName().equals("Integer");
+ }
+
+ return false;
+ }
+
+ protected Map<css_declaration, Boolean> handleStyle(Style style) {
+ if (style instanceof NamedStyle) {
+ return Collections.emptyMap();
+ }
+
+ Map<css_declaration, Boolean> declarations = new LinkedHashMap<>();
+
+ for (EStructuralFeature feature : style.eClass().getEAllStructuralFeatures()) {
+ if (NotationPackage.eINSTANCE.getStyle().isSuperTypeOf(feature.getEContainingClass())) {
+ Object currentValue = style.eGet(feature);
+ Object defaultValue = feature.getDefaultValue();
+ boolean check = currentValue == null ? currentValue != defaultValue : !currentValue.equals(defaultValue);
+
+ css_declaration declaration = handleStyleFeature(style, feature);
+ if (!declaration.getValueTokens().isEmpty()) { // If expression is null, the type of this property is not supported
+ declarations.put(declaration, check);
+ }
+ }
+ }
+
+ return declarations;
+ }
+
+ // FIXME: Use a helper to determine whether the custom styles are computed or forced
+ protected Map<css_declaration, Boolean> handleCustomStyle(CustomStyle customStyle, View view) {
+ Map<css_declaration, Boolean> declarations = new LinkedHashMap<>();
+
+ GMFToCSSConverter converter = GMFToCSSConverter.instance;
+
+ handleCustomStyle(view, NamedStyleProperties.ELEMENT_ICON, VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON, declarations, converter.convert(customStyle.showElementIcon()));
+ handleCustomStyle(view, NamedStyleProperties.SHADOW, VisualInformationPapyrusConstants.SHADOWFIGURE, declarations, converter.convert(customStyle.showShadow()));
+ handleCustomStyle(view, NamedStyleProperties.QUALIFIED_NAME_DEPTH, VisualInformationPapyrusConstants.QUALIFIED_NAME, declarations, converter.convert(customStyle.getQualifiedNameDepth()));
+
+ return declarations;
+ }
+
+ protected void handleCustomStyle(View view, String cssProperty, String eAnnotationName, Map<css_declaration, Boolean> result, List<CssTok> expression) {
+ css_declaration cssDeclaration = CSSFactory.eINSTANCE.createcss_declaration();
+
+ setProperty(cssDeclaration, cssProperty);
+
+ setValueTokens(cssDeclaration, expression);
+
+ boolean check = view.getEAnnotation(eAnnotationName) != null;
+ result.put(cssDeclaration, check);
+ }
+
+ protected css_declaration handleStyleFeature(Style style, EStructuralFeature feature) {
+ css_declaration declaration = CSSFactory.eINSTANCE.createcss_declaration();
+
+ setProperty(declaration, feature.getName());
+
+ GMFToCSSConverter converter = GMFToCSSConverter.instance;
+
+ if (isString(feature)) {
+ setValueTokens(declaration, converter.convert((String) style.eGet(feature)));
+ }
+
+ if (isInteger(feature)) {
+ if (feature.getName().endsWith("Color")) {
+ Color color = FigureUtilities.integerToColor((Integer) style.eGet(feature));
+ setValueTokens(declaration, converter.convert(color));
+ color.dispose();
+ } else {
+ setValueTokens(declaration, converter.convert((Integer) style.eGet(feature)));
+ }
+ }
+
+ if (feature.getEType() == NotationPackage.eINSTANCE.getGradientData()) {
+ setValueTokens(declaration, converter.convert((GradientData) style.eGet(feature)));
+ }
+
+ if (feature.getEType() instanceof EEnum) {
+ setValueTokens(declaration, converter.convert((Enumerator) style.eGet(feature)));
+ }
+
+ if (isBoolean(feature)) {
+ setValueTokens(declaration, converter.convert((Boolean) style.eGet(feature)));
+ }
+
+ return declaration;
+ }
+
+ protected final void setProperty(css_declaration declaration, String property) {
+ css_property cssProperty = CSSFactory.eINSTANCE.createcss_property();
+ cssProperty.setName(property);
+ declaration.setProperty(cssProperty);
+ }
+
+ protected final void setValueTokens(css_declaration declaration, List<CssTok> tokens) {
+ declaration.getValueTokens().clear();
+ declaration.getValueTokens().addAll(tokens);
+ }
+
+ protected final void setCharset(stylesheet stylesheet, String charset) {
+ charset cssCharset = CSSFactory.eINSTANCE.createcharset();
+ cssCharset.setCharset(charset);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/provider/CSSCustomStyleDelegate.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/provider/CSSCustomStyleDelegate.java
index 6949b3a2568..c73de5174a1 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/provider/CSSCustomStyleDelegate.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/provider/CSSCustomStyleDelegate.java
@@ -19,6 +19,7 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
import org.eclipse.papyrus.infra.emf.appearance.style.AnnotationStyleProvider;
import org.eclipse.papyrus.infra.emf.appearance.style.AppearanceStyleProvider;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.NamedStyleProperties;
import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
import org.eclipse.papyrus.infra.gmfdiag.css.helper.CSSDOMSemanticElementHelper;
import org.eclipse.papyrus.infra.gmfdiag.css.helper.StringHelper;
@@ -30,7 +31,6 @@ import org.w3c.dom.css.CSSValue;
*
* @author Camille Letavernier
*/
-// FIXME: Use constants for the CSS Properties elementIcon, qualifiedNameDepth and shadow
@SuppressWarnings("restriction")
public class CSSCustomStyleDelegate implements CustomStyle {
@@ -72,7 +72,7 @@ public class CSSCustomStyleDelegate implements CustomStyle {
return provider.showElementIcon(view);
}
- CSSValue cssValue = engine.retrievePropertyValue(element, "elementIcon"); //$NON-NLS-1$
+ CSSValue cssValue = engine.retrievePropertyValue(element, NamedStyleProperties.ELEMENT_ICON);
if (cssValue == null) {
return false;
}
@@ -86,7 +86,7 @@ public class CSSCustomStyleDelegate implements CustomStyle {
return provider.getQualifiedNameDepth(view);
}
- CSSValue cssValue = engine.retrievePropertyValue(element, "qualifiedNameDepth"); //$NON-NLS-1$
+ CSSValue cssValue = engine.retrievePropertyValue(element, NamedStyleProperties.QUALIFIED_NAME_DEPTH);
if (cssValue == null) {
return NONE_VALUE;
}
@@ -124,7 +124,7 @@ public class CSSCustomStyleDelegate implements CustomStyle {
return provider.showShadow(view);
}
- CSSValue cssValue = engine.retrievePropertyValue(element, "shadow"); //$NON-NLS-1$
+ CSSValue cssValue = engine.retrievePropertyValue(element, NamedStyleProperties.SHADOW);
if (cssValue == null) {
return false;
}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css3.xtext.ui/src/org/eclipse/papyrus/infra/gmfdiag/css3/ui/contentassist/CustomCSSProposalProvider.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css3.xtext.ui/src/org/eclipse/papyrus/infra/gmfdiag/css3/ui/contentassist/CustomCSSProposalProvider.java
index a8c8215c6fc..a3a79aa4ea7 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css3.xtext.ui/src/org/eclipse/papyrus/infra/gmfdiag/css3/ui/contentassist/CustomCSSProposalProvider.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css3.xtext.ui/src/org/eclipse/papyrus/infra/gmfdiag/css3/ui/contentassist/CustomCSSProposalProvider.java
@@ -224,9 +224,9 @@ public class CustomCSSProposalProvider extends AbstractCSSProposalProvider {
"transparency", //$NON-NLS-1$
"fontSize", //$NON-NLS-1$
"displayName", //$NON-NLS-1$
- "elementIcon", //$NON-NLS-1$
- "shadow", //$NON-NLS-1$
- "qualifiedNameDepth", //$NON-NLS-1$
+ NamedStyleProperties.ELEMENT_ICON,
+ NamedStyleProperties.SHADOW,
+ NamedStyleProperties.QUALIFIED_NAME_DEPTH,
"lineStyle", //$NON-NLS-1$
"lineDashLength", //$NON-NLS-1$
"lineDashGap", //$NON-NLS-1$
@@ -238,6 +238,7 @@ public class CustomCSSProposalProvider extends AbstractCSSProposalProvider {
"svgCssFile", //$NON-NLS-1$
"svgCssClass", //$NON-NLS-1$
"canonical", //$NON-NLS-1$
+ NamedStyleProperties.IMAGE_PATH,
NamedStyleProperties.BORDER_STYLE,
NamedStyleProperties.BOTTOM_MARGIN_PROPERTY,
NamedStyleProperties.DISPLAY_BORDER,
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ShapeDisplayCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ShapeDisplayCompartmentEditPart.java
index 57207c7d9e7..212591c2766 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ShapeDisplayCompartmentEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ShapeDisplayCompartmentEditPart.java
@@ -184,7 +184,7 @@ public class ShapeDisplayCompartmentEditPart extends ResizableCompartmentEditPar
if (shapesToDisplay != null && !shapesToDisplay.isEmpty()) {
for (RenderedImage image : shapesToDisplay) {
if (image != null) {
- IFigure imageFigure = new BorderedScalableImageFigure(image, false, getUseOriginalColors(), true);
+ IFigure imageFigure = new BorderedScalableImageFigure(image, false, getUseOriginalColors(), true, true);
imageFigure.setOpaque(false);
imageFigure.setVisible(true);
contentPane.add(imageFigure);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java
index ec5220c360e..a2aaa1fa711 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/BorderedScalableImageFigure.java
@@ -10,6 +10,7 @@
*
* CEA LIST - Initial API and implementation
* Mickael ADAM (ALL4TEC) - mickael.adam@all4tec.net - implementation of layout BorderedLayoutManager to provide maintain ratio and color set
+ * Fanch BONNABESSE (ALL4TEC) - fanch.bonnabesse@all4tec.net - Bug 502531
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
@@ -35,6 +36,10 @@ public class BorderedScalableImageFigure extends ScalableImageFigure {
private RenderedImage lastRenderedImage;
public BorderedScalableImageFigure(RenderedImage renderedImage, boolean useDefaultImageSize, boolean useOriginalColors, boolean antiAlias) {
+ this(renderedImage, useDefaultImageSize, useOriginalColors, antiAlias, true);
+ }
+
+ public BorderedScalableImageFigure(RenderedImage renderedImage, boolean useDefaultImageSize, boolean useOriginalColors, boolean antiAlias, boolean isModificationPreferredSize) {
super(renderedImage, useDefaultImageSize, useOriginalColors, antiAlias);
// set a layout manager to override maintain ratio behavior
setLayoutManager(new BorderedLayoutManager());
@@ -42,9 +47,11 @@ public class BorderedScalableImageFigure extends ScalableImageFigure {
// assure that ShapeFlowLayout gets the actual image size as preferred size. Otherwise, it would
// scale the image to identical width and height which would make it impossible to calculate the
// original aspect ratio (SVG specific workaround was in place before, see bug 500999).
- setPreferredImageSize(
- renderedImage.getSWTImage().getBounds().width,
- renderedImage.getSWTImage().getBounds().height);
+ if (isModificationPreferredSize) {
+ setPreferredImageSize(
+ renderedImage.getSWTImage().getBounds().width,
+ renderedImage.getSWTImage().getBounds().height);
+ }
}
@Override
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecorator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecorator.java
index ce53c1d19ba..9fcaa38432b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecorator.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecorator.java
@@ -165,7 +165,7 @@ public class ShapeDecorator extends AbstractDecorator implements NotificationLis
figure.setLayoutManager(new ShapeFlowLayout());
for (RenderedImage image : shapesToDisplay) {
- BorderedScalableImageFigure subFigure = new BorderedScalableImageFigure(image, false, true, true);
+ BorderedScalableImageFigure subFigure = new BorderedScalableImageFigure(image, false, true, true, false);
figure.add(subFigure);
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/StyleBasedShapeProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/StyleBasedShapeProvider.java
index 26f2ca856d4..090bf0a9595 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/StyleBasedShapeProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/StyleBasedShapeProvider.java
@@ -8,18 +8,24 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Fanch BONNABESSE (ALL4TEC) - fanch.bonnabesse@all4tec.net - Bug 502531
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
+import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
@@ -37,22 +43,23 @@ import org.w3c.dom.svg.SVGDocument;
*/
public class StyleBasedShapeProvider extends AbstractShapeProvider {
- protected static final String STYLE_PROPERTY = "svgFile";
+ protected static final String STYLE_PROPERTY = "svgFile"; //$NON-NLS-1$
+
+ protected static final String IMAGE_PATH_PROPERTY = "imagePath"; //$NON-NLS-1$
private ProviderNotificationManager manager;
private List<SVGDocument> listEmptySVG;
private List<RenderedImage> listEmptyRendered;
private List<SVGDocument> listSingletonSVG;
- private List<RenderedImage> listSingletonRendered;
+ private List<RenderedImage> listRenderedImages;
public StyleBasedShapeProvider() {
listEmptySVG = new ArrayList<SVGDocument>(0);
listEmptyRendered = new ArrayList<RenderedImage>(0);
listSingletonSVG = new ArrayList<SVGDocument>(1);
listSingletonSVG.add(null);
- listSingletonRendered = new ArrayList<RenderedImage>(1);
- listSingletonRendered.add(null);
+ listRenderedImages = new ArrayList<RenderedImage>();
}
/**
@@ -72,24 +79,51 @@ public class StyleBasedShapeProvider extends AbstractShapeProvider {
return doGetShapes(v);
}
- protected List<RenderedImage> doGetShapes(View view) {
- String svgFile = extract((StringValueStyle) view.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), STYLE_PROPERTY));
- if (svgFile == null) {
- return listEmptyRendered;
+ protected List<RenderedImage> doGetShapes(final View view) {
+ if (null != listRenderedImages) {
+ listRenderedImages.clear();
}
- SVGDocument svg = getSVGDocument(view, svgFile);
- if (svg == null) {
- Activator.log.warn("Invalid SVG File path: " + svgFile); //$NON-NLS-1$
- return null;
+
+ // Check the 'svg' document with the property 'svgFile'
+ List<SVGDocument> documents = getSVGDocument(view);
+ if ((null != documents) && (!documents.isEmpty())) {
+ for (SVGDocument document : documents) {
+ if (null == document) {
+ continue;
+ }
+ try {
+ RenderedImage renderSVGDocument = renderSVGDocument(view, document);
+ if (null != renderSVGDocument) {
+ listRenderedImages.add(renderSVGDocument);
+ }
+ } catch (IOException ex) {
+ Activator.log.error(ex);
+ }
+ }
}
- RenderedImage img = null;
- try {
- img = renderSVGDocument(view, svg);
- } catch (IOException e) {
- Activator.log.error("Failed to render the svg file: " + svgFile, e); //$NON-NLS-1$
+
+ // Check the other image file with the property 'imagePath'
+ String path = NotationUtils.getStringValue(view, IMAGE_PATH_PROPERTY, null);
+ if ((null != path) && (0 < path.length())) {
+ URL url;
+ try {
+ url = new URL(path);
+ listRenderedImages.add(RenderedImageFactory.getInstance(url));
+ } catch (MalformedURLException e) {
+ URI typeResourceURI = view.eResource().getURI();
+ if (null != typeResourceURI) {
+ String workspaceRelativeFolderPath = typeResourceURI.trimSegments(1).toPlatformString(true);
+ try {
+ url = new URL("platform:/resource/" + workspaceRelativeFolderPath + File.separatorChar + path); //$NON-NLS-1$
+ listRenderedImages.add(RenderedImageFactory.getInstance(url));
+ } catch (MalformedURLException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
}
- listSingletonRendered.set(0, img);
- return listSingletonRendered;
+
+ return listRenderedImages;
}
/**
@@ -154,7 +188,9 @@ public class StyleBasedShapeProvider extends AbstractShapeProvider {
}
String svgFile = extract((StringValueStyle) v.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), STYLE_PROPERTY));
- return (svgFile != null);
+ String imagePath = NotationUtils.getStringValue(v, IMAGE_PATH_PROPERTY, null);
+
+ return (svgFile != null || imagePath != null);
}
/**
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java
index 4d7e468eca7..12b5e9326f5 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/NamedStyleProperties.java
@@ -164,13 +164,25 @@ public interface NamedStyleProperties {
/** The port resizable namestyle propery. */
public static final String IS_PORT_RESIZABLE = "isPortResizable";//$NON-NLS-1$
-
+
/* Label used to identify the forced CSS values */
public static final String CSS_FORCE_VALUE = "PapyrusCSSForceValue"; // $NON-NLS-1$
/** name of the CSS property that manages the enablement of the {@link StyleBasedShapeProvider} */
- public static final String SHAPE_STYLE_PROPERTY = "shapeStyle";
+ public static final String SHAPE_STYLE_PROPERTY = "shapeStyle"; //$NON-NLS-1$
/** name of the CSS property that manages the enablement of the {@link StyleBasedShapeProvider} for decoration */
- public static final String SHAPE_DECORATION_STYLE_PROPERTY = "shapeDecorationStyle";
+ public static final String SHAPE_DECORATION_STYLE_PROPERTY = "shapeDecorationStyle"; //$NON-NLS-1$
+
+ /** NameStyle property to show an icon next to the label of an element. */
+ public static final String ELEMENT_ICON = "elementIcon"; //$NON-NLS-1$
+
+ /** NameStyle property to define the depth of the qualified name to display. */
+ public static final String QUALIFIED_NAME_DEPTH = "qualifiedNameDepth"; //$NON-NLS-1$
+
+ /** NameStyle property to display a shadow under the shape. */
+ public static final String SHADOW = "shadow"; //$NON-NLS-1$
+
+ /** NamedStyle property used to show an image on the symbol compartment. */
+ public static final String IMAGE_PATH = "imagePath"; //$NON-NLS-1$
}

Back to the top