extend SequenceFlow [message #1097251] |
Thu, 29 August 2013 08:46  |
Eclipse User |
|
|
|
hi;
I want to extend a Sequence Flow with an attribut when it links two event (that I defined).
In ather words I want the behaviour of Sequence Flow persist and I want to have a new connection shape in a sub palette.
is it possible?
thanks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: extend SequenceFlow [message #1125212 is a reply to message #1124262] |
Fri, 04 October 2013 05:19   |
Eclipse User |
|
|
|
Hi Robert;
Quote:
package org.eclipse.bpmn2.modeler.examples.time;
import org.eclipse.bpmn2.BaseElement;
import org.eclipse.bpmn2.Event;
import org.eclipse.bpmn2.modeler.core.features.FeatureContainer;
import org.eclipse.bpmn2.modeler.core.features.event.definitions.AbstractAddEventDefinitionFeature;
import org.eclipse.bpmn2.modeler.core.features.event.definitions.AbstractEventDefinitionFeatureContainer;
import org.eclipse.bpmn2.modeler.core.features.event.definitions.CreateEventDefinition;
import org.eclipse.bpmn2.modeler.core.features.event.definitions.DecorationAlgorithm;
import org.eclipse.bpmn2.modeler.core.runtime.CustomTaskImageProvider;
import org.eclipse.bpmn2.modeler.core.utils.BusinessObjectUtil;
import org.eclipse.bpmn2.modeler.core.utils.GraphicsUtil;
import org.eclipse.bpmn2.modeler.core.utils.ModelUtil;
import org.eclipse.bpmn2.modeler.core.utils.StyleUtil;
import org.eclipse.bpmn2.modeler.core.utils.StyleUtil.FillStyle;
import org.eclipse.bpmn2.modeler.examples.time.MyModel.MyEventDefinition;
import org.eclipse.bpmn2.modeler.examples.time.MyModel.MyModelPackage;
import org.eclipse.bpmn2.modeler.ui.features.activity.task.CustomTaskFeatureContainer;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.mm.MmPackage;
import org.eclipse.graphiti.mm.algorithms.Ellipse;
import org.eclipse.graphiti.mm.algorithms.Image;
import org.eclipse.graphiti.mm.algorithms.Polygon;
import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeService;
public class MyEventDefinitionFeatureContainer extends CustomTaskFeatureContainer {
private final static String TYPE_VALUE = "MyEventDefinition";
private final static String CUSTOM_TASK_ID = "org.eclipse.bpmn2.modeler.examples.customtask.eventDefinition1";
public MyEventDefinitionFeatureContainer() {
}
@Override
public String getId(EObject object) {
EStructuralFeature f = ModelUtil.getAnyAttribute(object, "type");
if (f!=null) {
Object id = object.eGet(f);
if (TYPE_VALUE.equals(id))
return CUSTOM_TASK_ID;
}
return null;
}
protected FeatureContainer createFeatureContainer(IFeatureProvider fp) {
return new AbstractEventDefinitionFeatureContainer() {
@Override
public ICreateFeature getCreateFeature(IFeatureProvider fp) {
return new CreateMyEventDefinitionFeature(fp);
}
@Override
protected Shape drawForStart(DecorationAlgorithm algorithm, ContainerShape shape) {
return draw(algorithm,shape);
}
@Override
protected Shape drawForEnd(DecorationAlgorithm algorithm, ContainerShape shape) {
return draw(algorithm,shape);
}
@Override
protected Shape drawForThrow(DecorationAlgorithm algorithm, ContainerShape shape) {
return draw(algorithm,shape);
}
@Override
protected Shape drawForCatch(DecorationAlgorithm algorithm, ContainerShape shape) {
return draw(algorithm,shape);
}
@Override
protected Shape drawForBoundary(DecorationAlgorithm algorithm, ContainerShape shape) {
return draw(algorithm,shape);
}
private Shape draw(DecorationAlgorithm algorithm, ContainerShape shape) {
Shape iconShape = Graphiti.getPeService().createShape(shape, false);
Image img = CustomTaskImageProvider.createImage(customTaskDescriptor, iconShape, customTaskDescriptor.getIcon(), 30, 30);
Graphiti.getGaService().setLocationAndSize(img, 3, 3, 30, 30);
return iconShape;
}
};
}
public class CreateMyEventDefinitionFeature extends CreateEventDefinition<MyEventDefinition> {
public CreateMyEventDefinitionFeature(IFeatureProvider fp) {
super(fp, "My Event Definition", "Create My Event Definition");
}
@Override
public EClass getBusinessObjectClass() {
return MyModelPackage.eINSTANCE.getMyEventDefinition();
}
@Override
protected String getStencilImageId() {
return null;
}
}
}
this implementation allow me to add MyEventDefinition(appeare on xml), but, it doesn't show the graphic image on the diagram.
by the way, I want to show the attribute of MyEventDefinition on the diagram.
I really feel that I'm carrying on you so much , but I'm counting on your generosity.
I'm waiting for your response.
Thank you very much.
|
|
|
Re: extend SequenceFlow [message #1129244 is a reply to message #1125212] |
Tue, 08 October 2013 08:47   |
Eclipse User |
|
|
|
Hi,
when I read about the plugin extension I deduced that we could extend the bpmn2.0 metamodel using an ecore file, indeed, The demands of my work oblige me to have a new meta-classes that extend from defined meta-classes (event Definition and sequence flow).
the super imlementation of canCreate() return true only if the element invoked is type of BaseElement, in the custom task example I remarked that you didn't define any meta-class, and I saw that this could be the problem of not having a BaseElement type.
In my case I defined MyEventDefinition (extends EventDefinition), and as it mentioned in my previous comment, I'm permitted to add MyEventDefinition and effectevly, it is shown on the xml file, but it doesn't figure on the graphic.
I tried to solve this graphic problem by redefining the addFeature, but unfortunately I didn't get the wanted result.
so please could you take a look and tell me what should I do.
waiting for your help.
thanks
|
|
|
|
|
|
|
|
|
Re: extend SequenceFlow [message #1198781 is a reply to message #1198394] |
Wed, 20 November 2013 09:03   |
Eclipse User |
|
|
|
ok, so it looks like <dependency> is an extension element, which means you have to create an extension model. The CustomTask screencast shows how to do that.
So, I have a couple of questions:
1. should Dependency have any of the attributes of any of the existing BPMN2 connection elements (i.e. SequenceFlow, Association, etc.) If so, you can define your Dependency element as a subclass of an existing BPMN2 element.
2. what will be the container for your Dependency elements? For example, SequenceFlows are contained in a FlowElementsContainer (more precisely, one of its subclasses like Process or SubProcess or Choreography). If Dependency will be treated similarly, then it MUST subclass a BPMN2 element (in this example, it must be a FlowElement if it's going to be contained in a FlowElementsContainer).
3. can Dependency be treated like an extension element? That is, can its containment look something like this:
<bpmn2:process ...>
<bpmn2:extensionElements>
<tns:dependency sourceref="xx" targetref="yy" property="zz"/>
</bpmn2:extensionElements>
if it cannot be contained like one of the existing BPMN2 elements, then it needs to go in the <bpmn2:extensionElements> container.
Also keep in mind that your extension element will belong to a different namespace (in the example above "tns" will be the namespace of your EMF model).
Lastly, Dependency should have an "id" attribute if it will be referenced by other elements in your model. At the very least it should subclass the BPMN2 BaseElement.
Cheers,
Bob
|
|
|
|
|
|
Re: extend SequenceFlow [message #1209799 is a reply to message #1203650] |
Mon, 25 November 2013 13:07   |
Eclipse User |
|
|
|
Hi Robert,
the SampleCustomSequenceFlowFeatureContainer class situated under org.eclipse.bpmn2.modeler.runtime.example bundle aims to create a sequence flow named Mitigation Flow.
Quote:
public class SampleCustomSequenceFlowFeatureContainer extends CustomConnectionFeatureContainer {
@Override
protected IFeatureContainer createFeatureContainer(IFeatureProvider fp) {
return new SequenceFlowFeatureContainer()
{
@Override
public IAddFeature getAddFeature(IFeatureProvider fp) {
return new AddSequenceFlowFeature(fp) {
/* (non-Javadoc)
* @see org.eclipse.bpmn2.modeler.ui.features.flow.SequenceFlowFeatureContainer.AddSequenceFlowFeature#decorateConnection(org.eclipse.graphiti.features.context.IAddConnectionContext, org.eclipse.graphiti.mm.pictograms.Connection, org.eclipse.bpmn2.SequenceFlow)
*
* This implementation of SequenceFlow's decorateConnection() changes the appearance of the connection
* to distinguish it from regular SequenceFlows.
*/
@Override
protected void decorateConnection(IAddConnectionContext context, Connection connection,
SequenceFlow businessObject) {
super.decorateConnection(context, connection, businessObject);
connection.getGraphicsAlgorithm().setLineWidth(3);
connection.getGraphicsAlgorithm().setLineStyle(LineStyle.DASH);
}
};
}
@Override
public ICreateConnectionFeature getCreateConnectionFeature(IFeatureProvider fp) {
return new CreateSequenceFlowFeature(fp) {
@Override
public SequenceFlow createBusinessObject(ICreateConnectionContext context) {
SequenceFlow businessObject = super.createBusinessObject(context);
return businessObject;
}
@Override
public String getCreateImageId() {
return SampleImageProvider.getImageId(customTaskDescriptor, IconSize.SMALL);
}
@Override
public String getCreateLargeImageId() {
return SampleImageProvider.getImageId(customTaskDescriptor, IconSize.LARGE);
}
};
}
};
}
the methods getCreateConnectionFeature and getAddFeature define the nature of the connection which is in the particular example above is a SquenceFlow.
is it possible to create an equivalent to SquenceFlow named "Dependency" which is a FlowElement defined in myEcore in order to get this kind of tag in the xml file:
<Dependency sourceref="xx" targetref="yy" property="zz">
it doesn't matter if it came as like as this form:
<bpmn2:process ...>
<bpmn2:extensionElements>
<tns:dependency sourceref="xx" targetref="yy" property="zz"/>
</bpmn2:extensionElements>
I tried to reform my request and I hope that you get me.
thank you very very much
your are the best.
waiting for your response.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|