List of usage examples for org.eclipse.jface.action IAction IMAGE
String IMAGE
To view the source code for org.eclipse.jface.action IAction IMAGE.
Click Source Link
"image"). From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java
License:Open Source License
/** * Synchronizes the UI with the given property. * * @param propertyName/*w w w . jav a2 s . c o m*/ * the name of the property, or <code>null</code> meaning all * applicable properties */ @Override public void update(String propertyName) { if (widget != null) { // determine what to do final boolean textChanged = (propertyName == null) || propertyName.equals(IAction.TEXT); boolean imageChanged = (propertyName == null) || propertyName.equals(IAction.IMAGE); final boolean tooltipTextChanged = (propertyName == null) || propertyName.equals(IAction.TOOL_TIP_TEXT); final boolean enableStateChanged = (propertyName == null) || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); final boolean checkChanged = ((action.getStyle() == IAction.AS_CHECK_BOX) || (action.getStyle() == IAction.AS_RADIO_BUTTON)) && ((propertyName == null) || propertyName.equals(IAction.CHECKED)); if (!showImage) { // do not update the image if not show image imageChanged = false; } if (widget instanceof ToolItem) { final ToolItem ti = (ToolItem) widget; String text = action.getText(); // the set text is shown only if there is no image or if forced // by MODE_FORCE_TEXT final boolean showText = (text != null) && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action)); // only do the trimming if the text will be used if (showText && (text != null)) { text = Action.removeAcceleratorText(text); text = Action.removeMnemonics(text); } if (textChanged) { final String textToSet = showText ? text : ""; //$NON-NLS-1$ final boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0; if (rightStyle || !ti.getText().equals(textToSet)) { // In addition to being required to update the text if // it // gets nulled out in the action, this is also a // workaround // for bug 50151: Using SWT.RIGHT on a ToolBar leaves // blank space ti.setText(textToSet); } } if (imageChanged) { // only substitute a missing image if it has no text updateImages(!showText); } if (tooltipTextChanged || textChanged) { String toolTip = action.getToolTipText(); if ((toolTip == null) || (toolTip.length() == 0)) { toolTip = text; } final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); final String commandId = action.getActionDefinitionId(); if ((callback != null) && (commandId != null) && (toolTip != null)) { final String acceleratorText = callback.getAcceleratorText(commandId); if ((acceleratorText != null) && (acceleratorText.length() != 0)) { toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$ new Object[] { toolTip, acceleratorText }); } } // if the text is showing, then only set the tooltip if // different if (!showText || ((toolTip != null) && !toolTip.equals(text))) { ti.setToolTipText(toolTip); } else { ti.setToolTipText(null); } } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) { ti.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (ti.getSelection() != bv) { ti.setSelection(bv); } } return; } if (widget instanceof MenuItem) { final MenuItem mi = (MenuItem) widget; if (textChanged) { int accelerator = 0; String acceleratorText = null; final ActionEx updatedAction = getAction(); String text = null; accelerator = updatedAction.getAccelerator(); final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); // Block accelerators that are already in use. if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) { accelerator = 0; } /* * Process accelerators on GTK in a special way to avoid Bug 42009. We * will override the native input method by allowing these reserved * accelerators to be placed on the menu. We will only do this for * "Ctrl+Shift+[0-9A-FU]". */ final String commandId = updatedAction.getActionDefinitionId(); if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) { final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback; final IKeyLookup lookup = KeyLookupFactory.getDefault(); final TriggerSequence[] triggerSequences = bindingManagerCallback .getActiveBindingsFor(commandId); for (final TriggerSequence triggerSequence : triggerSequences) { final Trigger[] triggers = triggerSequence.getTriggers(); if (triggers.length == 1) { final Trigger trigger = triggers[0]; if (trigger instanceof KeyStroke) { final KeyStroke currentKeyStroke = (KeyStroke) trigger; final int currentNaturalKey = currentKeyStroke.getNaturalKey(); if ((currentKeyStroke .getModifierKeys() == (lookup.getCtrl() | lookup.getShift())) && (((currentNaturalKey >= '0') && (currentNaturalKey <= '9')) || ((currentNaturalKey >= 'A') && (currentNaturalKey <= 'F')) || (currentNaturalKey == 'U'))) { accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey; acceleratorText = triggerSequence.format(); break; } } } } } if (accelerator == 0) { if ((callback != null) && (commandId != null)) { acceleratorText = callback.getAcceleratorText(commandId); } } IContributionManagerOverrides overrides = null; if (getParent() != null) { overrides = getParent().getOverrides(); } if (overrides != null) { text = getParent().getOverrides().getText(this); } mi.setAccelerator(accelerator); if (text == null) { text = updatedAction.getText(); } if ((text != null) && (acceleratorText == null)) { // use extracted accelerator text in case accelerator // cannot be fully represented in one int (e.g. // multi-stroke keys) acceleratorText = LegacyActionTools.extractAcceleratorText(text); if ((acceleratorText == null) && (accelerator != 0)) { acceleratorText = Action.convertAccelerator(accelerator); } } if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } // add "..." if the action will show a dialog if (updatedAction.isShowDialog()) { text = text + dialogIndicator; } if (acceleratorText == null) { mi.setText(text); } else { mi.setText(text + '\t' + acceleratorText); } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) { mi.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (mi.getSelection() != bv) { mi.setSelection(bv); } } return; } if (widget instanceof Button) { final Button button = (Button) widget; if (imageChanged) { updateImages(false); } if (textChanged) { String text = action.getText(); final boolean showText = (text != null) && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action)); // only do the trimming if the text will be used if (showText) { text = Action.removeAcceleratorText(text); } final String textToSet = showText ? text : ""; //$NON-NLS-1$ button.setText(textToSet); } if (tooltipTextChanged) { button.setToolTipText(action.getToolTipText()); } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) { button.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (button.getSelection() != bv) { button.setSelection(bv); } } return; } } }
From source file:com.github.haixing_hu.swt.menu.MenuManagerEx.java
License:Open Source License
@Override public void update(String property) { final IContributionItem items[] = getItems(); for (final IContributionItem item : items) { item.update(property);//from w ww . ja v a 2s . com } if ((menu != null) && !menu.isDisposed() && (menu.getParentItem() != null)) { if (IAction.TEXT.equals(property)) { String text = getOverrides().getText(this); if (text == null) { text = getMenuText(); } if (text != null) { final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); if (callback != null) { final int index = text.indexOf('&'); if ((index >= 0) && (index < (text.length() - 1))) { final char character = Character.toUpperCase(text.charAt(index + 1)); if (callback.isAcceleratorInUse(SWT.ALT | character) && isTopLevelMenu()) { if (index == 0) { text = text.substring(1); } else { text = text.substring(0, index) + text.substring(index + 1); } } } } menu.getParentItem().setText(text); } } else if (IAction.IMAGE.equals(property) && (image != null)) { final LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources()); menu.getParentItem().setImage(localManager.createImage(image)); disposeOldImages(); imageManager = localManager; } } }
From source file:com.nokia.tools.media.utils.tooltip.DynamicTooltip.java
License:Open Source License
protected void addContributedControls(final Composite composite, boolean focusState) { Composite toolBarComposite = null; Composite sectionsComposite = null; children.clear();/*from w ww .j a va2 s . c om*/ if (style == EStyle.MENU) { GridLayout gl = new GridLayout(2, false); gl.marginHeight = gl.marginWidth = gl.horizontalSpacing = 0; composite.setLayout(gl); toolBarComposite = new Composite(composite, SWT.NONE); gl = new GridLayout(1, false); // gl.marginHeight = gl.marginWidth = 0; toolBarComposite.setLayout(gl); toolBarComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); } // horizontal toolbar if (style == EStyle.HORIZONTAL_HORIZONTAL || style == EStyle.HORIZONTAL_VERTICAL) { GridLayout gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = gl.verticalSpacing = 0; composite.setLayout(gl); toolBarComposite = new Composite(composite, SWT.NONE); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; toolBarComposite.setLayout(gl); toolBarComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); } // vertical toolbar if (style == EStyle.VERTICAL_VERTICAL || style == EStyle.VERTICAL_HORIZONTAL) { GridLayout gl = new GridLayout(2, false); gl.marginHeight = gl.marginWidth = gl.horizontalSpacing = 0; composite.setLayout(gl); toolBarComposite = new Composite(composite, SWT.NONE); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; toolBarComposite.setLayout(gl); toolBarComposite.setLayoutData(new GridData(SWT.NONE, SWT.FILL, false, true)); } sectionsComposite = new Composite(composite, SWT.NONE); GridLayout gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; sectionsComposite.setLayout(gl); sectionsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); toolBarComposite.setBackground(composite.getBackground()); sectionsComposite.setBackground(composite.getBackground()); Set<ToolbarItemContribution> toolbarContributions = new TreeSet<ToolbarItemContribution>(); toolbarContributions.addAll(collectToolbarContributions(focusState)); List<SectionContribution> sectionContributions = collectSectionContributions(focusState); for (SectionContribution contribution : sectionContributions) { if (contribution.uiClass != null) { try { IDynamicTooltipUIContribution ui = contribution.uiClass.newInstance(); ui.setTooltip(this); ui.setUIContainer(uiContainer); ui.setSelection(selection); ui.setContext(context); configureUIContribution(ui); ToolbarItemContribution[] tcs = ui.contributeToolbar(); if (tcs != null) { for (ToolbarItemContribution tc : tcs) { toolbarContributions.add(tc); } } ui.createControls(sectionsComposite, focusState); } catch (Exception e) { e.printStackTrace(); } } } if (sectionsComposite.getChildren().length == 0) { sectionsComposite.dispose(); } if (toolbarContributions.size() > 0) { GridLayout layout = (GridLayout) toolBarComposite.getLayout(); layout.horizontalSpacing = 1; if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style || EStyle.VERTICAL_HORIZONTAL == style || EStyle.VERTICAL_VERTICAL == style) { CoolBar cb = null; if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style) { cb = new CoolBar(toolBarComposite, SWT.FLAT | SWT.HORIZONTAL); cb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } else { cb = new CoolBar(toolBarComposite, SWT.FLAT | SWT.VERTICAL); cb.setLayoutData(new GridData(GridData.FILL_VERTICAL)); } Map<String, ToolBarManager> linkMap = new LinkedHashMap<String, ToolBarManager>(); final Map<ContributionItem, ToolbarItemContribution> map = new HashMap<ContributionItem, ToolbarItemContribution>(); for (final ToolbarItemContribution contribution : toolbarContributions) { ToolBarManager toolBar = linkMap.get(contribution.getTarget()); if (toolBar == null) { if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style) { toolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL); } else { toolBar = new ToolBarManager(SWT.FLAT | SWT.VERTICAL); } linkMap.put(contribution.getTarget(), toolBar); } if (contribution.getAction() == null) { Action action = new Action(contribution.getLabel()) { @Override public void run() { // do nothing } }; action.setImageDescriptor(contribution.getIcon()); action.setDisabledImageDescriptor(contribution.getDisabledIcon()); action.setHoverImageDescriptor(contribution.getHoverIcon()); ActionContributionItem item = new ActionContributionItem(action); map.put(item, contribution); toolBar.add(item); } else { IAction action = contribution.getAction(); if (contribution.getAction() instanceof IDynamicTooltipToolbarAction) { ((IDynamicTooltipToolbarAction) action).setTooltip(DynamicTooltip.this); ((IDynamicTooltipToolbarAction) action).setUIContainer(uiContainer); ((IDynamicTooltipToolbarAction) action).setSelection(selection); } if (action instanceof SeparatorAction) { Separator separator = new Separator(); map.put(separator, contribution); toolBar.add(separator); } else { ActionContributionItem item = new ActionContributionItem(action); map.put(item, contribution); toolBar.add(item); } } } Point preffered = new Point(0, 0); for (Map.Entry<String, ToolBarManager> entry : linkMap.entrySet()) { CoolItem ci = new CoolItem(cb, SWT.NONE); ToolBar tb = entry.getValue().createControl(cb); ci.setControl(tb); Point tbSize = tb.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point cbSize = ci.computeSize(tbSize.x, tbSize.y); ci.setSize(cbSize); ci.setPreferredSize(cbSize); ci.setMinimumSize(tbSize); if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style) { preffered.x += cbSize.x; preffered.y = Math.max(preffered.y, cbSize.y); } else { preffered.x = Math.max(preffered.x, cbSize.x); preffered.y += cbSize.y; } for (int i = 0; i < tb.getItems().length; i++) { ToolItem item = tb.getItems()[i]; ContributionItem actionItem = (ContributionItem) item.getData(); if (actionItem instanceof ActionContributionItem) { createChildTooltip(map.get(actionItem), item); } } } cb.setLocked(false); cb.setLayoutData(new GridData(preffered.x, preffered.y)); } else if (EStyle.MENU == style) { for (final ToolbarItemContribution contribution : toolbarContributions) { Composite itemComposite = null; itemComposite = createMenuComposite(toolBarComposite); if (contribution.getAction() instanceof SeparatorAction) { itemComposite.setEnabled(false); final Canvas img = new Canvas(itemComposite, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); gd.heightHint = 5; gd.horizontalSpan = 3; img.setLayoutData(gd); img.setBackground(itemComposite.getBackground()); img.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setForeground(ColorConstants.black); e.gc.drawLine(0, 2, img.getSize().x - 1, 2); } }); continue; } final Canvas img = new Canvas(itemComposite, SWT.NONE); img.setBackground(itemComposite.getBackground()); final Label label = new Label(itemComposite, SWT.NONE); label.setBackground(itemComposite.getBackground()); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); label.setText(contribution.getLabel() != null ? contribution.getLabel() : ""); label.setEnabled(!contribution.isDisabled()); final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.TEXT.equals(event.getProperty())) { label.setText(contribution.getLabel() != null ? contribution.getLabel() : ""); layout(); } if (IAction.ENABLED.equals(event.getProperty())) { label.setEnabled(!contribution.isDisabled()); } } }; contribution.addPropertyChangeListener(propertyChangeListener); label.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { contribution.removePropertyChangeListener(propertyChangeListener); } }); if (contribution.tooltip != null) { final Canvas arrow = new Canvas(itemComposite, SWT.NONE); arrow.setBackground(itemComposite.getBackground()); arrow.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); final Image image = ARROW_IMAGE.createImage(); arrow.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { image.dispose(); } }); ((GridData) arrow.getLayoutData()).widthHint = image.getImageData().width; ((GridData) arrow.getLayoutData()).heightHint = image.getImageData().height; arrow.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); } img.setToolTipText(contribution.getLabel()); final IPropertyChangeListener labelChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.TEXT.equals(event.getProperty())) { img.setToolTipText(contribution.getLabel()); } } }; contribution.addPropertyChangeListener(labelChangeListener); img.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { contribution.removePropertyChangeListener(labelChangeListener); } }); final Image[] image = new Image[] { contribution.isDisabled() ? contribution.getDisabledIcon().createImage() : contribution.getIcon().createImage() }; final Image[] hoverImage = new Image[] { (contribution.isDisabled() || contribution.getHoverIcon() == null) ? image[0] : contribution.getHoverIcon().createImage() }; final IPropertyChangeListener imageChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.IMAGE.equals(event.getProperty()) || IAction.ENABLED.equals(event.getProperty())) { if (image[0] != null) { image[0].dispose(); } if (hoverImage[0] != null) { hoverImage[0].dispose(); } image[0] = contribution.isDisabled() ? contribution.getDisabledIcon().createImage() : contribution.getIcon().createImage(); hoverImage[0] = (contribution.isDisabled() || contribution.getHoverIcon() == null) ? image[0] : contribution.getHoverIcon().createImage(); img.redraw(); } } }; contribution.addPropertyChangeListener(imageChangeListener); img.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { contribution.removePropertyChangeListener(imageChangeListener); if (image[0] != null) { image[0].dispose(); } if (hoverImage[0] != null) { hoverImage[0].dispose(); } } }); img.setLayoutData( new GridData(image[0].getImageData().width + 4, image[0].getImageData().height + 4)); img.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image[0], 2, 2); } }); if (EStyle.MENU == style) { DynamicTooltip tooltip = createChildTooltip(contribution, itemComposite); registerOnClickAction(contribution, itemComposite, tooltip); for (Control control : itemComposite.getChildren()) { registerOnClickAction(contribution, control, tooltip); } } } } } // set proper number of columns for horizontal sections alignment if ((style == EStyle.HORIZONTAL_HORIZONTAL || style == EStyle.VERTICAL_HORIZONTAL) && !sectionsComposite.isDisposed()) { ((GridLayout) sectionsComposite.getLayout()).numColumns = sectionsComposite.getChildren().length; } if (toolBarComposite.getChildren().length == 0) { toolBarComposite.dispose(); } if (sectionsComposite.isDisposed() && toolBarComposite.isDisposed()) { composite.dispose(); } }
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);/*from w ww. ja v a 2s . 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:org.eclipse.rcptt.ui.panels.Actions.java
License:Open Source License
public static final IObservableValue observeImageDescriptor(IAction action) { return JFaceProperties.value(IAction.class, "imageDescriptor", //$NON-NLS-1$ IAction.IMAGE).observe(action); }
From source file:org.eclipse.ui.actions.LabelRetargetAction.java
License:Open Source License
/** * The action handler has changed. Update self. *//* ww w.java2 s. c o m*/ protected void propagateChange(PropertyChangeEvent event) { super.propagateChange(event); String prop = event.getProperty(); if (prop.equals(IAction.TEXT)) { String str = (String) event.getNewValue(); super.setText(appendAccelerator(str)); } else if (prop.equals(IAction.TOOL_TIP_TEXT)) { String str = (String) event.getNewValue(); super.setToolTipText(str); } else if (prop.equals(IAction.IMAGE)) { updateImages(getActionHandler()); } }
From source file:org.eclipse.ui.internal.handlers.CommandLegacyActionWrapper.java
License:Open Source License
public final void setActionDefinitionId(final String id) { // Get the old values. final boolean oldChecked = isChecked(); final String oldDescription = getDescription(); final boolean oldEnabled = isEnabled(); final boolean oldHandled = isHandled(); final ImageDescriptor oldDefaultImage = getImageDescriptor(); final ImageDescriptor oldDisabledImage = getDisabledImageDescriptor(); final ImageDescriptor oldHoverImage = getHoverImageDescriptor(); final String oldText = getText(); // Update the command. final Command oldBaseCommand = command.getCommand(); oldBaseCommand.removeCommandListener(commandListener); final ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); final Command newBaseCommand = commandService.getCommand(id); command = new ParameterizedCommand(newBaseCommand, null); newBaseCommand.addCommandListener(commandListener); // Get the new values. final boolean newChecked = isChecked(); final String newDescription = getDescription(); final boolean newEnabled = isEnabled(); final boolean newHandled = isHandled(); final ImageDescriptor newDefaultImage = getImageDescriptor(); final ImageDescriptor newDisabledImage = getDisabledImageDescriptor(); final ImageDescriptor newHoverImage = getHoverImageDescriptor(); final String newText = getText(); // Fire property change events, as necessary. if (newChecked != oldChecked) { if (oldChecked) { firePropertyChange(IAction.CHECKED, Boolean.TRUE, Boolean.FALSE); } else {//from www . j a va 2 s.c o m firePropertyChange(IAction.CHECKED, Boolean.FALSE, Boolean.TRUE); } } if (!Util.equals(oldDescription, newDescription)) { firePropertyChange(IAction.DESCRIPTION, oldDescription, newDescription); firePropertyChange(IAction.TOOL_TIP_TEXT, oldDescription, newDescription); } if (newEnabled != oldEnabled) { if (oldEnabled) { firePropertyChange(IAction.ENABLED, Boolean.TRUE, Boolean.FALSE); } else { firePropertyChange(IAction.ENABLED, Boolean.FALSE, Boolean.TRUE); } } if (newHandled != oldHandled) { if (oldHandled) { firePropertyChange(IAction.HANDLED, Boolean.TRUE, Boolean.FALSE); } else { firePropertyChange(IAction.HANDLED, Boolean.FALSE, Boolean.TRUE); } } if (!Util.equals(oldDefaultImage, newDefaultImage)) { firePropertyChange(IAction.IMAGE, oldDefaultImage, newDefaultImage); } if (!Util.equals(oldDisabledImage, newDisabledImage)) { firePropertyChange(IAction.IMAGE, oldDisabledImage, newDisabledImage); } if (!Util.equals(oldHoverImage, newHoverImage)) { firePropertyChange(IAction.IMAGE, oldHoverImage, newHoverImage); } if (!Util.equals(oldText, newText)) { firePropertyChange(IAction.TEXT, oldText, newText); } }
From source file:org.python.pydev.ui.MenuManagerCopiedToAddCreateMenuWithMenuParent.java
License:Open Source License
public void update(String property) { IContributionItem items[] = getItems(); for (int i = 0; i < items.length; i++) { items[i].update(property);//from w w w. ja v a2s . com } if (menu != null && !menu.isDisposed() && menu.getParentItem() != null) { if (IAction.TEXT.equals(property)) { String text = getOverrides().getText(this); if (text == null) { text = getMenuText(); } if (text != null) { ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); if (callback != null) { int index = text.indexOf('&'); if (index >= 0 && index < text.length() - 1) { char character = Character.toUpperCase(text.charAt(index + 1)); if (callback.isAcceleratorInUse(SWT.ALT | character)) { if (index == 0) { text = text.substring(1); } else { text = text.substring(0, index) + text.substring(index + 1); } } } } menu.getParentItem().setText(text); } } else if (IAction.IMAGE.equals(property) && image != null) { LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources()); menu.getParentItem().setImage(localManager.createImage(image)); disposeOldImages(); imageManager = localManager; } } }
From source file:org.rssowl.ui.internal.views.explorer.BookMarkExplorer.java
License:Open Source License
private void doFilter(BookMarkFilter.Type type) { /* Remember Selection */ if (type != BookMarkFilter.Type.SHOW_ALL) fLastFilterType = type;/*from w w w. j a va 2 s . c o m*/ else if (fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_ALL) fLastFilterType = fBookMarkFilter.getType(); /* Change Filter Type */ fBookMarkFilter.setType(type); fViewer.refresh(false); /* Restore Expanded Elements */ restoreExpandedElements(); /* Update Image */ fToolBarManager.find(FILTER_ACTION).update(IAction.IMAGE); }
From source file:org.rssowl.ui.internal.views.explorer.BookMarkExplorer.java
License:Open Source License
private void doGrouping(BookMarkGrouping.Type type) { /* Remember Selection */ if (type != BookMarkGrouping.Type.NO_GROUPING) fLastGroupType = type;//from w ww.java 2s. c o m else if (fBookMarkGrouping.getType() != BookMarkGrouping.Type.NO_GROUPING) fLastGroupType = fBookMarkGrouping.getType(); /* Temporary change Sorter to reflect grouping */ if (!fSortByName) { if (type.equals(BookMarkGrouping.Type.NO_GROUPING)) fBookMarkComparator.setType(BookMarkSorter.Type.DEFAULT_SORTING); else if (type.equals(BookMarkGrouping.Type.GROUP_BY_LAST_VISIT)) fBookMarkComparator.setType(BookMarkSorter.Type.SORT_BY_LAST_VISIT_DATE); else if (type.equals(BookMarkGrouping.Type.GROUP_BY_POPULARITY)) fBookMarkComparator.setType(BookMarkSorter.Type.SORT_BY_POPULARITY); } /* Refresh w/o updating Labels */ fBookMarkGrouping.setType(type); fViewer.refresh(false); /* Restore Sorter */ fBookMarkComparator .setType(fSortByName ? BookMarkSorter.Type.SORT_BY_NAME : BookMarkSorter.Type.DEFAULT_SORTING); /* Restore expanded Elements */ restoreExpandedElements(); /* Update Image */ fToolBarManager.find(GROUP_ACTION).update(IAction.IMAGE); }