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;
}
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);
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations