Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Prevent selection of (background) image
Prevent selection of (background) image [message #654400] Tue, 15 February 2011 15:22 Go to next message
Harald Stangl is currently offline Harald StanglFriend
Messages: 7
Registered: February 2011
Junior Member
Hi,

I need to have an image displayed in the background of my diagram that should not be selectable but only settable via a custom feature. I need this to prevent users from (accidentally) selecting, moving, resizing the image.

While loading the image already works nicely, I'm not quite sure how to realize the non-selectability.

I wanted to create a selection behavior and simply return a zero sized rectangle for the click area of the image. Unfortunately this doesn't work as my graphics algorithm is an Image which is realized by an GFImageFigure. The PictogramElementDelegate performs a check in the createFigureForGraphicsAlgorithm() method and only asks the tool behavior provider for a click area if the figure is at least of type GFAbstractShape which the GFImageFigure is not.

Does anyone know of another way to achieve the desired behavior?
Re: Prevent selection of (background) image [message #654521 is a reply to message #654400] Wed, 16 February 2011 08:04 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
The standard way in Graphiti to achieve a diagram element that is not
selectable is simply setting the active flag on its pictogram element to
false. Does that solve it?

Michael
Re: Prevent selection of (background) image [message #654551 is a reply to message #654521] Wed, 16 February 2011 09:39 Go to previous messageGo to next message
Harald Stangl is currently offline Harald StanglFriend
Messages: 7
Registered: February 2011
Junior Member
I also tried that, but this results in the image not being shown at all. I also tried a simple rectangle instead of an image as graphics algorithm to check if this is again a specialty of the image, but the rectangle also did not work.

Is this considered to be a bug and should I file a bug report for that?
Re: Prevent selection of (background) image [message #654797 is a reply to message #654551] Thu, 17 February 2011 07:53 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Not sure...

Could you provide a code snippet of what you are doing exactly?

Michael
Re: Prevent selection of (background) image [message #654811 is a reply to message #654797] Thu, 17 February 2011 09:34 Go to previous messageGo to next message
Jos Warmer is currently offline Jos WarmerFriend
Messages: 114
Registered: October 2010
Senior Member
Hi,

I am not sure what your goal is exactly. Do you want the figure to be not selectable, or just not editable (meaning not resizable and not movable)? If you only want to make them not editable you can define getResizeShapeFeature(), getMoveShapeFeature() etc. to return null, for the chosen element.type. This way one can still select the element (and e.g. see the properties in the property view), but not change it in any way.

Jos
Re: Prevent selection of (background) image [message #654900 is a reply to message #654400] Thu, 17 February 2011 14:50 Go to previous messageGo to next message
Harald Stangl is currently offline Harald StanglFriend
Messages: 7
Registered: February 2011
Junior Member
Ok, so here is my use case: I need users to be able to load an image in the background that serves as a kind of blueprint for them. They are then going to create "marker" elements on top of that image to mark certain regions in the image.

As my users don't need to select the background image, I'd prefer the inactive way. I did some tests and came to the following findings:

-Inactive container shapes are never drawn
-If there is a container shape that contains another shape, the following happens to the (child) shape:

-Container shape active and child shape active: shape is drawn
-Container shape active and child shape inactive: shape is drawn
-Container shape inactive and child shape inactive: shape is not drawn
-Container shape inactive and child shape active: shape is drawn but drag and resize behavior is buggy: if the child shape is dragged or resized, this is reflected but the diagram is not updated so it appears as if the move did not work. Only after the diagram has been closed and opened again, the shape appears at the right position.

The code for my tests is quite simple:
Diagram diagram = getDiagram();
ContainerShape container = Graphiti.getPeCreateService().createContainerShape(diagram, false);
Rectangle rect = Graphiti.getGaCreateService().createRectangle(container);
Graphiti.getGaLayoutService().setLocationAndSize(rect, 0, 0,diagram.getGraphicsAlgorithm().getWidth(), diagram.getGraphicsAlgorithm().getWidth());
[...]
RoundedRectangle rect = Graphiti.getGaCreateService().createRoundedRectangle(contain er, 5, 5);
Graphiti.getGaLayoutService().setLocationAndSize(rect, context.getX(), context.getY(), context.getWidth(),
context.getHeight());
Re: Prevent selection of (background) image [message #655075 is a reply to message #654900] Fri, 18 February 2011 09:13 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Right, graphic algorithsm for inactive root shapes are not drawn, they are
only drawn when inside another active shape. So my approach wonÄt work in
your case. (Inactive shapes are meant for structuring inside a
representation.)

So I think Jos approach would be the way to go: use an active shape and
disable moving and resizing via the feature provider. Additionally you can
change the selection behavior by overriding getSelection in the tool
behavior provider and return another object to be selected (even the
previously selected one) in case the user selects the root image.

Michael
Re: Prevent selection of (background) image [message #655530 is a reply to message #654400] Mon, 21 February 2011 15:45 Go to previous messageGo to next message
Harald Stangl is currently offline Harald StanglFriend
Messages: 7
Registered: February 2011
Junior Member
Thanks for your input, I finally took the approach described by Jos.
At first I had two features, one for move and one for resize, which always returned false for canMove and canResize, but simply returning null in the feature provider is even easier and gives a better result.
Re: Prevent selection of (background) image [message #662144 is a reply to message #655530] Tue, 29 March 2011 14:04 Go to previous message
J. Weimar is currently offline J. WeimarFriend
Messages: 8
Registered: March 2011
Location: Germany
Junior Member
Dear Harald,
I have a similar problem of providing images in my diagram which the user inserts from her/his project, and then draws diagram elements on top. My difficulty is in providing the image (see separate thread). It seems that you have solved this by using GFImage directly instead of using an ImageProvider. Could you provide some code snippets to explain how you did this? Thanks, Jörg.
Previous Topic:how to create a circle in Graphiti
Next Topic:how to remove context menu items of a MultiPageEditor
Goto Forum:
  


Current Time: Thu Apr 25 08:48:17 GMT 2024

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

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

Back to the top