Search in sources :

Example 1 with CanExecute

use of org.eclipse.e4.core.di.annotations.CanExecute 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 2 with CanExecute

use of org.eclipse.e4.core.di.annotations.CanExecute 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 3 with CanExecute

use of org.eclipse.e4.core.di.annotations.CanExecute in project whole by wholeplatform.

the class FragmentModelTransactionHandler method canExecute.

@CanExecute
public boolean canExecute(@Named(FRAGMENT_XWL_PARAMETER_ID) String fragmentXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) throws Exception {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(fragmentXwl, predicateXwl, bm);
        return isEnabled(bm);
    } catch (Exception e) {
        return false;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 4 with CanExecute

use of org.eclipse.e4.core.di.annotations.CanExecute in project whole by wholeplatform.

the class TypedModelTransactionHandler method canExecute.

@CanExecute
public boolean canExecute(@Named(ED_URI_PARAMETER_ID) String edUri, @Optional @Named(FD_URI_PARAMETER_ID) String fdUri, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(edUri, fdUri, bm);
        return isEnabled(bm);
    } catch (Exception e) {
        return false;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) RollbackException(org.whole.lang.lifecycle.RollbackException) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 5 with CanExecute

use of org.eclipse.e4.core.di.annotations.CanExecute in project whole by wholeplatform.

the class OperationHandler method canExecute.

@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) throws Exception {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        return !viewer.getEditDomain().isDisabled() && isEnabled(bm);
    } catch (Exception e) {
        return false;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Aggregations

CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)8 ITransactionScope (org.whole.lang.bindings.ITransactionScope)6 ChannelData (alma.acs.nsstatistics.ChannelData)2 RollbackException (org.whole.lang.lifecycle.RollbackException)2 Execute (org.eclipse.e4.core.di.annotations.Execute)1 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)1