Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Adding a child edit part ???
Adding a child edit part ??? [message #218827] Mon, 03 July 2006 13:32 Go to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
Hi,

I'm having problems adding a child editpart to a parent editpart.

The parent editpart:
1. Has a figure that uses a toolbar layout.
2. Has only one policy - a layoutpolicy that subclasses the
flowlayouteditpolicy.
3. Extends AbstractGraphicalEditPart and implements Adapter, Internal.

The problem I have is that the child editpart is added to the Diagram
editpart, not to the editpart that is supposed to be the parent? The real
parent figure updates and adds the child to the figure (although it is
added to the top of the figure and not the bottom - due to the index
always being -1, because the parent figure's children member is always
null - and you cannot select any of the newly added children).

I'm not sure where I'm going wrong?
1. Does the parent editpart need to implement NodeEditPart?
2. Does the parent editpart need anymore policies?
3. Am I doing something wrong in the create command?

Here's the relevant code parts ...

The layoutpolicy:

protected Command getCreateCommand (CreateRequest request)
{
ChildPubCreateCommand cmd = new ChildPublisherCreateCommand();

PublFigModel pubFigMod = (PubFigModel)request.getNewObject ();
DomPartFigModel domPartFigMod =
(DomPartFigModel)getHost().getModel();

EditPart after = getInsertionReference(request);

DSContentAdapter modelListener = new DSContentAdapter(getHost());
domPartFigMod.getDomainParticipant().eAdapters().add (modelListener);

cmd.setChild (pubFigMod);
//cmd.setParent ((Diagram) (getHost ().getModel ()));
cmd.setParent (domPartFigMod, (DomPartEditPart) getHost ());

int index = getHost ().getChildren ().indexOf (after);
cmd.setIndex (index);
cmd.setIndex (1);

return cmd;
}

//-------------------------------------

ChildPubCreateCommand:

public void setChild(PubFigModel child)
{
m_child = child;
}

public void setParent(DomPartFigModel parent, DomPartEditPart editPart)
{
m_parent = parent;
m_parentEditPart = editPart;
}

public void execute ()
{
//m_diagram.getFigures ().add (m_child);
boolean add = m_parent.getDomPart ().getPubs ().add
(m_child.getPub());
}

I'm not sure if I'm using execute correctly? From my understanding,
execute updates the model. The model I'm using is split into different
packages:
1. There is the Figure Model - which holds all the figure details
(location, etc).
2. There is the actual data Model. The data is an ERefernce in the figure
model.

So, in execute the m_parent is the figureModel, which gets the relavant
datatype EReference (in the data package), which gets a list member then
adds m_child.getPub() to the list (m_child being the figure model, which
is getting the EReference data from the data package).

I'm new to GEF/EMF and I sure I'm missing something basic here; and/or
doing something daft?

Thanks in advance.
Mark Robinson
Re: Adding a child edit part ??? [message #218911 is a reply to message #218827] Tue, 04 July 2006 14:42 Go to previous messageGo to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
I have fixed this.

Cheers.
Re: Adding a child edit part ??? [message #218917 is a reply to message #218911] Tue, 04 July 2006 19:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: reinalt.gmail.com

hi mark...
can u help??
i'm trying to add Shapes figures(children) to a Container
figure(Parent).Problem is i want to use FlowLayoutEditPolicy for the
parent Figure but dont know what Figure shud the ContainerEditPart draw.
Shud it b FreeformLayer or smthng else.how to use
FlowLayout?? Also wot r the other things tht shud be taken care of wen
adding children figures to the parentFigure???

thnx,
ronald
Re: Adding a child edit part ??? [message #219015 is a reply to message #218917] Thu, 06 July 2006 12:12 Go to previous messageGo to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
reinalt wrote:

> hi mark...
> can u help??
> i'm trying to add Shapes figures(children) to a Container
> figure(Parent).Problem is i want to use FlowLayoutEditPolicy for the
> parent Figure but dont know what Figure shud the ContainerEditPart draw.
> Shud it b FreeformLayer or smthng else.how to use
> FlowLayout?? Also wot r the other things tht shud be taken care of wen
> adding children figures to the parentFigure???

> thnx,
> ronald

I'm still learning GEF so don't take this answer as gospel. Here's a brief
outline of the steps you need. It is a complicated process and may take a
while (weeks) to get your head around.

The parent figure will need a ToolbarLayout:

public class myParent extends Figure
{
...

public myParent ()
{
...
setLayoutManager (new ToolbarLayout ());
...
}

...
}

The parent EditPart will need a FlowLayoutEditPolicy. You need to subclass
the FlowlayoutEditPolicy then install the policy on the parentEditPart:

public class myParentEditPart ...
{
...

protected void createEditPolicies ()
{
installEditPolicy (EditPolicy.LAYOUT_ROLE, new
myFlowLayoutEditPolicy());
}

...
}

Your FlowLayoutEditPolicy needs to implement getCreateCommand (),
something along these lines:

public class myFlowLayoutEditPolicy extends FlowLayoutPolicy
{
...

protected Command getCreateCommand (CreateRequest request)
{
MyCreateCommand cmd = new MyCreateCommand ();
// Set the parent and child of the command here
...
}
}

You need to create a command class which will update the model.
GEF will then send a notification to your parent EditPart.
You need to catch the notification in notifyChanged () in your parent
EditPart, and call refreshChildren - which should create your child
EditPart and child Figure (provided you have supplied GEF with an EditPart
Factory and a FigureCreation Factory)

@Override
public void notifyChanged (Notification notification)
{
super.notifyChanged (notification);

int type = notification.getEventType ();

switch (type)
{
case Notification.ADD:
case Notification.ADD_MANY:
refreshChildren ();
refreshVisuals ();
break;
}
}

refreshChildren will also call your parent EditPart's getModelChildren ().
You need to return a list of the parent's model children here. This should
be the same list that you added to in your create command class !!!

Hopefully, this will point you in the right direction.

Mark Robinson
Re: Adding a child edit part ??? [message #219031 is a reply to message #219015] Thu, 06 July 2006 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: reinalt.gmail.com

Thnx a lot Mark...
i have another problem in Shapes Example.If i add a new Panel Figure to
the Container figure ,it doesn't reflect in the Editor ....


protected IFigure createFigure() {
Figure f = new FreeformLayer();
f.setBorder(new MarginBorder(3));
f.setLayoutManager(new FreeformLayout());

Panel panel = new Panel();
panel.setBackgroundColor(ColorConstants.lightBlue);
f.add(panel);

return f;
}

reinalt.
Re: Adding a child edit part ??? [message #219038 is a reply to message #219031] Thu, 06 July 2006 13:31 Go to previous messageGo to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
reinalt wrote:

> Thnx a lot Mark...
> i have another problem in Shapes Example.If i add a new Panel Figure to
> the Container figure ,it doesn't reflect in the Editor ....


> protected IFigure createFigure() {
> Figure f = new FreeformLayer();
> f.setBorder(new MarginBorder(3));
> f.setLayoutManager(new FreeformLayout());

> Panel panel = new Panel();
> panel.setBackgroundColor(ColorConstants.lightBlue);
> f.add(panel);

> return f;
> }

> reinalt.

I've never used the FreeFormLayer so I can't be sure, but here's some code
from a figure in the Logic Example that comes with GEF ...


public CircuitFigure() {
setBorder(new CircuitBorder());
ScrollPane scrollpane = new ScrollPane();
pane = new FreeformLayer();
pane.setLayoutManager(new FreeformLayout());
setLayoutManager(new StackLayout());
add(scrollpane);
scrollpane.setViewport(new FreeformViewport());
scrollpane.setContents(pane);

createConnectionAnchors();
setBackgroundColor(ColorConstants.listBackground);
setOpaque(true);
}


Mark
Re: Adding a child edit part ??? [message #219047 is a reply to message #219038] Thu, 06 July 2006 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: reinalt.gmail.com

ok tht was maah mistake....
panel was getting added but its bounds were (0,0,0,0).
So it worked after setting new bounds...
thnx newyayz...

protected IFigure createFigure() {
FreeformLayer f = new FreeformLayer();
f.setBorder(new MarginBorder(3));
f.setLayoutManager(new FreeformLayout());

Panel panel = new Panel();
panel.setLayoutManager(new FreeformLayout());
panel.setBounds(new Rectangle(0,0,500,500));
panel.setBackgroundColor(ColorConstants.gray);
return f;
}

reinalt
Please !!! [message #224013 is a reply to message #218827] Wed, 11 October 2006 08:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: abrahamalon.gmail.com

I need to add a child to a container Shape (not to the root container) and I don't know how to do it. If you have get it please show me how, If you could let me see your code pleaseeeee
Re: Adding a child edit part ??? [message #707913 is a reply to message #218827] Tue, 02 August 2011 08:04 Go to previous messageGo to next message
Karthikeyan Missing name is currently offline Karthikeyan Missing nameFriend
Messages: 47
Registered: July 2011
Member
Hi,

Myself able to add new Shape in the container using notifychanged method, but when i try to createChangeConstraintCommand in editpolicy, it does not call the notifychanged method ie refreshVisuals not being called because its bounds reflect in model code, so it does not reflect in the editor container. Can you tell me what may be the problem.

Regards,
Karthikeyan

[Updated on: Wed, 10 August 2011 04:19]

Report message to a moderator

Re: Adding a child edit part ??? [message #718683 is a reply to message #707913] Thu, 25 August 2011 04:20 Go to previous message
Karthikeyan Missing name is currently offline Karthikeyan Missing nameFriend
Messages: 47
Registered: July 2011
Member
Hi,
It has been solved, the problem is the changes does not reflect in model, so myself added a line like object.setId(object.getId()), then notifychanged has been called.

Regards,
Karthikeyan
Previous Topic:Adding Sequence Flow to BPMN2 Editor
Next Topic:gef freeform figure
Goto Forum:
  


Current Time: Thu Apr 25 12:57:21 GMT 2024

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

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

Back to the top