Search in sources :

Example 1 with MHandledItem

use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem in project ACS by ACS-Community.

the class PeriodicRefreshHandler method execute.

/**
	 * Starts a {@link NotifyServiceUpdateJob} with 10 seconds refresh period,
	 * which will notify the interested parts via the IEventBroker.
	 * <p>
	 * An alternative implementation could get parameter <code>@Active MPart part</code> injected
	 * and notify the part directly, without IEventBroker.
	 */
@Execute
public void execute(MHandledItem handledItem) {
    // sync menu item state
    sharedIsSelected = handledItem.isSelected();
    for (MItem menuItem : menuItemsToSync.values()) {
        menuItem.setSelected(sharedIsSelected);
    }
    // start or stop the periodic refresh job
    if (sharedIsSelected) {
        if (job == null) {
            // start periodic refreshes
            job = new NotifyServiceUpdateJob(eventModel, sync, statusLineWriter, eventBroker, refreshDelaySeconds * 1000);
            job.schedule();
            System.out.println("Scheduled refresh job.");
        } else {
            System.out.println("Error: refresh job is already running!");
        }
    } else {
        if (job != null) {
            job.cancel();
            job = null;
            System.out.println("Cancelled refresh job.");
        } else {
            System.out.println("Error: refresh job is already cancelled!");
        }
    }
}
Also used : MItem(org.eclipse.e4.ui.model.application.ui.menu.MItem) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 2 with MHandledItem

use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem in project ACS by ACS-Community.

the class SubscribeNCHandler method canExecute.

@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object obj, MHandledItem handledItem) {
    boolean canExecute = false;
    if (subscriptionChangeJobMap.isEmpty()) {
        // disable while previous subscription change actions are still running
        List<ChannelData> ncList = getSelectedNCs(obj);
        if (!ncList.isEmpty()) {
            canExecute = true;
            // if multiple NCs are selected, they must all be in the same subscription state,
            // otherwise we don't allow the subscription change
            Boolean sharedIsSubscribed = null;
            for (ChannelData nc : ncList) {
                // all selected NCs must be subscribable
                if (!nc.isSubscribable()) {
                    canExecute = false;
                    break;
                }
                if (sharedIsSubscribed == null) {
                    // the first NC we are checking
                    sharedIsSubscribed = new Boolean(eventModel.isSubscribed(nc));
                } else {
                    if (eventModel.isSubscribed(nc) != sharedIsSubscribed.booleanValue()) {
                        canExecute = false;
                        break;
                    }
                }
            }
            // We dynamically update the menu item state to display the correct toggle symbol.
            if (canExecute) {
                handledItem.setSelected(sharedIsSubscribed);
            }
        }
    }
    return canExecute;
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 3 with MHandledItem

use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem in project ACS by ACS-Community.

the class SubscribeNCHandler method execute.

/**
	 * Allows one or many NCs to be selected, which is why we use 'Object' instead of 'ChannelData' as the selection.
	 */
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object obj, MHandledItem handledItem) {
    List<ChannelData> ncList = getSelectedNCs(obj);
    for (ChannelData nc : ncList) {
        // We simply toggle the subscription, ignoring the CHECK menu item state.
        // In fact we have to manually toggle the menu in the end, since the UI-induced toggling got lost 
        // when eclipse called 'canExecute' right before this method.
        boolean previousIsSubscribed = eventModel.isSubscribed(nc);
        SubscriptionChangeJob job = (previousIsSubscribed ? new UnsubscribeJob(nc) : new SubscribeJob(nc));
        subscriptionChangeJobMap.put(nc.getName(), job);
        job.schedule();
        handledItem.setSelected(!previousIsSubscribed);
    }
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 4 with MHandledItem

use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem in project eclipse.platform.ui by eclipse-platform.

the class CustomizePerspectiveDialog method getToolTipText.

private String getToolTipText(MItem item) {
    String text = item.getLocalizedTooltip();
    if (item instanceof MHandledItem) {
        MHandledItem handledItem = (MHandledItem) item;
        EBindingService bs = context.get(EBindingService.class);
        ParameterizedCommand cmd = handledItem.getWbCommand();
        if (cmd == null) {
            cmd = generateParameterizedCommand(handledItem, context);
        }
        TriggerSequence sequence = bs.getBestSequenceFor(handledItem.getWbCommand());
        if (sequence != null) {
            if (text == null) {
                try {
                    text = cmd.getName();
                } catch (NotDefinedException e) {
                    return null;
                }
            }
            // $NON-NLS-1$
            text = text + " (" + sequence.format() + ')';
        }
        return text;
    } else if (OpaqueElementUtil.isOpaqueMenuItem(item)) {
        Object opaque = OpaqueElementUtil.getOpaqueItem(item);
        if (opaque instanceof ActionContributionItem) {
            return ((ActionContributionItem) opaque).getAction().getText();
        }
    } else if (OpaqueElementUtil.isOpaqueToolItem(item)) {
        Object opaque = OpaqueElementUtil.getOpaqueItem(item);
        if (opaque instanceof ActionContributionItem) {
            return ((ActionContributionItem) opaque).getAction().getToolTipText();
        }
    }
    return text;
}
Also used : MHandledItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledItem) TriggerSequence(org.eclipse.jface.bindings.TriggerSequence) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 5 with MHandledItem

use of org.eclipse.e4.ui.model.application.ui.menu.MHandledItem in project eclipse.platform.ui by eclipse-platform.

the class MenuPopulationTest method assertIcon.

private void assertIcon(HandledContributionItem item, String targetIcon) {
    final MHandledItem model = item.getModel();
    String iconString = model.getIconURI();
    assertEquals(targetIcon, iconString.substring(iconString.lastIndexOf('/')));
}
Also used : MHandledItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledItem)

Aggregations

CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)5 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)3 Execute (org.eclipse.e4.core.di.annotations.Execute)3 MParameter (org.eclipse.e4.ui.model.application.commands.MParameter)3 MHandledItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledItem)3 ChannelData (alma.acs.nsstatistics.ChannelData)2 Onclick (aero.minova.rcp.form.model.xsd.Onclick)1 MButton (aero.minova.rcp.model.form.MButton)1 MDetail (aero.minova.rcp.model.form.MDetail)1 WFCDetailPart (aero.minova.rcp.rcp.parts.WFCDetailPart)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 ECommandService (org.eclipse.e4.core.commands.ECommandService)1 EBindingService (org.eclipse.e4.ui.bindings.EBindingService)1 MCommand (org.eclipse.e4.ui.model.application.commands.MCommand)1 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)1 MItem (org.eclipse.e4.ui.model.application.ui.menu.MItem)1 HandledContributionItem (org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem)1 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 MenuManager (org.eclipse.jface.action.MenuManager)1