Search in sources :

Example 1 with DeferredModelCommandInvoker

use of org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker in project ovirt-engine by oVirt.

the class AbstractModelBoundPopupPresenterWidget method init.

/**
 * Initialize the view from the given model.
 */
public void init(final T model) {
    this.model = model;
    getView().init(model);
    // Set up async operation listeners to automatically display/hide progress bar
    asyncOperationCounter = 0;
    addRegisteredHandler(AsyncOperationStartedEvent.getType(), event -> {
        if (event.getTarget() != getModel() || getModel().getProgress() != null) {
            return;
        }
        if (asyncOperationCounter == 0) {
            startProgress(null);
        }
        asyncOperationCounter++;
    });
    addRegisteredHandler(AsyncOperationCompleteEvent.getType(), event -> {
        if (event.getTarget() != getModel() || getModel().getProgress() != null) {
            return;
        }
        asyncOperationCounter--;
        if (asyncOperationCounter == 0) {
            stopProgress();
        }
    });
    // Set up model command invoker
    this.modelCommandInvoker = new DeferredModelCommandInvoker(model) {

        @Override
        protected void commandFailed(UICommand command) {
            // Clear Window and ConfirmWindow models when "Cancel" command execution fails
            if (command.getIsCancel() && command.getTarget() instanceof Model) {
                Model source = (Model) command.getTarget();
                source.setWindow(null);
                source.setConfirmWindow(null);
            }
        }

        @Override
        protected void commandFinished(UICommand command) {
            // Enforce popup close after executing "Cancel" command
            if (command.getIsCancel()) {
                hideAndUnbind();
            }
        }
    };
    // Set common popup properties
    updateTitle(model);
    updateMessage(model);
    updateItems(model);
    updateHashName(model);
    updateHelpTag(model);
    model.getPropertyChangedEvent().addListener((ev, sender, args) -> {
        String propName = args.propertyName;
        if ("Title".equals(propName)) {
            // $NON-NLS-1$
            updateTitle(model);
        } else if ("Message".equals(propName)) {
            // $NON-NLS-1$
            updateMessage(model);
        } else if ("Items".equals(propName)) {
            // $NON-NLS-1$
            updateItems(model);
        } else if ("HashName".equals(propName)) {
            // $NON-NLS-1$
            updateHashName(model);
        } else if ("HelpTag".equals(propName)) {
            // $NON-NLS-1$
            updateHelpTag(model);
        } else if ("OpenDocumentation".equals(propName)) {
            // $NON-NLS-1$
            openDocumentation(model);
        }
    });
    // Add popup footer buttons
    addFooterButtons(model);
    if (model.getCommands() instanceof ObservableCollection) {
        ObservableCollection<UICommand> commands = (ObservableCollection<UICommand>) model.getCommands();
        commands.getCollectionChangedEvent().addListener((ev, sender, args) -> {
            getView().removeButtons();
            addFooterButtons(model);
            getView().updateTabIndexes();
        });
    }
    // Register dialog model property change listener
    popupHandler.initDialogModelListener(model);
    // Initialize popup contents from the model
    getView().edit(model);
    getView().updateTabIndexes();
    if (!model.hasEventBusSet()) {
        model.setEventBus((EventBus) getEventBus());
    }
}
Also used : DeferredModelCommandInvoker(org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker) ObservableCollection(org.ovirt.engine.ui.uicompat.ObservableCollection) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 2 with DeferredModelCommandInvoker

use of org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker in project ovirt-engine by oVirt.

the class AbstractActionStackPanelItem method addDoubleClickHandler.

void addDoubleClickHandler(final W widget, final M modelProvider) {
    if (modelProvider instanceof SearchableTableModelProvider<?, ?>) {
        widget.addDomHandler(event -> {
            SearchableListModel model = ((SearchableTableModelProvider<?, ?>) modelProvider).getModel();
            UICommand command = model.getDoubleClickCommand();
            if (command != null && command.getIsExecutionAllowed()) {
                DeferredModelCommandInvoker invoker = new DeferredModelCommandInvoker(model);
                invoker.invokeCommand(command);
            }
        }, DoubleClickEvent.getType());
    }
}
Also used : SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) DeferredModelCommandInvoker(org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker) SearchableTableModelProvider(org.ovirt.engine.ui.common.uicommon.model.SearchableTableModelProvider) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Aggregations

DeferredModelCommandInvoker (org.ovirt.engine.ui.common.uicommon.model.DeferredModelCommandInvoker)2 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)2 SearchableTableModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableTableModelProvider)1 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)1 ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)1 Model (org.ovirt.engine.ui.uicommonweb.models.Model)1 SearchableListModel (org.ovirt.engine.ui.uicommonweb.models.SearchableListModel)1 ObservableCollection (org.ovirt.engine.ui.uicompat.ObservableCollection)1