use of org.eclipse.e4.core.di.annotations.Optional 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.Optional in project ACS by ACS-Community.
the class MyStatusBar method getNotified.
@Inject
@Optional
private void getNotified(@UIEventTopic(STATUS_BAR_TOPIC_ID) MessageWithTime msgWithTime) {
if (slm != null) {
String flashMsg = msgWithTime.msg;
int timeSeconds = msgWithTime.timeSeconds;
slm.setMessage(flashMsg);
// TODO fix truncation of larger strings, e.g.
// slm.getControl().pack(true); ??
clearFlashJob();
msgRestoreJob = new Job(MyStatusBar.class.getSimpleName() + "RemoveFlashMessage") {
@Override
protected IStatus run(IProgressMonitor monitor) {
// restore the previous message
uiSync.syncExec(new Runnable() {
@Override
public void run() {
slm.setMessage(permanentMessage);
}
});
return Status.OK_STATUS;
}
};
msgRestoreJob.schedule(timeSeconds * 1000);
}
}
Aggregations