|
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 |
Alex Kravets Messages: 561 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
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04532 seconds