/* * Fallbacks in case a property provider does not exist */ public static String getDisplayName(EObject object) { String objName = null; if (object instanceof BPMNDiagram) { Bpmn2DiagramType type = ModelUtil.getDiagramType((BPMNDiagram) object); if (type == Bpmn2DiagramType.CHOREOGRAPHY) { objName = "Choreography Diagram"; } else if (type == Bpmn2DiagramType.COLLABORATION) { objName = "Collaboration Diagram"; } else if (type == Bpmn2DiagramType.PROCESS) { objName = "Process Diagram"; } } if (objName == null) { objName = ModelUtil.toDisplayName(object.eClass().getName()); } EStructuralFeature feature = object.eClass().getEStructuralFeature("name"); if (feature != null) { String name = (String) object.eGet(feature); if (name == null || name.isEmpty()) name = "Unnamed " + objName; else name = objName + " \"" + name + "\""; return name; } feature = object.eClass().getEStructuralFeature("id"); if (feature != null) { if (object.eGet(feature) != null) objName = (String) object.eGet(feature); } feature = object.eClass().getEStructuralFeature("qName"); if (feature != null) { Object qName = object.eGet(feature); if (qName != null) { return qName.toString(); } } return objName; }
void createDefinitionsIfMissing() { EList<EObject> contents = resource.getContents(); if (contents.isEmpty() || !(contents.get(0) instanceof DocumentRoot)) { TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource); if (domain != null) { final DocumentRoot docRoot = FACTORY.createDocumentRoot(); final Definitions definitions = FACTORY.createDefinitions(); // definitions.setId(EcoreUtil.generateUUID()); ModelUtil.setID(definitions, resource); Collaboration collaboration = FACTORY.createCollaboration(); // collaboration.setId(EcoreUtil.generateUUID()); ModelUtil.setID(collaboration, resource); Participant participant = FACTORY.createParticipant(); // participant.setId(EcoreUtil.generateUUID()); ModelUtil.setID(participant, resource); participant.setName("Internal"); collaboration.getParticipants().add(participant); definitions.getRootElements().add(collaboration); domain .getCommandStack() .execute( new RecordingCommand(domain) { @Override protected void doExecute() { docRoot.setDefinitions(definitions); resource.getContents().add(docRoot); } }); return; } } }
private BPMNDiagram createDIDiagram(BaseElement bpmnElement) { BPMNDiagram bpmnDiagram = DIUtils.findBPMNDiagram(bpmnElement, true); // if this container does not have a BPMNDiagram, create one if (bpmnElement instanceof Process) { if (bpmnDiagram == null) { // unless this Process is referenced by a Pool for (Collaboration c : ModelUtil.getAllObjectsOfType(bpmnElement.eResource(), Collaboration.class)) { for (Participant p : c.getParticipants()) { if (!ModelUtil.isParticipantBand(p)) { if (p.getProcessRef() == bpmnElement) { bpmnDiagram = DIUtils.findBPMNDiagram(p, true); break; } } } if (bpmnDiagram != null) break; } } else { // Always create a new BPMNDiagram if this Process is being referenced by a Participant Band // for (Collaboration c : ModelUtil.getAllObjectsOfType(bpmnElement.eResource(), // Collaboration.class)) { // for (Participant p : c.getParticipants()) { // if (ModelUtil.isParticipantBand(p)) { // if (p.getProcessRef() == bpmnElement) { // bpmnDiagram = null; // break; // } // } // } // if (bpmnDiagram==null) // break; // } } } if (bpmnDiagram == null) { FlowElementsContainer container = getRootElementContainer(bpmnElement); if (container == null) { diagnostics.add(IStatus.ERROR, bpmnElement, Messages.DIGenerator_No_Diagram); return this.bpmnDiagram; } BPMNPlane plane = BpmnDiFactory.eINSTANCE.createBPMNPlane(); plane.setBpmnElement(container); bpmnDiagram = BpmnDiFactory.eINSTANCE.createBPMNDiagram(); bpmnDiagram.setName(ExtendedPropertiesProvider.getTextValue(container)); bpmnDiagram.setPlane(plane); definitions.getDiagrams().add(bpmnDiagram); } return bpmnDiagram; }
@Override public String getHeaderText() { if (headerText != null) return headerText; String text = ""; if (feature != null) { if (feature.eContainer() instanceof EClass) { EClass eclass = this.listComposite.getListItemClass(); text = ModelUtil.getLabel(eclass, feature); } else text = ModelUtil.toDisplayName(feature.getName()); } return text; }
public Lane createLane(Object target) { Lane lane = FACTORY.createLane(); // lane.setId(EcoreUtil.generateUUID()); ModelUtil.setID(lane, resource); FlowElementsContainer container = getFlowElementContainer(target); if (container.getLaneSets().isEmpty()) { LaneSet laneSet = FACTORY.createLaneSet(); // laneSet.setId(EcoreUtil.generateUUID()); container.getLaneSets().add(laneSet); } container.getLaneSets().get(0).getLanes().add(lane); ModelUtil.setID(lane); return lane; }
@Override public EObject createFeature(Resource resource, EClass eClass) { // what kind of object should we create? Property or DataStore? if (eClass == null) { if (ModelUtil.findNearestAncestor(object, new Class[] {Process.class, Event.class}) != null) // nearest ancestor is a Process or Event, so new object will be a Property eClass = Bpmn2Package.eINSTANCE.getProperty(); else if (ModelUtil.findNearestAncestor(object, new Class[] {DocumentRoot.class}) != null) eClass = Bpmn2Package.eINSTANCE.getDataStore(); } if (eClass != null) { return Bpmn2ModelerFactory.create(resource, eClass); } return null; }
@Override public boolean canDelete(IDeleteContext context) { // Participant bands in a ChoreographyTask only be "deleted" (from the model) // if there are no other references to the participant; but they can be "removed" // (from the ChoreographyTask's participantRef list) at any time. // @see RemoveChoreographyParticipantFeature PictogramElement pe = context.getPictogramElement(); if (ChoreographyUtil.isChoreographyParticipantBand(pe)) { int referenceCount = 0; Participant participant = BusinessObjectUtil.getFirstElementOfType(pe, Participant.class); Definitions definitions = ModelUtil.getDefinitions(participant); TreeIterator<EObject> iter = definitions.eAllContents(); while (iter.hasNext()) { EObject o = iter.next(); for (EReference reference : o.eClass().getEAllReferences()) { if (!reference.isContainment() && !(o instanceof DiagramElement)) { if (reference.isMany()) { List list = (List) o.eGet(reference); for (Object referencedObject : list) { if (referencedObject == participant) ++referenceCount; } } else { Object referencedObject = o.eGet(reference); if (referencedObject == participant) ++referenceCount; } } } } return referenceCount <= 1; } return true; }
private BPMNShape createDIShape( BPMNDiagram bpmnDiagram, BaseElement bpmnElement, float x, float y, boolean doImport) { BPMNPlane plane = bpmnDiagram.getPlane(); BPMNShape bpmnShape = null; for (DiagramElement de : plane.getPlaneElement()) { if (de instanceof BPMNShape) { if (bpmnElement == ((BPMNShape) de).getBpmnElement()) { bpmnShape = (BPMNShape) de; break; } } } if (bpmnShape == null) { bpmnShape = BpmnDiFactory.eINSTANCE.createBPMNShape(); bpmnShape.setBpmnElement(bpmnElement); Bounds bounds = DcFactory.eINSTANCE.createBounds(); bounds.setX(x); bounds.setY(y); ShapeStyle ss = preferences.getShapeStyle(bpmnElement); bounds.setWidth(ss.getDefaultWidth()); bounds.setHeight(ss.getDefaultHeight()); bpmnShape.setBounds(bounds); plane.getPlaneElement().add(bpmnShape); preferences.applyBPMNDIDefaults(bpmnShape, null); ModelUtil.setID(bpmnShape); if (doImport) importer.importShape(bpmnShape); } return bpmnShape; }
public void setValue(EObject object, EStructuralFeature feature, Object current) { // build the list of valid choices for this object/feature and cache it; // we'll need it again later in modify() choices = null; List<String> items = new ArrayList<String>(); choices = ModelUtil.getChoiceOfValues(object, feature); items.addAll(choices.keySet()); this.setItems(items.toArray(new String[items.size()])); // find the index of the current value in the choices list // need to handle both cases where current value matches the // choices key (a String) or an EObject int index = -1; for (int i = 0; i < items.size(); ++i) { if (current == choices.get(items.get(i))) { index = i; break; } if (current instanceof String) { if (current.equals(items.get(i))) { index = i; break; } } } this.setValue(new Integer(index)); }
private TargetRuntime getTargetRuntime(EObject object) { DiagramEditor editor = ModelUtil.getDiagramEditor(object); if (editor != null) { return (TargetRuntime) editor.getAdapter(TargetRuntime.class); } return null; }
private Collaboration getOrCreateCollaboration() { final List<RootElement> rootElements = getDefinitions().getRootElements(); for (RootElement element : rootElements) { if (element instanceof Collaboration) { return (Collaboration) element; } } TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource); final Collaboration collaboration = FACTORY.createCollaboration(); // collaboration.setId(EcoreUtil.generateUUID()); ModelUtil.setID(collaboration, resource); if (domain != null) { domain .getCommandStack() .execute( new RecordingCommand(domain) { @Override protected void doExecute() { addCollaborationToRootElements(rootElements, collaboration); } }); } return collaboration; }
@Override public PictogramElement add(IAddContext context) { IPeService peService = Graphiti.getPeService(); IGaService gaService = Graphiti.getGaService(); BaseElement element = (BaseElement) context.getNewObject(); IAddConnectionContext addConContext = (IAddConnectionContext) context; Connection connection = peService.createFreeFormConnection(getDiagram()); Object importProp = context.getProperty(DIImport.IMPORT_PROPERTY); if (importProp != null && (Boolean) importProp) { connection.setStart(addConContext.getSourceAnchor()); connection.setEnd(addConContext.getTargetAnchor()); } else { ContainerShape sourceContainer = (ContainerShape) addConContext.getSourceAnchor().eContainer(); ContainerShape targetContainer = (ContainerShape) addConContext.getTargetAnchor().eContainer(); Tuple<FixPointAnchor, FixPointAnchor> anchors = AnchorUtil.getSourceAndTargetBoundaryAnchors( sourceContainer, targetContainer, connection); connection.setStart(anchors.getFirst()); connection.setEnd(anchors.getSecond()); } if (ModelUtil.hasName(element)) { ConnectionDecorator labelDecorator = Graphiti.getPeService().createConnectionDecorator(connection, true, 0.5, true); Text text = gaService.createText(labelDecorator, ModelUtil.getName(element)); peService.setPropertyValue( labelDecorator, UpdateBaseElementNameFeature.TEXT_ELEMENT, Boolean.toString(true)); text.setStyle(StyleUtil.getStyleForText(getDiagram())); } Polyline connectionLine = gaService.createPolyline(connection); connectionLine.setForeground(manageColor(StyleUtil.CLASS_FOREGROUND)); decorateConnectionLine(connectionLine); createDIEdge(connection, element); createConnectionDecorators(connection); hook(addConContext, connection, element); return connection; }
@Override public Hashtable<String, Object> getChoiceOfValues() { List<EObject> values = new ArrayList<EObject>(); // search for all Properties and DataStores // Properties are contained in the nearest enclosing Process or Event; // DataStores are contained in the DocumentRoot EObject container = ModelUtil.getContainer(object); Object p = owner.getProperty(UI_SHOW_ITEMS_IN_SCOPE); if (p instanceof Boolean && (Boolean) p) { values.addAll( ModelUtil.collectAncestorObjects( container, "properties", new Class[] {Activity.class})); // $NON-NLS-1$ values.addAll( ModelUtil.collectAncestorObjects( container, "properties", new Class[] {Process.class})); // $NON-NLS-1$ values.addAll( ModelUtil.collectAncestorObjects( container, "properties", new Class[] {Event.class})); // $NON-NLS-1$ values.addAll( ModelUtil.collectAncestorObjects( container, "dataStore", new Class[] {DocumentRoot.class})); // $NON-NLS-1$ values.addAll( ModelUtil.collectAncestorObjects( container, "flowElements", new Class[] {FlowElementsContainer.class}, new Class[] {ItemAwareElement.class})); // $NON-NLS-1$ } else { if (container instanceof Activity) { Activity activity = (Activity) container; if (object instanceof DataInputAssociation) { values.addAll(ModelUtil.getItemAwareElements(activity.getDataInputAssociations())); } else { values.addAll(ModelUtil.getItemAwareElements(activity.getDataOutputAssociations())); } } else if (container instanceof ThrowEvent) { ThrowEvent event = (ThrowEvent) container; values.addAll(ModelUtil.getItemAwareElements(event.getDataInputAssociation())); } else if (container instanceof CatchEvent) { CatchEvent event = (CatchEvent) container; values.addAll(ModelUtil.getItemAwareElements(event.getDataOutputAssociation())); } } super.setChoiceOfValues(values); return super.getChoiceOfValues(); }
public void laneToTop(Lane lane) { LaneSet laneSet = FACTORY.createLaneSet(); // laneSet.setId(EcoreUtil.generateUUID()); ModelUtil.setID(laneSet, resource); laneSet.getLanes().add(lane); Process process = getOrCreateProcess(getInternalParticipant()); process.getLaneSets().add(laneSet); }
public Participant addParticipant() { Collaboration collaboration = getOrCreateCollaboration(); Participant participant = FACTORY.createParticipant(); // participant.setId(EcoreUtil.generateUUID()); ModelUtil.setID(participant, resource); collaboration.getParticipants().add(participant); return participant; }
public MessageFlow createMessageFlow(InteractionNode source, InteractionNode target) { MessageFlow messageFlow = FACTORY.createMessageFlow(); // messageFlow.setId(EcoreUtil.generateUUID()); ModelUtil.setID(messageFlow, resource); messageFlow.setSourceRef(source); messageFlow.setTargetRef(target); getOrCreateCollaboration().getMessageFlows().add(messageFlow); return messageFlow; }
public static String getLabel(EObject object, EStructuralFeature feature) { String label = ""; ExtendedPropertiesAdapter adapter = (ExtendedPropertiesAdapter) AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class); if (adapter != null) label = adapter.getFeatureDescriptor(feature).getLabel(object); else label = ModelUtil.toDisplayName(feature.getName()); label = label.replaceAll(" Ref$", ""); return label; }
private InputOutputSpecification getOrCreateIOSpecification(Object target) { Process process = getOrCreateProcess(getParticipant(target)); if (process.getIoSpecification() == null) { InputOutputSpecification ioSpec = FACTORY.createInputOutputSpecification(); // ioSpec.setId(EcoreUtil.generateUUID()); ModelUtil.setID(ioSpec, resource); process.setIoSpecification(ioSpec); } return process.getIoSpecification(); }
public DIGenerator(DIImport importer) { this.importer = importer; elements = importer.getImportedElements(); diagnostics = importer.getDiagnostics(); editor = importer.getEditor(); diagram = editor.getDiagramTypeProvider().getDiagram(); bpmnDiagram = BusinessObjectUtil.getFirstElementOfType(diagram, BPMNDiagram.class); definitions = ModelUtil.getDefinitions(bpmnDiagram); preferences = Bpmn2Preferences.getInstance(definitions); }
public SequenceFlow createSequenceFlow(FlowNode source, FlowNode target) { SequenceFlow sequenceFlow = FACTORY.createSequenceFlow(); // sequenceFlow.setId(EcoreUtil.generateUUID()); ModelUtil.setID(sequenceFlow, resource); addFlowElement(source, sequenceFlow); sequenceFlow.setSourceRef(source); sequenceFlow.setTargetRef(target); return sequenceFlow; }
public String getId(EObject object) { if (object == null) return null; List<EStructuralFeature> features = ModelUtil.getAnyAttributes(object); for (EStructuralFeature f : features) { if ("sampleCustomTaskId".equals(f.getName())) { Object attrValue = object.eGet(f); return (String) attrValue; } } return null; }
public Process getOrCreateProcess(Participant participant) { if (participant.getProcessRef() == null) { Process process = FACTORY.createProcess(); // process.setId(EcoreUtil.generateUUID()); ModelUtil.setID(process, resource); process.setName("Process for " + participant.getName()); getDefinitions().getRootElements().add(process); participant.setProcessRef(process); } return participant.getProcessRef(); }
/* * Various model object and feature UI property methods */ public static String getLabel(Object object) { String label = ""; if (object instanceof EObject) { EObject eObject = (EObject) object; ExtendedPropertiesAdapter adapter = (ExtendedPropertiesAdapter) AdapterUtil.adapt(eObject, ExtendedPropertiesAdapter.class); if (adapter != null) label = adapter.getObjectDescriptor().getLabel(eObject); else label = ModelUtil.toDisplayName(eObject.eClass().getName()); } else label = object.toString(); label = label.replaceAll(" Ref$", ""); return label; }
@Override protected EObject addListItem(EObject object, EStructuralFeature feature) { InputSet inputSet = throwEvent.getInputSet(); if (inputSet == null) { inputSet = FACTORY.createInputSet(); throwEvent.setInputSet(inputSet); ModelUtil.setID(inputSet); } // generate a unique parameter name String base = "inParam"; int suffix = 1; String name = base + suffix; for (; ; ) { boolean found = false; for (DataInput p : inputSet.getDataInputRefs()) { if (name.equals(p.getName())) { found = true; break; } } if (!found) break; name = base + ++suffix; } DataInput param = (DataInput) super.addListItem(object, feature); // add the new parameter to the InputSet (param).setName(name); inputSet.getDataInputRefs().add(param); // create a DataInputAssociation DataInputAssociation inputAssociation = FACTORY.createDataInputAssociation(); throwEvent.getDataInputAssociation().add(inputAssociation); inputAssociation.setTargetRef((DataInput) param); ModelUtil.setID(inputAssociation); return param; }
private void addCollaborationToRootElements( final List<RootElement> rootElements, final Collaboration collaboration) { Participant participant = FACTORY.createParticipant(); // participant.setId(EcoreUtil.generateUUID()); ModelUtil.setID(participant, resource); participant.setName("Internal"); for (RootElement element : rootElements) { if (element instanceof Process) { participant.setProcessRef((Process) element); break; } } collaboration.getParticipants().add(participant); rootElements.add(collaboration); }
protected void modify(EObject object, EStructuralFeature feature, Object value) { if (cellEditor instanceof CustomComboBoxCellEditor) { value = ((CustomComboBoxCellEditor) cellEditor).getChoice(value); } boolean result = ModelUtil.setValue(getEditingDomain(), object, feature, value); // if (result==false || getDiagramEditor().getDiagnostics()!=null) { // // revert the change and display error errorList message. // ErrorUtils.showErrorMessage(getDiagramEditor().getDiagnostics().getMessage()); // } // else { // ErrorUtils.showErrorMessage(null); // tableViewer.refresh(); // } tableViewer.refresh(); }
public Association createAssociation(BaseElement source, BaseElement target) { BaseElement e = null; if (getParticipant(source) != null) { e = source; } else if (getParticipant(target) != null) { e = target; } else { e = getInternalParticipant(); } Association association = FACTORY.createAssociation(); addArtifact(e, association); // association.setId(EcoreUtil.generateUUID()); ModelUtil.setID(association, resource); association.setSourceRef(source); association.setTargetRef(target); return association; }
public Lane createLane(Lane targetLane) { Lane lane = FACTORY.createLane(); // lane.setId(EcoreUtil.generateUUID()); ModelUtil.setID(lane, resource); if (targetLane.getChildLaneSet() == null) { targetLane.setChildLaneSet(ModelHandler.FACTORY.createLaneSet()); } LaneSet targetLaneSet = targetLane.getChildLaneSet(); targetLaneSet.getLanes().add(lane); lane.getFlowNodeRefs().addAll(targetLane.getFlowNodeRefs()); targetLane.getFlowNodeRefs().clear(); return lane; }
@Override public Connection create(ICreateConnectionContext context) { try { A source = getSourceBo(context); B target = getTargetBo(context); ModelHandler mh = ModelHandler.getInstance(getDiagram()); AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor()); BaseElement flow = createFlow(mh, source, target); // flow.setId(EcoreUtil.generateUUID()); addContext.setNewObject(flow); Connection connection = (Connection) getFeatureProvider().addIfPossible(addContext); ModelUtil.setID(flow); return connection; } catch (IOException e) { Activator.logError(e); } return null; }
@Override protected List<Object> getModelChildren() { List<Object> retList = new ArrayList<Object>(); FlowElement elem = getFlowElement(); if (elem instanceof FlowElementsContainer) { FlowElementsContainer container = (FlowElementsContainer) elem; return getFlowElementsContainerChildren(container); } else if (elem instanceof ChoreographyActivity) { ChoreographyActivity ca = (ChoreographyActivity) elem; retList.addAll(ca.getParticipantRefs()); } else if (elem instanceof CallActivity) { // render a Call Activity with its called element target // (a Process or Global Task) as the child node. CallableElement target = ((CallActivity) elem).getCalledElementRef(); if (target != null) { retList.add(target); } } else if (elem instanceof CatchEvent) { retList.addAll(((CatchEvent) elem).getEventDefinitions()); retList.addAll(((CatchEvent) elem).getDataOutputAssociation()); } else if (elem instanceof ThrowEvent) { retList.addAll(((ThrowEvent) elem).getEventDefinitions()); retList.addAll(((ThrowEvent) elem).getDataInputAssociation()); } if (elem instanceof Activity) { // Boundary Events are children nodes of Activities Definitions definitions = ModelUtil.getDefinitions(elem); if (definitions != null) { TreeIterator<EObject> iter = definitions.eAllContents(); while (iter.hasNext()) { EObject o = iter.next(); if (o instanceof BoundaryEvent && ((BoundaryEvent) o).getAttachedToRef() == elem) { retList.add(o); } } retList.addAll(((Activity) elem).getDataInputAssociations()); retList.addAll(((Activity) elem).getDataOutputAssociations()); } } return retList; }