Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Controlling size of the shape in editor during editor resize
Controlling size of the shape in editor during editor resize [message #1699677] Thu, 25 June 2015 18:38 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
I represent my model as a static shape in Graphiti. It looks somewhat similar to XSD editor in Eclipse.

http://www.eclipse.org/webtools/initial-contribution/IBM/evalGuides/XMLToolsEval_files/XSD_Editor_top_level_view.gif

When I resize XSD editor the schema table is resized as well, looks like it has minimum width and height. I'd like to do the same thing in my Graphiti editor, what is the best way to accomplish this? Is there something that already allows me to do this?

Thanks,
Alex
Re: Controlling size of the shape in editor during editor resize [message #1699804 is a reply to message #1699677] Fri, 26 June 2015 16:55 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
I was able to achieve the resize by using createPartControl() of DiagramEditor:

public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		super.createPartControl(parent);
		Control[] children = parent.getChildren();
		children[0].addControlListener(new ControlListener() {
			
			@Override
			public void controlResized(ControlEvent e) {
				EList<Shape> children = diagram.getChildren();
				Shape channelShape = null;
				
				for(Shape child : children){
					EList<Property> properties = child.getProperties();
					for(Property property : properties){
						String key = property.getKey();
						if(key.equals(ChannelDiagramConstants.COMPONENT_NAME)){
							if(property.getValue().equals("Channel")){
								channelShape = child;
								break;
							}
						}
					}
				}
				
				Composite source = (Composite) e.getSource();
				Point size = source.getSize();
				
				GraphicsAlgorithm ga = channelShape.getGraphicsAlgorithm();
				int x = ga.getX();
				int y = ga.getY();
				final ResizeShapeContext resizeContext = new ResizeShapeContext(channelShape);
				//resizeContext.setHeight(ga.getY());
				resizeContext.setWidth(size.x - 250);
				resizeContext.setX(x);
				resizeContext.setY(y);
				
				getEditingDomain().getCommandStack().execute(new RecordingCommand(getEditingDomain()) {
					
					@Override
					protected void doExecute() {
						IResizeShapeFeature resizeShapeFeature = getDiagramTypeProvider().getFeatureProvider().getResizeShapeFeature(resizeContext);
						resizeShapeFeature.resizeShape(resizeContext);
						
					}
				});
			}
			
			@Override
			public void controlMoved(ControlEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
	}


It work with exception of resizing being not as smooth as I want it to be, as you can see in this video. I don't know if this expected behavior or something can be done to make it more smooth. One of solutions would be put call to IResizeShapeFeature.resizeShape() into a thread so that resizing is not done on every ControlEvent fire, but something like 5 seconds after last one. Still, I'd like to find out if Graphiti has some solution that it offers.

Thanks,
Alex

[Updated on: Fri, 26 June 2015 16:56]

Report message to a moderator

Re: Controlling size of the shape in editor during editor resize [message #1700104 is a reply to message #1699804] Tue, 30 June 2015 07:31 Go to previous messageGo to next message
Jerome Sivadier is currently offline Jerome SivadierFriend
Messages: 14
Registered: May 2015
Junior Member
Hello Alex,

I had to do the same in my editor to have a resize feature that works on a screen resize, I have not found any other way in Graphiti to do so.

Best regards.
Jerome
Re: Controlling size of the shape in editor during editor resize [message #1700189 is a reply to message #1700104] Tue, 30 June 2015 14:45 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex, Jerome,

right, there is nothing like this in Graphiti. Please file an enhancement
bugzilla if you want to see such a feature in a future release.

Thanks,
Michael
Re: Controlling size of the shape in editor during editor resize [message #1700430 is a reply to message #1700189] Thu, 02 July 2015 14:30 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
Thanks Michael, Jerome

It's such a small feature and I am thinking it won't be widely used so I am not sure if it needs to be included in base Graphiti feature.

Another question I have is how do I go about resizing child components? Is there something in place that automatically adjusts children's size based on parent's size change?
Re: Controlling size of the shape in editor during editor resize [message #1700545 is a reply to message #1700430] Fri, 03 July 2015 12:37 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

sorry, there is no such automated feature. You will have to resize children
when you resize the parent.

Michael
Previous Topic:attaching a document as an attribute to an Eclass
Next Topic:Creating connection without corresponding business object
Goto Forum:
  


Current Time: Wed Jan 17 01:49:41 GMT 2018

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

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