Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Brodt2014-07-16 12:37:58 -0400
committerBob Brodt2014-07-16 12:37:58 -0400
commit0a97863229061d194e0693d1467073c5d4afb8db (patch)
tree30a7d26b3077a07aa8b88f8d729015fd98211d4c
parent443d65a5fe6ec95b373baf42e0c2eb47a428f66e (diff)
downloadorg.eclipse.bpmn2-modeler-0a97863229061d194e0693d1467073c5d4afb8db.tar.gz
org.eclipse.bpmn2-modeler-0a97863229061d194e0693d1467073c5d4afb8db.tar.xz
org.eclipse.bpmn2-modeler-0a97863229061d194e0693d1467073c5d4afb8db.zip
Fix ShapeStyle overrides from .bpmn2config files.
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/Bpmn2Preferences.java93
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/ShapeStyle.java11
-rw-r--r--plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/BPMN2Editor.java64
3 files changed, 95 insertions, 73 deletions
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/Bpmn2Preferences.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/Bpmn2Preferences.java
index f78df301..15de6b33 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/Bpmn2Preferences.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/Bpmn2Preferences.java
@@ -428,53 +428,54 @@ public class Bpmn2Preferences implements IResourceChangeListener, IPropertyChang
List<ShapeStyle> defaultShapeStyles = TargetRuntime.getDefaultRuntime().getShapeStyles();
String path = getShapeStylePath(rt);
Preferences prefs = defaultPreferences.node(path);
- for (ShapeStyle ss : rt.getShapeStyles()) {
+ for (ShapeStyle ss : defaultShapeStyles) {
String value = ShapeStyle.encode(ss);
prefs.put(ss.getObject(), value);
}
- if (rt!=TargetRuntime.getDefaultRuntime()) {
- for (ShapeStyle ss : defaultShapeStyles) {
- String value = ShapeStyle.encode(ss);
- prefs.put(ss.getObject(), value);
- }
- }
}
}
public void unloadDefaults(TargetRuntime rt, String key) {
- if (key.equals(PREF_TOOL_PROFILE)) {
- for (ModelEnablementDescriptor med : rt.getModelEnablements()) {
- String path = getToolProfilePath(rt);
- Preferences prefs = defaultPreferences.node(path);
- prefs.remove(med.getId());
- }
- }
- else if (key.equals(PREF_MODEL_ENABLEMENT)) {
- for (ModelEnablementDescriptor med : rt.getModelEnablements()) {
- String path = getModelEnablementsPath(rt, med.getId());
- Preferences prefs = defaultPreferences.node(path);
- for (String s : med.getAllEnabled()) {
- prefs.remove(s);
+ try {
+ if (key.equals(PREF_TOOL_PROFILE)) {
+ for (ModelEnablementDescriptor med : rt.getModelEnablements()) {
+ String path = getToolProfilePath(rt);
+ Preferences prefs = defaultPreferences.node(path);
+ prefs.remove(med.getId());
}
}
- String path = getModelEnablementsPath(rt, null);
- Preferences prefs = defaultPreferences.node(path);
- for (Entry<EClass, List<EStructuralFeature>> e : rt.getModelExtensions(0).entrySet()) {
- for (EStructuralFeature f : e.getValue()) {
- String s = e.getKey().getName() + "." + f.getName();
- prefs.remove(s);
+ else if (key.equals(PREF_MODEL_ENABLEMENT)) {
+ for (ModelEnablementDescriptor med : rt.getModelEnablements()) {
+ String path = getModelEnablementsPath(rt, med.getId());
+ Preferences prefs = defaultPreferences.node(path);
+ for (String s : med.getAllEnabled()) {
+ prefs.remove(s);
+ }
+ }
+ String path = getModelEnablementsPath(rt, null);
+ Preferences prefs = defaultPreferences.node(path);
+ for (Entry<EClass, List<EStructuralFeature>> e : rt.getModelExtensions(0).entrySet()) {
+ for (EStructuralFeature f : e.getValue()) {
+ String s = e.getKey().getName() + "." + f.getName();
+ prefs.remove(s);
+ }
}
}
- }
- else if (key.equals(PREF_SHAPE_STYLE)) {
- // Use ShapeStyles defined in the Default Target Runtime if an extension does not provide its own.
- String path = getShapeStylePath(rt);
- Preferences prefs = defaultPreferences.node(path);
- if (rt!=TargetRuntime.getDefaultRuntime()) {
- for (ShapeStyle ss : rt.getShapeStyles()) {
- prefs.remove(ss.getObject());
+ else if (key.equals(PREF_SHAPE_STYLE)) {
+ String path = getShapeStylePath(rt);
+ Preferences prefs = defaultPreferences.node(path);
+ prefs.removeNode();
+ if (instancePreferences!=null) {
+ prefs = instancePreferences.node(path);
+ prefs.removeNode();
}
+ if (instancePreferenceCache!=null)
+ instancePreferenceCache.shapeStyles.clear();
+ if (shapeStyles!=null)
+ shapeStyles.clear();
}
+ } catch (BackingStoreException e) {
+ e.printStackTrace();
}
}
@@ -696,15 +697,29 @@ public class Bpmn2Preferences implements IResourceChangeListener, IPropertyChang
}
public void setShapeStyle(String name, ShapeStyle style) {
- if (style.isDirty()) {
- shapeStyles.put(name, style);
+ if (style!=null) {
+ if (style.isDirty()) {
+ shapeStyles.put(name, style);
+ if (instancePreferenceCache!=null) {
+ instancePreferenceCache.shapeStyles.put(name, style);
+ }
+ String key = getShapeStyleKey(getRuntime(), name);
+ String value = ShapeStyle.encode(style);
+ put(key, value);
+ style.setDirty(false);
+ }
+ }
+ else {
+ shapeStyles.remove(name);
if (instancePreferenceCache!=null) {
- instancePreferenceCache.shapeStyles.put(name, style);
+ instancePreferenceCache.shapeStyles.remove(name);
}
+
String key = getShapeStyleKey(getRuntime(), name);
- String value = ShapeStyle.encode(style);
+ String path = getShapeStylePath(getRuntime());
+ Preferences prefs = defaultPreferences.node(path);
+ String value = prefs.get(name, "");
put(key, value);
- style.setDirty(false);
}
}
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/ShapeStyle.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/ShapeStyle.java
index 899245c4..56910d17 100644
--- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/ShapeStyle.java
+++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/preferences/ShapeStyle.java
@@ -13,6 +13,7 @@
package org.eclipse.bpmn2.modeler.core.preferences;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.bpmn2.BaseElement;
@@ -283,22 +284,18 @@ public class ShapeStyle extends BaseRuntimeExtensionDescriptor {
super.setConfigFile(configFile);
if (configFile!=null) {
Bpmn2Preferences prefs = Bpmn2Preferences.getInstance(configFile.getProject());
- prefs.loadDefaults(targetRuntime, Bpmn2Preferences.PREF_SHAPE_STYLE);
+ prefs.setShapeStyle(getObject(), this);
}
}
public void dispose() {
- // remove the ModelEnablement classes and features that may
+ // remove the ShapeStyle classes that may
// have been defined in this Model Extension
if (configFile!=null) {
Bpmn2Preferences prefs = Bpmn2Preferences.getInstance(configFile.getProject());
- prefs.unloadDefaults(targetRuntime, Bpmn2Preferences.PREF_SHAPE_STYLE);
+ prefs.setShapeStyle(getObject(), null);
}
super.dispose();
- if (configFile!=null) {
- Bpmn2Preferences prefs = Bpmn2Preferences.getInstance(configFile.getProject());
- prefs.loadDefaults(targetRuntime, Bpmn2Preferences.PREF_SHAPE_STYLE);
- }
}
@Override
diff --git a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/BPMN2Editor.java b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/BPMN2Editor.java
index 12d30621..4c5f6c54 100644
--- a/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/BPMN2Editor.java
+++ b/plugins/org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/editor/BPMN2Editor.java
@@ -16,7 +16,8 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.Hashtable;
+import java.util.Map.Entry;
import org.eclipse.bpmn2.Activity;
import org.eclipse.bpmn2.Assignment;
@@ -53,7 +54,6 @@ import org.eclipse.bpmn2.Import;
import org.eclipse.bpmn2.InputOutputSpecification;
import org.eclipse.bpmn2.Interface;
import org.eclipse.bpmn2.ItemDefinition;
-import org.eclipse.bpmn2.Lane;
import org.eclipse.bpmn2.LinkEventDefinition;
import org.eclipse.bpmn2.ManualTask;
import org.eclipse.bpmn2.Message;
@@ -61,7 +61,6 @@ import org.eclipse.bpmn2.MessageEventDefinition;
import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.MultiInstanceLoopCharacteristics;
import org.eclipse.bpmn2.Operation;
-import org.eclipse.bpmn2.Participant;
import org.eclipse.bpmn2.Performer;
import org.eclipse.bpmn2.PotentialOwner;
import org.eclipse.bpmn2.Process;
@@ -103,7 +102,6 @@ import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.DiagramEditorAdapter;
import org.eclipse.bpmn2.modeler.core.utils.ErrorUtils;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
-import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
import org.eclipse.bpmn2.modeler.core.utils.ModelUtil;
import org.eclipse.bpmn2.modeler.core.utils.ModelUtil.Bpmn2DiagramType;
import org.eclipse.bpmn2.modeler.core.utils.StyleUtil;
@@ -205,7 +203,6 @@ import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
@@ -1340,7 +1337,7 @@ public class BPMN2Editor extends DiagramEditor implements IPreferenceChangeListe
}
@Override
- public void preferenceChange(PreferenceChangeEvent event) {
+ public void preferenceChange(final PreferenceChangeEvent event) {
getPreferences().reload();
if (event.getKey().contains("/"+Bpmn2Preferences.PREF_MODEL_ENABLEMENT+"/")) //$NON-NLS-1$ //$NON-NLS-2$
@@ -1354,36 +1351,49 @@ public class BPMN2Editor extends DiagramEditor implements IPreferenceChangeListe
}
if (event.getKey().contains("/"+Bpmn2Preferences.PREF_SHAPE_STYLE+"/")) { //$NON-NLS-1$ //$NON-NLS-2$
+ int i = event.getKey().lastIndexOf('/');
+ if (i<=0)
+ return;
+ // Get the object type whose ShapeStyle has changed (e.g. "Task")
+ // and change it if possible. This needs to run in a transaction.
+ final String name = event.getKey().substring(i+1);
getEditingDomain().getCommandStack().execute(new RecordingCommand(getEditingDomain()) {
@Override
protected void doExecute() {
IFeatureProvider fp = BPMN2Editor.this.getDiagramTypeProvider().getFeatureProvider();
IPeService peService = Graphiti.getPeService();
- TreeIterator<EObject> iter = getDiagramTypeProvider().getDiagram().eAllContents();
- while (iter.hasNext()) {
- EObject o = iter.next();
- if (o instanceof PictogramElement) {
- PictogramElement pe = (PictogramElement)o;
- BaseElement be = BusinessObjectUtil.getFirstElementOfType(pe, BaseElement.class);
- if (be!=null) {
- TreeIterator<EObject> childIter = pe.eAllContents();
- while (childIter.hasNext()) {
- o = childIter.next();
- if (o instanceof GraphicsAlgorithm) {
- GraphicsAlgorithm ga = (GraphicsAlgorithm)o;
- if (peService.getPropertyValue(ga, Bpmn2Preferences.PREF_SHAPE_STYLE)!=null) {
+ // Collect all PictogramElements and their corresponding GraphicsAlgorithms
+ // to which the ShapeStyle change applies.
+ Resource resource = getDiagramTypeProvider().getDiagram().eResource();
+ for (PictogramElement pe : ModelUtil.getAllObjectsOfType(resource, PictogramElement.class)) {
+ BaseElement be = BusinessObjectUtil.getFirstElementOfType(pe, BaseElement.class);
+ // The Business Object class name must match the ShapeStyle type
+ if (be!=null && be.eClass().getName().equals(name)) {
+ // find all of this PE's GraphicsAlgorithrms that have the
+ // PREF_SHAPE_STYLE property set - this is the GA to which
+ // the ShapeStyle applies.
+ TreeIterator<EObject> childIter = pe.eAllContents();
+ while (childIter.hasNext()) {
+ EObject o = childIter.next();
+ if (o instanceof GraphicsAlgorithm) {
+ GraphicsAlgorithm ga = (GraphicsAlgorithm)o;
+ if (peService.getPropertyValue(ga, Bpmn2Preferences.PREF_SHAPE_STYLE)!=null) {
+ // If the ShapeStyle for this BaseElement has already
+ // been changed by the user, do not reset it.
+ String style = ShapeStyle.encode(ShapeStyle.getShapeStyle(be));
+ if (style.equals(event.getNewValue())) {
StyleUtil.applyStyle(ga, be);
+ if (pe instanceof Shape && FeatureSupport.isLabelShape((Shape)pe)) {
+ UpdateContext context = new UpdateContext(pe);
+ IUpdateFeature feature = fp.getUpdateFeature(context);
+ if (feature!=null) {
+ feature.update(context);
+ }
+ }
}
}
-
- }
- }
- if (pe instanceof Shape && FeatureSupport.isLabelShape((Shape)pe)) {
- UpdateContext context = new UpdateContext(pe);
- IUpdateFeature feature = fp.getUpdateFeature(context);
- if (feature!=null) {
- feature.update(context);
}
+
}
}
}

Back to the top