Search in sources :

Example 1 with ToastNotification

use of org.ovirt.engine.ui.common.widget.uicommon.tasks.ToastNotification in project ovirt-engine by oVirt.

the class TasksPresenterWidget method onBind.

@SuppressWarnings("unchecked")
@Override
public void onBind() {
    super.onBind();
    taskModelProvider.getModel().getItemsChangedEvent().addListener(new IEventListener<EventArgs>() {

        @Override
        public void eventRaised(Event<? extends EventArgs> ev, Object sender, EventArgs args) {
            getView().updateTaskStatus(taskModelProvider.getModel());
            Collection<Job> jobs = taskModelProvider.getModel().getItems();
            jobs.forEach(job -> {
                String id = job.getCorrelationId().startsWith(TaskListModel.WEBADMIN) ? job.getCorrelationId() : job.getId().toString();
                if (JobExecutionStatus.STARTED.equals(job.getStatus())) {
                    // Since its a set, it will be replaced when its a duplicate.
                    runningTasks.add(id);
                } else if (JobExecutionStatus.FINISHED.equals(job.getStatus()) || JobExecutionStatus.FAILED.equals(job.getStatus()) || JobExecutionStatus.ABORTED.equals(job.getStatus())) {
                    if (runningTasks.contains(id) || (ACTION_TYPE_WHITELIST.contains(job.getActionType()) && job.getEndTime().after(lastNotificationDate))) {
                        ToastNotification notification = ToastNotification.createNotification(// $NON-NLS-1$
                        getPrefixText(job.getStatus()) + " " + job.getDescription());
                        notification.setStatus(getNotificationStatus(job.getStatus()));
                    }
                    runningTasks.remove(id);
                }
                lastNotificationDate = new Date();
            });
        }
    });
}
Also used : JobExecutionStatus(org.ovirt.engine.core.common.job.JobExecutionStatus) Arrays(java.util.Arrays) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) AbstractOverlayPresenterWidget(org.ovirt.engine.ui.webadmin.section.main.presenter.AbstractOverlayPresenterWidget) Date(java.util.Date) Job(org.ovirt.engine.core.common.job.Job) Collection(java.util.Collection) Inject(com.google.inject.Inject) ToastNotification(org.ovirt.engine.ui.common.widget.uicommon.tasks.ToastNotification) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) Set(java.util.Set) Event(org.ovirt.engine.ui.uicompat.Event) NotificationStatus(org.ovirt.engine.ui.common.widget.uicommon.tasks.ToastNotification.NotificationStatus) EventBus(com.google.web.bindery.event.shared.EventBus) TaskListModel(org.ovirt.engine.ui.uicommonweb.models.events.TaskListModel) HashSet(java.util.HashSet) ActionType(org.ovirt.engine.core.common.action.ActionType) List(java.util.List) TaskModelProvider(org.ovirt.engine.ui.webadmin.uicommon.model.TaskModelProvider) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) Collections(java.util.Collections) ToastNotification(org.ovirt.engine.ui.common.widget.uicommon.tasks.ToastNotification) Collection(java.util.Collection) Date(java.util.Date) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs)

Aggregations

Inject (com.google.inject.Inject)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 Job (org.ovirt.engine.core.common.job.Job)1 JobExecutionStatus (org.ovirt.engine.core.common.job.JobExecutionStatus)1 ToastNotification (org.ovirt.engine.ui.common.widget.uicommon.tasks.ToastNotification)1 NotificationStatus (org.ovirt.engine.ui.common.widget.uicommon.tasks.ToastNotification.NotificationStatus)1 TaskListModel (org.ovirt.engine.ui.uicommonweb.models.events.TaskListModel)1 EnumTranslator (org.ovirt.engine.ui.uicompat.EnumTranslator)1 Event (org.ovirt.engine.ui.uicompat.Event)1 EventArgs (org.ovirt.engine.ui.uicompat.EventArgs)1 IEventListener (org.ovirt.engine.ui.uicompat.IEventListener)1 AbstractOverlayPresenterWidget (org.ovirt.engine.ui.webadmin.section.main.presenter.AbstractOverlayPresenterWidget)1