use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.
the class UserPermissionListModel method syncSearch.
@Override
protected void syncSearch() {
if (getEntity() == null) {
return;
}
IdQueryParameters mlaParams = new IdQueryParameters(getEntity().getId());
mlaParams.setRefresh(getIsQueryFirstTime());
Frontend.getInstance().runQuery(QueryType.GetPermissionsOnBehalfByAdElementId, mlaParams, new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
ArrayList<Permission> list = returnValue.getReturnValue();
ArrayList<Permission> newList = new ArrayList<>();
for (Permission permission : list) {
if (!permission.getRoleId().equals(ApplicationGuids.quotaConsumer.asGuid())) {
newList.add(permission);
}
}
setItems(newList);
}));
setIsQueryFirstTime(false);
}
use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.
the class ImportTemplateModel method init.
public void init(final Collection<VmTemplate> externalTemplates, final Guid storageDomainId) {
Frontend.getInstance().runQuery(QueryType.Search, new SearchParameters(createSearchPattern(externalTemplates), SearchType.VmTemplate), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {
@Override
public void onSuccess(QueryReturnValue returnValue) {
UIConstants constants = ConstantsManager.getInstance().getConstants();
List<VmTemplate> vmtList = returnValue.getReturnValue();
List<ImportTemplateData> templateDataList = new ArrayList<>();
for (VmTemplate template : externalTemplates) {
ImportTemplateData templateData = new ImportTemplateData(template);
boolean templateExistsInSystem = vmtList.contains(template);
templateData.setExistsInSystem(templateExistsInSystem);
if (templateExistsInSystem) {
templateData.enforceClone(constants.importTemplateThatExistsInSystemMustClone());
} else if (!template.isBaseTemplate() && findAnyVmTemplateById(vmtList, template.getBaseTemplateId()) == null) {
templateData.enforceClone(constants.importTemplateWithoutBaseMustClone());
}
templateDataList.add(templateData);
}
setItems(templateDataList);
withDataCenterLoaded(storageDomainId, r -> doInit());
}
private VmTemplate findAnyVmTemplateById(List<VmTemplate> vmtList, Guid templateId) {
for (VmTemplate vmt : vmtList) {
if (templateId.equals(vmt.getId())) {
return vmt;
}
}
return null;
}
}));
}
use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.
the class GlusterClusterSnapshotConfigModel method clusterSelectedItemChanged.
private void clusterSelectedItemChanged() {
Cluster selectedCluster = getClusters().getSelectedItem();
if (selectedCluster == null) {
return;
}
AsyncDataProvider.getInstance().getGlusterSnapshotConfig(new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {
@Override
public void onSuccess(QueryReturnValue returnValue) {
Pair<List<GlusterVolumeSnapshotConfig>, List<GlusterVolumeSnapshotConfig>> configs = returnValue.getReturnValue();
if (configs != null) {
List<GlusterVolumeSnapshotConfig> clusterConfigOptions = configs.getFirst();
Collections.sort(clusterConfigOptions, Comparator.comparing(GlusterVolumeSnapshotConfig::getParamName));
setModelItems(getClusterConfigOptions(), clusterConfigOptions, existingClusterConfigs);
} else {
getClusterConfigOptions().setItems(null);
}
}
private void setModelItems(ListModel<EntityModel<GlusterVolumeSnapshotConfig>> listModel, List<GlusterVolumeSnapshotConfig> cfgs, Map<String, String> fetchedCfgsBackup) {
List<EntityModel<GlusterVolumeSnapshotConfig>> coll = new ArrayList<>();
for (GlusterVolumeSnapshotConfig cfg : cfgs) {
EntityModel<GlusterVolumeSnapshotConfig> cfgModel = new EntityModel<>();
cfgModel.setEntity(cfg);
fetchedCfgsBackup.put(cfg.getParamName(), cfg.getParamValue());
coll.add(cfgModel);
}
// set the entity items
listModel.setItems(coll);
}
}), selectedCluster.getId(), null);
}
use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.
the class GlusterVolumeSnapshotListModel method editSnapshotSchedule.
public void editSnapshotSchedule() {
if (getWindow() != null) {
return;
}
final UIConstants constants = ConstantsManager.getInstance().getConstants();
final GlusterVolumeSnapshotModel snapshotModel = new GlusterVolumeSnapshotModel(true, true);
snapshotModel.setHelpTag(HelpTag.edit_volume_snapshot_schedule);
// $NON-NLS-1$
snapshotModel.setHashName("edit_volume_snapshot_schedule");
snapshotModel.setTitle(constants.editVolumeSnapshotScheduleTitle());
setWindow(snapshotModel);
snapshotModel.startProgress();
AsyncDataProvider.getInstance().getVolumeSnapshotSchedule(new AsyncQuery<>(new AsyncCallback<GlusterVolumeSnapshotSchedule>() {
@Override
public void onSuccess(final GlusterVolumeSnapshotSchedule schedule) {
if (schedule == null) {
snapshotModel.setMessage(ConstantsManager.getInstance().getConstants().unableToFetchVolumeSnapshotSchedule());
return;
}
snapshotModel.getSnapshotName().setEntity(schedule.getSnapshotNamePrefix());
snapshotModel.getDescription().setEntity(schedule.getSnapshotDescription());
snapshotModel.getRecurrence().setSelectedItem(schedule.getRecurrence());
if (schedule.getEndByDate() == null) {
snapshotModel.getEndByOptions().setSelectedItem(EndDateOptions.NoEndDate);
} else {
snapshotModel.getEndByOptions().setSelectedItem(EndDateOptions.HasEndDate);
snapshotModel.getEndDate().setEntity(schedule.getEndByDate());
}
if (schedule.getRecurrence() != GlusterVolumeSnapshotScheduleRecurrence.UNKNOWN) {
Map<String, String> timeZones = TimeZoneType.GENERAL_TIMEZONE.getTimeZoneList();
snapshotModel.getTimeZones().setSelectedItem(Linq.firstOrNull(timeZones.entrySet(), item -> item.getKey().startsWith(schedule.getTimeZone())));
}
switch(schedule.getRecurrence()) {
case INTERVAL:
snapshotModel.getInterval().setSelectedItem(String.valueOf(schedule.getInterval()));
break;
case HOURLY:
break;
case DAILY:
snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
break;
case WEEKLY:
List<DayOfWeek> daysList = new ArrayList<>();
for (String day : schedule.getDays().split(",")) {
// $NON-NLS-1$
daysList.add(getDayOfWeek(day));
}
snapshotModel.getDaysOfTheWeek().setSelectedItem(daysList);
snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
break;
case MONTHLY:
snapshotModel.getDaysOfMonth().setSelectedItem(schedule.getDays());
snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
break;
}
snapshotModel.getStartAt().setEntity(schedule.getStartDate());
snapshotModel.stopProgress();
}
private DayOfWeek getDayOfWeek(String day) {
switch(day) {
case // $NON-NLS-1$
"Sun":
return DayOfWeek.Sunday;
case // $NON-NLS-1$
"Mon":
return DayOfWeek.Monday;
case // $NON-NLS-1$
"Tue":
return DayOfWeek.Tuesday;
case // $NON-NLS-1$
"Wed":
return DayOfWeek.Wednesday;
case // $NON-NLS-1$
"Thu":
return DayOfWeek.Thursday;
case // $NON-NLS-1$
"Fri":
return DayOfWeek.Friday;
case // $NON-NLS-1$
"Sat":
return DayOfWeek.Saturday;
default:
return null;
}
}
private Date getExecutionTimeValue(GlusterVolumeSnapshotSchedule schedule) {
Date dt = new Date();
dt.setHours(schedule.getExecutionTime().getHours());
dt.setMinutes(schedule.getExecutionTime().getMinutes());
return dt;
}
}), getEntity().getId());
snapshotModel.getClusterName().setEntity(getEntity().getClusterName());
snapshotModel.getVolumeName().setEntity(getEntity().getName());
// $NON-NLS-1$
UICommand okCommand = UICommand.createDefaultOkUiCommand("onEditSnapshotSchedule", this);
snapshotModel.getCommands().add(okCommand);
// $NON-NLS-1$
UICommand cancelCommand = UICommand.createCancelUiCommand("cancel", this);
snapshotModel.getCommands().add(cancelCommand);
}
use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.
the class SnapshotModel method updateVmConfiguration.
public void updateVmConfiguration(final AsyncCallback<Void> onUpdateAsyncCallback) {
Snapshot snapshot = getEntity();
if (snapshot == null) {
return;
}
AsyncDataProvider.getInstance().getVmConfigurationBySnapshot(new AsyncQuery<>(vm -> {
Snapshot snapshot1 = getEntity();
if (vm != null && snapshot1 != null) {
setVm(vm);
setDisks(vm.getDiskList());
setNics(vm.getInterfaces());
setApps(Arrays.asList(snapshot1.getAppList() != null ? snapshot1.getAppList().split(",") : // $NON-NLS-1$
new String[] {}));
Collections.sort(getDisks(), new DiskByDiskAliasComparator());
Collections.sort(getNics(), new LexoNumericNameableComparator<>());
}
onUpdateAsyncCallback.onSuccess(null);
}), snapshot.getId());
}
Aggregations