Home » Eclipse Projects » BPMN 2.0 Modeler » Adding attributes, specifying their type at runtime
Adding attributes, specifying their type at runtime [message #1415614] |
Wed, 03 September 2014 07:39 |
Francesco Scialpi Messages: 5 Registered: August 2014 |
Junior Member |
|
|
Hi.
I am trying to extend the BPMN metamodel, as follows.
Suppose I want to add to a ServiceTask a "processingTime" parameter, whose type is numeric. So, for a Service Task we want a new PropertyTab containing this parameter.
Fine, I can do that.
Now suppose the parameter can be:
- a hard-coded number (i.e. we want the final user to specify a number, plain and simple)
- a sample from a distribution (i.e. we want the final user to specify the kind of distribution: normal, lognormal etc., and also the parameters for the chosen distribution: mean, standardDeviation, mode, min, max, etc.)
The final user, when compiling the Processing Time fields, should be able to choose between "Numeric" and "Distribution" kind of parameter, and shown fields to be filled should change accordingly.
I don't know how to accomplish this. Would you kindly offer some support?
Thanks.
|
|
|
Re: Adding attributes, specifying their type at runtime [message #1416163 is a reply to message #1415614] |
Thu, 04 September 2014 13:15 |
|
Wow. this is an odd use case
The attribute's data type will have to be specified as "EString" so that it can accomodate both of these values. This can be done in your extension's plugin.xml like so:
<modelExtension
id="org.my.extension.modelExtension.serviceTask"
runtimeId="org.my.extension"
name="Service Task Extension"
type="ServiceTask">
<property name="processingTime" type="EString"/>
</modelExtension>
Then you'll have to provide your own Property Tab rendering class, like so:
<propertyTab
id="org.my.extension.serviceTask.tab"
replaceTab="org.eclipse.bpmn2.modeler.serviceTask.tab"
class="org.my.extension.ServiceTaskPropertySection"
type="org.eclipse.bpmn2.ServiceTask"
label="Service Task">
</propertyTab>
In your ServiceTaskPropertySection implementation, instantiate a Detail Composite class, like so:
public class ServiceTaskPropertySection extends ActivityPropertySection {
/* (non-Javadoc)
* @see org.eclipse.bpmn2.modeler.ui.property.AbstractBpmn2PropertySection#createSectionRoot()
*/
@Override
protected AbstractDetailComposite createSectionRoot() {
return new ServiceTaskDetailComposite(this);
}
@Override
public AbstractDetailComposite createSectionRoot(Composite parent, int style) {
return new ServiceTaskDetailComposite(parent,style);
}
}
Finally, your ServiceTaskDetailComposite implementation needs to determine what actually needs to be rendered for your "processingTime" attribute and construct the appropriate field editor, maybe something like this:
public static class ServiceTaskDetailComposite extends DefaultDetailComposite {
public ServiceTaskDetailComposite(AbstractBpmn2PropertySection section) {
super(section);
}
public ServiceTaskDetailComposite(Composite parent, int style) {
super(parent, style);
}
@Override
protected void bindAttribute(Composite parent, EObject object, EAttribute attribute, String label) {
if ("processingTime".equals(attribute.getName())) {
if (processingTimeIsIntegerField()) {
ObjectEditor editor = new IntObjectEditor(this,object,attribute);
editor.createControl(parent,label);
}
else if (processingTimeIsEnumField()) {
ObjectEditor editor = new ComboObjectEditor(this,object,attribute) {
@Override
protected Hashtable<String, Object> getChoiceOfValues(EObject object, EStructuralFeature feature) {
Hashtable<String,Object> choices = new Hashtable<String,Object>();
choices.put("Normal", "normal");
choices.put("Log Normal", "lognormal");
}
};
editor.createControl(parent,label);
// create other field editors here for your distribution-specific values
}
}
else
super.bindAttribute(parent, object, attribute, label);
}
}
I haven't actually tried this, and you may need to fiddle with overriding getValue() and setValue() on the field editors to convert data types to/from EString.
Also, you haven't said if "processingTime" needs to be an XML element if it represents a probability distribution type, which should probably contain the distribution-specific variables (mean, standard deviation, etc.) If that's the case, then we have a completely different can of worms
HTH,
Bob
|
|
| |
Goto Forum:
Current Time: Sat Sep 07 17:48:34 GMT 2024
Powered by FUDForum. Page generated in 0.02654 seconds
|