Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Actions in my ActionBarAdvisor
Actions in my ActionBarAdvisor [message #443917] Tue, 07 February 2006 05:57 Go to next message
Eclipse UserFriend
I have a simple problem with accessing the actions defined in my
ActionBarAdvisor.
I'm sure some experienced RCP programmer can help me.

What I do:
I create ApplicationActionBarAdvisor that extends ActionBarAdvisor. In the
makeActions( ), I implement what the action should do (e.g. playAction) and
in the fillCoolBar( ), I add the action to the toolbar.
And now I want to disable the playAction from my view (PlaybackView extends
ViewPart).
But I find no way of obtaining a reference to the action.

The code:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private Action playAction;

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}

protected void makeActions(final IWorkbenchWindow window) {
playAction = new Action() {
public void run() {
...
}
}
}

protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
coolBar.add(toolbar);
toolbar.add(fileOpenAction);
toolbar.add(new Separator());
toolbar.add(playAction);
}

Koen
Re: Actions in my ActionBarAdvisor [message #444010 is a reply to message #443917] Wed, 08 February 2006 03:04 Go to previous messageGo to next message
Eclipse UserFriend
HI Koen,

if you want to enable/disable your action based on a selection in a
viewer then you can do this:

Implement in your action the ISelectionListener and the
ActionFactory.IWorkbenchAction interface:

public class MyAction extends Action implements ISelectionListener,
ActionFactory.IWorkbenchAction {
private final IWorkbenchWindow window;

public final static String ID = "org.eclipsercp.hyperbola.addContact";

private IStructuredSelection selection;

public MyAction (IWorkbenchWindow window) {
this.window = window;
setId(ID);
setText("&My Action");
window.getSelectionService().addSelectionListener(this);
}

public void selectionChanged(IWorkbenchPart part,
ISelection incoming) {
// Selection containing elements
if (incoming instanceof IStructuredSelection) {
selection = (IStructuredSelection) incoming;
setEnabled(selection.size() == 1
&& selection.getFirstElement() instanceof MyClass);
} else {
// Other selections, for example containing text or of other kinds.
setEnabled(false);
}
}


public void dispose() {
window.getSelectionService().removeSelectionListener(this);
}
}

In your view you add the viewer to the selection provider list:
...
getSite().setSelectionProvider(treeViewer);
...


Hope this helps

Reinhard

Koen schrieb:
> I have a simple problem with accessing the actions defined in my
> ActionBarAdvisor.
> I'm sure some experienced RCP programmer can help me.
>
> What I do:
> I create ApplicationActionBarAdvisor that extends ActionBarAdvisor. In the
> makeActions( ), I implement what the action should do (e.g. playAction) and
> in the fillCoolBar( ), I add the action to the toolbar.
> And now I want to disable the playAction from my view (PlaybackView extends
> ViewPart).
> But I find no way of obtaining a reference to the action.
>
> The code:
> public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
> private Action playAction;
>
> public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
> super(configurer);
> }
>
> protected void makeActions(final IWorkbenchWindow window) {
> playAction = new Action() {
> public void run() {
> ...
> }
> }
> }
>
> protected void fillCoolBar(ICoolBarManager coolBar) {
> IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
> coolBar.add(toolbar);
> toolbar.add(fileOpenAction);
> toolbar.add(new Separator());
> toolbar.add(playAction);
> }
>
> Koen
>
>
Re: Actions in my ActionBarAdvisor [message #444019 is a reply to message #443917] Wed, 08 February 2006 06:10 Go to previous message
Eclipse UserFriend
I don't know whether this method is right or wrong but it works.
For this you need the reference of getWindowConfigurer() in your view. for this you need a varible of IWorkbenchWindowConfigurer in your view and define one setter method fot this.
In postWindow() method of workbench you can set the getWindowConfigurer() reference to the view by using setter method
after that you can access your menu item.
Previous Topic:Add a new project to an empty eclipse workspace programatically
Next Topic:Accessing files within a plugin: "Workspace is closed" error
Goto Forum:
  


Current Time: Wed Jul 30 17:46:32 EDT 2025

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

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

Back to the top