Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx3
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleDiagram.xwt21
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddAllModelStyleSheetCommand.java72
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddModelStyleSheetCommand.java57
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/CustomModelStyleSheetListener.java93
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/ModelStyleSheetObservableList.java150
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveAllModelStyleSheetValueCommand.java85
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveObjectCommand.java71
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java60
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSStyleSheetContentProvider.java12
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ModelCSSEngine.java66
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSStyles.java7
13 files changed, 684 insertions, 16 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF
index 7bba2c1af66..27279d9c38b 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/META-INF/MANIFEST.MF
@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0"
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
+ com.google.guava
Bundle-Vendor: Eclipse Modeling Project
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.0.0.qualifier
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx
index b172a3d7644..6b4fb350795 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/css.ctx
@@ -61,6 +61,9 @@
<elements name="DiagramStyle" supertypes="//@dataContexts.0/@elements.0">
<properties name="css_stylesheets" label="Diagram style sheets" type="Reference" multiplicity="-1" description="The style sheets associated to this diagram"/>
</elements>
+ <elements name="ModelStyle">
+ <properties name="modelStyleSheets" label="Model style sheets" type="Reference" multiplicity="-1" description="The style sheets associated to this model"/>
+ </elements>
<modelElementFactory href="ppe:/environment/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/Environment.xmi#//@modelElementFactories.0"/>
</dataContexts>
<dataContexts name="modelstylesheets" label="StyleSheets">
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleDiagram.xwt b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleDiagram.xwt
index 5d97981f0a2..4361f29795b 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleDiagram.xwt
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/model/properties/ui/SingleDiagram.xwt
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
-<Composite
+<Composite xmlns:ppe="clr-namespace:org.eclipse.papyrus.views.properties.widgets"
+ xmlns="http://www.eclipse.org/xwt/presentation"
xmlns:ppel="clr-namespace:org.eclipse.papyrus.views.properties.widgets.layout"
- xmlns:ppe="clr-namespace:org.eclipse.papyrus.views.properties.widgets"
- xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt"
+ xmlns:x="http://www.eclipse.org/xwt"
xmlns:css="clr-namespace:org.eclipse.papyrus.infra.gmfdiag.css.properties.widgets">
<Composite.layout>
<ppel:PropertiesLayout numColumns="1"></ppel:PropertiesLayout>
@@ -18,15 +18,22 @@
<Composite.layout>
<GridLayout></GridLayout>
</Composite.layout>
- <css:ResetStyleWidget input="{Binding}" property="CSS:PapyrusCSSStyle:cssStyle"></css:ResetStyleWidget>
+ <css:ResetStyleWidget property="CSS:PapyrusCSSStyle:cssStyle"
+ input="{Binding}"></css:ResetStyleWidget>
</Composite>
<Composite>
<Composite.layout>
- <ppel:PropertiesLayout numColumns="1"></ppel:PropertiesLayout>
+ <ppel:PropertiesLayout numColumns="2"></ppel:PropertiesLayout>
</Composite.layout>
<ppe:MultiReference input="{Binding}"
property="CSS:DiagramStyle:css_stylesheets"></ppe:MultiReference>
- <ppe:MultiString property="CSS:PapyrusCSSStyle:cssClass"
- input="{Binding}"></ppe:MultiString>
+ <ppe:MultiReference input="{Binding}"
+ property="CSS:ModelStyle:modelStyleSheets"></ppe:MultiReference>
+ </Composite>
+ <Composite>
+ <Composite.layout>
+ <ppel:PropertiesLayout numColumns="1"></ppel:PropertiesLayout>
+ </Composite.layout>
+ <ppe:MultiString input="{Binding}" property="CSS:PapyrusCSSStyle:cssClass"></ppe:MultiString>
</Composite>
</Composite> \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddAllModelStyleSheetCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddAllModelStyleSheetCommand.java
new file mode 100644
index 00000000000..cb94158affb
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddAllModelStyleSheetCommand.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Mickaël Adam (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage;
+
+/**
+ * Add stylesheet's model Command.
+ *
+ * @author Mickael ADAM
+ */
+public class AddAllModelStyleSheetCommand extends RecordingCommand {
+
+ /** The resource. */
+ private Resource resource;
+
+ /** The values. */
+ private Collection<?> values;
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * the domain
+ * @param resource
+ * the resource
+ * @param values
+ * the values
+ */
+ public AddAllModelStyleSheetCommand(TransactionalEditingDomain domain, Resource resource, Collection<?> values) {
+ super(domain);
+ this.resource = resource;
+ this.values = values;
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ public void doExecute() {
+
+ //Get the model styleSheet on the resource
+ Object modelStyleSheetObject = EcoreUtil.getObjectByType(resource.getContents(), StylesheetsPackage.Literals.MODEL_STYLE_SHEETS);
+
+ //For each styleSheet
+ for(Object styleSheetRef : values) {
+ //Add it to the modelStyleSheet
+ ((ModelStyleSheets)modelStyleSheetObject).getStylesheets().add((StyleSheet)styleSheetRef);
+ }
+ //Add the modelStyleSheet to the resource
+ resource.getContents().add(((ModelStyleSheets)modelStyleSheetObject));
+ }
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddModelStyleSheetCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddModelStyleSheetCommand.java
new file mode 100644
index 00000000000..003e001fe40
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/AddModelStyleSheetCommand.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Mickaël Adam (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+/**
+ * Command to add a object to the resource.
+ *
+ * @author Mickael ADAM
+ */
+public class AddModelStyleSheetCommand extends RecordingCommand {
+
+ /** The resource. */
+ private Resource resource;
+
+ /** The object. */
+ private EObject object;
+
+ /**
+ * Instantiates a new adds the model style sheet command.
+ *
+ * @param domain
+ * the domain
+ * @param resource
+ * the resource
+ * @param object
+ * the object
+ */
+ public AddModelStyleSheetCommand(TransactionalEditingDomain domain, Resource resource, EObject object) {
+ super(domain);
+ this.resource = resource;
+ this.object = object;
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+
+ public void doExecute() {
+ resource.getContents().add(object);
+ }
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/CustomModelStyleSheetListener.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/CustomModelStyleSheetListener.java
new file mode 100644
index 00000000000..a812ec51726
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/CustomModelStyleSheetListener.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;
+
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage;
+
+/**
+ * A Listener for ModelStyleSheet List
+ *
+ * @author Mickaël ADAM
+ */
+public class CustomModelStyleSheetListener extends AdapterImpl {
+
+ private final IChangeListener listener;
+
+ private boolean disposed;
+
+ /**
+ * Instantiates a new custom model styleSheet listener.
+ *
+ * @param notationResource
+ * the notation resource
+ * @param source
+ * the source
+ * @param listener
+ * the listener
+ */
+ public CustomModelStyleSheetListener(Resource notationResource, ModelStyleSheets source, IChangeListener listener) {
+
+ this.listener = listener;
+
+ //add an eAdapter on it
+ source.eAdapters().add(this);
+ //Get all StyleSheets from the modelStyleSheet
+ EList<StyleSheet> objectsFromModelSS = source.getStylesheets();
+
+ for(StyleSheet styleSheet : objectsFromModelSS) {
+ styleSheet.eAdapters().add(this);
+ }
+ }
+
+ /**
+ * Notify changed.
+ *
+ * @param notification
+ * the notification
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ //The listener has been disposed: remove it from the notifier
+ //and ignore the notification
+ if(disposed) {
+ ((Notifier)notification.getNotifier()).eAdapters().remove(this);
+ return;
+ }
+
+ if(notification.getFeature() == StylesheetsPackage.eINSTANCE.getModelStyleSheets_Stylesheets()) {
+ if(!notification.isTouch()) {
+ handleChange(notification.getNotifier());
+ }
+ }
+ }
+
+ private void handleChange(Object value) {
+ if(value instanceof ModelStyleSheets) {
+ listener.handleChange(null);
+ }
+ }
+
+ public void dispose() {
+ this.disposed = true;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/ModelStyleSheetObservableList.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/ModelStyleSheetObservableList.java
new file mode 100644
index 00000000000..841972297a7
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/ModelStyleSheetObservableList.java
@@ -0,0 +1,150 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Mickaël Adam (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.EObjectListValueStyle;
+import org.eclipse.papyrus.infra.emf.databinding.EMFObservableList;
+import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
+
+
+/**
+ *
+ * EMFObservableList containing stylesheets of the model.
+ *
+ * @author Mickael ADAM
+ *
+ */
+public class ModelStyleSheetObservableList extends EMFObservableList implements IChangeListener {
+
+ /** The notation resource. */
+ private Resource notationResource;
+
+ /** The domain. */
+ private EditingDomain domain;
+
+ /** The listener. */
+ private CustomModelStyleSheetListener listener;
+
+ /**
+ * Constructor.
+ *
+ * @param notationResource
+ * the notation resource
+ * @param wrappedList
+ * the wrapped list
+ * @param domain
+ * the domain
+ * @param source
+ * the source
+ * @param feature
+ * the feature
+ */
+ public ModelStyleSheetObservableList(Resource notationResource, List<?> wrappedList, EditingDomain domain, EObject source, EStructuralFeature feature) {
+ super(wrappedList, domain, source, feature);
+ this.notationResource = notationResource;
+ this.domain = domain;
+
+ source.eAdapters().add(listener = new CustomModelStyleSheetListener(notationResource, (ModelStyleSheets)source, this));
+ }
+
+ /**
+ * Used to add manually.
+ *
+ * @param values
+ * the values
+ * @return the command to add values
+ * @see org.eclipse.papyrus.infra.emf.databinding.EMFObservableList#getAddAllCommand(java.util.Collection)
+ */
+ @Override
+ public Command getAddAllCommand(Collection<?> values) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+ compoundCommand.append(super.getAddAllCommand(values));
+ compoundCommand.append(new AddAllModelStyleSheetCommand((TransactionalEditingDomain)domain, notationResource, values));
+ return compoundCommand;
+ }
+
+ /**
+ * Used to remove manually styleSheet.
+ *
+ * @param value
+ * the value
+ * @return the removes command
+ * @see org.eclipse.papyrus.infra.emf.databinding.EMFObservableList#getRemoveCommand(java.lang.Object)
+ */
+ @Override
+ public Command getRemoveCommand(Object value) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+ compoundCommand.append(super.getRemoveCommand(value));
+
+ //Retrieve all instance of EObjectListValueStyleImpl on all CSSDiagramImpl to
+ EList<EObject> objectsFromResource = notationResource.getContents();
+ for(Object objectFromResource : objectsFromResource) {
+ //For each CSSDiagramImpl of the resource look for EObjectListValueStyleImpl
+ if(objectFromResource instanceof CSSDiagram) {
+ EList<EObject> objectsFromDiagram = ((CSSDiagram)objectFromResource).getStyles();
+ for(Object objectFromDiagram : objectsFromDiagram) {
+ //For each EObjectListValueStyleImpl of each diagram
+ if(objectFromDiagram instanceof EObjectListValueStyle) {
+ for(Object styleSheetReference : ((EObjectListValueStyle)objectFromDiagram).getEObjectListValue()) {
+ //If the current style sheet to delete from model exist on a diagram, add it on the root
+ if(value == styleSheetReference) {
+ compoundCommand.append(new RemoveObjectCommand((TransactionalEditingDomain)domain, (EObject)styleSheetReference));
+ compoundCommand.append(new AddModelStyleSheetCommand((TransactionalEditingDomain)domain, notationResource, (EObject)styleSheetReference));
+ }
+ }
+ }
+ }
+ }
+ }
+ return compoundCommand;
+ }
+
+ /**
+ * Used to remove all StyleSheets before replace the new list.
+ *
+ * @param values
+ * the values
+ * @return the removes the all command
+ * @see org.eclipse.papyrus.infra.emf.databinding.EMFObservableList#getRemoveAllCommand(java.util.Collection)
+ */
+ @Override
+ public Command getRemoveAllCommand(Collection<?> values) {
+ return new RemoveAllModelStyleSheetValueCommand((TransactionalEditingDomain)domain, notationResource, values);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.emf.databinding.EMFObservableList#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ source.eAdapters().remove(listener);
+ listener.dispose();
+ listener = null;
+ super.dispose();
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveAllModelStyleSheetValueCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveAllModelStyleSheetValueCommand.java
new file mode 100644
index 00000000000..d2cd3de9113
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveAllModelStyleSheetValueCommand.java
@@ -0,0 +1,85 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;
+
+import java.util.Collection;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;
+
+/**
+ *
+ * Command to remove all styleSheets from the resource.
+ *
+ * @author Mickael ADAM
+ *
+ */
+public class RemoveAllModelStyleSheetValueCommand extends RecordingCommand {
+
+ /** The values. */
+ private Collection<?> values;
+
+ /** The resource. */
+ private Resource resource;
+
+ /** The domain. */
+ private TransactionalEditingDomain domain;
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * the domain
+ * @param resource
+ * the resource
+ * @param values
+ * the values
+ */
+ public RemoveAllModelStyleSheetValueCommand(TransactionalEditingDomain domain, Resource resource, Collection<?> values) {
+ super(domain);
+ this.resource = resource;
+ this.values = values;
+ this.domain = domain;
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @Override
+ public void doExecute() {
+ for(Object value : values) {
+ if(value instanceof StyleSheetReference) {
+ StyleSheetReference styleSheet = (StyleSheetReference)value;
+
+ // Create a request to delete the styleSheet
+ DestroyElementRequest request = new DestroyElementRequest((TransactionalEditingDomain)domain, (EObject)styleSheet, false);
+ // Get the command to delete the styleSheet
+ DestroyElementCommand command = new DestroyElementCommand(request);
+ try {
+ //execute command
+ command.execute(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveObjectCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveObjectCommand.java
new file mode 100644
index 00000000000..a6c9ed44e25
--- /dev/null
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/databinding/RemoveObjectCommand.java
@@ -0,0 +1,71 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Mickaël Adam (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+
+/**
+ *
+ * Command to remove an EObject from its containing resource and/or its containing object.
+ *
+ * @author Mickael ADAM
+ *
+ */
+public class RemoveObjectCommand extends RecordingCommand {
+
+
+ /** The object. */
+ private EObject object;
+
+ /** The domain. */
+ private TransactionalEditingDomain domain;
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * the domain
+ * @param object
+ * the object
+ */
+ public RemoveObjectCommand(TransactionalEditingDomain domain, EObject object) {
+ super(domain);
+ this.domain = domain;
+ this.object = object;
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @Override
+ protected void doExecute() {
+ // Create a request to delete the object
+ DestroyElementRequest request = new DestroyElementRequest((TransactionalEditingDomain)domain, (EObject)object, false);
+ // Get the command to delete the object
+ DestroyElementCommand command = new DestroyElementCommand(request);
+ try {
+ //execute command
+ command.execute(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java
index 382e23367e9..0e8635fe76e 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/modelelement/CSSModelElement.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2014 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,28 +8,41 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Mickaël Adam (ALL4TEC) mickael.adam@all4tec.net - bug 429642
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.properties.modelelement;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.infra.core.utils.TransactionHelper;
+import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
+import org.eclipse.papyrus.infra.gmfdiag.css.engine.ModelCSSEngine;
import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSDiagram;
import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSStyles;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.creation.StyleSheetFactory;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding.DiagramStyleSheetObservableList;
+import org.eclipse.papyrus.infra.gmfdiag.css.properties.databinding.ModelStyleSheetObservableList;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.provider.CSSStyleSheetContentProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.properties.provider.CSSStyleSheetLabelProvider;
import org.eclipse.papyrus.infra.gmfdiag.css.provider.CSSClassContentProvider;
+import org.eclipse.papyrus.infra.gmfdiag.css.resource.CSSNotationResource;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsFactory;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage;
import org.eclipse.papyrus.infra.gmfdiag.properties.modelelement.CustomStyleModelElement;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.creation.StringEditionFactory;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
+import com.google.common.base.Optional;
+
public class CSSModelElement extends CustomStyleModelElement {
@@ -46,6 +59,9 @@ public class CSSModelElement extends CustomStyleModelElement {
if(CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
return new StyleSheetFactory((View)this.source);
}
+ if(CSSStyles.CSS_MODEL_STYLESHEETS_KEY.equals(propertyPath)) {
+ return new StyleSheetFactory((View)this.source);
+ }
if(CSSStyles.CSS_GMF_CLASS_KEY.equals(propertyPath)) {
StringEditionFactory factory = new StringEditionFactory();
factory.setContentProvider(getContentProvider(propertyPath));
@@ -60,6 +76,41 @@ public class CSSModelElement extends CustomStyleModelElement {
if(CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
return new DiagramStyleSheetObservableList((View)source, domain, propertyPath);
}
+ if(CSSStyles.CSS_MODEL_STYLESHEETS_KEY.equals(propertyPath)) {
+ //Get the resource
+ final Resource notationResource = source.eResource();
+ //The model styleSheet
+ ModelStyleSheets modelStyleSheetsSource = null;
+ //Get the model styleSheet Object
+ Object modelStyleSheetObject = EcoreUtil.getObjectByType(notationResource.getContents(), StylesheetsPackage.Literals.MODEL_STYLE_SHEETS);
+ //If the model styleSheet exist
+ if(modelStyleSheetObject instanceof ModelStyleSheets) {
+ // set modelStyleSheetsSource
+ modelStyleSheetsSource = (ModelStyleSheets)modelStyleSheetObject;
+ } else {
+ //or create a model styleSheet
+ modelStyleSheetsSource = StylesheetsFactory.eINSTANCE.createModelStyleSheets();
+ //Optional used to pass the modelStyleSheetsSource on runnable without final
+ final Optional<ModelStyleSheets> modelStyleSheetsOnOptional = Optional.of(modelStyleSheetsSource);
+ try {
+ TransactionHelper.run(domain, new Runnable() {
+
+ public void run() {
+ //Add modelStylesheet to the resource without command
+ notationResource.getContents().add(modelStyleSheetsOnOptional.get());
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ //Initialize the adapter of the engine to listen model styleSheet
+ ExtendedCSSEngine engine = ((CSSNotationResource)notationResource).getModelEngine();
+ if(engine instanceof ModelCSSEngine) {
+ ((ModelCSSEngine)engine).initAdapter();
+ }
+ }
+ return new ModelStyleSheetObservableList(notationResource, modelStyleSheetsSource.getStylesheets(), domain, modelStyleSheetsSource, StylesheetsPackage.Literals.MODEL_STYLE_SHEETS__STYLESHEETS);
+ }
return super.doGetObservable(propertyPath);
}
@@ -68,6 +119,9 @@ public class CSSModelElement extends CustomStyleModelElement {
if(CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY.equals(propertyPath)) {
return new CSSStyleSheetLabelProvider();
}
+ if(CSSStyles.CSS_MODEL_STYLESHEETS_KEY.equals(propertyPath)) {
+ return new CSSStyleSheetLabelProvider();
+ }
return super.getLabelProvider(propertyPath);
}
@@ -76,7 +130,9 @@ public class CSSModelElement extends CustomStyleModelElement {
if(propertyPath.equals(CSSStyles.CSS_DIAGRAM_STYLESHEETS_KEY)) {
return new CSSStyleSheetContentProvider(source);
}
-
+ if(propertyPath.equals(CSSStyles.CSS_MODEL_STYLESHEETS_KEY)) {
+ return new CSSStyleSheetContentProvider(source);
+ }
if(propertyPath.equals(CSSStyles.CSS_GMF_CLASS_KEY)) {
Diagram diagram = ((View)source).getDiagram();
if(diagram instanceof CSSDiagram) {
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSStyleSheetContentProvider.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSStyleSheetContentProvider.java
index 9fa6f8c6e82..a9c657711db 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSStyleSheetContentProvider.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.properties/src/org/eclipse/papyrus/infra/gmfdiag/css/properties/provider/CSSStyleSheetContentProvider.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.papyrus.infra.emf.providers.EMFContentProvider;
+import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StylesheetsPackage;
import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
@@ -52,8 +53,15 @@ public class CSSStyleSheetContentProvider extends EMFContentProvider {
List<Object> result = new LinkedList<Object>();
for(Resource resource : CSSStyleSheetContentProvider.this.context.eResource().getResourceSet().getResources()) {
for(Object object : resource.getContents()) {
- if(object instanceof StyleSheet) {
- result.add(object);
+ if(object instanceof ModelStyleSheets) {
+ ModelStyleSheets styleSheets = (ModelStyleSheets)object;
+ for(StyleSheet styleSheet : styleSheets.getStylesheets()) {
+ result.add(styleSheet);
+ }
+ } else {
+ if(object instanceof StyleSheet) {
+ result.add(object);
+ }
}
}
}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ModelCSSEngine.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ModelCSSEngine.java
index a14cb2dfdbf..de95d45f224 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ModelCSSEngine.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ModelCSSEngine.java
@@ -9,7 +9,8 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 429422
- *
+ * Mickael ADAM (ALL4TEC) mickael.adam@ALL4TEC.net - bug 429642
+ *
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.engine;
@@ -18,13 +19,18 @@ import java.net.URL;
import org.eclipse.e4.ui.css.core.dom.IElementProvider;
import org.eclipse.e4.ui.css.core.engine.CSSElementContext;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
import org.eclipse.papyrus.infra.gmfdiag.css.resource.CSSNotationResource;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.ModelStyleSheets;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheet;
import org.eclipse.papyrus.infra.gmfdiag.css.stylesheets.StyleSheetReference;
+import org.eclipse.swt.widgets.Display;
import org.w3c.dom.Element;
/**
@@ -42,6 +48,22 @@ public class ModelCSSEngine extends ExtendedCSSEngineImpl {
private final Resource model;
+ /** A adapter for the model styleSheet. */
+ Adapter adapter = new AdapterImpl() {
+
+ public void notifyChanged(Notification notification) {
+ ModelCSSEngine.this.reset();
+
+ DiagramHelper.setNeedsRefresh();
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ DiagramHelper.refreshDiagrams();
+ }
+ });
+ }
+ };
+
/**
* Creates a ModelCSSEngine for the requested resource.
*
@@ -50,8 +72,26 @@ public class ModelCSSEngine extends ExtendedCSSEngineImpl {
public ModelCSSEngine(Resource model) {
super(getParentCSSEngine(model));
this.model = model;
+ initAdapter();
+ }
+
+ /**
+ * Initialize the adapter attached to model styleSheet.
+ *
+ */
+ public void initAdapter() {
+ for(EObject eObject : model.getContents()) {
+ if(eObject instanceof ModelStyleSheets) {
+ ModelStyleSheets styleSheets = (ModelStyleSheets)eObject;
+ styleSheets.eAdapters().add(adapter);
+ for(StyleSheet styleSheet : styleSheets.getStylesheets()) {
+ styleSheet.eAdapters().add(adapter);
+ }
+ }
+ }
}
+
private static ExtendedCSSEngine getParentCSSEngine(Resource resource) {
ExtendedCSSEngine result;
if(resource instanceof CSSNotationResource) {
@@ -79,8 +119,14 @@ public class ModelCSSEngine extends ExtendedCSSEngineImpl {
@Override
protected void parseStyleSheet(StyleSheetReference styleSheet) throws IOException {
String path = styleSheet.getPath();
- if(path.startsWith("/")) {
- path = "platform:/plugin" + path;
+ if(path.startsWith("/")) { //Either plug-in or workspace
+ path = "platform:/resource" + path;
+ URL url = new URL(path);
+ try {
+ url.openConnection();
+ } catch (IOException ex) {
+ path = "platform:/plugin" + styleSheet.getPath();
+ }
} else {
URI uri = URI.createURI(styleSheet.getPath());
uri = uri.resolve(model.getURI());
@@ -90,6 +136,20 @@ public class ModelCSSEngine extends ExtendedCSSEngineImpl {
parseStyleSheet(url.openStream());
}
+ @Override
+ public void dispose() {
+ for(EObject eObject : model.getContents()) {
+ if(eObject instanceof ModelStyleSheets) {
+ ModelStyleSheets styleSheets = (ModelStyleSheets)eObject;
+ styleSheets.eAdapters().remove(adapter);
+ for(StyleSheet styleSheet : styleSheets.getStylesheets()) {
+ styleSheet.eAdapters().remove(adapter);
+ }
+ }
+ }
+ super.dispose();
+ }
+
//Unsupported operations. The ModelCSSEngine should not be used directly.
@Override
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSStyles.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSStyles.java
index a82d04faac4..0e2754c549b 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSStyles.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/notation/CSSStyles.java
@@ -41,6 +41,10 @@ public interface CSSStyles {
* The Diagram Stylesheets key
*/
public static final String CSS_DIAGRAM_STYLESHEETS_KEY = "css_stylesheets"; //$NON-NLS-1$
+ /**
+ * The Model Stylesheets key
+ */
+ public static final String CSS_MODEL_STYLESHEETS_KEY = "modelStyleSheets"; //$NON-NLS-1$
/**
* The list of reserved CSS Keywords used in GMF NamedStyle
@@ -51,7 +55,8 @@ public interface CSSStyles {
CSS_GMF_ID_KEY,
CSS_GMF_CLASS_KEY,
CSS_GMF_STYLE_KEY,
- CSS_DIAGRAM_STYLESHEETS_KEY
+ CSS_DIAGRAM_STYLESHEETS_KEY,
+ CSS_MODEL_STYLESHEETS_KEY
}));
}

Back to the top