use of org.ovirt.engine.ui.uicommonweb.models.vms.ExistingPoolModelBehavior in project ovirt-engine by oVirt.
the class PoolListModel method edit.
public void edit() {
final VmPool pool = getSelectedItem();
if (getWindow() != null) {
return;
}
final PoolListModel poolListModel = this;
Frontend.getInstance().runQuery(QueryType.GetVmDataByPoolId, new IdQueryParameters(pool.getVmPoolId()), new AsyncQuery<QueryReturnValue>(result -> {
final VM vm = result.getReturnValue();
final ExistingPoolModelBehavior behavior = new ExistingPoolModelBehavior(vm, pool);
behavior.getPoolModelBehaviorInitializedEvent().addListener((ev, sender, args) -> {
final PoolModel model = behavior.getModel();
for (EntityModel<VmPoolType> item : model.getPoolType().getItems()) {
if (item.getEntity() == pool.getVmPoolType()) {
model.getPoolType().setSelectedItem(item);
break;
}
}
String cdImage = null;
if (vm != null) {
model.getDataCenterWithClustersList().setSelectedItem(null);
model.getDataCenterWithClustersList().setSelectedItem(Linq.firstOrNull(model.getDataCenterWithClustersList().getItems(), new Linq.DataCenterWithClusterPredicate(vm.getStoragePoolId(), vm.getClusterId())));
model.getTemplateWithVersion().setIsChangeable(false);
cdImage = vm.getIsoPath();
model.getVmType().setSelectedItem(vm.getVmType());
} else {
model.getDataCenterWithClustersList().setSelectedItem(Linq.firstOrNull(model.getDataCenterWithClustersList().getItems()));
}
model.getDataCenterWithClustersList().setIsChangeable(vm == null);
boolean hasCd = !StringHelper.isNullOrEmpty(cdImage);
model.getCdImage().setIsChangeable(hasCd);
model.getCdAttached().setEntity(hasCd);
model.getProvisioning().setIsChangeable(false);
model.getStorageDomain().setIsChangeable(false);
});
PoolModel model = new PoolModel(behavior);
model.setCustomPropertiesKeysList(AsyncDataProvider.getInstance().getCustomPropertiesList());
// $NON-NLS-1$
model.setIsAdvancedModeLocalStorageKey("wa_pool_dialog");
setWindow(model);
VmBasedWidgetSwitchModeCommand switchModeCommand = new VmBasedWidgetSwitchModeCommand();
switchModeCommand.init(model);
model.getCommands().add(switchModeCommand);
// $NON-NLS-1$
UICommand command = UICommand.createDefaultOkUiCommand("OnSave", poolListModel);
model.getCommands().add(command);
// $NON-NLS-1$
model.getCommands().add(UICommand.createCancelUiCommand("Cancel", poolListModel));
model.setTitle(ConstantsManager.getInstance().getConstants().editPoolTitle());
model.setHelpTag(HelpTag.edit_pool);
// $NON-NLS-1$
model.setHashName("edit_pool");
model.initialize();
model.getName().setEntity(pool.getName());
model.getDescription().setEntity(pool.getVmPoolDescription());
model.getComment().setEntity(pool.getComment());
model.getPoolStateful().setEntity(pool.isStateful());
model.getAssignedVms().setEntity(pool.getAssignedVmsCount());
model.getPrestartedVms().setEntity(pool.getPrestartedVms());
// $NON-NLS-1$
model.setPrestartedVmsHint("0-" + pool.getAssignedVmsCount());
model.getMaxAssignedVmsPerUser().setEntity(pool.getMaxAssignedVmsPerUser());
}));
}
Aggregations