Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
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 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

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 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
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 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
Registered: July 2009
Senior Member
ok - I finally solved my layout/icon problem Smile
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
Re: How to place a second icon into a CustomShapeFeatureContainer [message #1735514 is a reply to message #1735446] Mon, 20 June 2016 14:14 Go to previous message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
Registered: July 2009
Senior Member
Here is also a screenshot of my customized task element
http://blog.imixs.org/wp-content/uploads/2016/06/bpmn2-customtask.png
Previous Topic:How to use a custom icons?
Next Topic:Dynamically update the layout of a customTaskElement
Goto Forum:
  


Current Time: Fri Apr 19 15:13:35 GMT 2024

Powered by FUDForum. Page generated in 0.01783 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top