List of usage examples for org.eclipse.jface.action IAction getStyle
int getStyle();
From source file:com.aptana.ide.server.ui.views.GenericServersView.java
License:Open Source License
/** * Creates and registers the context menu *///from ww w .j a va2 s .com private void createPopupMenu() { deleteAction = ActionFactory.DELETE.create(getViewSite().getWorkbenchWindow()); MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown(true); getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.DELETE.getId(), new Action() { public void run() { doDelete(); } }); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems(); for (int i = 0; i < items.length; i++) { if (items[i] instanceof ActionContributionItem) { ActionContributionItem aci = (ActionContributionItem) items[i]; IAction action = aci.getAction(); if (action == openLog) { // adds the Open Log action to the context menu as a push button instead of // drop-down boolean enabled = action.isEnabled(); action = new OpenLogAction(serverViewer, Action.AS_PUSH_BUTTON); action.setEnabled(enabled); } if (action.isEnabled() && action.getStyle() != Action.AS_DROP_DOWN_MENU) { if (action.getText() == null || action.getText().length() == 0) { action.setText(action.getToolTipText()); } manager.add(action); } } else { if (items[i] instanceof Separator) { manager.add(new Separator()); } } } manager.add(new Separator()); IStructuredSelection selection = (IStructuredSelection) serverViewer.getSelection(); final IServer server = (IServer) selection.getFirstElement(); if (server != null) { deleteAction.setText(StringUtils.format(Messages.ServersView_DELETE, getShortenName(server))); // deleteAction.setEnabled(server.getServerState() == IServer.STATE_STOPPED); deleteAction.setEnabled(server.canDelete().isOK()); manager.add(deleteAction); Action action = new Action() { public void run() { doEdit(server); } }; action.setText(StringUtils.format(Messages.ServersView_EDIT, getShortenName(server))); IStatus canModify = server.canModify(); IStatus canModifyInStoppedStateOnly = server.canModifyInStoppedStateOnly(); action.setEnabled(((canModifyInStoppedStateOnly == null || canModifyInStoppedStateOnly.getCode() == IStatus.OK) ? server.getServerState() == IServer.STATE_STOPPED : true) && (canModify == null || canModify.getCode() == IStatus.OK)); manager.add(action); } // deleteAction.setEnabled(!selection.isEmpty()); manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); // Allow } private String getShortenName(final IServer server) { String name = server.getName(); int length = name.length(); if (length > MAX_SHOWN_SERVER_NAME) { int delta = (length - 15) / 2; int pivot = length / 2; int start = pivot - delta; int end = pivot + delta; String s1 = name.substring(0, start); String s2 = name.substring(end, length); String s = s1 + ELLIPSIS + s2; return s; } return name; } }); Menu menu = menuMgr.createContextMenu(serverViewer.getControl()); serverViewer.getControl().setMenu(menu); getSite().registerContextMenu(menuMgr, serverViewer); }
From source file:com.diffplug.common.swt.jface.JFaceRx.java
License:Apache License
/** * Returns an `RxBox<Boolean>` for the toggle state of the given action as an RxBox. * <p>//from w w w. java 2 s. c om * Applicable to IAction.AS_CHECK_BOX and AS_RADIO_BUTTON. */ public static @SwtThread RxBox<Boolean> toggle(IAction action) { Preconditions.checkArgument(SwtMisc.flagIsSet(IAction.AS_CHECK_BOX, action.getStyle()) || SwtMisc.flagIsSet(IAction.AS_RADIO_BUTTON, action.getStyle())); RxBox<Boolean> box = RxBox.of(action.isChecked()); action.addPropertyChangeListener(e -> { if ("checked".equals(e.getProperty())) { box.set((Boolean) e.getNewValue()); } }); Rx.subscribe(box, isChecked -> { action.setChecked(isChecked); }); return box; }
From source file:com.netxforge.netxstudio.screens.parts.ChartScreenViewer.java
License:Open Source License
protected void resetToggledActions() { for (IAction a : getActions()) { if (a.getStyle() == IAction.AS_CHECK_BOX) { a.setChecked(false);//from w w w . j a v a 2 s . c o m } } }
From source file:com.nokia.tools.s60.ide.actions.menu.GeneralRetargetAction.java
License:Open Source License
public GeneralRetargetAction(IAction template) { this(template.getId(), template.getText(), template.getToolTipText(), template.getStyle()); setImageDescriptor(template.getImageDescriptor()); setDisabledImageDescriptor(template.getDisabledImageDescriptor()); setDescription(template.getDescription()); }
From source file:fable.framework.toolbox.CheckableActionGroup.java
License:Open Source License
public void add(IAction action) { if (action.getStyle() != IAction.AS_CHECK_BOX) throw new RuntimeException("Only check actions are supported!"); action.addPropertyChangeListener(this); actions.add(action);/* w w w. j a v a2 s. c o m*/ }
From source file:org.eclipse.birt.report.designer.internal.ui.swt.custom.TabbedPropertyTitle.java
License:Open Source License
public void setActions(IAction[] actions) { if (actions != null) { if (toolbar != null) { while (toolbar.getItemCount() > 0) { ToolItem item = toolbar.getItem(0); IAction action = (IAction) actionMap.get(item); if (action != null) action.removePropertyChangeListener(this); item.dispose();//w w w . j a v a 2 s . c om } actionMap.clear(); toolbar.dispose(); } toolbar = new ToolBar(label, SWT.FLAT); toolbar.setBackground(gbg); GridData gd = new GridData(); gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = SWT.END; gd.grabExcessVerticalSpace = true; gd.verticalAlignment = SWT.CENTER; toolbar.setLayoutData(gd); for (int i = 0; i < actions.length; i++) { IAction action = actions[i]; int flags = SWT.PUSH; if (action != null) { int style = action.getStyle(); if (style == IAction.AS_CHECK_BOX) { flags = SWT.CHECK; } else if (style == IAction.AS_RADIO_BUTTON) { flags = SWT.RADIO; } else if (style == IAction.AS_DROP_DOWN_MENU) { flags = SWT.DROP_DOWN; } } ToolItem item = new ToolItem(toolbar, flags); item.addListener(SWT.Selection, getToolItemListener()); action.addPropertyChangeListener(this); actionMap.put(item, action); } updateToolBar(); label.layout(); } else { if (toolbar != null) { toolbar.dispose(); toolbar = null; } } }
From source file:org.eclipse.birt.report.designer.internal.ui.swt.custom.TabbedPropertyTitle.java
License:Open Source License
private void handleWidgetSelection(Event e, ToolItem item) { boolean selection = item.getSelection(); int style = item.getStyle(); IAction action = (IAction) actionMap.get(item); if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (action.getStyle() == IAction.AS_CHECK_BOX) { action.setChecked(selection); }//from w w w. j a v a 2 s.c o m } else if ((style & SWT.RADIO) != 0) { if (action.getStyle() == IAction.AS_RADIO_BUTTON) { action.setChecked(selection); } } else if ((style & SWT.DROP_DOWN) != 0) { if (e.detail == 4) { // on drop-down button if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { IMenuCreator mc = action.getMenuCreator(); ToolItem ti = (ToolItem) item; if (mc != null) { Menu m = mc.getMenu(ti.getParent()); if (m != null) { Point point = ti.getParent().toDisplay(new Point(e.x, e.y)); m.setLocation(point.x, point.y); // waiting m.setVisible(true); return; // we don't fire the action } } } } } action.runWithEvent(e); }
From source file:org.eclipse.birt.report.designer.internal.ui.swt.custom.TabbedPropertyTitle.java
License:Open Source License
private void updateToolBar() { if (toolbar != null) { ResourceManager parentResourceManager = JFaceResources.getResources(); LocalResourceManager localManager = new LocalResourceManager(parentResourceManager); for (int i = 0; i < toolbar.getItemCount(); i++) { ToolItem item = toolbar.getItem(i); IAction action = (IAction) actionMap.get(item); if (action != null) { ImageDescriptor image = null; if (action.getImageDescriptor() != null) image = action.getImageDescriptor(); if (image != null) item.setImage(localManager.createImageWithDefault(image)); item.setToolTipText(action.getToolTipText()); if (IAction.AS_CHECK_BOX == action.getStyle()) { item.setSelection(action.isChecked()); }/*from ww w.j a v a2 s. c om*/ item.setEnabled(action.isEnabled()); } } disposeOldImages(); imageManager = localManager; if (toolbar.isFocusControl()) toolbar.setFocus(); } }
From source file:org.eclipse.debug.ui.AbstractDebugView.java
License:Open Source License
/** * Saves the checked state for all actions contributed to the toolbar * manager that function as a toggle action. The states are saved in * the Debug UI plugin's preference store. * // www . j a v a 2 s.c o m * @since 2.1 */ protected void saveAllCheckedActionStates() { IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager(); IContributionItem[] items = tbm.getItems(); for (int i = 0; i < items.length; i++) { IContributionItem iContributionItem = items[i]; if (iContributionItem instanceof ActionContributionItem) { ActionContributionItem item = (ActionContributionItem) iContributionItem; IAction action = item.getAction(); if (action.getStyle() == IAction.AS_CHECK_BOX && action.isEnabled()) { saveCheckedActionState(action); } } } }
From source file:org.eclipse.debug.ui.AbstractDebugView.java
License:Open Source License
/** * Configures this view's toolbar. Subclasses implement * <code>#configureToolBar(IToolBarManager)</code> to * contribute actions to the toolbar./*from w w w . j a v a 2s . co m*/ * <p> * To properly initialize toggle actions that are contributed * to this view, state is restored for toggle actions that have * a persisted state in the Debug UI plugin's preferences. As well, any * toggle actions that have an initial state of 'checked' are invoked. The * actions' states are restored and the actions are invoked in a runnable, * after the view is created. * </p> */ protected void initializeToolBar() { final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager(); configureToolBar(tbm); getViewSite().getActionBars().updateActionBars(); // This is done in a runnable to be run after this view's pane // is created Runnable r = new Runnable() { public void run() { if (!isAvailable()) { return; } IContributionItem[] items = tbm.getItems(); if (items != null) { for (int i = 0; i < items.length; i++) { if (items[i] instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) items[i]).getAction(); if (!SkipAllBreakpointsAction.ACTION_ID.equals(action.getId())) { if (action.getStyle() == IAction.AS_CHECK_BOX) { initActionState(action); if (action.isChecked()) { action.run(); } } } } } setMemento(null); } updateObjects(); } }; asyncExec(r); }