How to add new Layers and show specific figures in Them? [message #526839] |
Tue, 13 April 2010 04:32  |
Eclipse User |
|
|
|
Hi,
Can any body point to a piece of code or example where a new layer addition ( like connection and gridlayer) has been done...
After doing that how can i tell the editpart that my figure should be added in the above layer??
[Updated on: Tue, 13 April 2010 04:50] by Moderator
|
|
|
|
Re: How to add new Layers and show specific figures in Them? [message #1015951 is a reply to message #1015926] |
Mon, 04 March 2013 06:54  |
Eclipse User |
|
|
|
Hi,
you can do that by exdending RootEditPart:
public class CustomScalableFreeformRootEditPart extends ScalableFreeformRootEditPart {
public static final String CUSTOM_LAYER = "Custom layer";
...
@Override
protected void createLayers(LayeredPane layeredPane) {
super.createLayers(layeredPane);
FreeformLayer customLayer = new FreeformLayer();
customLayer .setLayoutManager(new FreeformLayout());
layeredPane.addLayerAfter(customLayer , CUSTOM_LAYER, LayerConstants.SCALABLE_LAYERS);
}
}
Then in the EditPart that is parent of the EditPart being added to the custom layer:
public class ParentEditPart extends AbstractGraphicalEditPart {
...
@Override
protected void addChildVisual(EditPart childEditPart, int index) {
IFigure child = ((GraphicalEditPart) childEditPart).getFigure();
if (childEditPart instanceof CustomEditPart) {
getLayer(CustomScalableFreeformRootEditPart.CUSTOM_LAYER).add(child, index);
} else {
super.add(child, index);
}
}
@Override
protected void removeChildVisual(EditPart childEditPart) {
IFigure child = ((GraphicalEditPart) childEditPart).getFigure();
if (childEditPart instanceof CustomEditPart) {
getLayer(CustomScalableFreeformRootEditPart.CUSTOM_LAYER).remove(index);
} else {
super.remove(child);
}
}
}
Note that the code above will probably throw exceptions because of wrong index.
This is because model indexes are not sync with visual indexes.
(The model of CustomEditPart is eg at index 1, but the visual representation is at index 0)
So you have to reimplement indexing or don't use indexing at all. (*.add(child, -1))
|
|
|
Powered by
FUDForum. Page generated in 0.26463 seconds