Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » drop down action?
drop down action? [message #455864] Fri, 20 May 2005 18:31 Go to next message
Anima Gupta is currently offline Anima GuptaFriend
Messages: 44
Registered: July 2009
Member
Hi,

does anyone know how to populate Action on a toolbar which is of type
"IAction.AS_DROP_DOWN_MENU" with values?

Thanks!

Anima.
Re: drop down action? [message #455870 is a reply to message #455864] Fri, 20 May 2005 21:42 Go to previous messageGo to next message
Anima Gupta is currently offline Anima GuptaFriend
Messages: 44
Registered: July 2009
Member
just to be more clear here:

I have defined a Action of the time IAction.AS_DROP_DOWN_MENU - It shows
up as a down arrow, along with image on the toolbar of the view - which
is great.
...
....
Action filterAction = new Action("Filter",IAction.AS_DROP_DOWN_MENU) {
public void run() {
...
}
};
filterAction.setImageDescriptor(Images.ICON_FILTER);
filterAction.setToolTipText("Filter");
IToolBarManager toolbarManager =
getViewSite().getActionBars().getToolBarManager();
toolbarManager.add(filterAction);
....
...

Now I want to put some list of values in it, but I cannot see any
methods on Action to do so.

I see a ActionContributionItem class, and I am using it like this:

ActionContributionItem a = new ActionContributionItem(filterAction);
IMenuManager m = new MenuManager();
m.add(new Action("only active"){public void run(){}});
m.add(new Action("only obsolete"){public void run(){}});
a.fill(((MenuManager) m).getMenu(), 1);

....
....

But this does not see to show the drop down of 2 menu items when I click
the filterAction that shows up on the toolbar -

Can anyone tell me what I am doing wrong, or missing something?

Thanks.

Anima.




Anima Gupta wrote:
> Hi,
>
> does anyone know how to populate Action on a toolbar which is of type
> "IAction.AS_DROP_DOWN_MENU" with values?
>
> Thanks!
>
> Anima.
>
Re: drop down action? [message #455944 is a reply to message #455870] Mon, 23 May 2005 18:33 Go to previous message
Eclipse UserFriend
Originally posted by: venkatrj.gmail.com

Hi,

You need to use ActionContributionItem class. I have a sample action class
below.

package com.microstrategy.web.sdk.seditor.actions;

import java.util.Iterator;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuCreator;

public class DropDownAction extends Action implements IMenuCreator {
private Menu fMenu;

public DropDownAction() {
setText("My Actions");
setMenuCreator(this);
}

public void dispose() {
if (fMenu != null) {
fMenu.dispose();
fMenu= null;
}
}

public Menu getMenu(Menu parent) {
return null;
}

public Menu getMenu(Control parent) {
if (fMenu != null)
fMenu.dispose();

fMenu= new Menu(parent);
int i= 0;
Action filterAction = new Action("Filter") {
public void run() {}
};
Action gen = new Action("gen",IAction.AS_DROP_DOWN_MENU){
public void run(){}
};
addActionToMenu(fMenu, filterAction);
new MenuItem(fMenu, SWT.SEPARATOR);
addActionToMenu(fMenu, gen);

return fMenu;
}

protected void addActionToMenu(Menu parent, Action action) {
ActionContributionItem item= new
ActionContributionItem(action);
item.fill(parent, -1);
}

public void run() {

}

/**
* Get's rid of the menu, because the menu hangs on to
* the searches, etc.
*/
void clear() {
dispose();
}
}

In the View, add the following code to add the above action.
DropDownAction dn = new DropDownAction();
manager.add(dn);

I hope this will solve your problem.

--venkat

Anima Gupta wrote:

> just to be more clear here:

> I have defined a Action of the time IAction.AS_DROP_DOWN_MENU - It shows
> up as a down arrow, along with image on the toolbar of the view - which
> is great.
> ...
> ....
> Action filterAction = new Action("Filter",IAction.AS_DROP_DOWN_MENU) {
> public void run() {
>
...
> }
> };
> filterAction.setImageDescriptor(Images.ICON_FILTER);
> filterAction.setToolTipText("Filter");
> IToolBarManager toolbarManager =
> getViewSite().getActionBars().getToolBarManager();
> toolbarManager.add(filterAction);
> ....
> ...

> Now I want to put some list of values in it, but I cannot see any
> methods on Action to do so.

> I see a ActionContributionItem class, and I am using it like this:

> ActionContributionItem a = new ActionContributionItem(filterAction);
> IMenuManager m = new MenuManager();
> m.add(new Action("only active"){public void run(){}});
> m.add(new Action("only obsolete"){public void run(){}});
> a.fill(((MenuManager) m).getMenu(), 1);

> ....
> ....

> But this does not see to show the drop down of 2 menu items when I click
> the filterAction that shows up on the toolbar -

> Can anyone tell me what I am doing wrong, or missing something?

> Thanks.

> Anima.




> Anima Gupta wrote:
>> Hi,
>>
>> does anyone know how to populate Action on a toolbar which is of type
>> "IAction.AS_DROP_DOWN_MENU" with values?
>>
>> Thanks!
>>
>> Anima.
>>
Previous Topic:Equal Height widgets on PocketPC
Next Topic:Check when user changes tabitem
Goto Forum:
  


Current Time: Fri Apr 26 09:56:32 GMT 2024

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

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

Back to the top