Permalink
Browse files

Merge pull request #5 from bbrodt/generate-readable-ids

generate human-readable IDs
  • Loading branch information...
2 parents e8aa118 + 8f0babd commit 8d59778719da29611c23e8099d253a9d6ec8d71c @imeikas committed Jul 6, 2011
Showing with 208 additions and 38 deletions.
  1. +31 −15 org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/ModelHandler.java
  2. +111 −0 org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIImport.java
  3. +2 −1 org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/di/DIUtils.java
  4. +5 −2 ...clipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AbstractBpmnAddFeature.java
  5. +3 −1 ...n2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/AbstractCreateFlowElementFeature.java
  6. +3 −1 ...deler.core/src/org/eclipse/bpmn2/modeler/core/features/data/AbstractCreateRootElementFeature.java
  7. +5 −2 ...pmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/flow/AbstractCreateFlowFeature.java
  8. +3 −1 ...2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromDiagramToLaneFeature.java
  9. +3 −1 ...er.core/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromDiagramToParticipantFeature.java
  10. +3 −1 ...pmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromLaneToLaneFeature.java
  11. +3 −1 ...deler.core/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromLaneToParticipantFeature.java
  12. +3 −1 ...er.core/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromParticipantToDiagramFeature.java
  13. +3 −1 ...deler.core/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromParticipantToLaneFeature.java
  14. +3 −1 ...ore/src/org/eclipse/bpmn2/modeler/core/features/lane/MoveFromParticipantToParticipantFeature.java
  15. +3 −1 ...n2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/artifact/CreateTextAnnotationFeature.java
  16. +3 −1 ...se.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/artifact/GroupFeatureContainer.java
  17. +3 −1 ....modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/conversation/CreateConversationFeature.java
  18. +3 −1 ...se.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/DataInputFeatureContainer.java
  19. +3 −1 ...e.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/DataOutputFeatureContainer.java
  20. +3 −1 ...modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/data/DataStoreReferenceFeatureContainer.java
  21. +3 −1 ....bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/features/event/BoundaryEventCreateFeature.java
  22. +3 −1 ...i/src/org/eclipse/bpmn2/modeler/ui/features/event/definitions/CancelEventDefinitionContainer.java
  23. +3 −1 ...mn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/property/ImprovedAdvancedPropertiesComposite.java
@@ -40,6 +40,7 @@
import org.eclipse.bpmn2.di.BPMNDiagram;
import org.eclipse.bpmn2.di.BPMNEdge;
import org.eclipse.bpmn2.di.BPMNShape;
+import org.eclipse.bpmn2.modeler.core.di.DIImport;
import org.eclipse.bpmn2.modeler.core.features.BusinessObjectUtil;
import org.eclipse.bpmn2.util.Bpmn2ResourceImpl;
import org.eclipse.dd.di.DiagramElement;
@@ -72,11 +73,14 @@ void createDefinitionsIfMissing() {
if (domain != null) {
final DocumentRoot docRoot = FACTORY.createDocumentRoot();
final Definitions definitions = FACTORY.createDefinitions();
- definitions.setId(EcoreUtil.generateUUID());
+// definitions.setId(EcoreUtil.generateUUID());
+ DIImport.setID(definitions,resource);
Collaboration collaboration = FACTORY.createCollaboration();
- collaboration.setId(EcoreUtil.generateUUID());
+// collaboration.setId(EcoreUtil.generateUUID());
+ DIImport.setID(collaboration,resource);
Participant participant = FACTORY.createParticipant();
- participant.setId(EcoreUtil.generateUUID());
+// participant.setId(EcoreUtil.generateUUID());
+ DIImport.setID(participant,resource);
participant.setName("Internal");
collaboration.getParticipants().add(participant);
definitions.getRootElements().add(collaboration);
@@ -149,7 +153,8 @@ private InputOutputSpecification getOrCreateIOSpecification(Object target) {
Process process = getOrCreateProcess(getParticipant(target));
if (process.getIoSpecification() == null) {
InputOutputSpecification ioSpec = FACTORY.createInputOutputSpecification();
- ioSpec.setId(EcoreUtil.generateUUID());
+// ioSpec.setId(EcoreUtil.generateUUID());
+ DIImport.setID(ioSpec,resource);
process.setIoSpecification(ioSpec);
}
return process.getIoSpecification();
@@ -169,7 +174,8 @@ public void moveFlowNode(FlowNode node, Object source, Object target) {
public Participant addParticipant() {
Collaboration collaboration = getOrCreateCollaboration();
Participant participant = FACTORY.createParticipant();
- participant.setId(EcoreUtil.generateUUID());
+// participant.setId(EcoreUtil.generateUUID());
+ DIImport.setID(participant,resource);
collaboration.getParticipants().add(participant);
return participant;
}
@@ -196,7 +202,8 @@ public void moveLane(Lane movedLane, Participant sourceParticipant, Participant
public Process getOrCreateProcess(Participant participant) {
if (participant.getProcessRef() == null) {
Process process = FACTORY.createProcess();
- process.setId(EcoreUtil.generateUUID());
+// process.setId(EcoreUtil.generateUUID());
+ DIImport.setID(process,resource);
process.setName("Process for " + participant.getName());
getDefinitions().getRootElements().add(process);
participant.setProcessRef(process);
@@ -206,7 +213,8 @@ public Process getOrCreateProcess(Participant participant) {
public Lane createLane(Lane targetLane) {
Lane lane = FACTORY.createLane();
- lane.setId(EcoreUtil.generateUUID());
+// lane.setId(EcoreUtil.generateUUID());
+ DIImport.setID(lane,resource);
if (targetLane.getChildLaneSet() == null) {
targetLane.setChildLaneSet(ModelHandler.FACTORY.createLaneSet());
@@ -223,28 +231,32 @@ public Lane createLane(Lane targetLane) {
public Lane createLane(Object target) {
Lane lane = FACTORY.createLane();
- lane.setId(EcoreUtil.generateUUID());
+// lane.setId(EcoreUtil.generateUUID());
+ DIImport.setID(lane,resource);
FlowElementsContainer container = getFlowElementContainer(target);
if (container.getLaneSets().isEmpty()) {
LaneSet laneSet = FACTORY.createLaneSet();
- laneSet.setId(EcoreUtil.generateUUID());
+// laneSet.setId(EcoreUtil.generateUUID());
container.getLaneSets().add(laneSet);
}
container.getLaneSets().get(0).getLanes().add(lane);
+ DIImport.setID(lane);
return lane;
}
public void laneToTop(Lane lane) {
LaneSet laneSet = FACTORY.createLaneSet();
- laneSet.setId(EcoreUtil.generateUUID());
+// laneSet.setId(EcoreUtil.generateUUID());
+ DIImport.setID(laneSet,resource);
laneSet.getLanes().add(lane);
Process process = getOrCreateProcess(getInternalParticipant());
process.getLaneSets().add(laneSet);
}
public SequenceFlow createSequenceFlow(FlowNode source, FlowNode target) {
SequenceFlow sequenceFlow = FACTORY.createSequenceFlow();
- sequenceFlow.setId(EcoreUtil.generateUUID());
+// sequenceFlow.setId(EcoreUtil.generateUUID());
+ DIImport.setID(sequenceFlow,resource);
addFlowElement(source, sequenceFlow);
sequenceFlow.setSourceRef(source);
@@ -254,7 +266,8 @@ public SequenceFlow createSequenceFlow(FlowNode source, FlowNode target) {
public MessageFlow createMessageFlow(InteractionNode source, InteractionNode target) {
MessageFlow messageFlow = FACTORY.createMessageFlow();
- messageFlow.setId(EcoreUtil.generateUUID());
+// messageFlow.setId(EcoreUtil.generateUUID());
+ DIImport.setID(messageFlow,resource);
messageFlow.setSourceRef(source);
messageFlow.setTargetRef(target);
getOrCreateCollaboration().getMessageFlows().add(messageFlow);
@@ -280,7 +293,8 @@ public Association createAssociation(BaseElement source, BaseElement target) {
}
Association association = FACTORY.createAssociation();
addArtifact(e, association);
- association.setId(EcoreUtil.generateUUID());
+// association.setId(EcoreUtil.generateUUID());
+ DIImport.setID(association,resource);
association.setSourceRef(source);
association.setTargetRef(target);
return association;
@@ -296,7 +310,8 @@ private Collaboration getOrCreateCollaboration() {
}
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);
final Collaboration collaboration = FACTORY.createCollaboration();
- collaboration.setId(EcoreUtil.generateUUID());
+// collaboration.setId(EcoreUtil.generateUUID());
+ DIImport.setID(collaboration,resource);
if (domain != null) {
domain.getCommandStack().execute(new RecordingCommand(domain) {
@@ -311,7 +326,8 @@ protected void doExecute() {
private void addCollaborationToRootElements(final List<RootElement> rootElements, final Collaboration collaboration) {
Participant participant = FACTORY.createParticipant();
- participant.setId(EcoreUtil.generateUUID());
+// participant.setId(EcoreUtil.generateUUID());
+ DIImport.setID(participant,resource);
participant.setName("Internal");
for (RootElement element : rootElements) {
if (element instanceof Process) {
@@ -11,6 +11,7 @@
package org.eclipse.bpmn2.modeler.core.di;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.List;
import org.eclipse.bpmn2.Association;
@@ -41,7 +42,12 @@
import org.eclipse.dd.dc.Point;
import org.eclipse.dd.di.DiagramElement;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.datatypes.ILocation;
@@ -73,6 +79,8 @@
private ModelHandler modelHandler;
private IFeatureProvider featureProvider;
private HashMap<BaseElement, PictogramElement> elements;
+ private static HashMap<ResourceSet, Hashtable<String, EObject>> ids = new HashMap<ResourceSet, Hashtable<String, EObject>>();
+ private static HashMap<String, Integer> defaultIds = new HashMap<String, Integer>();
private final IPeService peService = Graphiti.getPeService();
private final IGaService gaService = Graphiti.getGaService();
@@ -101,6 +109,20 @@ protected void doExecute() {
}
for (BPMNDiagram d : diagrams) {
+ TreeIterator<EObject> iter = d.eAllContents();
+ while (iter.hasNext()) {
+ EObject obj = iter.next();
+ EStructuralFeature feature = ((EObject)obj).eClass().getEStructuralFeature("id");
+ if (feature!=null) {
+ Object value = obj.eGet(feature);
+ if (value!=null) {
+ addID(obj,(String)value);
+ }
+ }
+ }
+ }
+
+ for (BPMNDiagram d : diagrams) {
featureProvider.link(diagram, d);
BPMNPlane plane = d.getPlane();
if (plane.getBpmnElement() == null) {
@@ -416,4 +438,93 @@ private void setAnchorLocation(PictogramElement elem, FixPointAnchor anchor, Poi
anchor.setLocation(p);
}
+
+
+ private static String getObjectName(EObject obj) {
+ String name;
+ EStructuralFeature feature = ((EObject)obj).eClass().getEStructuralFeature("bpmnElement");
+ if (feature!=null) {
+ EObject bpmnElement = (EObject) obj.eGet(feature);
+ name = obj.eClass().getName() + "_" + bpmnElement.eClass().getName();
+ }
+ else {
+ name = obj.eClass().getName();
+ }
+ return name;
+ }
+
+ public static String generateDefaultID(EObject obj) {
+ String name = getObjectName(obj);
+ Integer value = defaultIds.get(name);
+ if (value==null)
+ value = Integer.valueOf(1);
+ value = Integer.valueOf( value.intValue() + 1 );
+ defaultIds.put(name, Integer.valueOf(value));
+
+ return "_" + name + "_" + value;
+ }
+
+ public static String generateID(EObject obj) {
+ return generateID(obj,obj.eResource());
+ }
+
+ public static String generateID(EObject obj, Resource res) {
+ ResourceSet resSet = (res==null || res.getResourceSet()==null) ? null : res.getResourceSet();
+ if (resSet!=null) {
+ Hashtable<String, EObject> tab = ids.get(resSet);
+ if (tab==null) {
+ tab = new Hashtable<String, EObject>();
+ ids.put(resSet, tab);
+ }
+
+ String name = getObjectName(obj);
+ for (int i=1;; ++i) {
+ String id = name + "_" + i;
+ if (tab.get(id)==null) {
+ tab.put(id, obj);
+ return id;
+ }
+ }
+ }
+ return generateDefaultID(obj);
+ }
+
+ private static void addID(EObject obj, String id) {
+ Resource res = obj.eResource();
+ ResourceSet resSet = res.getResourceSet()==null ? null : res.getResourceSet();
+ if (res==null || resSet==null || id.startsWith("_")) {
+ String name = getObjectName(obj);
+ int newValue = 0;
+ try {
+ newValue = Integer.parseInt(id.substring(1));
+ } catch (Exception e) {
+ }
+ Integer oldValue = defaultIds.get(name);
+ if (oldValue==null || newValue > oldValue.intValue())
+ defaultIds.put(name, Integer.valueOf(newValue));
+ }
+ else {
+ Hashtable<String, EObject> tab = ids.get(resSet);
+ if (tab==null) {
+ tab = new Hashtable<String, EObject>();
+ ids.put(resSet, tab);
+ }
+ tab.put(id, obj);
+ }
+ }
+
+ public static void setID(EObject obj) {
+ setID(obj,obj.eResource());
+ }
+
+ public static void setID(EObject obj, Resource res) {
+ EStructuralFeature feature = ((EObject)obj).eClass().getEStructuralFeature("id");
+ if (feature!=null) {
+ obj.eSet(feature, generateID(obj,res));
+ }
+ }
+
+ public void clearIDs(Resource res) {
+
+ }
}
@@ -140,7 +140,7 @@ public static BPMNShape createDIShape(Shape shape, BaseElement elem, int x, int
BPMNDiagram bpmnDiagram = (BPMNDiagram) eObject;
bpmnShape = BpmnDiFactory.eINSTANCE.createBPMNShape();
- bpmnShape.setId(EcoreUtil.generateUUID());
+// bpmnShape.setId(EcoreUtil.generateUUID());
bpmnShape.setBpmnElement(elem);
Bounds bounds = DcFactory.eINSTANCE.createBounds();
bounds.setX(x);
@@ -151,6 +151,7 @@ public static BPMNShape createDIShape(Shape shape, BaseElement elem, int x, int
List<DiagramElement> elements = bpmnDiagram.getPlane().getPlaneElement();
elements.add(bpmnShape);
+ DIImport.setID(shape);
fp.link(shape, new Object[] { elem, bpmnShape });
break;
@@ -25,6 +25,7 @@
import org.eclipse.bpmn2.modeler.core.Activator;
import org.eclipse.bpmn2.modeler.core.ModelHandler;
import org.eclipse.bpmn2.modeler.core.ModelHandlerLocator;
+import org.eclipse.bpmn2.modeler.core.di.DIImport;
import org.eclipse.dd.dc.Bounds;
import org.eclipse.dd.dc.DcFactory;
import org.eclipse.dd.dc.Point;
@@ -65,7 +66,7 @@ protected void createDIShape(Shape gShape, BaseElement elem, BPMNShape shape) {
BPMNDiagram bpmnDiagram = (BPMNDiagram) eObject;
shape = BpmnDiFactory.eINSTANCE.createBPMNShape();
- shape.setId(EcoreUtil.generateUUID());
+// shape.setId(EcoreUtil.generateUUID());
shape.setBpmnElement(elem);
Bounds bounds = DcFactory.eINSTANCE.createBounds();
if (elem instanceof Activity) {
@@ -79,6 +80,7 @@ protected void createDIShape(Shape gShape, BaseElement elem, BPMNShape shape) {
shape.setBounds(bounds);
addShape(shape, bpmnDiagram);
+ DIImport.setID(shape);
}
}
}
@@ -111,7 +113,7 @@ protected void createDIEdge(Connection connection, BaseElement conElement, BPMNE
BPMNDiagram bpmnDiagram = (BPMNDiagram) eObject;
edge = BpmnDiFactory.eINSTANCE.createBPMNEdge();
- edge.setId(EcoreUtil.generateUUID());
+// edge.setId(EcoreUtil.generateUUID());
edge.setBpmnElement(conElement);
if (conElement instanceof Association) {
@@ -145,6 +147,7 @@ protected void createDIEdge(Connection connection, BaseElement conElement, BPMNE
edge.getWaypoint().add(point);
addShape(edge, bpmnDiagram);
+ DIImport.setID(edge);
}
}
}
@@ -18,6 +18,7 @@
import org.eclipse.bpmn2.Lane;
import org.eclipse.bpmn2.modeler.core.Activator;
import org.eclipse.bpmn2.modeler.core.ModelHandler;
+import org.eclipse.bpmn2.modeler.core.di.DIImport;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
@@ -46,7 +47,7 @@ public boolean canCreate(ICreateContext context) {
try {
ModelHandler handler = ModelHandler.getInstance(getDiagram());
element = createFlowElement(context);
- element.setId(EcoreUtil.generateUUID());
+// element.setId(EcoreUtil.generateUUID());
if (FeatureSupport.isTargetLane(context) && element instanceof FlowNode) {
((FlowNode) element).getLanes().add(
(Lane) getBusinessObjectForPictogramElement(context.getTargetContainer()));
@@ -57,6 +58,7 @@ public boolean canCreate(ICreateContext context) {
Activator.logError(e);
}
addGraphicalRepresentation(context, element);
+ DIImport.setID(element);
return new Object[] { element };
}
@@ -16,6 +16,7 @@
import org.eclipse.bpmn2.modeler.core.Activator;
import org.eclipse.bpmn2.modeler.core.ModelHandler;
import org.eclipse.bpmn2.modeler.core.ModelHandlerLocator;
+import org.eclipse.bpmn2.modeler.core.di.DIImport;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
@@ -39,13 +40,14 @@ public boolean canCreate(ICreateContext context) {
try {
ModelHandler handler = ModelHandlerLocator.getModelHandler(getDiagram().eResource());
element = createRootElement();
- element.setId(EcoreUtil.generateUUID());
+// element.setId(EcoreUtil.generateUUID());
handler.addRootElement(element);
} catch (IOException e) {
Activator.logError(e);
}
addGraphicalRepresentation(context, element);
+ DIImport.setID(element);
return new Object[] { element };
}
Oops, something went wrong.

0 comments on commit 8d59778

Please sign in to comment.