use of org.eclipse.jface.action.IMenuCreator in project yamcs-studio by yamcs.
the class ActionsInputDialog method createActions.
/**
* Creates the actions.
*/
private void createActions() {
addAction = new Action("Add") {
@Override
public void run() {
}
};
addAction.setMenuCreator(new IMenuCreator() {
private Menu menu;
@Override
public void dispose() {
if (menu != null) {
menu.dispose();
menu = null;
}
}
@Override
public Menu getMenu(final Control parent) {
if (menu != null) {
menu.dispose();
}
menu = createMenu(parent, false);
return menu;
}
@Override
public Menu getMenu(final Menu parent) {
return null;
}
});
addAction.setToolTipText("Add an action");
addAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/add.gif"));
copyAction = new Action() {
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
AbstractWidgetAction newAction = ((AbstractWidgetAction) selection.getFirstElement()).getCopy();
actionsInput.addAction(newAction);
actionsViewer.setSelection(new StructuredSelection(newAction));
refreshActionsViewer(newAction);
}
}
};
copyAction.setText("Copy Action");
copyAction.setToolTipText("Copy the selected action");
copyAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/copy.gif"));
copyAction.setEnabled(false);
removeAction = new Action() {
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
actionsList.remove((AbstractWidgetAction) selection.getFirstElement());
refreshActionsViewer(null);
this.setEnabled(false);
}
}
};
removeAction.setText("Remove Action");
removeAction.setToolTipText("Remove the selected action from the list");
removeAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/delete.gif"));
removeAction.setEnabled(false);
moveUpAction = new Action() {
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
AbstractWidgetAction widgetAction = (AbstractWidgetAction) selection.getFirstElement();
int i = actionsList.indexOf(widgetAction);
if (i > 0) {
actionsList.remove(widgetAction);
actionsList.add(i - 1, widgetAction);
refreshActionsViewer(widgetAction);
}
}
}
};
moveUpAction.setText("Move Up Action");
moveUpAction.setToolTipText("Move up the selected action");
moveUpAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_prev.gif"));
moveUpAction.setEnabled(false);
moveDownAction = new Action() {
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
AbstractWidgetAction widgetAction = (AbstractWidgetAction) selection.getFirstElement();
int i = actionsList.indexOf(widgetAction);
if (i < actionsList.size() - 1) {
actionsList.remove(widgetAction);
actionsList.add(i + 1, widgetAction);
refreshActionsViewer(widgetAction);
}
}
}
};
moveDownAction.setText("Move Down Action");
moveDownAction.setToolTipText("Move down the selected action");
moveDownAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_next.gif"));
moveDownAction.setEnabled(false);
}
use of org.eclipse.jface.action.IMenuCreator in project yamcs-studio by yamcs.
the class OPIEditorActionBarContributor method buildActions.
@Override
protected void buildActions() {
addRetargetAction(new UndoRetargetAction());
addRetargetAction(new RedoRetargetAction());
addRetargetAction(new DeleteRetargetAction());
addRetargetAction(new ZoomInRetargetAction());
addRetargetAction(new ZoomOutRetargetAction());
addRetargetAction(new MatchWidthRetargetAction());
addRetargetAction(new MatchHeightRetargetAction());
addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
RetargetAction a = new RetargetAction(GEFActionConstants.TOGGLE_GRID_VISIBILITY, "Toggle Grid Visibility", IAction.AS_CHECK_BOX);
a.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
"icons/grid.png"));
addRetargetAction(a);
a = new RetargetAction(GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY, "Toggle Snap To Geometry", IAction.AS_CHECK_BOX);
a.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/snap2geometry.png"));
addRetargetAction(a);
a = new RetargetAction(GEFActionConstants.TOGGLE_RULER_VISIBILITY, "Toggle Ruler Visibility", IAction.AS_CHECK_BOX);
a.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/ruler.png"));
addRetargetAction(a);
for (DistributeType dt : DistributeType.values()) {
if (dt != DistributeType.HORIZONTAL_GAP) {
a = new RetargetAction(dt.getActionID(), dt.getLabel());
a.setImageDescriptor(dt.getImageDescriptor());
addRetargetAction(a);
}
}
// This is only for action displaying in toolbar
a = new RetargetAction(DistributeType.HORIZONTAL_GAP.getActionID(), DistributeType.HORIZONTAL_GAP.getLabel(), IAction.AS_DROP_DOWN_MENU);
a.setImageDescriptor(DistributeType.HORIZONTAL_GAP.getImageDescriptor());
a.setMenuCreator(new IMenuCreator() {
Menu menu;
@Override
public Menu getMenu(Menu parent) {
return null;
}
@Override
public Menu getMenu(Control parent) {
if (menu != null)
return menu;
MenuManager manager = new MenuManager();
for (DistributeType dt : DistributeType.values()) {
if (dt != DistributeType.HORIZONTAL_GAP)
manager.add(getAction(dt.getActionID()));
}
menu = manager.createContextMenu(parent);
return menu;
}
@Override
public void dispose() {
if (menu != null) {
menu.dispose();
menu = null;
}
}
});
addRetargetAction(a);
}
use of org.eclipse.jface.action.IMenuCreator in project dbeaver by serge-rider.
the class SelectCRSAction method getMenuCreator.
@Override
public IMenuCreator getMenuCreator() {
return new MenuCreator(control -> {
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(manager -> {
menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_4326));
menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_3857));
menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_3395));
menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_SIMPLE));
menuManager.add(new Separator());
List<Integer> recentSRIDs = GISEditorUtils.getRecentSRIDs();
if (!recentSRIDs.isEmpty()) {
for (Integer recentSRID : recentSRIDs) {
menuManager.add(new SetCRSAction(valueEditor, recentSRID));
}
menuManager.add(new Separator());
}
menuManager.add(new Action(GISMessages.panel_select_crs_action_menu_manager_other) {
@Override
public void run() {
SelectCRSAction.this.run();
}
});
menuManager.add(new Action(GISMessages.panel_select_crs_action_menu_manager_config) {
@Override
public void run() {
new GISViewerConfigurationDialog(valueEditor.getEditorControl().getShell()).open();
}
});
});
return menuManager;
});
}
use of org.eclipse.jface.action.IMenuCreator in project dbeaver by serge-rider.
the class SelectTilesAction method getMenuCreator.
@Override
public IMenuCreator getMenuCreator() {
return new MenuCreator(control -> {
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(manager -> {
if (valueEditor.getValueSRID() != 0) {
for (LeafletTilesDescriptor ld : GeometryViewerRegistry.getInstance().getLeafletTiles()) {
menuManager.add(new SetTilesAction(valueEditor, ld));
}
}
});
return menuManager;
});
}
Aggregations