List of usage examples for org.eclipse.jface.action IContributionManagerOverrides getAccelerator
public Integer getAccelerator(IContributionItem item);
From source file:com.architexa.org.eclipse.gef.internal.ui.palette.ToolbarDropdownContributionItem.java
License:Open Source License
/** * Synchronizes the UI with the given property. * * @param propertyName the name of the property, or <code>null</code> meaning all * applicable properties *///from ww w. jav a 2 s . c o m public void update(String propertyName) { if (widget != null) { // determine what to do boolean textChanged = propertyName == null || propertyName.equals(Action.TEXT); boolean imageChanged = propertyName == null || propertyName.equals(Action.IMAGE); boolean tooltipTextChanged = propertyName == null || propertyName.equals(Action.TOOL_TIP_TEXT); boolean enableStateChanged = propertyName == null || propertyName.equals(Action.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX) && (propertyName == null || propertyName.equals(Action.CHECKED)); if (widget instanceof ToolItem) { ToolItem ti = (ToolItem) widget; if (imageChanged) { updateImages(true); } if (tooltipTextChanged) ti.setToolTipText(action.getToolTipText()); if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) ti.setEnabled(shouldBeEnabled); } if (checkChanged) { boolean bv = action.isChecked(); if (ti.getSelection() != bv) ti.setSelection(bv); } return; } if (widget instanceof MenuItem) { MenuItem mi = (MenuItem) widget; boolean isContextMenu = belongsToContextMenu(mi); // We only install an accelerator if the menu item doesn't // belong to a context menu (right mouse button menu). if (textChanged) { if (isContextMenu) { String text = action.getText(); if (text != null) { text = Action.removeAcceleratorText(text); mi.setText(text); } } else { String text = null; IContributionManagerOverrides overrides = null; if (getParent() != null) overrides = getParent().getOverrides(); if (overrides != null) text = getParent().getOverrides().getText(this); if (text == null) text = action.getText(); if (text != null) { String label = Action.removeAcceleratorText(text); String accText = null; Integer acc = null; if (overrides != null) { accText = overrides.getAcceleratorText(this); acc = overrides.getAccelerator(this); } if ((accText == null) && (label.length() + 1 < text.length())) accText = text.substring(label.length() + 1); if (acc == null) acc = new Integer(action.getAccelerator()); if (acc.intValue() >= 0) mi.setAccelerator(acc.intValue()); if (accText == null) mi.setText(label); else mi.setText(label + '\t' + accText); } } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) mi.setEnabled(shouldBeEnabled); } if (checkChanged) { boolean bv = action.isChecked(); if (mi.getSelection() != bv) mi.setSelection(bv); } return; } if (widget instanceof Button) { Button button = (Button) widget; if (imageChanged) { if (updateImages(false)) { // don't update text if it has an image textChanged = false; } } if (textChanged) { String text = action.getText(); if (text != null) button.setText(text); } if (tooltipTextChanged) button.setToolTipText(action.getToolTipText()); if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) button.setEnabled(shouldBeEnabled); } if (checkChanged) { boolean bv = action.isChecked(); if (button.getSelection() != bv) button.setSelection(bv); } return; } } }
From source file:org.eclipse.gef.internal.ui.palette.ToolbarDropdownContributionItem.java
License:Open Source License
/** * Synchronizes the UI with the given property. * /*from www.j a v a 2 s.c o m*/ * @param propertyName * the name of the property, or <code>null</code> meaning all * applicable properties */ public void update(String propertyName) { if (widget != null) { // determine what to do boolean textChanged = propertyName == null || propertyName.equals(Action.TEXT); boolean imageChanged = propertyName == null || propertyName.equals(Action.IMAGE); boolean tooltipTextChanged = propertyName == null || propertyName.equals(Action.TOOL_TIP_TEXT); boolean enableStateChanged = propertyName == null || propertyName.equals(Action.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX) && (propertyName == null || propertyName.equals(Action.CHECKED)); if (widget instanceof ToolItem) { ToolItem ti = (ToolItem) widget; if (imageChanged) { updateImages(true); } if (tooltipTextChanged) ti.setToolTipText(action.getToolTipText()); if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) ti.setEnabled(shouldBeEnabled); } if (checkChanged) { boolean bv = action.isChecked(); if (ti.getSelection() != bv) ti.setSelection(bv); } return; } if (widget instanceof MenuItem) { MenuItem mi = (MenuItem) widget; boolean isContextMenu = belongsToContextMenu(mi); // We only install an accelerator if the menu item doesn't // belong to a context menu (right mouse button menu). if (textChanged) { if (isContextMenu) { String text = action.getText(); if (text != null) { text = Action.removeAcceleratorText(text); mi.setText(text); } } else { String text = null; IContributionManagerOverrides overrides = null; if (getParent() != null) overrides = getParent().getOverrides(); if (overrides != null) text = getParent().getOverrides().getText(this); if (text == null) text = action.getText(); if (text != null) { String label = Action.removeAcceleratorText(text); String accText = null; Integer acc = null; if (overrides != null) { accText = overrides.getAcceleratorText(this); acc = overrides.getAccelerator(this); } if ((accText == null) && (label.length() + 1 < text.length())) accText = text.substring(label.length() + 1); if (acc == null) acc = new Integer(action.getAccelerator()); if (acc.intValue() >= 0) mi.setAccelerator(acc.intValue()); if (accText == null) mi.setText(label); else mi.setText(label + '\t' + accText); } } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) mi.setEnabled(shouldBeEnabled); } if (checkChanged) { boolean bv = action.isChecked(); if (mi.getSelection() != bv) mi.setSelection(bv); } return; } if (widget instanceof Button) { Button button = (Button) widget; if (imageChanged) { if (updateImages(false)) { // don't update text if it has an image textChanged = false; } } if (textChanged) { String text = action.getText(); if (text != null) button.setText(text); } if (tooltipTextChanged) button.setToolTipText(action.getToolTipText()); if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) button.setEnabled(shouldBeEnabled); } if (checkChanged) { boolean bv = action.isChecked(); if (button.getSelection() != bv) button.setSelection(bv); } return; } } }