Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Global Copy Action not Working
Global Copy Action not Working [message #225303] Mon, 30 October 2006 13:13 Go to next message
Eclipse UserFriend
Originally posted by: mike.aol.com

I have read all the threads in this newsgroup and I still can't get the
global copy action to be retargeted for my GEF editor. I have
successfully implemented an analogous action for paste in the same
places. Here's what I've done:

ActionBarAdvisor: create, register, and add ActionFactory.COPY to the
main menu:

copyAction = ActionFactory.COPY.create(window);
register(copyAction);
...
menu.add(copyAction);

Implement an action, CopyTopologyObjectsAction, that extends
SelectionAction, using the same id as the global action:
ActionFactory.COPY.getId(). My calculateEnabled() method checks for
appropriate selected objects, which I know works fine for the context
menu that I'm using for this action. I set the ID, etc., in its init()
method:
protected void init() {
super.init();
setId(ID);
setText("&Copy");
setLazyEnablementCalculation(false);
}

In my editor:
protected void createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
IAction action;
...
action = new CopyTopologyObjectsAction((IWorkbenchPart)this);
registry.registerAction(action);
getSelectionActions().add(action.getId());

public void init(IEditorSite pageSite, IEditorInput input) throws
PartInitException {
super.init(pageSite, input);
ActionRegistry registry = getActionRegistry();
IActionBars bars = pageSite.getActionBars();
...
id = ActionFactory.COPY.getId();
bars.setGlobalActionHandler(id,
registry.getAction(CopyTopologyObjectsAction.ID)); //note: ID is "copy"

In my ContextMenuProvider:
public void buildContextMenu(IMenuManager manager) {
...
action = getActionRegistry().getAction(CopyTopologyObjectsAction.ID);

manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);

The Copy action appears in the main menu, but it is never enabled. Any
clues what I'm doing wrong or how I can better debug this?

Thanks,
Mike Gering
Re: Global Copy Action not Working [message #225379 is a reply to message #225303] Mon, 30 October 2006 17:37 Go to previous messageGo to next message
Xiang Qinxian is currently offline Xiang QinxianFriend
Messages: 119
Registered: July 2009
Senior Member
在 2006-10-30一的 08:13 -0500,Mike Gering写道:
> I have read all the threads in this newsgroup and I still can't get the
> global copy action to be retargeted for my GEF editor. I have
> successfully implemented an analogous action for paste in the same
> places. Here's what I've done:
>
> ActionBarAdvisor: create, register, and add ActionFactory.COPY to the
> main menu:
>
> copyAction = ActionFactory.COPY.create(window);
> register(copyAction);
> ...
> menu.add(copyAction);
>
> Implement an action, CopyTopologyObjectsAction, that extends
> SelectionAction, using the same id as the global action:
> ActionFactory.COPY.getId(). My calculateEnabled() method checks for
> appropriate selected objects, which I know works fine for the context
> menu that I'm using for this action. I set the ID, etc., in its init()
> method:
> protected void init() {
> super.init();
> setId(ID);
> setText("&Copy");
> setLazyEnablementCalculation(false);
> }
>
> In my editor:
> protected void createActions() {
> super.createActions();
> ActionRegistry registry = getActionRegistry();
> IAction action;
> ...
> action = new CopyTopologyObjectsAction((IWorkbenchPart)this);
> registry.registerAction(action);
> getSelectionActions().add(action.getId());
>
> public void init(IEditorSite pageSite, IEditorInput input) throws
> PartInitException {
> super.init(pageSite, input);
> ActionRegistry registry = getActionRegistry();
> IActionBars bars = pageSite.getActionBars();
> ...
> id = ActionFactory.COPY.getId();
> bars.setGlobalActionHandler(id,
> registry.getAction(CopyTopologyObjectsAction.ID)); //note: ID is "copy"
>
> In my ContextMenuProvider:
> public void buildContextMenu(IMenuManager manager) {
> ...
> action = getActionRegistry().getAction(CopyTopologyObjectsAction.ID);
>
> manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
>
> The Copy action appears in the main menu, but it is never enabled. Any
> clues what I'm doing wrong or how I can better debug this?
>
> Thanks,
> Mike Gering
Hi,
That action do not heard from selection change.
in gef.ActionBarContributor class, you will find a method as follows:

protected void addRetargetAction(RetargetAction action) {
addAction(action);
retargetActions.add(action);

//please pay attention this line
getPage().addPartListener(action);


addGlobalActionKey(action.getId());
}

try to add it to your create actions method, or selectionchange method.

> bars.setGlobalActionHandler(id,
> registry.getAction(CopyTopologyObjectsAction.ID));

Regards,

Qinxian
Re: Global Copy Action not Working [message #225412 is a reply to message #225379] Tue, 31 October 2006 00:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mike.aol.com

Thanks, but I'm still missing something very basic.

Xiang Qinxian wrote:

> That action do not heard from selection change.
> in gef.ActionBarContributor class, you will find a method as follows:
>
> protected void addRetargetAction(RetargetAction action) {
> addAction(action);
> retargetActions.add(action);
>
> //please pay attention this line
> getPage().addPartListener(action);
>
>
> addGlobalActionKey(action.getId());
> }
>
> try to add it to your create actions method, or selectionchange method.

In the above, "action" refers to the global "copy" action, right? If so,
how can I get a reference to it from my makeActions() method?

Regards,
Mike
Re: Global Copy Action not Working [message #225420 is a reply to message #225412] Tue, 31 October 2006 03:22 Go to previous messageGo to next message
Xiang Qinxian is currently offline Xiang QinxianFriend
Messages: 119
Registered: July 2009
Senior Member
在 2006-10-30一的 19:40 -0500,Mike Gering写道:
> Thanks, but I'm still missing something very basic.
>
> Xiang Qinxian wrote:
>
> > That action do not heard from selection change.
> > in gef.ActionBarContributor class, you will find a method as follows:
> >
> > protected void addRetargetAction(RetargetAction action) {
> > addAction(action);
> > retargetActions.add(action);
> >
> > //please pay attention this line
> > getPage().addPartListener(action);
> >
> >
> > addGlobalActionKey(action.getId());
> > }
> >
> > try to add it to your create actions method, or selectionchange method.
>
> In the above, "action" refers to the global "copy" action, right? If so,
> how can I get a reference to it from my makeActions() method?
>
Hi,
No, Sooorry my english, I'm china.
>From your code, you do not use ActionBarContributor but directly handle
action in editorpart. it's no matter.
and there is a need that this action need updated, someone responsible
for notificate it.
now can only add one line from your code,
getPage().addPartlistner(action)
after your register copy action.

other code is just for demo the need notificating action update.

Regards,

Qinxian
> Regards,
> Mike
Re: Global Copy Action not Working [message #225551 is a reply to message #225420] Tue, 31 October 2006 13:58 Go to previous message
Eclipse UserFriend
Originally posted by: mike.aol.com

Got it! Thanks, Xinxian!

Regards,
Mike
Previous Topic:Connection Anchor
Next Topic:UpdateListener.firePainting(Rectangle, Map) causes NullPointerException
Goto Forum:
  


Current Time: Thu Apr 25 19:07:09 GMT 2024

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

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

Back to the top