Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » How to change the target runtime and the color of events(I am changing the target runtime with setCurrentRuntime, but for start and end events the default color is taken)
How to change the target runtime and the color of events [message #1237347] Wed, 29 January 2014 13:22 Go to next message
Peter Gernold is currently offline Peter GernoldFriend
Messages: 11
Registered: January 2014
Junior Member
Hi,

I have extended BPMN2Editor. By this extension I have an own palette and additionally changed the color of start and end event. In case the target runtime at the project properties has been set to 'None', then I want to open the editor with my runtime. I have hoped to solve this issue by:
---------------------------------------------------------------------------------
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
// set the runtime hard coded that the correct one is taken
// needs to be called before INIT that the palette is taken correctly
super.getPreferences().put("target.runtime", "my.runtime");
super.init(site, input);

// determine the correct target runtime
targetRuntime = super.getPreferences().getRuntime();
if (!"my.runtime".equals(targetRuntime.getId())) {
for (TargetRuntime rt : TargetRuntime.getAllRuntimes()) {
if ("my.runtime".equals(rt.getId())) {
targetRuntime = rt;
break;
}
}
}
if (targetRuntime == null) {
targetRuntime = TargetRuntime.getDefaultRuntime();
}

// change the color (currently not working)
// normally we should expect that replacing the runtime should also set the colors
// correctly, but this is not working
ShapeStyle shape;
for (Class key : targetRuntime.getShapeStyles().keySet()) {
if (key.getCanonicalName().equals("org.eclipse.bpmn2.StartEvent")) {
shape = targetRuntime.getShapeStyle(key);
shape.setShapeForeground(ShapeStyle.DEFAULT_COLOR.BLACK);
shape.setShapeBackground(ShapeStyle.DEFAULT_COLOR.BLACK);
shape.setDirty(true);
} else if (key.getCanonicalName().equals("org.eclipse.bpmn2.EndEvent")) {
shape = targetRuntime.getShapeStyle(key);
shape.setShapeForeground(ShapeStyle.DEFAULT_COLOR.BLUE);
shape.setShapeBackground(ShapeStyle.DEFAULT_COLOR.BLUE);
shape.setDirty(true);
}
}

// set the target runtime
TargetRuntime.setCurrentRuntime(targetRuntime);
super.getPreferences().setRuntime(targetRuntime);
}

---------------------------------------------------------------------------------

My issue is that 'my.runtime' is used (the correct palette is shown by the editor), but colors of the start and end events are not correct. The colors are always taken from "org.eclipse.bpmn2.modeler.runtime.none", which has been verified by changing the colors in the debugger.
Any idea how to solve this issue? Thanks
Peter
Re: How to change the target runtime and the color of events [message #1237396 is a reply to message #1237347] Wed, 29 January 2014 15:55 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 Peter, welcome to the forum Smile

First, it's probably NOT a good idea to change the Target Runtime for the project from an editor without letting the user know that something is happening behind the scenes. This should be a conscious decision made by the user. Reasons for this are 1. it's very rude Wink 2. what if you had multiple Target Runtime extensions from different vendors doing the same thing?

Second, please use the public API (plugin extension points) and don't override the BPMN2 Modeler core/UI methods. For example, the things you're trying to do might be handled in the initialize() method of your IBpmn2RuntimeExtension implementation class. If there's something you need that can't be handled with the public API, please raise an enhancement request.

That said, try calling super.getPreferences().flush() and see if that fixes the problem.

Cheers,
Bob

[Updated on: Wed, 29 January 2014 16:00]

Report message to a moderator

Re: How to change the target runtime and the color of events [message #1237654 is a reply to message #1237396] Thu, 30 January 2014 08:54 Go to previous messageGo to next message
Peter Gernold is currently offline Peter GernoldFriend
Messages: 11
Registered: January 2014
Junior Member
Hi Robert,
Many thanks for the fast reply. You are right with your remarks that I should not change the target runtime at the project properties. Indeed I want to change the runtime not for the whole project, but only for my extension.
But I have faced the issue that setting the new runtime by
TargetRuntime.setCurrentRuntime(targetRuntime);
is working for the palette and the propertyTabs, but not for the colors of the start and end event. And it does not change the project settings (what is wanted).
Strange is that my runtime is used, which can be seen at the palette and the propertyTabs, but not the styles. Though all is set in plugin.xml.
Interesting is also that changing the colors for a project, which has "myRuntime" as target runtime, will be reflected in the diagram; but for a project for which "None" is the target runtime the color changes does not have any effects.
The question is why is the color change not working in the second case though my own runtime is taken? Why I have to change the style though it is part of the plugin.xml?


At the end: Calling super.getPreferences().flush() has not solved my issue.
Re: How to change the target runtime and the color of events [message #1238000 is a reply to message #1237654] Fri, 31 January 2014 06:04 Go to previous messageGo to next message
Peter Gernold is currently offline Peter GernoldFriend
Messages: 11
Registered: January 2014
Junior Member
Hi Bob,
My solution is to set the target runtime, open the editor and to set afterwards the original target runtime. This is done only for my extension.
It is working, I have not to change the target runtime at the project properties.
But one minor issue is remaining. The colors of the start/end event are cached project dependent. In case I open first the editor with target runtime A and then a second editor with target runtime B, in both editors the colors are taken from A. Using the other direction (first runtime B and then A), the colors of B will win.
Is there a way to invalidate the cache?
Thanks for your help
Peter
Re: How to change the target runtime and the color of events [message #1238038 is a reply to message #1238000] Fri, 31 January 2014 08:24 Go to previous message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hi Peter,

I've run across similar issues with the Preference cache and I'm starting to doubt my original design decision. Until I can resolve this and come up with a better idea, try using the getInstance(IProject) to load the cache and associate the preference instance with the project, then call dispose() and getInstance(IProject) again. I know it's a hack, but it might be a workaround for now.

[Updated on: Fri, 31 January 2014 08:25]

Report message to a moderator

Previous Topic:A subtype of ScriptTask
Next Topic:How to extend the BPMN Plane
Goto Forum:
  


Current Time: Tue Apr 23 17:03:39 GMT 2024

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

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

Back to the top