List of usage examples for org.eclipse.jface.action IAction removePropertyChangeListener
void removePropertyChangeListener(IPropertyChangeListener listener);
From source file:com.microsoft.tfs.client.common.ui.framework.action.ToolbarPulldownAction.java
License:Open Source License
/** * Removes a previously added sub-action from this * {@link ToolbarPulldownAction}. If the sub-action being removed is the * default sub-action, there will be no default sub-action after removing * it./*from w w w .ja v a 2s . c o m*/ * * @param subActionToRemove * a previously added sub-action to remove (must not be * <code>null</code>) */ public void removeSubAction(final IAction subActionToRemove) { Check.notNull(subActionToRemove, "subActionToRemove"); //$NON-NLS-1$ final int index = subActions.indexOf(subActionToRemove); if (index == -1) { throw new IllegalArgumentException( "the specified action is not contained in this ToolbarPulldownAction"); //$NON-NLS-1$ } final IAction defaultSubAction = getDefaultSubAction(); subActions.remove(subActionToRemove); subActionToRemove.removePropertyChangeListener(subActionPropertyChangeListener); recomputeEnablement(); if (defaultSubAction != null) { if (defaultSubAction == subActionToRemove) { defaultSubActionIndex = -1; } else { defaultSubActionIndex = subActions.indexOf(defaultSubAction); } } disposeSubActionMenu(); }
From source file:com.nokia.tools.media.utils.tooltip.TitlebarComposite.java
License:Open Source License
public void addTitleAction(final IAction action, EActionLocation location) { final Canvas canvas = new Canvas(titlebar, SWT.NONE); switch (location) { case BEGINNING: canvas.moveAbove(null);// ww w.java2 s .c o m break; case END: canvas.moveBelow(null); break; case ABOVE_TITLE: canvas.moveAbove(title); break; case BELOV_TITLE: default: canvas.moveBelow(title); break; } ((GridLayout) titlebar.getLayout()).numColumns++; if (resourcesToDispose == null) { resourcesToDispose = new ArrayList<Resource>(); } final CanvasListener canvasListener = new CanvasListener(action, canvas); final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.IMAGE == event.getProperty()) { ImageDescriptor imgDesc = action.getImageDescriptor(); ImageDescriptor hoverImgDesc = action.getHoverImageDescriptor(); ImageDescriptor disabledImgDesc = action.getDisabledImageDescriptor(); canvasListener.setImg(imgDesc); canvasListener.setHoverImg(hoverImgDesc); canvasListener.setDisabledImg(disabledImgDesc); } if (IAction.TEXT == event.getProperty() || IAction.TOOL_TIP_TEXT == event.getProperty()) { if (action.getToolTipText() != null) { canvas.setToolTipText(action.getToolTipText()); } else if (action.getText() != null) { canvas.setToolTipText(action.getText()); } } canvas.redraw(); canvas.update(); } }; action.addPropertyChangeListener(propertyChangeListener); canvas.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { action.removePropertyChangeListener(propertyChangeListener); } }); propertyChangeListener.propertyChange(new PropertyChangeEvent(this, IAction.IMAGE, null, null)); propertyChangeListener.propertyChange(new PropertyChangeEvent(this, IAction.TEXT, null, null)); Rectangle bounds = canvasListener.img.getBounds(); GridData gd = new GridData(bounds.width, bounds.height); canvas.setLayoutData(gd); canvas.addListener(SWT.Paint, canvasListener); canvas.addListener(SWT.MouseEnter, canvasListener); canvas.addListener(SWT.MouseExit, canvasListener); canvas.addListener(SWT.MouseUp, canvasListener); }
From source file:fable.framework.toolbox.MenuAction.java
License:Open Source License
@Override public void dispose() { if (fMenu != null) { fMenu.dispose();//from w w w .java 2s. c o m fMenu = null; } for (IAction action : actions) { action.removePropertyChangeListener(this); } actions.clear(); lastAction = null; }
From source file:org.dawb.common.ui.menu.CheckableActionGroup.java
License:Open Source License
public void clear() { for (IAction action : actions) { action.removePropertyChangeListener(this); }/* w ww .j a v a2 s . co m*/ actions.clear(); }
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 ww. j a v a 2 s. com*/ } 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.egit.ui.internal.dialogs.AbstractConfigureRemoteDialog.java
License:Open Source License
private Button createActionButton(Composite parent, int style, IAction action) { Button button = new Button(parent, style); button.setText(action.getText());/*from w ww .j av a2s . co m*/ button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { action.run(); } }); IPropertyChangeListener listener = event -> { if (IAction.ENABLED.equals(event.getProperty())) { if (!button.isDisposed()) { if (Display.getCurrent() == null) { button.getShell().getDisplay().syncExec(() -> { if (!button.isDisposed()) { button.setEnabled(action.isEnabled()); } }); } else { button.setEnabled(action.isEnabled()); } } } }; button.addDisposeListener(event -> action.removePropertyChangeListener(listener)); action.addPropertyChangeListener(listener); GridDataFactory.fillDefaults().applyTo(button); return button; }
From source file:org.eclipse.riena.e4.launcher.part.MenuHelper.java
License:Open Source License
private static IContextFunction createToggleFunction(final IConfigurationElement element) { final Object ice = element.getParent(); if (!(ice instanceof IConfigurationElement)) { return null; }/*from ww w . j av a 2s.c o m*/ // identify the type of contribution that this is final IConfigurationElement parent = (IConfigurationElement) ice; final int type = getType(parent.getName()); if (type == -1) { // unknown, don't create a toggling function return null; } final IContextFunction generator = new ContextFunction() { private ActionDescriptor getDescriptor(final IEclipseContext context) { switch (type) { case ActionDescriptor.T_WORKBENCH: final IWorkbenchWindow window = context.get(IWorkbenchWindow.class); return window == null ? null : new ActionDescriptor(element, type, window); case ActionDescriptor.T_EDITOR: return new ActionDescriptor(element, type, null); case ActionDescriptor.T_VIEW: final MPart part = context.get(MPart.class); if (part != null) { final Object object = part.getObject(); if (object instanceof CompatibilityPart) { return new ActionDescriptor(element, type, ((CompatibilityPart) object).getPart()); } } return null; default: return null; } } @Override public Object compute(final IEclipseContext context, final String contextKey) { final MHandledItem model = context.get(MHandledItem.class); if (model == null) { return null; } final ActionDescriptor desc = getDescriptor(context); final IAction action = desc.getAction(); final IPropertyChangeListener propListener = new IPropertyChangeListener() { public void propertyChange(final PropertyChangeEvent event) { if (IAction.CHECKED.equals(event.getProperty())) { boolean checked = false; if (event.getNewValue() instanceof Boolean) { checked = ((Boolean) event.getNewValue()).booleanValue(); } model.setSelected(checked); } } }; action.addPropertyChangeListener(propListener); final Runnable obj = new Runnable() { @Execute public void run() { action.removePropertyChangeListener(propListener); } }; model.setSelected(action.isChecked()); return obj; } }; return generator; }
From source file:org.eclipse.riena.e4.launcher.part.MenuHelper.java
License:Open Source License
public static MToolItem createToolItem(final MApplication application, final ActionContributionItem item) { final IAction action = item.getAction(); final String id = action.getActionDefinitionId(); if (id != null) { for (final MCommand command : application.getCommands()) { if (id.equals(command.getElementId())) { final MHandledToolItem toolItem = MenuFactoryImpl.eINSTANCE.createHandledToolItem(); toolItem.setCommand(command); toolItem.setContributorURI(command.getContributorURI()); String iconURI = getIconURI(action.getImageDescriptor(), application.getContext()); if (iconURI == null) { iconURI = getIconURI(id, application.getContext(), ICommandImageService.TYPE_DEFAULT); if (iconURI == null) { toolItem.setLabel(command.getCommandName()); } else { toolItem.setIconURI(iconURI); }// w w w. jav a 2 s.c o m } else { toolItem.setIconURI(iconURI); } if (action.getToolTipText() != null) { toolItem.setTooltip(action.getToolTipText()); } String disabledIconURI = getIconURI(action.getDisabledImageDescriptor(), application.getContext()); if (disabledIconURI == null) { disabledIconURI = getIconURI(id, application.getContext(), ICommandImageService.TYPE_DEFAULT); } if (disabledIconURI != null) { setDisabledIconURI(toolItem, disabledIconURI); } switch (action.getStyle()) { case IAction.AS_CHECK_BOX: toolItem.setType(ItemType.CHECK); toolItem.setSelected(action.isChecked()); break; case IAction.AS_RADIO_BUTTON: toolItem.setType(ItemType.RADIO); toolItem.setSelected(action.isChecked()); break; default: toolItem.setType(ItemType.PUSH); break; } final String itemId = item.getId(); toolItem.setElementId(itemId == null ? id : itemId); return toolItem; } } } else { final MDirectToolItem toolItem = MenuFactoryImpl.eINSTANCE.createDirectToolItem(); final String itemId = item.getId(); toolItem.setElementId(itemId); String iconURI = getIconURI(action.getImageDescriptor(), application.getContext()); if (iconURI == null) { if (itemId == null) { if (action.getText() != null) { toolItem.setLabel(action.getText()); } } else { iconURI = getIconURI(itemId, application.getContext(), ICommandImageService.TYPE_DEFAULT); if (iconURI == null) { if (action.getText() != null) { toolItem.setLabel(action.getText()); } } else { toolItem.setIconURI(iconURI); } } } else { toolItem.setIconURI(iconURI); } if (action.getToolTipText() != null) { toolItem.setTooltip(action.getToolTipText()); } switch (action.getStyle()) { case IAction.AS_CHECK_BOX: toolItem.setType(ItemType.CHECK); toolItem.setSelected(action.isChecked()); break; case IAction.AS_RADIO_BUTTON: toolItem.setType(ItemType.RADIO); toolItem.setSelected(action.isChecked()); break; default: toolItem.setType(ItemType.PUSH); break; } toolItem.setContributionURI("bundleclass://org.eclipse.ui.workbench/programmic.contribution"); //$NON-NLS-1$ toolItem.setObject(new DirectProxy(action)); toolItem.setEnabled(action.isEnabled()); final IPropertyChangeListener propertyListener = new IPropertyChangeListener() { public void propertyChange(final PropertyChangeEvent event) { final String property = event.getProperty(); if (property.equals(IAction.ENABLED)) { toolItem.setEnabled(action.isEnabled()); } else if (property.equals(IAction.CHECKED)) { toolItem.setSelected(action.isChecked()); } else if (property.equals(IAction.TEXT)) { toolItem.setLabel(action.getText()); } else if (property.equals(IAction.TOOL_TIP_TEXT)) { toolItem.setLabel(action.getToolTipText()); } } }; // property listener is removed in // DirectContributionItem#handleWidgetDispose() action.addPropertyChangeListener(propertyListener); toolItem.getTransientData().put(DirectContributionItem.DISPOSABLE, new Runnable() { public void run() { action.removePropertyChangeListener(propertyListener); } }); return toolItem; } return null; }
From source file:org.eclipse.ui.internal.cheatsheets.ActionRunner.java
License:Open Source License
public IStatus runAction(Action cheatSheetAction, CheatSheetManager csm) { IStatus status = Status.OK_STATUS;//from w w w. j a v a2 s. c om String pluginId = cheatSheetAction.getPluginID(); String className = cheatSheetAction.getActionClass(); String[] params = cheatSheetAction.getParams(); Bundle bundle = Platform.getBundle(pluginId); if (bundle == null) { String message = NLS.bind(Messages.get().ERROR_FINDING_PLUGIN_FOR_ACTION, (new Object[] { pluginId })); return new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, null); } Class actionClass; IAction action; try { actionClass = bundle.loadClass(className); } catch (Exception e) { String message = NLS.bind(Messages.get().ERROR_LOADING_CLASS_FOR_ACTION, (new Object[] { className })); return new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); } try { action = (IAction) actionClass.newInstance(); } catch (Exception e) { String message = NLS.bind(Messages.get().ERROR_CREATING_CLASS_FOR_ACTION, (new Object[] { className })); return new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); } final boolean[] listenerFired = { false }; final boolean[] listenerResult = { false }; IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IAction.RESULT) && event.getNewValue() instanceof Boolean) { listenerFired[0] = true; listenerResult[0] = ((Boolean) event.getNewValue()).booleanValue(); } } }; // Add PropertyChangeListener to the action, so we can detemine if a action was succesfull action.addPropertyChangeListener(propertyChangeListener); // Run the action for this ViewItem if (action instanceof ICheatSheetAction) { // Prepare parameters String[] clonedParams = null; if (params != null && params.length > 0) { clonedParams = new String[params.length]; System.arraycopy(params, 0, clonedParams, 0, params.length); for (int i = 0; i < clonedParams.length; i++) { String param = clonedParams[i]; if (param != null && param.startsWith("${") && param.endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$ param = param.substring(2, param.length() - 1); String value = csm.getDataQualified(param); clonedParams[i] = value == null ? ICheatSheetResource.EMPTY_STRING : value; } } } ((ICheatSheetAction) action).run(clonedParams, csm); } else { try { action.run(); } catch (Throwable e) { status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, Messages.get().EXCEPTION_RUNNING_ACTION, e); } } // Remove the PropertyChangeListener action.removePropertyChangeListener(propertyChangeListener); if (status.isOK() && listenerFired[0]) { if (!listenerResult[0]) { status = new Status(IStatus.WARNING, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, Messages.get().ACTION_FAILED, null); } } return status; }
From source file:org.eclipse.ui.internal.menus.MenuHelper.java
License:Open Source License
private static IContextFunction createToggleFunction(final IConfigurationElement element) { Object ice = element.getParent(); if (!(ice instanceof IConfigurationElement)) { return null; }/*from w ww .j a v a 2 s . c o m*/ // identify the type of contribution that this is IConfigurationElement parent = (IConfigurationElement) ice; final int type = getType(parent.getName()); if (type == -1) { // unknown, don't create a toggling function return null; } IContextFunction generator = new ContextFunction() { private ActionDescriptor getDescriptor(IEclipseContext context) { switch (type) { case ActionDescriptor.T_WORKBENCH: IWorkbenchWindow window = context.get(IWorkbenchWindow.class); return window == null ? null : new ActionDescriptor(element, type, window); case ActionDescriptor.T_EDITOR: return new ActionDescriptor(element, type, null); case ActionDescriptor.T_VIEW: MPart part = context.get(MPart.class); if (part != null) { Object object = part.getObject(); if (object instanceof CompatibilityPart) { return new ActionDescriptor(element, type, ((CompatibilityPart) object).getPart()); } } return null; default: return null; } } @Override public Object compute(IEclipseContext context) { final MHandledItem model = context.get(MHandledItem.class); if (model == null) { return null; } ActionDescriptor desc = getDescriptor(context); final IAction action = desc.getAction(); final IPropertyChangeListener propListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.CHECKED.equals(event.getProperty())) { boolean checked = false; if (event.getNewValue() instanceof Boolean) { checked = ((Boolean) event.getNewValue()).booleanValue(); } model.setSelected(checked); } } }; action.addPropertyChangeListener(propListener); Runnable obj = new Runnable() { @Execute public void run() { action.removePropertyChangeListener(propListener); } }; model.setSelected(action.isChecked()); return obj; } }; return generator; }