CustomStyle EditPart Size Change [message #1790251] |
Thu, 07 June 2018 13:36 |
Parsa Pourali Messages: 210 Registered: February 2014 |
Senior Member |
|
|
Hello,
(Note that I have posted this in GEF forum and got not working reply, so I thought maybe you got some experience on this)
I have a customStyle node. The edit part code for my custom style node is shown below. The custom style node has an image (the train area) as its primary shape. However, the size of the node edit part does not auto grow or shrink to the size of its primary shape. I have tried to set the size(layoutconstraints(bounds)) in refreshVisual method but it throws write transaction exception. I have tried to set the figure size , content pane size , and every thing! but still can not resize the figure's client area.
So, there are a few main concerns about customStyles:
1. Can we change the figure's initial size at all ?
2. More importantly, can we set a node's initial position ? I tried https://wiki.eclipse.org/index.php?title=Graphical_Modeling_Framework/Tips&redirect=no#Setting_Initial_Position_of_a_Node ,but it only works on diagram reopen and not on node creation.
3. When I use customeStyle, it does not show the label of the node (when set to node and not the border). Is it the intended behaviour?
public class InstanceRoleStyleEditPart extends AbstractNotSelectableShapeNodeEditPart implements IStyleEditPart {
/**
* the content pane.
*/
protected IFigure contentPane;
/**
* the primary shape.
*/
protected ImageFigure primaryShape;
/**
* Create a new {@link ChangingImageEditPart}.
*
* @param view
* the view.
*/
public InstanceRoleStyleEditPart(View view) {
super(view);
}
public DragTracker getDragTracker(Request request) {
return getParent().getDragTracker(request);
}
protected NodeFigure createNodeFigure() {
NodeFigure figure = createNodePlate();
figure.setLayoutManager(new XYLayout());
IFigure shape = createNodeShape();
figure.add(shape);
contentPane = setupContentPane(shape);
return figure;
}
private NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new AirStyleDefaultSizeNodeFigure(getMapMode().DPtoLP(40), getMapMode().DPtoLP(40));
return result;
}
/**
* Create the instance role figure.
*
* @return the created figure.
*/
protected ImageFigure createNodeShape() {
if (primaryShape == null) {
primaryShape = new ImageFigure();
}
return primaryShape;
}
/**
* Return the instance role figure.
*
* @return the instance role figure.
*/
public ImageFigure getPrimaryShape() {
return primaryShape;
}
/**
* Default implementation treats passed figure as content pane. Respects
* layout one may have set for generated figure.
*
* @param nodeShape
* instance of generated figure class
* @return the figure
*/
protected IFigure setupContentPane(IFigure nodeShape) {
return nodeShape; // use nodeShape itself as contentPane
}
public IFigure getContentPane() {
if (contentPane != null) {
return contentPane;
}
return super.getContentPane();
}
protected void refreshVisuals() {
CustomStyle customStyle = (CustomStyle) this.resolveSemanticElement();
if (customStyle.eContainer() instanceof DNode) {
ImageDescriptor imageDescriptorFromPlugin;
Image image;
imageDescriptorFromPlugin = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"images/shapes/shape_Train_Left45.png");
image = imageDescriptorFromPlugin.createImage();
this.getPrimaryShape().setImage(image);
}
}
protected void createDefaultEditPolicies() {
// empty.
}
}
Thanks,
Parsa
-
Attachment: train.png
(Size: 7.65KB, Downloaded 433 times)
[Updated on: Thu, 07 June 2018 19:33] Report message to a moderator
|
|
|
Re: CustomStyle EditPart Size Change [message #1790370 is a reply to message #1790251] |
Fri, 08 June 2018 17:12 |
Parsa Pourali Messages: 210 Registered: February 2014 |
Senior Member |
|
|
Note that I also used SiriusLayoutDataManager.INSTANCE.addData(new RootLayoutData(this, new Point(10, 10), new Dimension(200, 300))); on the edit part createFigure method to set its initial position but it says that LayoutDataManager is not designed for CustomStyles yet...
!MESSAGE This kind of diagram element (org.eclipse.sirius.diagram.business.internal.metamodel.spec.WorkspaceImageSpec) is not yet managed by the LayoutDataManager.
* this editpart is a workspaceimage, but the same thing for the customstyle is thrown.
Regards,
Parsa
[Updated on: Fri, 08 June 2018 17:34] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02217 seconds