use of org.eclipse.jface.action.IContributionManagerOverrides in project archi by archimatetool.
the class ToolbarDropdownContributionItem method update.
/**
* Synchronizes the UI with the given property.
*
* @param propertyName
* the name of the property, or <code>null</code> meaning all
* applicable properties
*/
@SuppressWarnings("deprecation")
@Override
public void update(String propertyName) {
if (widget != null) {
// determine what to do
boolean textChanged = propertyName == null || propertyName.equals(IAction.TEXT);
boolean imageChanged = propertyName == null || propertyName.equals(IAction.IMAGE);
boolean tooltipTextChanged = propertyName == null || propertyName.equals(IAction.TOOL_TIP_TEXT);
boolean enableStateChanged = propertyName == null || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED);
boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX) && (propertyName == null || propertyName.equals(IAction.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);
// 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;
}
}
}
use of org.eclipse.jface.action.IContributionManagerOverrides in project eclipse.platform.ui by eclipse-platform.
the class ToolBarManagerRenderer method subscribeUIElementTopicVisible.
@Inject
@Optional
private void subscribeUIElementTopicVisible(@UIEventTopic(UIEvents.UIElement.TOPIC_VISIBLE) Event event) {
// Ensure that this event is for a MToolBarElement
if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) {
return;
}
MToolBarElement itemModel = (MToolBarElement) event.getProperty(UIEvents.EventTags.ELEMENT);
IContributionItem ici = getContribution(itemModel);
if (ici == null) {
return;
}
ToolBarManager parent = null;
if (ici instanceof MenuManager) {
parent = (ToolBarManager) ((MenuManager) ici).getParent();
} else if (ici instanceof ContributionItem) {
parent = (ToolBarManager) ((ContributionItem) ici).getParent();
}
if (parent == null) {
ici.setVisible(itemModel.isVisible());
return;
}
IContributionManagerOverrides ov = parent.getOverrides();
// extra override mechanics controlling element visibility
if (ov == null) {
ici.setVisible(itemModel.isVisible());
} else {
Boolean visible = ov.getVisible(ici);
if (visible == null) {
// same as above: only change state if there are no extra
// override mechanics controlling element visibility
ici.setVisible(itemModel.isVisible());
}
}
updateWidget(parent);
}
use of org.eclipse.jface.action.IContributionManagerOverrides in project eclipse.platform.ui by eclipse-platform.
the class ToolBarManagerRenderer method createToolbar.
private ToolBar createToolbar(final MUIElement element, Composite parent) {
int orientation = getOrientation(element);
int style = orientation | SWT.WRAP | SWT.FLAT | SWT.RIGHT;
ToolBarManager manager = getManager((MToolBar) element);
if (manager == null) {
manager = new ToolBarManager(style);
IContributionManagerOverrides overrides = null;
MApplicationElement parentElement = element.getParent();
if (parentElement == null) {
parentElement = modelService.getContainer(element);
}
if (parentElement != null) {
overrides = (IContributionManagerOverrides) parentElement.getTransientData().get(IContributionManagerOverrides.class.getName());
}
manager.setOverrides(overrides);
linkModelToManager((MToolBar) element, manager);
} else {
ToolBar toolBar = manager.getControl();
if (toolBar != null && !toolBar.isDisposed() && (toolBar.getStyle() & orientation) == 0) {
toolBar.dispose();
}
manager.setStyle(style);
}
ToolBar btoolbar = manager.createControl(parent);
btoolbar.setData(manager);
btoolbar.setData(AbstractPartRenderer.OWNING_ME, element);
btoolbar.requestLayout();
return btoolbar;
}
Aggregations