use of org.ovirt.engine.ui.uicommonweb.models.vms.TemplateVmModelBehavior in project ovirt-engine by oVirt.
the class TemplateListModel method onSave.
private void onSave() {
final UnitVmModel model = (UnitVmModel) getWindow();
if (!model.validate()) {
return;
}
final String name = model.getName().getEntity();
boolean isBaseTemplate = false;
if (model.getBehavior().isExistingTemplateBehavior()) {
isBaseTemplate = ((TemplateVmModelBehavior) model.getBehavior()).getVmTemplate().isBaseTemplate();
} else if (model.getBehavior().isBlankTemplateBehavior()) {
isBaseTemplate = true;
}
if (isBaseTemplate) {
AsyncDataProvider.getInstance().isTemplateNameUnique(new AsyncQuery<>(isNameUnique -> {
if (model.getBehavior().isExistingTemplateBehavior()) {
selectedItem = ((TemplateVmModelBehavior) model.getBehavior()).getVmTemplate();
} else {
selectedItem = ((ExistingBlankTemplateModelBehavior) model.getBehavior()).getVmTemplate();
}
if (!isNameUnique && name.compareToIgnoreCase(selectedItem.getName()) != 0) {
model.getName().getInvalidityReasons().add(ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason());
model.getName().setIsValid(false);
model.setValidTab(TabName.GENERAL_TAB, false);
model.fireValidationCompleteEvent();
return;
}
String selectedCpu = model.getCustomCpu().getSelectedItem();
if (selectedCpu != null && !selectedCpu.isEmpty() && !model.getCustomCpu().getItems().contains(selectedCpu)) {
ConfirmationModel confirmModel = new ConfirmationModel();
confirmModel.setTitle(ConstantsManager.getInstance().getConstants().vmUnsupportedCpuTitle());
confirmModel.setMessage(ConstantsManager.getInstance().getConstants().vmUnsupportedCpuMessage());
confirmModel.setHelpTag(HelpTag.edit_unsupported_cpu);
// $NON-NLS-1$
confirmModel.setHashName("edit_unsupported_cpu");
confirmModel.getCommands().add(// $NON-NLS-1$
new UICommand("postNameUniqueCheck", TemplateListModel.this).setTitle(ConstantsManager.getInstance().getConstants().ok()).setIsDefault(true));
confirmModel.getCommands().add(// $NON-NLS-1$
UICommand.createCancelUiCommand("CancelConfirmation", TemplateListModel.this));
setConfirmWindow(confirmModel);
} else {
postNameUniqueCheck();
}
}), name, model.getSelectedDataCenter() == null ? null : model.getSelectedDataCenter().getId());
} else {
postNameUniqueCheck();
}
}
Aggregations