Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-03-19 10:26:32 +0000
committercletavernie2012-03-19 10:26:32 +0000
commit55ad9e14bc353ad6b09880c1b56a0b260eeedfac (patch)
tree89ef6578f0b6f0d8cb5e5cc97672dc7dda9b47d0 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org
parent7293985c3c7cff45fe02b74c0fd6630a4468dd28 (diff)
downloadorg.eclipse.papyrus-55ad9e14bc353ad6b09880c1b56a0b260eeedfac.tar.gz
org.eclipse.papyrus-55ad9e14bc353ad6b09880c1b56a0b260eeedfac.tar.xz
org.eclipse.papyrus-55ad9e14bc353ad6b09880c1b56a0b260eeedfac.zip
370797: [Theme] Papyrus should provide a support for CSS files on its diagrams
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370797
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/AppearanceConstraint.java99
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/IsEditPartConstraint.java6
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/NotationStyleHandlerProvider.java49
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/StyleHandlerManager.java57
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/AppearanceModelElementFactory.java44
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java2
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/StyleHandlerProvider.java61
7 files changed, 315 insertions, 3 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/AppearanceConstraint.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/AppearanceConstraint.java
new file mode 100644
index 00000000000..4807b18e152
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/AppearanceConstraint.java
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.constraint;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
+import org.eclipse.papyrus.infra.constraints.DisplayUnit;
+import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
+import org.eclipse.papyrus.infra.gmfdiag.properties.extension.StyleHandlerManager;
+import org.eclipse.papyrus.infra.gmfdiag.properties.modelelement.StyleHandlerProvider;
+import org.eclipse.papyrus.views.properties.Activator;
+
+/**
+ * A constraint matching an Object on which the Appearance properties can
+ * be applied. This constraint dispatches
+ *
+ * @author Camille Letavernier
+ */
+public class AppearanceConstraint implements Constraint {
+
+ private final List<Constraint> constraints;
+
+ private DisplayUnit display;
+
+ private ConstraintDescriptor descriptor;
+
+ public AppearanceConstraint() {
+ constraints = new LinkedList<Constraint>();
+ for(StyleHandlerProvider provider : StyleHandlerManager.instance.getStyleHandlerProviders()) {
+ try {
+ Constraint constraint = provider.createConstraint();
+ if(constraint == null) {
+ Activator.log.warn("StyleHandlerProvider " + provider.getClass().getName() + " provided an invalid Constraint");
+ } else {
+ constraints.add(constraint);
+ }
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ }
+ }
+ }
+
+ public boolean overrides(Constraint constraint) {
+ //Unsupported. The appearance property view constraints are not automatically overrideable
+ return false;
+ }
+
+ public boolean match(IStructuredSelection selection) {
+ for(Constraint constraint : constraints) {
+ if(constraint.match(selection)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void setConstraintDescriptor(ConstraintDescriptor descriptor) {
+ this.descriptor = descriptor;
+ display = getDisplay(descriptor);
+
+ for(Constraint constraint : constraints) {
+ try {
+ constraint.setConstraintDescriptor(descriptor);
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ }
+ }
+ }
+
+ public DisplayUnit getDisplayUnit() {
+ return display;
+ }
+
+ private DisplayUnit getDisplay(ConstraintDescriptor descriptor) {
+ if(descriptor.getDisplay() == null) {
+ if(descriptor.eContainer() instanceof ConstraintDescriptor) {
+ return getDisplay((ConstraintDescriptor)descriptor.eContainer());
+ }
+ }
+ return descriptor.getDisplay();
+ }
+
+ public ConstraintDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/IsEditPartConstraint.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/IsEditPartConstraint.java
index a44467b4f65..2a716fea4a8 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/IsEditPartConstraint.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/constraint/IsEditPartConstraint.java
@@ -12,18 +12,20 @@
package org.eclipse.papyrus.infra.gmfdiag.properties.constraint;
import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.papyrus.infra.constraints.constraints.AbstractConstraint;
import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
/**
- * Tests if the selection is an EditPart
+ * Tests if the selection is an EditPart (Excluding DiagramEditPart)
*
* @author Camille Letavernier
*/
public class IsEditPartConstraint extends AbstractConstraint {
+ @Override
public boolean match(Object selection) {
- return selection instanceof EditPart;
+ return selection instanceof EditPart && !(selection instanceof DiagramEditPart);
}
/**
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/NotationStyleHandlerProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/NotationStyleHandlerProvider.java
new file mode 100644
index 00000000000..fdba8fba81e
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/NotationStyleHandlerProvider.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.extension;
+
+import org.eclipse.gmf.runtime.notation.datatype.GradientData;
+import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.gmfdiag.properties.constraint.GMFNotationConstraint;
+import org.eclipse.papyrus.infra.gmfdiag.properties.modelelement.NotationModelElementFactory;
+import org.eclipse.papyrus.infra.gmfdiag.properties.modelelement.StyleHandlerProvider;
+import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory;
+
+/**
+ * Default implementation of StyleHandlerProvider
+ * Handles the GMF Notation views (With a low priority)
+ *
+ * @author Camille Letavernier
+ */
+public class NotationStyleHandlerProvider implements StyleHandlerProvider {
+
+ private ModelElementFactory factory = new NotationModelElementFactory();
+
+ public Constraint createConstraint() {
+ return new GMFNotationConstraint();
+ }
+
+ public boolean isProviderFor(Object selection) {
+ if(selection instanceof GradientData) {
+ return true;
+ }
+ return NotationHelper.findView(selection) != null;
+ }
+
+ public ModelElement createModelElement(Object selection, DataContextElement context) {
+ return factory.createFromSource(selection, context);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/StyleHandlerManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/StyleHandlerManager.java
new file mode 100644
index 00000000000..27f73c9509c
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/extension/StyleHandlerManager.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.extension;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.gmfdiag.properties.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.properties.modelelement.StyleHandlerProvider;
+
+
+public class StyleHandlerManager {
+
+ public static final String EXTENSION_ID = Activator.PLUGIN_ID + ".stylehandler";
+
+ private final List<StyleHandlerProvider> providers;
+
+ private StyleHandlerManager() {
+ Map<Integer, StyleHandlerProvider> providersMap = new TreeMap<Integer, StyleHandlerProvider>();
+
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+
+ for(IConfigurationElement e : config) {
+ try {
+ StyleHandlerProvider provider = (StyleHandlerProvider)e.createExecutableExtension("provider"); //$NON-NLS-1$
+ String priorityString = e.getAttribute("priority");
+ int priority = Integer.parseInt(priorityString);
+ providersMap.put(priority, provider);
+ } catch (NumberFormatException ex) {
+ Activator.log.error("The plugin " + e.getContributor() + " provided an invalid extension for " + EXTENSION_ID, ex);
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ }
+ }
+
+ providers = new LinkedList<StyleHandlerProvider>(providersMap.values());
+ }
+
+ public List<StyleHandlerProvider> getStyleHandlerProviders() {
+ return providers;
+ }
+
+ public static StyleHandlerManager instance = new StyleHandlerManager();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/AppearanceModelElementFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/AppearanceModelElementFactory.java
new file mode 100644
index 00000000000..11f5520683c
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/AppearanceModelElementFactory.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.modelelement;
+
+import org.eclipse.papyrus.infra.gmfdiag.properties.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.properties.extension.StyleHandlerManager;
+import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory;
+
+/**
+ * A ModelElementFactory for the Appearance property view. Dispatches the
+ * creation of ModelElement to the registered StyleHandlerProvider with
+ * the highest priority.
+ *
+ * @author Camille Letavernier
+ */
+public class AppearanceModelElementFactory implements ModelElementFactory {
+
+ public ModelElement createFromSource(Object sourceElement, DataContextElement context) {
+ for(StyleHandlerProvider provider : StyleHandlerManager.instance.getStyleHandlerProviders()) {
+ if(provider.isProviderFor(sourceElement)) {
+ ModelElement element = provider.createModelElement(sourceElement, context);
+ if(element == null) {
+ Activator.log.warn("The StyleHandlerProvider " + provider.getClass().getName() + " provided an invalid ModelElement");
+ }
+ return element;
+ }
+ }
+
+ Activator.log.warn("No StyleHandlerProvider found for the following object: " + sourceElement);
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
index c83369ed04d..49c6626c916 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java
@@ -61,7 +61,7 @@ public class GMFModelElement extends EMFModelElement {
}
@Override
- public IObservable doGetObservable(String propertyPath) {
+ protected IObservable doGetObservable(String propertyPath) {
FeaturePath featurePath = getFeaturePath(propertyPath);
EStructuralFeature feature = getFeature(propertyPath);
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/StyleHandlerProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/StyleHandlerProvider.java
new file mode 100644
index 00000000000..8f93d6981c7
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/StyleHandlerProvider.java
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright (c) 2012 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.properties.modelelement;
+
+import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
+import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
+import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
+
+/**
+ *
+ * Provides a ModelElement and a Constraint implementation for a given
+ * selection.
+ *
+ * More than one implementation can be provided, with different priorities,
+ * so that the Appearance property view can be used to edit different models,
+ * in different contexts (e.g. Notation model, CSS stylesheet, Preferences...)
+ *
+ * The Providers can be registered through the extension point:
+ * org.eclipse.papyrus.infra.gmfdiag.properties.stylehandler
+ *
+ * @author Camille Letavernier
+ *
+ */
+//TODO: Can this be generalized to the whole property view framework?
+public interface StyleHandlerProvider {
+
+ /**
+ * Returns a Constraint implementation
+ *
+ * @return
+ */
+ public Constraint createConstraint();
+
+ /**
+ * Tests whether this provider can handle the given selection.
+ *
+ * @param selection
+ * @return
+ */
+ public boolean isProviderFor(Object selection);
+
+ /**
+ * Returns a ModelElement for the given selection. This method can only be
+ * called when {@link #isProviderFor(Object)} returns true for the given
+ * selection.
+ *
+ * @param selection
+ * @param context
+ * @return
+ */
+ public ModelElement createModelElement(Object selection, DataContextElement context);
+}

Back to the top