Search in sources :

Example 1 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class ClusterModel method storagePool_SelectedItemChanged.

private void storagePool_SelectedItemChanged() {
    // possible versions for new cluster (when editing cluster, this event won't occur)
    // are actually the possible versions for the data-center that the cluster is going
    // to be attached to.
    final StoragePool selectedDataCenter = getDataCenter().getSelectedItem();
    if (selectedDataCenter == null) {
        getManagementNetwork().setItems(Collections.emptyList());
        return;
    }
    if (selectedDataCenter.isLocal()) {
        setMigrationTabAvailable(false);
    } else {
        setMigrationTabAvailable(true);
    }
    AsyncDataProvider.getInstance().getDataCenterVersions(new AsyncQuery<>(new AsyncCallback<List<Version>>() {

        @Override
        public void onSuccess(List<Version> versions) {
            Version versionToSelect = calculateNewVersionWhichShouldBeSelected(versions);
            getVersion().setItems(versions, versionToSelect);
        }

        private Version calculateNewVersionWhichShouldBeSelected(List<Version> versions) {
            ListModel<Version> version = getVersion();
            Version selectedVersion = version.getSelectedItem();
            if (!getIsEdit() && (selectedVersion == null || !versions.contains(selectedVersion) || selectedVersion.compareTo(selectedDataCenter.getCompatibilityVersion()) > 0)) {
                if (ApplicationModeHelper.getUiMode().equals(ApplicationMode.GlusterOnly)) {
                    return versions.stream().max(Comparator.naturalOrder()).orElse(null);
                } else {
                    return selectedDataCenter.getCompatibilityVersion();
                }
            } else if (getIsEdit()) {
                return Linq.firstOrNull(versions, x -> x.equals(getEntity().getCompatibilityVersion()));
            } else {
                return selectedVersion;
            }
        }
    }), ApplicationModeHelper.getUiMode().equals(ApplicationMode.GlusterOnly) ? null : selectedDataCenter.getId());
    if (getManagementNetwork().getIsChangable()) {
        loadDcNetworks(selectedDataCenter.getId());
    }
}
Also used : MacPoolModel(org.ovirt.engine.ui.uicommonweb.models.macpool.MacPoolModel) Arrays(java.util.Arrays) Provider(org.ovirt.engine.core.common.businessentities.Provider) Event(org.ovirt.engine.ui.uicompat.Event) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) SwitchType(org.ovirt.engine.core.common.network.SwitchType) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) HasEntity(org.ovirt.engine.ui.uicommonweb.models.HasEntity) Version(org.ovirt.engine.core.compat.Version) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) SortedListModel(org.ovirt.engine.ui.uicommonweb.models.SortedListModel) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) AdditionalFeature(org.ovirt.engine.core.common.businessentities.AdditionalFeature) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) Collection(java.util.Collection) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) MigrationBandwidthLimitType(org.ovirt.engine.core.common.businessentities.MigrationBandwidthLimitType) HasValidatedTabs(org.ovirt.engine.ui.uicommonweb.models.HasValidatedTabs) I18NNameValidation(org.ovirt.engine.ui.uicommonweb.validation.I18NNameValidation) StringHelper(org.ovirt.engine.core.compat.StringHelper) SerialNumberPolicyModel(org.ovirt.engine.ui.uicommonweb.models.vms.SerialNumberPolicyModel) Objects(java.util.Objects) ApplicationModeHelper(org.ovirt.engine.ui.uicommonweb.models.ApplicationModeHelper) List(java.util.List) MigrateOnErrorOptions(org.ovirt.engine.core.common.businessentities.MigrateOnErrorOptions) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) ValidationCompleteEvent(org.ovirt.engine.ui.uicommonweb.models.ValidationCompleteEvent) KeyValueModel(org.ovirt.engine.ui.uicommonweb.models.vms.key_value.KeyValueModel) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ProviderType(org.ovirt.engine.core.common.businessentities.ProviderType) FilteredListModel(org.ovirt.engine.ui.uicommonweb.models.FilteredListModel) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) HostWithProtocolAndPortAddressValidation(org.ovirt.engine.ui.uicommonweb.validation.HostWithProtocolAndPortAddressValidation) Guid(org.ovirt.engine.core.compat.Guid) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) NoMigrationPolicy(org.ovirt.engine.core.common.migration.NoMigrationPolicy) Frontend(org.ovirt.engine.ui.frontend.Frontend) NotNullIntegerValidation(org.ovirt.engine.ui.uicommonweb.validation.NotNullIntegerValidation) Network(org.ovirt.engine.core.common.businessentities.network.Network) MigrationPolicy(org.ovirt.engine.core.common.migration.MigrationPolicy) Pair(org.ovirt.engine.core.common.utils.Pair) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Linq(org.ovirt.engine.ui.uicommonweb.Linq) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) SerialNumberPolicy(org.ovirt.engine.core.common.businessentities.SerialNumberPolicy) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) SupportedAdditionalClusterFeature(org.ovirt.engine.core.common.businessentities.SupportedAdditionalClusterFeature) MacPool(org.ovirt.engine.core.common.businessentities.MacPool) TabName(org.ovirt.engine.ui.uicommonweb.models.TabName) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) FirewallType(org.ovirt.engine.core.common.network.FirewallType) Comparator(java.util.Comparator) Collections(java.util.Collections) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) IdAndNameQueryParameters(org.ovirt.engine.core.common.queries.IdAndNameQueryParameters) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Version(org.ovirt.engine.core.compat.Version) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class BookmarkListModel method syncSearch.

@Override
protected void syncSearch() {
    super.syncSearch();
    Frontend.getInstance().runQuery(QueryType.GetAllBookmarks, new QueryParametersBase(), new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
        List<Bookmark> resultList = returnValue.getReturnValue();
        if (resultList != null) {
            Collections.sort(resultList, COMPARATOR);
        }
        setIsBookmarkInitiated(true);
        setItems(resultList);
        setIsBookmarkInitiated(false);
    }));
}
Also used : Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase)

Example 3 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class ProviderModel method updateDatacentersForExternalProvider.

protected void updateDatacentersForExternalProvider() {
    AsyncDataProvider.getInstance().getDataCenterList(new AsyncQuery<>(new AsyncCallback<List<StoragePool>>() {

        @Override
        public void onSuccess(List<StoragePool> dataCenters) {
            StoragePool prevDataCenter = getPreviousDataCenter(dataCenters);
            Collections.sort(dataCenters, new NameableComparator());
            // any data center
            dataCenters.add(0, null);
            getDataCenter().setItems(dataCenters);
            getDataCenter().setSelectedItem(prevDataCenter);
            if (getDataCenter().getSelectedItem() == null) {
                getProxyHostPropertiesModel().disableProxyHost();
            }
        }

        private StoragePool getPreviousDataCenter(List<StoragePool> dataCenters) {
            Guid previousDataCenterId = getProxyHostPropertiesModel().getLastStoragePoolId();
            for (StoragePool dataCenter : dataCenters) {
                if (dataCenter.getId().equals(previousDataCenterId)) {
                    return dataCenter;
                }
            }
            return null;
        }
    }));
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class VmListModel method updateVM.

@Override
protected void updateVM(final UnitVmModel model) {
    final VM selectedItem = getSelectedItem();
    // explicitly pass non-editable field from the original VM
    getcurrentVm().setCreatedByUserId(selectedItem.getCreatedByUserId());
    getcurrentVm().setUseLatestVersion(model.getTemplateWithVersion().getSelectedItem().isLatest());
    if (selectedItem.isRunningOrPaused() && !selectedItem.isHostedEngine()) {
        AsyncDataProvider.getInstance().getVmChangedFieldsForNextRun(editedVm, getcurrentVm(), getUpdateVmParameters(false), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

            @Override
            public void onSuccess(QueryReturnValue returnValue) {
                List<String> changedFields = returnValue.getReturnValue();
                final boolean cpuHotPluggable = VmCommonUtils.isCpusToBeHotpluggedOrUnplugged(selectedItem, getcurrentVm());
                final boolean isHeadlessModeChanged = isHeadlessModeChanged(editedVm, getUpdateVmParameters(false));
                final boolean memoryHotPluggable = VmCommonUtils.isMemoryToBeHotplugged(selectedItem, getcurrentVm());
                final boolean minAllocatedMemoryChanged = selectedItem.getMinAllocatedMem() != getcurrentVm().getMinAllocatedMem();
                final boolean vmLeaseUpdated = VmCommonUtils.isVmLeaseToBeHotPluggedOrUnplugged(selectedItem, getcurrentVm());
                if (isHeadlessModeChanged) {
                    changedFields.add(constants.headlessMode());
                }
                // provide warnings if isVmUnpinned()
                if (!changedFields.isEmpty() || isVmUnpinned() || memoryHotPluggable || cpuHotPluggable || vmLeaseUpdated) {
                    VmNextRunConfigurationModel confirmModel = new VmNextRunConfigurationModel();
                    if (isVmUnpinned()) {
                        confirmModel.setVmUnpinned();
                    }
                    confirmModel.setTitle(ConstantsManager.getInstance().getConstants().editNextRunConfigurationTitle());
                    confirmModel.setHelpTag(HelpTag.edit_next_run_configuration);
                    // $NON-NLS-1$
                    confirmModel.setHashName("edit_next_run_configuration");
                    confirmModel.setChangedFields(changedFields);
                    confirmModel.setCpuPluggable(cpuHotPluggable);
                    confirmModel.setMemoryPluggable(memoryHotPluggable);
                    // it can be plugged only together with the memory, never alone
                    confirmModel.setMinAllocatedMemoryPluggable(memoryHotPluggable && minAllocatedMemoryChanged);
                    confirmModel.setVmLeaseUpdated(vmLeaseUpdated);
                    confirmModel.getCommands().add(// $NON-NLS-1$
                    new UICommand("updateExistingVm", VmListModel.this).setTitle(ConstantsManager.getInstance().getConstants().ok()).setIsDefault(true));
                    // $NON-NLS-1$
                    confirmModel.getCommands().add(UICommand.createCancelUiCommand("CancelConfirmation", VmListModel.this));
                    setConfirmWindow(confirmModel);
                } else {
                    updateExistingVm(false);
                }
            }

            private boolean isVmUnpinned() {
                if (selectedItem.isRunning()) {
                    if (selectedItem.getMigrationSupport() == MigrationSupport.PINNED_TO_HOST && getcurrentVm().getMigrationSupport() != MigrationSupport.PINNED_TO_HOST) {
                        return true;
                    }
                }
                return false;
            }
        }));
    } else {
        updateExistingVm(false);
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 5 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class VmBaseListModel method postShowWarningOnExistingVms.

private void postShowWarningOnExistingVms(final ExportVmModel exportModel, List<StoragePool> storagePools, QueryType getVmOrTemplateQuery) {
    StoragePool storagePool = storagePools.size() > 0 ? storagePools.get(0) : null;
    if (storagePool != null) {
        Guid storageDomainId = exportModel.getStorage().getSelectedItem().getId();
        GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(storagePool.getId(), storageDomainId);
        Frontend.getInstance().runQuery(getVmOrTemplateQuery, tempVar, new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
            ExportVmModel windowModel = (ExportVmModel) getWindow();
            List<T> foundVms = new ArrayList<>();
            if (returnValue != null) {
                Iterable<T> iterableReturnValue = asIterableReturnValue(returnValue.getReturnValue());
                for (T selectedItem1 : getSelectedItems()) {
                    for (T returnValueItem : iterableReturnValue) {
                        if (entititesEqualsNullSafe(returnValueItem, selectedItem1)) {
                            foundVms.add(selectedItem1);
                            break;
                        }
                    }
                }
            }
            if (foundVms.size() != 0) {
                windowModel.setMessage(composeEntityOnStorage(composeExistingVmsWarningMessage(foundVms)));
            }
            exportModel.stopProgress();
        }));
    } else {
        exportModel.stopProgress();
    }
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) UnitVmModelNetworkAsyncCallback(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModelNetworkAsyncCallback) ArrayList(java.util.ArrayList) ExportVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.ExportVmModel) Guid(org.ovirt.engine.core.compat.Guid) GetAllFromExportDomainQueryParameters(org.ovirt.engine.core.common.queries.GetAllFromExportDomainQueryParameters)

Aggregations

AsyncCallback (org.ovirt.engine.ui.frontend.AsyncCallback)16 ArrayList (java.util.ArrayList)11 Guid (org.ovirt.engine.core.compat.Guid)8 List (java.util.List)7 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)7 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)6 Frontend (org.ovirt.engine.ui.frontend.Frontend)6 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)6 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)5 Collections (java.util.Collections)4 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 VM (org.ovirt.engine.core.common.businessentities.VM)4 QueryType (org.ovirt.engine.core.common.queries.QueryType)4 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)4 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)4 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)4 UIConstants (org.ovirt.engine.ui.uicompat.UIConstants)4 Arrays (java.util.Arrays)3 Map (java.util.Map)3 Objects (java.util.Objects)3