delete an editPart [message #145435] |
Thu, 29 July 2004 10:02 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.02949 seconds