Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to add new Layers and show specific figures in Them?
How to add new Layers and show specific figures in Them? [message #526839] Tue, 13 April 2010 04:32 Go to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
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??


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Tue, 13 April 2010 04:50]

Report message to a moderator

Re: How to add new Layers and show specific figures in Them? [message #1015926 is a reply to message #526839] Mon, 04 March 2013 04:44 Go to previous messageGo to next message
Charu Sharma is currently offline Charu Sharma
Messages: 17
Registered: May 2011
Location: Pune
Junior Member
Hi,
I am also looking for same. Please let me know if you find solution.
sharmacharu08atgmaildotcom.

Thanks in advance.
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 Go to previous message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
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))
Previous Topic:highlight my node
Next Topic:ScalableFreeformRootEditPart negative coordinates
Goto Forum:
  


Current Time: Thu Jul 31 15:45:14 EDT 2014

Powered by FUDForum. Page generated in 0.02055 seconds