use of org.ovirt.engine.ui.uicommonweb.models.EntityModel 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());
}));
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class ClusterGlusterHookListModel method resolveConflicts.
private void resolveConflicts() {
if (getWindow() != null) {
return;
}
final GlusterHookEntity hookEntity = getSelectedItem();
if (hookEntity == null) {
return;
}
final GlusterHookResolveConflictsModel conflictsModel = new GlusterHookResolveConflictsModel();
conflictsModel.setTitle(ConstantsManager.getInstance().getConstants().resolveConflictsGlusterHookTitle());
conflictsModel.setHelpTag(HelpTag.gluster_hook_resolve_conflicts);
// $NON-NLS-1$
conflictsModel.setHashName("gluster_hook_resolve_conflicts");
hookEntity.setServerHooks(new ArrayList<GlusterServerHook>());
conflictsModel.setGlusterHookEntity(hookEntity);
setWindow(conflictsModel);
conflictsModel.startProgress();
AsyncDataProvider.getInstance().getGlusterHook(new AsyncQuery<>(returnValue -> {
List<GlusterServerHook> serverHooks = returnValue.getServerHooks();
hookEntity.setServerHooks(serverHooks);
ArrayList<EntityModel<GlusterServerHook>> serverHookModels = new ArrayList<>();
GlusterServerHook engineCopy = new GlusterServerHook();
engineCopy.setHookId(hookEntity.getId());
// $NON-NLS-1$
engineCopy.setServerName("Engine (Master)");
engineCopy.setStatus(hookEntity.getStatus());
engineCopy.setContentType(hookEntity.getContentType());
engineCopy.setChecksum(hookEntity.getChecksum());
EntityModel<GlusterServerHook> engineCopyModel = new EntityModel<>(engineCopy);
serverHookModels.add(engineCopyModel);
for (GlusterServerHook serverHook : serverHooks) {
serverHookModels.add(new EntityModel<>(serverHook));
}
conflictsModel.getHookSources().setItems(serverHookModels);
conflictsModel.getHookSources().setSelectedItem(engineCopyModel);
ArrayList<GlusterServerHook> serverHooksWithEngine = new ArrayList<>(serverHooks);
serverHooksWithEngine.add(0, engineCopy);
conflictsModel.getServerHooksList().setItems(serverHooksWithEngine);
conflictsModel.getServerHooksList().setSelectedItem(engineCopy);
conflictsModel.stopProgress();
// $NON-NLS-1$
UICommand command = UICommand.createDefaultOkUiCommand("OnResolveConflicts", ClusterGlusterHookListModel.this);
conflictsModel.getCommands().add(command);
// $NON-NLS-1$
command = new UICommand("Cancel", ClusterGlusterHookListModel.this);
command.setTitle(ConstantsManager.getInstance().getConstants().close());
command.setIsCancel(true);
conflictsModel.getCommands().add(command);
}), hookEntity.getId(), true);
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class ClusterGuideModel method onSelectHost.
public void onSelectHost() {
MoveHost model = (MoveHost) getWindow();
if (model.getProgress() != null) {
return;
}
if (!model.validate()) {
return;
}
model.setSelectedHosts(new ArrayList<MoveHostData>());
for (EntityModel a : model.getItems()) {
if (a.getIsSelected()) {
model.getSelectedHosts().add((MoveHostData) a);
}
}
Cluster cluster = model.getCluster().getSelectedItem();
final List<ActionParametersBase> parameterList = new ArrayList<>();
for (MoveHostData hostData : model.getSelectedHosts()) {
VDS host = hostData.getEntity();
// Try to change host's cluster as neccessary.
if (host.getClusterId() != null && !host.getClusterId().equals(cluster.getId())) {
parameterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
}
}
model.startProgress();
Frontend.getInstance().runMultipleAction(ActionType.ChangeVDSCluster, parameterList, result -> {
List<MoveHostData> hosts = ((MoveHost) getWindow()).getSelectedHosts();
List<ActionReturnValue> retVals = result.getReturnValue();
final List<ActionParametersBase> activateVdsParameterList = new ArrayList<>();
if (retVals != null && hosts.size() == retVals.size()) {
int i = 0;
for (MoveHostData selectedHostData : hosts) {
VDS selectedHost = selectedHostData.getEntity();
if (selectedHost.getStatus() == VDSStatus.PendingApproval && retVals.get(i) != null && retVals.get(i).getSucceeded()) {
Frontend.getInstance().runAction(ActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()));
} else if (selectedHostData.getActivateHost()) {
activateVdsParameterList.add(new VdsActionParameters(selectedHostData.getEntity().getId()));
}
i++;
}
}
if (activateVdsParameterList.isEmpty()) {
getWindow().stopProgress();
cancel();
postAction();
} else {
final String searchString = getVdsSearchString((MoveHost) getWindow());
Timer timer = new Timer() {
public void run() {
checkVdsClusterChangeSucceeded(searchString, parameterList, activateVdsParameterList);
}
};
timer.schedule(2000);
}
}, this);
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class PermissionListModel method onAdd.
private void onAdd() {
AdElementListModel model = (AdElementListModel) getWindow();
if (model.getProgress() != null) {
return;
}
if (model.getSearchType() != AdSearchType.EVERYONE && model.getSelectedItems() == null) {
cancel();
return;
}
ArrayList<DbUser> items = new ArrayList<>();
if (model.getSearchType() == AdSearchType.EVERYONE) {
DbUser tempVar = new DbUser();
tempVar.setId(ApplicationGuids.everyone.asGuid());
items.add(tempVar);
} else {
for (Object item : model.getItems()) {
EntityModel entityModel = (EntityModel) item;
if (entityModel.getIsSelected()) {
items.add((DbUser) entityModel.getEntity());
}
}
}
Role role = model.getRole().getSelectedItem();
// adGroup/user
ArrayList<ActionParametersBase> list = new ArrayList<>();
for (DbUser user : items) {
Permission perm = new Permission(user.getId(), role.getId(), getEntityGuid(), getObjectType());
if (user.isGroup()) {
DbGroup group = new DbGroup();
group.setId(user.getId());
group.setExternalId(user.getExternalId());
group.setName(user.getFirstName());
group.setDomain(user.getDomain());
group.setNamespace(user.getNamespace());
PermissionsOperationsParameters tempVar3 = new PermissionsOperationsParameters();
tempVar3.setPermission(perm);
tempVar3.setGroup(group);
list.add(tempVar3);
} else {
PermissionsOperationsParameters tempVar4 = new PermissionsOperationsParameters();
tempVar4.setPermission(perm);
tempVar4.setUser(user);
list.add(tempVar4);
}
}
model.startProgress();
Frontend.getInstance().runMultipleAction(ActionType.AddPermission, list, result -> {
AdElementListModel localModel = (AdElementListModel) result.getState();
localModel.stopProgress();
cancel();
}, model);
}
use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.
the class SystemPermissionListModel method onAttach.
private void onAttach() {
AdElementListModel model = (AdElementListModel) getWindow();
if (model.getProgress() != null) {
return;
}
if (model.getSelectedItems() == null) {
cancel();
return;
}
ArrayList<DbUser> items = new ArrayList<>();
for (Object item : model.getItems()) {
EntityModel entityModel = (EntityModel) item;
if (entityModel.getIsSelected()) {
items.add((DbUser) entityModel.getEntity());
}
}
Role role = model.getRole().getSelectedItem();
ArrayList<ActionParametersBase> list = new ArrayList<>();
for (DbUser user : items) {
Permission perm = new Permission(user.getId(), role.getId(), null, null);
if (user.isGroup()) {
DbGroup group = new DbGroup();
group.setId(user.getId());
group.setName(user.getFirstName());
group.setDomain(user.getDomain());
group.setExternalId(user.getExternalId());
group.setNamespace(user.getNamespace());
PermissionsOperationsParameters tempVar2 = new PermissionsOperationsParameters();
tempVar2.setPermission(perm);
tempVar2.setGroup(group);
list.add(tempVar2);
} else {
PermissionsOperationsParameters tempVar3 = new PermissionsOperationsParameters();
tempVar3.setPermission(perm);
tempVar3.setUser(user);
list.add(tempVar3);
}
}
model.startProgress();
Frontend.getInstance().runMultipleAction(ActionType.AddSystemPermission, list, result -> {
AdElementListModel localModel = (AdElementListModel) result.getState();
localModel.stopProgress();
cancel();
}, model);
}
Aggregations