Home » Eclipse Projects » GEF » Deleting
Deleting [message #81006] |
Tue, 27 May 2003 07:09  |
Eclipse User |
|
|
|
Originally posted by: sinleeh.hotmail.com
Dear all,
I was attempting to create a way to delete an editpart but with no luck. I
hope someone can show me the error of my way.
I have an edit part which I want to post a Delete ability. Lets call it
Deletable EditPart. Following the example of the Logic example. I extended
the ComponentEditPolicy to DeletableEditPolicy, overides
createDeleteCommand() in this policy with my deletion code, then install
this policy as COMPONENET_ROLE in createEditPolicies() in
DeletableEditPart.
However, after running the program, I find that I cannot delete the
editpart by pressing DEL key. I then put some println statements in
DeletableEditPolicy.createDeleteCommand() and realized that it is not
called.
I am pretty sure I miss out some other important parts to get it working,
can someone point it out to me?
Best regards and thanking you in advance,
Sinlee
|
|
|
Re: Deleting [message #81092 is a reply to message #81006] |
Tue, 27 May 2003 08:51   |
Eclipse User |
|
|
|
Can you delete from the Edit menu or a context menu? The LogicEditor captures
the DEL key by adding a KeyHandler to the viewer in configureGraphicalViewer().
viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
.setParent(getCommonKeyHandler()));
getCommonKeyHandler() returns a KeyHandler that binds the DEL key to the delete
action.
sharedKeyHandler.put(
KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(GEFActionConstants.DELETE));
Eric
Sin Lee Huang wrote:
> Dear all,
>
> I was attempting to create a way to delete an editpart but with no luck. I
> hope someone can show me the error of my way.
>
> I have an edit part which I want to post a Delete ability. Lets call it
> Deletable EditPart. Following the example of the Logic example. I extended
> the ComponentEditPolicy to DeletableEditPolicy, overides
> createDeleteCommand() in this policy with my deletion code, then install
> this policy as COMPONENET_ROLE in createEditPolicies() in
> DeletableEditPart.
>
> However, after running the program, I find that I cannot delete the
> editpart by pressing DEL key. I then put some println statements in
> DeletableEditPolicy.createDeleteCommand() and realized that it is not
> called.
>
> I am pretty sure I miss out some other important parts to get it working,
> can someone point it out to me?
>
> Best regards and thanking you in advance,
> Sinlee
>
|
|
|
Re: Deleting [message #81106 is a reply to message #81092] |
Tue, 27 May 2003 10:06   |
Eclipse User |
|
|
|
Originally posted by: sinleeh.hotmail.com
Dear Eric,
Thank you for your reply.
For the logic example (using the downloaded binary), I can delete using
DEL key or via the context menu. The delete option in the Edit menu is not
enabled.
I was working on my own project which I based it on the logic example when
I encountered the problem. I followed your advice and try to bind the DEL
key using the instruction you gave me but still have no luck. What I did
was simply copy and paste the relevent code you posted to my own class,
after consulting the logic source code. I can confirm that the program
code for the getCommonKeyHandler() is executed.
Then I did some digging. Putting a
if(getActionRegistry().getAction(GEFActionConstants.DELETE) == null)
statement after:
sharedKeyHandler.put(
KeyStroke.getPressed(SWT.DEL, 127, 0),
getActionRegistry().getAction(GEFActionConstants.DELETE));
shows that I have no IAction for GEFActionConstants.DELETE. Since I cannot
find any IAction that does setId(GEFActionConstants.DELETE) or similar, I
conclude that I don't need one. Please correct me if I'm wrong.
Nonetheless I decided to be a bit adventureous, this time providing my own
IAction. I created the following class:
class MyDeleteAction extends SelectionAction {
public MyDeleteAction (IEditorPart editor) {
super(editor);
setId(GEFActionConstants.DELETE);
}
//copied from logic example's IncrementDecrementAction
protected boolean calculateEnabled() {
if (getSelectedObjects().isEmpty()) {
return false; //(1)
}
List parts = getSelectedObjects();
for (int i=0; i<parts.size(); i++){
Object o = parts.get(i);
if (!(o instanceof EditPart)){
System.out.println("hello3");
return false;
}
public void run(){}
}
and putting: (Copied from LogicEditor.createActions (see notes)
ActionRegistry registry = getActionRegistry();
IAction action;
action = new EPLDeleteAction(this);
registry.registerAction(action);
getSelectionActions().add(action.getId());
before
viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
.setParent(getCommonKeyHandler()));
in configureGraphicalViewer(), I manage to get
MyDeleteAction.calculateEnabled() to execute. However, it returns false
since getSelectedObjects() is empty, i.e., execution reached line1.
Based on these information, I have the following questions:
(1)Do I really have to provide MyDeleteAction?, I always thought that
createDeleteCommand() in the appropriate ComponentEditPolicy will do.
(2)Did I derived MyDeleteAction correctly, i.e., from SelectionAction. And
if so, Why getSelectedObjects() returns an empty list?
Notes: I thought that in LogicEditor(), the GEF controller will
automatically call createActions(). However, in my editor class I need to
either call it explicitly. Did I go wrong anywhere.
Thanking you in advance,
Best regards,
Sinleeh
Eric Bordeau wrote:
> Can you delete from the Edit menu or a context menu? The LogicEditor
captures
> the DEL key by adding a KeyHandler to the viewer in
configureGraphicalViewer().
> viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
> .setParent(getCommonKeyHandler()));
> getCommonKeyHandler() returns a KeyHandler that binds the DEL key to the
delete
> action.
> sharedKeyHandler.put(
> KeyStroke.getPressed(SWT.DEL, 127, 0),
> getActionRegistry().getAction(GEFActionConstants.DELETE));
> Eric
> Sin Lee Huang wrote:
> > Dear all,
> >
> > I was attempting to create a way to delete an editpart but with no luck. I
> > hope someone can show me the error of my way.
> >
> > I have an edit part which I want to post a Delete ability. Lets call it
> > Deletable EditPart. Following the example of the Logic example. I extended
> > the ComponentEditPolicy to DeletableEditPolicy, overides
> > createDeleteCommand() in this policy with my deletion code, then install
> > this policy as COMPONENET_ROLE in createEditPolicies() in
> > DeletableEditPart.
> >
> > However, after running the program, I find that I cannot delete the
> > editpart by pressing DEL key. I then put some println statements in
> > DeletableEditPolicy.createDeleteCommand() and realized that it is not
> > called.
> >
> > I am pretty sure I miss out some other important parts to get it working,
> > can someone point it out to me?
> >
> > Best regards and thanking you in advance,
> > Sinlee
> >
|
|
|
Re: Deleting [message #81121 is a reply to message #81106] |
Tue, 27 May 2003 10:25   |
Eclipse User |
|
|
|
Sin Lee Huang wrote:
> Dear Eric,
>
> Thank you for your reply.
>
> For the logic example (using the downloaded binary), I can delete using
> DEL key or via the context menu. The delete option in the Edit menu is not
> enabled.
>
> I was working on my own project which I based it on the logic example when
> I encountered the problem. I followed your advice and try to bind the DEL
> key using the instruction you gave me but still have no luck. What I did
> was simply copy and paste the relevent code you posted to my own class,
> after consulting the logic source code. I can confirm that the program
> code for the getCommonKeyHandler() is executed.
>
> Then I did some digging. Putting a
> if(getActionRegistry().getAction(GEFActionConstants.DELETE) == null)
> statement after:
> sharedKeyHandler.put(
> KeyStroke.getPressed(SWT.DEL, 127, 0),
> getActionRegistry().getAction(GEFActionConstants.DELETE));
>
> shows that I have no IAction for GEFActionConstants.DELETE. Since I cannot
> find any IAction that does setId(GEFActionConstants.DELETE) or similar, I
> conclude that I don't need one. Please correct me if I'm wrong.
Are you subclassing GraphicalEditor or making your own implementation of
IEditorPart? GraphicalEditor.createActions() adds the DeleteAction (which is
available for you to use -- you don't have to implement your own delete action)
to the action registry. If you override createActions() in your editor, be sure
to call super.createActions().
> Nonetheless I decided to be a bit adventureous, this time providing my own
> IAction. I created the following class:
>
> class MyDeleteAction extends SelectionAction {
> public MyDeleteAction (IEditorPart editor) {
> super(editor);
> setId(GEFActionConstants.DELETE);
> }
>
> //copied from logic example's IncrementDecrementAction
> protected boolean calculateEnabled() {
> if (getSelectedObjects().isEmpty()) {
> return false; //(1)
> }
>
> List parts = getSelectedObjects();
> for (int i=0; i<parts.size(); i++){
> Object o = parts.get(i);
> if (!(o instanceof EditPart)){
> System.out.println("hello3");
> return false;
> }
> public void run(){}
> }
>
> and putting: (Copied from LogicEditor.createActions (see notes)
>
> ActionRegistry registry = getActionRegistry();
> IAction action;
> action = new EPLDeleteAction(this);
> registry.registerAction(action);
> getSelectionActions().add(action.getId());
>
> before
> viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
> .setParent(getCommonKeyHandler()));
>
> in configureGraphicalViewer(), I manage to get
> MyDeleteAction.calculateEnabled() to execute. However, it returns false
> since getSelectedObjects() is empty, i.e., execution reached line1.
>
> Based on these information, I have the following questions:
> (1)Do I really have to provide MyDeleteAction?, I always thought that
> createDeleteCommand() in the appropriate ComponentEditPolicy will do.
You can use GEF's DeleteAction
> (2)Did I derived MyDeleteAction correctly, i.e., from SelectionAction. And
> if so, Why getSelectedObjects() returns an empty list?
>
>
> Notes: I thought that in LogicEditor(), the GEF controller will
> automatically call createActions(). However, in my editor class I need to
> either call it explicitly. Did I go wrong anywhere.
Did you override init(IEditorSite, IEditorInput)? If so, you need to call
super.init(...) because that calls initializeActionRegistry() (which calls
createActions()) and it also adds the editor as a selection listener. Without
that, your selection dependent actions (like delete) don't get updated with the
current selection.
>
>
> Thanking you in advance,
>
> Best regards,
> Sinleeh
>
|
|
|
Re: Deleting [message #81136 is a reply to message #81121] |
Tue, 27 May 2003 10:44  |
Eclipse User |
|
|
|
Originally posted by: sinleeh.hotmail.com
Dear Eric,
Thank you very much for the prompt reply. I now manage to get the EditPart
to response to my DEL keystroke. The problem is that I had forgotten to
call super.init(Site,Input) after overiding it. (More precisely, I used
setSite(Site); setInput(Input)). After changing it over, all my problems
with non-responding DEL keystroke were resolved.
For others following this thread, I don't need my own delete action. The
default one works. I did not even use DeleteAction. The default one will
call createDeleteCommand() from the appropriate EditPolicy.
The problems were all mine. Thank you once again for helping me.
Best regards,
Sin Lee Huang
Eric Bordeau wrote:
> Sin Lee Huang wrote:
> > Dear Eric,
> >
> > Thank you for your reply.
> >
> > For the logic example (using the downloaded binary), I can delete using
> > DEL key or via the context menu. The delete option in the Edit menu is not
> > enabled.
> >
> > I was working on my own project which I based it on the logic example when
> > I encountered the problem. I followed your advice and try to bind the DEL
> > key using the instruction you gave me but still have no luck. What I did
> > was simply copy and paste the relevent code you posted to my own class,
> > after consulting the logic source code. I can confirm that the program
> > code for the getCommonKeyHandler() is executed.
> >
> > Then I did some digging. Putting a
> > if(getActionRegistry().getAction(GEFActionConstants.DELETE) == null)
> > statement after:
> > sharedKeyHandler.put(
> > KeyStroke.getPressed(SWT.DEL, 127, 0),
> > getActionRegistry().getAction(GEFActionConstants.DELETE));
> >
> > shows that I have no IAction for GEFActionConstants.DELETE. Since I cannot
> > find any IAction that does setId(GEFActionConstants.DELETE) or similar, I
> > conclude that I don't need one. Please correct me if I'm wrong.
> Are you subclassing GraphicalEditor or making your own implementation of
> IEditorPart? GraphicalEditor.createActions() adds the DeleteAction (which
is
> available for you to use -- you don't have to implement your own delete
action)
> to the action registry. If you override createActions() in your editor, be
sure
> to call super.createActions().
> > Nonetheless I decided to be a bit adventureous, this time providing my own
> > IAction. I created the following class:
> >
> > class MyDeleteAction extends SelectionAction {
> > public MyDeleteAction (IEditorPart editor) {
> > super(editor);
> > setId(GEFActionConstants.DELETE);
> > }
> >
> > //copied from logic example's IncrementDecrementAction
> > protected boolean calculateEnabled() {
> > if (getSelectedObjects().isEmpty()) {
> > return false; //(1)
> > }
> >
> > List parts = getSelectedObjects();
> > for (int i=0; i<parts.size(); i++){
> > Object o = parts.get(i);
> > if (!(o instanceof EditPart)){
> > System.out.println("hello3");
> > return false;
> > }
> > public void run(){}
> > }
> >
> > and putting: (Copied from LogicEditor.createActions (see notes)
> >
> > ActionRegistry registry = getActionRegistry();
> > IAction action;
> > action = new EPLDeleteAction(this);
> > registry.registerAction(action);
> > getSelectionActions().add(action.getId());
> >
> > before
> > viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)
> > .setParent(getCommonKeyHandler()));
> >
> > in configureGraphicalViewer(), I manage to get
> > MyDeleteAction.calculateEnabled() to execute. However, it returns false
> > since getSelectedObjects() is empty, i.e., execution reached line1.
> >
> > Based on these information, I have the following questions:
> > (1)Do I really have to provide MyDeleteAction?, I always thought that
> > createDeleteCommand() in the appropriate ComponentEditPolicy will do.
> You can use GEF's DeleteAction
> > (2)Did I derived MyDeleteAction correctly, i.e., from SelectionAction. And
> > if so, Why getSelectedObjects() returns an empty list?
> >
> >
> > Notes: I thought that in LogicEditor(), the GEF controller will
> > automatically call createActions(). However, in my editor class I need to
> > either call it explicitly. Did I go wrong anywhere.
> Did you override init(IEditorSite, IEditorInput)? If so, you need to call
> super.init(...) because that calls initializeActionRegistry() (which calls
> createActions()) and it also adds the editor as a selection listener.
Without
> that, your selection dependent actions (like delete) don't get updated with
the
> current selection.
> >
> >
> > Thanking you in advance,
> >
> > Best regards,
> > Sinleeh
> >
|
|
|
Goto Forum:
Current Time: Wed Jul 23 17:36:59 EDT 2025
Powered by FUDForum. Page generated in 0.18731 seconds
|