Home » Eclipse Projects » BPMN 2.0 Modeler » How to place a second icon into a CustomShapeFeatureContainer
How to place a second icon into a CustomShapeFeatureContainer [message #1734130] |
Sat, 04 June 2016 15:49 |
Ralph Soika Messages: 193 Registered: July 2009 |
Senior Member |
|
|
Can anybody give me a short help how to add additional images into a custom task container?
What I want to do is to overwrite the getAddFeature() method and the decorateShape() method of my new AddTaskFeature() implementation:
@Override
protected TaskFeatureContainer createFeatureContainer(IFeatureProvider fp) {
return new TaskFeatureContainer() {
@Override
public IAddFeature getAddFeature(IFeatureProvider fp) {
return new AddTaskFeature(fp) {
@Override
protected void decorateShape(IAddContext context, ContainerShape containerShape,Task businessObject) {
super.decorateShape(context, containerShape, businessObject);
// my code goes here....
}
}
}
}
I can't figure out how to place a new custom icon element into my customTask container depending on the properties of my business object.
For example I want to place a warning icon if some parameters are out of range.
But when I add a code like this:
Shape shape = containerShape.getChildren().get(0);
GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
Image img = CustomTaskImageProvider.createImage(customTaskDescriptor, ga,
warning_image, 24, 24);
Graphiti.getGaService().setLocationAndSize(img, 12, 12, 24, 24);
the origin image which is configured in the extension point of the plugin.xml file is lost.
How is the correct way to place an additional image into the custom task container?
Thanks for any help
===
Ralph
|
|
|
Re: How to place a second icon into a CustomShapeFeatureContainer [message #1735012 is a reply to message #1734130] |
Tue, 14 June 2016 15:39 |
|
Hi Ralph,
This looks right to me. Make sure your new image does not overlap and "hide" the original image.
Also. you may want to think about implementing this as a validation constraint instead. All the icon handling is done by the validation framework, and you get the benefit of being able to add a tooltip message to the warning icon.
Cheers,
Bob
|
|
|
Re: How to place a second icon into a CustomShapeFeatureContainer [message #1735425 is a reply to message #1735012] |
Sun, 19 June 2016 08:32 |
Ralph Soika Messages: 193 Registered: July 2009 |
Senior Member |
|
|
Hi Bob,
the behavior is really strange.
When I add a new element form the palette into the diagram, the shaping is correct (default icon and custom icon are displayed).
When I save and load the diagram the default icon is lost and only the custom icon is shown.
Setting the background color works fine in both cases.
@Override
protected TaskFeatureContainer createFeatureContainer(IFeatureProvider fp) {
return new TaskFeatureContainer() {
@Override
public IAddFeature getAddFeature(IFeatureProvider fp) {
return new AddTaskFeature(fp) {
@Override
protected void decorateShape(IAddContext context, ContainerShape containerShape,
Task businessObject) {
super.decorateShape(context, containerShape, businessObject);
setCustomStyle(containerShape);
}
};
}
@Override
public ICreateFeature getCreateFeature(IFeatureProvider fp) {
return new CreateTaskFeature(fp) {
};
}
@Override
public IUpdateFeature getUpdateFeature(IFeatureProvider fp) {
MultiUpdateFeature multiUpdate = (MultiUpdateFeature) super.getUpdateFeature(fp);
multiUpdate.addFeature(new AbstractUpdateBaseElementFeature<Task>(fp) {
@Override
public boolean update(IUpdateContext context) {
// important to clear flag...
setCustomStyle((ContainerShape) context.getPictogramElement());
DIUtils.updateDIShape(context.getPictogramElement());
return true;
}
@Override
public IReason updateNeeded(IUpdateContext context) {
IReason reason = super.updateNeeded(context);
if (reason.toBoolean())
return reason;
PictogramElement pe = context.getPictogramElement();
String propertyValue = FeatureSupport.getPropertyValue(pe, "evaluate.property");
if (propertyValue == null || propertyValue.isEmpty()) {
propertyValue = "false";
}
// Now evaluate the corresponding property of our
// Business object
Boolean attributeValue = false;
BaseElement ta = (BaseElement) getBusinessObjectForPictogramElement(pe);
Value valueUpdateACL = ImixsBPMNPlugin.getItemValueByName(ta, "keyUpdateACL", "xs:boolean",
"false");
if (valueUpdateACL.getValue() != null && valueUpdateACL.getValue().contains("true")) {
attributeValue = true;
}
// update is needed if the property has changed....
if (Boolean.parseBoolean(propertyValue) != attributeValue) {
return Reason.createTrueReason("evaluate.property changed");
}
return Reason.createFalseReason("");
}
});
return multiUpdate;
}
private void setCustomStyle(ContainerShape containerShape) {
Task ta = BusinessObjectUtil.getFirstElementOfType(containerShape, Task.class);
if (ta != null) {
// evaluate ACL setting
boolean bACLSetting = false;
Value valueUpdateACL = ImixsBPMNPlugin.getItemValueByName(ta, "keyUpdateACL", "xs:boolean",
"false");
String propertyValue = valueUpdateACL.getValue();
if (propertyValue != null && propertyValue.contains("true"))
bACLSetting = true;
// compute current width..
int width = containerShape.getGraphicsAlgorithm().getWidth();
Shape shape = containerShape.getChildren().get(0);
// Add custoom Image
GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
if (bACLSetting) {
Image img = loadCustomTaskIcon("inbox.png", ga);
Graphiti.getGaService().setLocation(img, width-24, 2);
}
// set background color
ShapeStyle shapeStyle = new ShapeStyle();
if (bACLSetting)
shapeStyle.setDefaultColors(PROCESSENTITY_BACKGROUND);
else
shapeStyle.setDefaultColors(PROCESSENTITY_BACKGROUND_ACL);
StyleUtil.applyStyle(shape.getGraphicsAlgorithm(), ta, shapeStyle);
// finally we update the new property value stored in the
// pictorgramElement...
FeatureSupport.setPropertyValue(containerShape, "evaluate.property", propertyValue);
}
}
};
}
Could it be that the getCreateFeature() is incorrect in this situation?
I also think that if I am implementing a validation constraint, I need to implement the getUpdateFeature() and getAddFeature() - right?
===
Ralph
|
|
|
Re: How to place a second icon into a CustomShapeFeatureContainer [message #1735446 is a reply to message #1735425] |
Sun, 19 June 2016 16:37 |
Ralph Soika Messages: 193 Registered: July 2009 |
Senior Member |
|
|
ok - I finally solved my layout/icon problem
The solution was to render all icons - also the default icon which was defined in the plugin.xml.
Another important step is to clear the GraphicsAlgorithmChildren by calling
shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().clear();
If not, each update call creates new images. After I cleared the children list, I can now add all my icons depending on the property state of my BusinessObject.
My custom helper method to layout the ContainerShape now looks like this:
private void updateShapeStyle(ContainerShape containerShape) {
Task ta = BusinessObjectUtil.getFirstElementOfType(containerShape, Task.class);
if (ta != null) {
// compute current width to place icons into the upper right corner..
int width = containerShape.getGraphicsAlgorithm().getWidth();
int xPos=width-20;
PictogramElement pe = containerShape.getGraphicsAlgorithm().getPictogramElement();
// compute the layoutStatus from the current businessObject.....
String newLayoutStatus = getNewLayoutStatus(pe, ta);
// get the shape for the layout instructions....
Shape shape = containerShape.getChildren().get(0);
// first we clear all existing children of that shape...
shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().clear();
// set the background color
ShapeStyle shapeStyle = new ShapeStyle();
shapeStyle.setDefaultColors(PROCESSENTITY_BACKGROUND);
// add the default image into the upper left corner....
Image imga = loadCustomTaskIcon("process-bubble.png", shape.getGraphicsAlgorithm());
Graphiti.getGaService().setLocationAndSize(imga, 2, 2, 24, 24);
// Add 1. custom Image
if (newLayoutStatus.contains("keyupdateacl=true")) {
Image img = loadCustomTaskIcon("user_group.gif", shape.getGraphicsAlgorithm());
Graphiti.getGaService().setLocation(img,xPos, 2);
xPos=xPos-20;
}
// Add 2. custom Image
if (newLayoutStatus.contains("txteditorid=")) {
Image img = loadCustomTaskIcon("form.gif", shape.getGraphicsAlgorithm());
Graphiti.getGaService().setLocation(img,xPos, 2);
}
StyleUtil.applyStyle(shape.getGraphicsAlgorithm(), ta, shapeStyle);
// finally update the new property value which is verified in the updateNeeded() method
System.out.println("set new layout status: ");
FeatureSupport.setPropertyValue(containerShape, "layoutstatus.property", newLayoutStatus);
}
}
What made it really difficulty to me was the fact, that I have to override the getUpdateFeature method and the getAddFeature method.
Both methods are calling my helper method updateShapeStyle(ContainerShape containerShape) to layout the ContainerShape.
But both methods provide complete different context objects (ContainerShape and IUpdateContext). This makes it very tricky to convert from these objects to a common object type.
===
Ralph
|
|
| |
Goto Forum:
Current Time: Tue Sep 17 18:02:08 GMT 2024
Powered by FUDForum. Page generated in 0.03902 seconds
|