Search in sources :

Example 1 with UIEvents

use of org.eclipse.e4.ui.workbench.UIEvents in project eclipse.platform.ui by eclipse-platform.

the class TrimStack method handleTransientDataEvents.

/**
 * This is the new way to handle UIEvents (as opposed to subscring and unsubscribing them with
 * the event broker.
 *
 * The method is described in detail at http://wiki.eclipse.org/Eclipse4/RCP/Event_Model
 */
@SuppressWarnings("unchecked")
@Inject
@Optional
private void handleTransientDataEvents(@UIEventTopic(UIEvents.ApplicationElement.TOPIC_TRANSIENTDATA) org.osgi.service.event.Event event) {
    // Prevent exceptions on shutdown
    if (trimStackTB == null || trimStackTB.isDisposed() || minimizedElement.getWidget() == null) {
        return;
    }
    Object changedElement = event.getProperty(UIEvents.EventTags.ELEMENT);
    if (!(changedElement instanceof MUIElement)) {
        return;
    }
    String key;
    if (UIEvents.isREMOVE(event)) {
        key = ((Entry<String, Object>) event.getProperty(UIEvents.EventTags.OLD_VALUE)).getKey();
    } else {
        key = ((Entry<String, Object>) event.getProperty(UIEvents.EventTags.NEW_VALUE)).getKey();
    }
    if (key.equals(IPresentationEngine.OVERRIDE_ICON_IMAGE_KEY)) {
        ToolItem toolItem = getChangedToolItem((MUIElement) changedElement);
        if (toolItem != null) {
            toolItem.setImage(getImage((MUILabel) toolItem.getData()));
        }
    } else if (key.equals(IPresentationEngine.OVERRIDE_TITLE_TOOL_TIP_KEY)) {
        ToolItem toolItem = getChangedToolItem((MUIElement) changedElement);
        if (toolItem != null) {
            toolItem.setToolTipText(getLabelText((MUILabel) toolItem.getData()));
        }
    }
}
Also used : MUILabel(org.eclipse.e4.ui.model.application.ui.MUILabel) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) ToolItem(org.eclipse.swt.widgets.ToolItem) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Aggregations

Inject (javax.inject.Inject)1 Optional (org.eclipse.e4.core.di.annotations.Optional)1 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)1 MUILabel (org.eclipse.e4.ui.model.application.ui.MUILabel)1 ToolItem (org.eclipse.swt.widgets.ToolItem)1