Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Style attributes were not considered(On shapes with default attributes, values set in a style have no effect)
Style attributes were not considered [message #869331] Thu, 03 May 2012 08:38 Go to next message
Steffen K. is currently offline Steffen K.Friend
Messages: 1
Registered: May 2012
Junior Member

we from the Spray project have a problem with the usage of styles in Graphiti.
It's our plan to set all relevant style attributes (e.g. line widht, line style) for a shape on one style.

But we faced a problem with the usage of styles. If we e.g. want to set the line width for an ellipse within a style, this has no effect in Graphiti.

Below the source code for a better illustration of our issue (AddFeature - creation of an ellipse and usage of style for the attribute line width).

public class AddUseCaseFeature extends AbstractAddShapeFeature {

	public AddUseCaseFeature(IFeatureProvider fp) {

	public PictogramElement add(IAddContext context) {
		Diagram targetDiagram = (Diagram) context.getTargetContainer();

		IPeCreateService peCreateService = Graphiti.getPeCreateService();
		ContainerShape containerShape = 
                  peCreateService.createContainerShape(targetDiagram, true);

		int width = context.getWidth() < 100 ? 100 : context.getWidth();
		int height = context.getHeight() < 40 ? 40 : context.getHeight();

		IGaService gaService = Graphiti.getGaService();

		// create ellipse
		GraphicsAlgorithm e = gaService.createEllipse(containerShape);
		// create style and set attributes
		Style style = gaService.createStyle(getDiagram(), "Test1");
		// set line width to 10
		// set style on ellipse

                gaService.setLocationAndSize(e, context.getX(), context.getY(), 
                                             width, height);


		return containerShape;

The result of this source code is an ellipse with a line width of 1 and not as declared in the style with a width of 10 (see image below).


We tried a lot and the only possibility we found, is to set the line width on the ellipse first to "null" and after that the value set in the style is considered. With the procedure we override the values which were set initially by graphiti on the creation of a new shape element.

So if we add the source code snippet below to our implementation the line width of the style is used by Graphiti.

		// set line width to 10
		// [b]overwrite standard line width of ellipse[/b]
		// set style on ellipse

If we do so, we get the expected result (see attachment below).

For us it's important to know, if there is a better solution to handle our requirement. We designed our application in a way, were we want to set all values for the style of a shape on a seperate style object and not directly on the shape element (e.g. the ellipse).

Is there maybe a way to disable the setting of default style attributes by Graphiti on the instantiation of a new shape element? Is there a possibility to change the hierarchy in which way the valid style attributes are determine?

We will be gratefull for any suggestion or solution.

Re: Style attributes were not considered [message #869343 is a reply to message #869331] Thu, 03 May 2012 08:59 Go to previous message
Fabio Filippelli is currently offline Fabio FilippelliFriend
Messages: 2
Registered: December 2011
Junior Member
We also analyzed that on the creation of an element (ellipse, rectangle and so on) some default attributes will be set directly for the GraphicsAlgorithm.

Maybe it is better not to set default attributes directly.
In my opinion that could be changed. So if the user defines a style for the diagram, the attributes of the style will be gained and not the default attributes that an user may want to override.

IsnĀ“t it better to define a "default style" that will be set on every creation? So if we call the setStyle method, this default style will be changed with our style.

See your code snippet here (from GaServiceImpl):
	private void setDefaultGraphicsAlgorithmValues(GraphicsAlgorithm graphicsAlgorithm) {
		setLocationAndSize(graphicsAlgorithm, 0, 0, 0, 0);
		// graphicsAlgorithm.unsetLineVisible();

[Updated on: Thu, 03 May 2012 09:00]

Report message to a moderator

Previous Topic:Rotated text can not be saved?
Next Topic:Connections between BoxRelativeAnchors with different GAs
Goto Forum:

Current Time: Thu Aug 17 23:42:57 GMT 2017

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

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