0

I have a toolbar that I use to switch over perspectives. Each button in my toolbar opens a different perspective. I want to emphasize the user feeling what is opened at the time and I want to work my buttons as toggles with states "DOWN" and "UP". The code I use to add new BaseActions to the toolbar:

ToolBarManager toolBarManager = new ToolBarManager();
coolBar.add(toolBarManager);
toolBarManager.add(ordersDownload);

and part of the code of my BaseAction which changes button behaviour to toggle:

public class BaseAction implements IAction {

@Override
public int getStyle() {
    return SWT.TOGGLE;
}

Inside IAction there is a method boolean isChecked but it doesnt work at all as always when I click on the toolbar button its state is inverted (DOWN -> UP, UP -> DOWN). I dont want to have more than one Button (Toggle) at the same time with state DOWN so I want to somehow call state UP for all buttons and leave only one with state DOWN.

The picture that shows how it should look like

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Bartek Szczypien
  • 333
  • 4
  • 17
  • `getStyle` must return one of the `IAction.AS_xxxx` values - `SWT.TOGGLE` is not valid. It is more usual to extend `org.eclipse.jface.action.Action` rather than trying to implement the whole of `IAction` yourself. – greg-449 Apr 14 '16 at 10:17

1 Answers1

0

Ok it is partly solved. As greg-449 suggested IAction.AS_RADIO_BUTTON should be used for IAction style. After I removed Separators (as theyextends AbstractGroupMarker) from my toolbar there is always one toggle DOWN (when mouse click occures all other toggles are set to UP). Now i need to switch over toggles programmatically, I use:

ActionContributionItem lItem = (ActionContributionItem)Facade.toolbar.getItems()[1];
lItem.getWidget().notifyListeners(SWT.Selection, new Event());

which switches to another perspective (which means that my IAction->runWithEvent function is called properly) but the clicked toggle is not switched (not set as DOWN, the previously used toggle stay DOWN)

Bartek Szczypien
  • 333
  • 4
  • 17