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