Search in sources :

Example 1 with Optional

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;
}
Also used : ChannelData(alma.acs.nsstatistics.ChannelData) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 2 with Optional

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);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Job(org.eclipse.core.runtime.jobs.Job) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Aggregations

ChannelData (alma.acs.nsstatistics.ChannelData)1 Inject (javax.inject.Inject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Optional (org.eclipse.e4.core.di.annotations.Optional)1