Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Positionning a border item
Positionning a border item [message #630235] Fri, 01 October 2010 09:35 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

In my diagram, I have a node with child elements on the border (it is a block with input/output ports on the border). To do this, in my gmfgraph, I set the "Affixed parent side" property of my port Node.
When the user add ports on the block figures, the first port is set in the middle of the parent side, then other ports which are added are positionned each time under the last one (if the parent side is WEST). In case the parent side is EAST, the first port is also positionned in the middle of the side, but other ports are posionned above.

I would like my first port to be positionned at the top of the side (with a margin) and other ports under it.
Is there an easy way to do this or do I have to create my own BorderItemLocator ? If I have to override BorderItemLocator, which method do I have to override in order to achieve the desired result ?

The ports won't be selectable, so the user won't be able to move them once they have been created (and they will be created programmatically, depending on the type of block which is created).

Thanks for your help.
Re: Positionning a border item [message #630255 is a reply to message #630235] Fri, 01 October 2010 10:37 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Hi Cedric,


I have a figure which positions its children on the border. Depending on some information in the child figure I decide which position it should have on the parent's border.

in the parent figure editpart , in the addFixedChild method, I check some conditions on the child, and then I do something like:

 
 int position = findPositionForThisChild(....);
 BorderItemLocator locator = new MyCustom_BorderItemlocator(
				getMainFigure(), position);
		getBorderedFigure().getBorderItemContainer().setConstraint(
				newChildFigure, locator);
 


And then, in my border locator, I position my child exactly in the middle, on the SOUTH or EAST border.

protected Point getPreferredLocation(int side, IFigure borderItem) {
		Rectangle bounds = getParentBorder();
		int parentFigureWidth = bounds.width;
		int parentFigureHeight = bounds.height;
		int parentFigureX = bounds.x;
		int parentFigureY = bounds.y;
		int x = parentFigureX;
		int y = parentFigureY;

		Dimension borderItemSize = getSize(borderItem);


		if (side == PositionConstants.SOUTH) {
			x += parentFigureWidth / 2 - borderItemSize.width/2 ;
			y = parentFigureY + parentFigureHeight
				- getBorderItemOffset().height;
		}
		else
			if (side == PositionConstants.EAST)
			{
				x += parentFigureWidth - getBorderItemOffset().width;
				y += parentFigureHeight /2 - borderItemSize.height/2; 
			}
		return new Point(x, y);
	}





I hope it will help,
cheers,
Emil.





Re: Positionning a border item [message #632240 is a reply to message #630255] Tue, 12 October 2010 08:59 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hi Emil,

Thanks for the reply and sorry for my late answer but I was busy trying several options here.

I tried to create my own custom border locator but the problem is that the bounds of my parent figure are not set yet.
In fact when my parent figure is created I programmatically add children to it. The way I do it is like this:

1) I implement the "getConfigureCommand" of the edit helper in order to return a configure command in which the children are created.
2) This command creates a CreateElementRequest and retrieves the corresponding command and executes it.

I am not sure if this is the appropriate way to do it but I have no clue how to do it. I found this but I have no clue where to put this code so that the children are created at the same time that my parent node is created. Any idea ?

I really have no idea how I can solve what seems like a simple problem: be able to create blocks with predefined input and output ports when the block is created, and that those ports are positionned properly on the block.
I would like also to have a good reference on the GMF framework but I couldn't find any (nor any good book). There's the API documentation but it is very poor and doesn't give a good overview of GMF.
Re: Positionning a border item [message #632268 is a reply to message #630235] Tue, 12 October 2010 11:32 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Hi Cedric,

I'm not sure I can help you.

Quote:

1) I implement the "getConfigureCommand" of the edit helper in order to return a configure command in which the children are created.
2) This command creates a CreateElementRequest and retrieves the corresponding command and executes it.



I'm not sure that executing a command at that point is the right thing to do. That piece of code is meant to return a command, not execute it. Try to return your created command (or a compond command).
As an alternative solution, you could also take a look at the generated code in the class "ParentElementCreateCommand" and create your border element there. You will then have a single command for the creation of both parent element and border child.


good luck,
emil.

Re: Positionning a border item [message #632284 is a reply to message #630235] Tue, 12 October 2010 12:37 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hi Emil,

Thanks for your answer. I guess I didn't explain very well. What I meant is that the configure command creates and executes another command in its doExecuteWithResult method.
If I use my debugger, I'm first executing the doExecuteWithResult method of the "ParentElementCreateCommand" (like suggested in your message). In this method (generated), there is a call to doGenerate which creates a configure command (which is in fact my custom command creating the input and output ports). This custom command is then executed which has for consequence to execute my code to create the ports. So, this would be similar as if I would put the code to create the ports directly in the "ParentElementCreateCommand".

In fact this code was taken from the GMF example for the logic diagram. It works partially fine because my ports are indeed created. But what doesn't work is the position of these ports. I can't find a solution to position the ports where I want and it is becoming a bit frustrating (I've been trying to find a solution for days, mostly by trials and errors in modifying the generated code). Furthermore, another strange thing which happens is that the blocks can only be resized to be bigger. I can't reduce their size when there are ports created.

If you would have to do something like that, how would you proceed ? Maybe the way I'm doing it is completely wrong (I don't know, since I can't find any good documentation about the GMF code).
Re: Positionning a border item [message #632288 is a reply to message #630235] Tue, 12 October 2010 13:10 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Well ... I know exactly the feeling of spending days trying to find a solution for a problem which seems very simple (very difficult to explain to somebody -- the boss for example -- how you spend several days trying to position a figure to the right place). I think this is the drawback when using a technology like gmf - you have a lot of very complex feature already implemented for you but you spend days for implementing a simple feature. I'm sorry I cannot help you here ... and indeed, there is no documentation on the gmf code at all. The only documentation is the code itself.

cheers,
emil.
Re: Positionning a border item [message #632548 is a reply to message #632288] Wed, 13 October 2010 11:56 Go to previous message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
What is even more frustrating is that I was able to achieve a correct result with a previous release of GMF. I used the Amalgamation project (DSL toolkit) for which the generated code behaved correctly.
I recently downloaded Helios and there the generated code doesn't work properly.
As far as I remember, it's a code generation issue because if I open my code generated from the DSL toolkit in Helios, it works fine Sad
Previous Topic:Child Meta Feature must reference Meta Class
Next Topic:how to access a property of component in code
Goto Forum:
  


Current Time: Thu Apr 25 14:14:10 GMT 2024

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

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

Back to the top