Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » delete an editPart
delete an editPart [message #145435] Thu, 29 July 2004 10:02 Go to next message
Eclipse UserFriend
Originally posted by: jerome.lafon.bull.net

Hi!
I have some problems for deleting editParts.
I have a MultiPageEditorPart and on the first page I put a
GraphicalEditorWithPalette. In the configureGraphicalViewer() there is:
KeyHandler keyHandler = new KeyHandler();
keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(ActionFactory.DELETE));

What should I add for implementing the delete action ?

Thanks
Re: delete an editPart [message #145487 is a reply to message #145435] Thu, 29 July 2004 13:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

> What should I add for implementing the delete action ?

Hello,

When the delete action is run, it will send a req_delete on each selecte=
d
EditPart. These EditParts have to return a delete command for that reque=
st.
To do that, you have to write an EditPolicy subclass to return the delet=
e =

command
for a req_delete. Then you have to install that EditPolicy on each =

deletable EditPart.


- First be sure that the parent model objects will notify their listener=
s =

when one
of their children gets deleted, and that their EditParts call =

this.refreshChildren()
when they receive the "child deleted event" from their model.

- Next, write a Command subclass to delete a child in the model. In the =
=

most simple case,
this should look like that:

public class DeleteCommand extends Command
{
private ParentClass parent;
private ChildClass child;
=

public DeleteCommand(ParentClass parent, ChildClass child)
{
this.parent =3D parent;
this.child =3D child;
}
public execute()
{
parent.remove(child);
}
public redo()
{ =

parent.remove(child);
}
public undo()
{
parent.add(child);
}
}

- Next, write an EditPolicy to return that Command when a req_delete is =
=

sent.
GEF provide an EditPolicy for that, ComponentEditPolicy, you just have t=
o =

subclass it
and to implement the createDeleteCommand method to return your command. =
=

Here is an
example of this:

public class MyComponentEditPolicy extends ComponentEditPolicy
{
protected Command createDeleteCommand(GroupRequest request)
{
ParentClass parent =3D (ParentClass)getHost().getParent().getModel();
ChildClass child =3D (ChildClass)getHost().getModel();
DeleteCommand command =3D new DeleteCommand(parent, child);
return command;
}
}

- Next, you have to install that EditPolicy on each deletable EditPart. =
=

The appropriate role
for that is the component role. So you install this EditPolicy to your =

EditParts by overriding
the EditPart.createEditPolicies() method:

protected void createEditPolicies()
{
super.createEditPolicies();
installEditPolicy(EditPolicy.COMPONENT_ROLE, new MyComponentEditPolicy(=
));
...
}

I think that's all you need...

hope this will help,

r=E9gis
Re: delete an editPart [message #155288 is a reply to message #145487] Sat, 23 October 2004 19:40 Go to previous message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi

thanks for the code example!!

I have implemented all the stuff. The DeleteCommand will be created if I
Select the GEF element in the UI....but if I press the DEL/Entf key nothing
happens!

Any idea?!


greetings

Andreas
Previous Topic:Grouping of related properties in the PropertyView
Next Topic:Combined parent-child property descriptors
Goto Forum:
  


Current Time: Sat Apr 27 04:19:24 GMT 2024

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

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

Back to the top