Search in sources :

Example 66 with EntityModel

use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.

the class UiCommonEditorVisitor method visit.

@SuppressWarnings("unchecked")
@Override
public <T> boolean visit(final EditorContext<T> ctx) {
    final String absolutePath = ctx.getAbsolutePath();
    LeafValueEditor<T> currentLeafEditor = ctx.asLeafValueEditor();
    if (currentLeafEditor == null) {
        // Ignore non-leaf Editors
        return super.visit(ctx);
    }
    final LeafValueEditor<T> editor = getActualEditor(currentLeafEditor);
    // If this Editor implements HasValueChangeHandlers, register a value change listener
    if (editor instanceof HasValueChangeHandlers) {
        ((HasValueChangeHandlers<T>) editor).addValueChangeHandler(event -> setInModel(ctx, event.getSource(), event.getValue()));
    }
    final UiCommonEditor<T> functionalEditor = getFunctionalEditor(currentLeafEditor);
    if (functionalEditor != null) {
        // Pass in the EditorDelegate
        if (editor instanceof HasEditorDelegate) {
            ((HasEditorDelegate<T>) editor).setDelegate(ctx.getEditorDelegate());
        }
        // Set tab index, unless it's being set manually (i.e. already been set)
        if (functionalEditor.getTabIndex() <= 0) {
            functionalEditor.setTabIndex(++tabIndexCounter);
        }
        // Add key press handler
        functionalEditor.addKeyPressHandler(event -> {
            if (KeyCodes.KEY_ENTER == event.getNativeEvent().getKeyCode()) {
                setInModel(ctx, editor, editor.getValue());
            }
        });
    }
    // Handle owner entity models
    if (ownerModels.containsKey(absolutePath)) {
        Model ownerModel = ownerModels.get(absolutePath);
        // If this editor edits a ListModel, initialize it
        if (editor instanceof TakesConstrainedValueListEditor && ownerModel instanceof ListModel) {
            updateListEditor((TakesConstrainedValueListEditor<T>) editor, (ListModel) ownerModel);
        } else if (editor instanceof TakesConstrainedValueEditor && ownerModel instanceof ListModel) {
            updateListEditor((TakesConstrainedValueEditor<T>) editor, (ListModel) ownerModel);
        }
        if (functionalEditor != null) {
            // Register a property change listener on the owner entity model
            ownerModel.getPropertyChangedEvent().addListener((ev, sender, args) -> {
                Model owner = (Model) sender;
                String propName = args.propertyName;
                // IsValid
                if ("IsValid".equals(propName)) {
                    // $NON-NLS-1$
                    onIsValidPropertyChange(functionalEditor, owner);
                } else // IsChangable
                if ("IsChangable".equals(propName)) {
                    // $NON-NLS-1$
                    onIsChangablePropertyChange(functionalEditor, owner);
                } else // ChangeProhibitionReason
                if ("ChangeProhibitionReason".equals(propName)) {
                    // $NON-NLS-1$
                    onChangeProhibitionReasonChange(functionalEditor, owner);
                } else // IsAvailable
                if ("IsAvailable".equals(propName)) {
                    // $NON-NLS-1$
                    onIsAvailablePropertyChange(functionalEditor, owner);
                }
            });
            // Update editor since we might have missed property change
            // events fired as part of the entity model constructor
            onIsValidPropertyChange(functionalEditor, ownerModel);
            onIsChangablePropertyChange(functionalEditor, ownerModel);
            onChangeProhibitionReasonChange(functionalEditor, ownerModel);
            onIsAvailablePropertyChange(functionalEditor, ownerModel);
        }
    }
    // Register listeners
    // $NON-NLS-1$
    eventMap.registerListener(// $NON-NLS-1$
    absolutePath, // $NON-NLS-1$
    "EntityChanged", (ev, sender, args) -> editor.setValue((T) ((EntityModel) sender).getEntity()));
    // $NON-NLS-1$
    eventMap.registerListener(// $NON-NLS-1$
    absolutePath, // $NON-NLS-1$
    "ItemsChanged", (ev, sender, args) -> updateListEditor((TakesConstrainedValueEditor<T>) editor, (ListModel) sender));
    eventMap.registerListener(absolutePath, "SelectedItemChanged", (ev, sender, args) -> {
        // $NON-NLS-1$
        T selectedItem = (T) ((ListModel) sender).getSelectedItem();
        if (editor instanceof TakesConstrainedValueListEditor && ownerModels.get(absolutePath) instanceof ListModel) {
            editor.setValue((T) Arrays.asList(selectedItem));
        } else {
            editor.setValue(selectedItem);
        }
    });
    eventMap.registerListener(absolutePath, "SelectedItemsChanged", (ev, sender, args) -> {
        // $NON-NLS-1$
        if (editor instanceof TakesConstrainedValueListEditor && ownerModels.get(absolutePath) instanceof ListModel) {
            ((TakesConstrainedValueListEditor) editor).setListValue((List<T>) ((ListModel) sender).getSelectedItems());
        }
    });
    return super.visit(ctx);
}
Also used : ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) TakesConstrainedValueListEditor(org.ovirt.engine.ui.common.widget.editor.TakesConstrainedValueListEditor) HasEditorDelegate(com.google.gwt.editor.client.HasEditorDelegate) HasValueChangeHandlers(com.google.gwt.event.logical.shared.HasValueChangeHandlers) TakesConstrainedValueEditor(org.ovirt.engine.ui.common.widget.editor.TakesConstrainedValueEditor)

Example 67 with EntityModel

use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.

the class SanStorageModelBase method postPrepareSanStorageForEdit.

private void postPrepareSanStorageForEdit(final SanStorageModelBase model, boolean isStorageActive, StorageDomain storage) {
    model.setStorageDomain(storage);
    VDS host = getContainer().getHost().getSelectedItem();
    if (Objects.equals(previousGetLunsByVGIdHost, host) && isStorageActive) {
        return;
    }
    previousGetLunsByVGIdHost = host;
    Guid hostId = host != null && isStorageActive ? host.getId() : null;
    setValuesForMaintenance(model);
    getContainer().startProgress();
    AsyncDataProvider.getInstance().getLunsByVgId(new AsyncQuery<>(lunList -> model.applyData(lunList, true, Linq.findSelectedItems((Collection<EntityModel<?>>) getSelectedItem()), isInMaintenance, metadata)), storage.getStorage(), hostId);
}
Also used : NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) Event(org.ovirt.engine.ui.uicompat.Event) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) GetDeviceListQueryParameters(org.ovirt.engine.core.common.queries.GetDeviceListQueryParameters) ValueEventArgs(org.ovirt.engine.ui.uicommonweb.models.hosts.ValueEventArgs) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) DiscoverSendTargetsQueryParameters(org.ovirt.engine.core.common.queries.DiscoverSendTargetsQueryParameters) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) Model(org.ovirt.engine.ui.uicommonweb.models.Model) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) IntegerValidation(org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) Linq(org.ovirt.engine.ui.uicommonweb.Linq) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) Collection(java.util.Collection) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) StorageServerConnectionParametersBase(org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) EventDefinition(org.ovirt.engine.ui.uicompat.EventDefinition) VDS(org.ovirt.engine.core.common.businessentities.VDS) LunStatus(org.ovirt.engine.core.common.businessentities.storage.LunStatus) ObservableCollection(org.ovirt.engine.ui.uicompat.ObservableCollection) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) VDS(org.ovirt.engine.core.common.businessentities.VDS) Collection(java.util.Collection) ObservableCollection(org.ovirt.engine.ui.uicompat.ObservableCollection) Guid(org.ovirt.engine.core.compat.Guid)

Example 68 with EntityModel

use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.

the class StorageDataCenterListModel method onAttach.

private void onAttach() {
    final ListModel<EntityModel<StoragePool>> model = (ListModel<EntityModel<StoragePool>>) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (getEntity() == null) {
        cancel();
        return;
    }
    ArrayList<StoragePool> items = new ArrayList<>();
    for (EntityModel<StoragePool> a : model.getItems()) {
        if (a.getIsSelected()) {
            items.add(a.getEntity());
        }
    }
    if (items.size() == 0) {
        cancel();
        return;
    }
    setSelectedDataCentersForAttach(items);
    model.startProgress();
    if (getEntity().getStorageDomainType() == StorageDomainType.Data) {
        StoragePool dataCenter = items.get(0);
        ArrayList<StorageDomain> storageDomains = new ArrayList<>();
        storageDomains.add(getEntity());
        AsyncDataProvider.getInstance().getStorageDomainsWithAttachedStoragePoolGuid(new AsyncQuery<>(attachedStorageDomains -> {
            if (!attachedStorageDomains.isEmpty()) {
                ConfirmationModel confirmationModel = new ConfirmationModel();
                setWindow(null);
                setWindow(confirmationModel);
                List<String> stoageDomainNames = new ArrayList<>();
                for (StorageDomainStatic domain : attachedStorageDomains) {
                    stoageDomainNames.add(domain.getStorageName());
                }
                confirmationModel.setItems(stoageDomainNames);
                confirmationModel.setTitle(ConstantsManager.getInstance().getConstants().storageDomainsAttachedToDataCenterWarningTitle());
                confirmationModel.setMessage(ConstantsManager.getInstance().getConstants().storageDomainsAttachedToDataCenterWarningMessage());
                confirmationModel.setHelpTag(HelpTag.attach_storage_domain_confirmation);
                // $NON-NLS-1$
                confirmationModel.setHashName("attach_storage_domain_confirmation");
                confirmationModel.getLatch().setIsAvailable(true);
                confirmationModel.getLatch().setIsChangeable(true);
                // $NON-NLS-1$
                UICommand onApprove = new UICommand("OnAttachApprove", StorageDataCenterListModel.this);
                onApprove.setTitle(ConstantsManager.getInstance().getConstants().ok());
                onApprove.setIsDefault(true);
                confirmationModel.getCommands().add(onApprove);
                // $NON-NLS-1$
                UICommand cancel = new UICommand("Cancel", StorageDataCenterListModel.this);
                cancel.setTitle(ConstantsManager.getInstance().getConstants().cancel());
                cancel.setIsCancel(true);
                confirmationModel.getCommands().add(cancel);
            } else {
                executeAttachStorageDomains(model);
            }
        }), dataCenter, storageDomains);
    } else {
        executeAttachStorageDomains(model);
    }
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) LexoNumericComparator(org.ovirt.engine.core.common.businessentities.comparators.LexoNumericComparator) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) StorageDomainPoolParametersBase(org.ovirt.engine.core.common.action.StorageDomainPoolParametersBase) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) Model(org.ovirt.engine.ui.uicommonweb.models.Model) AttachStorageDomainToPoolParameters(org.ovirt.engine.core.common.action.AttachStorageDomainToPoolParameters) RemoveStorageDomainParameters(org.ovirt.engine.core.common.action.RemoveStorageDomainParameters) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) ActionUtils(org.ovirt.engine.core.common.ActionUtils) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) StorageDomainSharedStatus(org.ovirt.engine.core.common.businessentities.StorageDomainSharedStatus) List(java.util.List) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) Comparator(java.util.Comparator) Collections(java.util.Collections) DeactivateStorageDomainWithOvfUpdateParameters(org.ovirt.engine.core.common.action.DeactivateStorageDomainWithOvfUpdateParameters) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) DetachStorageDomainFromPoolParameters(org.ovirt.engine.core.common.action.DetachStorageDomainFromPoolParameters) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ArrayList(java.util.ArrayList) List(java.util.List) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 69 with EntityModel

use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.

the class QuotaUserListModel method onAdd.

public void onAdd() {
    AdElementListModel model = (AdElementListModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (model.getSelectedItems() == null && model.getSearchType() != AdSearchType.EVERYONE) {
        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());
            }
        }
    }
    model.startProgress();
    ArrayList<ActionParametersBase> list = new ArrayList<>();
    PermissionsOperationsParameters permissionParams;
    for (DbUser user : items) {
        Permission perm = new Permission(user.getId(), ApplicationGuids.quotaConsumer.asGuid(), getEntity().getId(), VdcObjectType.Quota);
        permissionParams = new PermissionsOperationsParameters();
        if (user.isGroup()) {
            DbGroup group = new DbGroup();
            group.setId(user.getId());
            group.setExternalId(user.getExternalId());
            group.setName(user.getFirstName());
            group.setDomain(user.getDomain());
            permissionParams.setGroup(group);
        } else {
            permissionParams.setUser(user);
        }
        permissionParams.setPermission(perm);
        list.add(permissionParams);
    }
    Frontend.getInstance().runMultipleAction(ActionType.AddPermission, list, result -> {
        QuotaUserListModel localModel = (QuotaUserListModel) result.getState();
        localModel.stopProgress();
        cancel();
    }, model);
    cancel();
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Permission(org.ovirt.engine.core.common.businessentities.Permission) AdElementListModel(org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 70 with EntityModel

use of org.ovirt.engine.ui.uicommonweb.models.EntityModel in project ovirt-engine by oVirt.

the class ExportRepoImageModel method executeCommand.

@Override
public void executeCommand(UICommand command) {
    super.executeCommand(command);
    startProgress();
    ArrayList<ActionParametersBase> actionParameters = new ArrayList<>();
    for (EntityModel entity : getEntities()) {
        actionParameters.add(new ExportRepoImageParameters(// Source
        ((DiskImage) entity.getEntity()).getId(), // Destination
        getStorageDomain().getSelectedItem().getId()));
    }
    Frontend.getInstance().runMultipleAction(ActionType.ExportRepoImage, actionParameters, result -> {
        ImportExportRepoImageBaseModel model = (ImportExportRepoImageBaseModel) result.getState();
        model.stopProgress();
        model.cancel();
    }, this);
}
Also used : ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ExportRepoImageParameters(org.ovirt.engine.core.common.action.ExportRepoImageParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Aggregations

EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)105 ArrayList (java.util.ArrayList)56 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)27 List (java.util.List)26 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)23 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)22 ListModel (org.ovirt.engine.ui.uicommonweb.models.ListModel)22 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)22 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)20 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)19 ActionType (org.ovirt.engine.core.common.action.ActionType)18 Frontend (org.ovirt.engine.ui.frontend.Frontend)18 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)17 Guid (org.ovirt.engine.core.compat.Guid)17 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)16 QueryType (org.ovirt.engine.core.common.queries.QueryType)16 NoSelectionModel (com.google.gwt.view.client.NoSelectionModel)13 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)13