Search in sources :

Example 6 with SelectionTreeNodeModel

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

the class TagListModel method entityPropertyChanged.

@Override
protected void entityPropertyChanged(Object sender, PropertyChangedEventArgs e) {
    super.entityPropertyChanged(sender, e);
    if (e.propertyName.equals("IsSelectedNullable")) {
        // $NON-NLS-1$
        SelectionTreeNodeModel selectionTreeNodeModel = (SelectionTreeNodeModel) sender;
        TagModel tagModel = (TagModel) selectionTreeNodeModel.getEntity();
        tagModel.setSelection(selectionTreeNodeModel.getIsSelectedNullable());
        onTagSelectionChanged(tagModel, e);
    }
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)

Example 7 with SelectionTreeNodeModel

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

the class RoleListModel method onSave.

public void onSave() {
    RoleModel model = (RoleModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    role = commandType != CommandType.Edit ? new Role() : getSelectedItem();
    role.setType(model.getIsAdminRole().getEntity() ? RoleType.ADMIN : RoleType.USER);
    if (!model.validate()) {
        return;
    }
    role.setName(model.getName().getEntity());
    role.setDescription(model.getDescription().getEntity());
    ArrayList<ActionGroup> actions = new ArrayList<>();
    HashMap<ActionGroup, ActionGroup> actionDistinctSet = new HashMap<>();
    for (SelectionTreeNodeModel sm : model.getPermissionGroupModels()) {
        for (SelectionTreeNodeModel smChild : sm.getChildren()) {
            if (smChild.getIsSelectedNullable() == null || smChild.getIsSelectedNullable()) {
                for (SelectionTreeNodeModel smGrandChild : smChild.getChildren()) {
                    if (smGrandChild.getIsSelectedNullable()) {
                        ActionGroup actionGroup = ActionGroup.valueOf(smGrandChild.getTitle());
                        if (actionDistinctSet.containsKey(actionGroup)) {
                            continue;
                        }
                        actionDistinctSet.put(actionGroup, actionGroup);
                        actions.add(actionGroup);
                    }
                }
            }
        }
    }
    ActionReturnValue returnValue;
    model.startProgress();
    if (commandType != CommandType.Edit) {
        // Add a new role.
        RoleWithActionGroupsParameters tempVar = new RoleWithActionGroupsParameters();
        tempVar.setRole(role);
        tempVar.setActionGroups(actions);
        Frontend.getInstance().runAction(ActionType.AddRoleWithActionGroups, tempVar, result -> {
            RoleListModel localModel = (RoleListModel) result.getState();
            localModel.postOnSaveNew(result.getReturnValue());
        }, this);
    } else {
        detachActionGroup = new ArrayList<>(publicAttachedActions);
        detachActionGroup.removeAll(actions);
        attachActionGroup = actions;
        attachActionGroup.removeAll(publicAttachedActions);
        Frontend.getInstance().runAction(ActionType.UpdateRole, new RolesOperationsParameters(role), result -> {
            RoleListModel roleListModel = (RoleListModel) result.getState();
            ActionReturnValue retVal = result.getReturnValue();
            if (retVal != null && retVal.getSucceeded()) {
                if (roleListModel.detachActionGroup.size() > 0) {
                    ActionGroupsToRoleParameter tempVar2 = new ActionGroupsToRoleParameter();
                    tempVar2.setActionGroups(roleListModel.detachActionGroup);
                    tempVar2.setRoleId(roleListModel.role.getId());
                    Frontend.getInstance().runAction(ActionType.DetachActionGroupsFromRole, tempVar2);
                }
                if (roleListModel.attachActionGroup.size() > 0) {
                    ActionGroupsToRoleParameter tempVar3 = new ActionGroupsToRoleParameter();
                    tempVar3.setActionGroups(roleListModel.attachActionGroup);
                    tempVar3.setRoleId(roleListModel.role.getId());
                    Frontend.getInstance().runAction(ActionType.AttachActionGroupsToRole, tempVar3);
                }
                roleListModel.getWindow().stopProgress();
                roleListModel.cancel();
            } else {
                roleListModel.getWindow().stopProgress();
            }
        }, this);
    }
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) ActionGroupsToRoleParameter(org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) RoleWithActionGroupsParameters(org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters) RolesOperationsParameters(org.ovirt.engine.core.common.action.RolesOperationsParameters)

Example 8 with SelectionTreeNodeModel

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

the class RoleTreeView method createLeafSelectionTreeNodeModel.

protected static SelectionTreeNodeModel createLeafSelectionTreeNodeModel(boolean isReadOnly, RoleNode third) {
    SelectionTreeNodeModel thirdNode;
    thirdNode = createSelectionTreeNodeModel(isReadOnly, third);
    thirdNode.setIsSelectedNotificationPrevent(true);
    thirdNode.setIsSelectedNullable(false);
    thirdNode.setTooltip(third.getTooltip());
    return thirdNode;
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)

Example 9 with SelectionTreeNodeModel

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

the class UserEventNotifierListModel method onSave.

public void onSave() {
    EventNotificationModel model = (EventNotificationModel) getWindow();
    if (!model.validate()) {
        return;
    }
    ArrayList<ActionParametersBase> toAddList = new ArrayList<>();
    ArrayList<ActionParametersBase> toRemoveList = new ArrayList<>();
    // var selected = model.EventGroupModels.SelectMany(a => a.Children).Where(a => a.IsSelected == true);
    ArrayList<SelectionTreeNodeModel> selected = new ArrayList<>();
    for (SelectionTreeNodeModel node : model.getEventGroupModels()) {
        for (SelectionTreeNodeModel child : node.getChildren()) {
            if (child.getIsSelectedNullable() != null && child.getIsSelectedNullable().equals(true)) {
                selected.add(child);
            }
        }
    }
    Collection<EventSubscriber> existing = getItems() != null ? getItems() : new ArrayList<EventSubscriber>();
    ArrayList<SelectionTreeNodeModel> added = new ArrayList<>();
    ArrayList<EventSubscriber> removed = new ArrayList<>();
    // check what has been added:
    for (SelectionTreeNodeModel selectedEvent : selected) {
        boolean selectedInExisting = false;
        for (EventSubscriber existingEvent : existing) {
            if (selectedEvent.getTitle().equals(existingEvent.getEventUpName())) {
                selectedInExisting = true;
                break;
            }
        }
        if (!selectedInExisting) {
            added.add(selectedEvent);
        }
    }
    // check what has been deleted:
    for (EventSubscriber existingEvent : existing) {
        boolean existingInSelected = false;
        for (SelectionTreeNodeModel selectedEvent : selected) {
            if (selectedEvent.getTitle().equals(existingEvent.getEventUpName())) {
                existingInSelected = true;
                break;
            }
        }
        if (!existingInSelected) {
            removed.add(existingEvent);
        }
    }
    if (!StringHelper.isNullOrEmpty(model.getOldEmail()) && !model.getOldEmail().equals(model.getEmail().getEntity())) {
        for (EventSubscriber a : existing) {
            toRemoveList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getEventUpName(), EventNotificationMethod.SMTP, a.getMethodAddress(), a.getSubscriberId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
        for (SelectionTreeNodeModel a : selected) {
            toAddList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getTitle(), EventNotificationMethod.SMTP, model.getEmail().getEntity(), getEntity().getId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
    } else {
        for (SelectionTreeNodeModel a : added) {
            toAddList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getTitle(), EventNotificationMethod.SMTP, model.getEmail().getEntity(), getEntity().getId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
        for (EventSubscriber a : removed) {
            toRemoveList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getEventUpName(), EventNotificationMethod.SMTP, a.getMethodAddress(), a.getSubscriberId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
    }
    if (toRemoveList.size() > 0) {
        EventSubscriptionFrontendActionAsyncCallback callback = new EventSubscriptionFrontendActionAsyncCallback(toAddList, toRemoveList);
        for (ActionParametersBase param : toRemoveList) {
            Frontend.getInstance().runAction(ActionType.RemoveEventSubscription, param, callback);
        }
    } else if (toAddList.size() > 0) {
        Frontend.getInstance().runMultipleAction(ActionType.AddEventSubscription, toAddList);
    }
    cancel();
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) EventSubscriptionParametesBase(org.ovirt.engine.core.common.action.EventSubscriptionParametesBase) EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 10 with SelectionTreeNodeModel

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

the class UserEventNotifierListModel method manageEvents.

public void manageEvents() {
    EventNotificationModel model = new EventNotificationModel();
    setWindow(model);
    model.setTitle(ConstantsManager.getInstance().getConstants().addEventNotificationTitle());
    model.setHelpTag(HelpTag.add_event_notification);
    // $NON-NLS-1$
    model.setHashName("add_event_notification");
    ArrayList<EventNotificationEntity> eventTypes = ApplicationModeHelper.getModeSpecificEventNotificationTypeList();
    Map<EventNotificationEntity, HashSet<AuditLogType>> availableEvents = AsyncDataProvider.getInstance().getAvailableNotificationEvents();
    Translator translator = EnumTranslator.getInstance();
    ArrayList<SelectionTreeNodeModel> list = new ArrayList<>();
    Collection<EventSubscriber> items = getItems() == null ? new ArrayList<EventSubscriber>() : getItems();
    for (EventNotificationEntity eventType : eventTypes) {
        SelectionTreeNodeModel stnm = new SelectionTreeNodeModel();
        stnm.setTitle(eventType.toString());
        stnm.setDescription(translator.translate(eventType));
        list.add(stnm);
        for (AuditLogType logtype : availableEvents.get(eventType)) {
            SelectionTreeNodeModel eventGrp = new SelectionTreeNodeModel();
            String description;
            try {
                description = translator.translate(logtype);
            } catch (MissingResourceException e) {
                description = logtype.toString();
            }
            eventGrp.setTitle(logtype.toString());
            eventGrp.setDescription(description);
            eventGrp.setParent(list.get(list.size() - 1));
            eventGrp.setIsSelectedNotificationPrevent(true);
            eventGrp.setIsSelectedNullable(false);
            for (EventSubscriber es : items) {
                if (es.getEventUpName().equals(logtype.toString())) {
                    eventGrp.setIsSelectedNullable(true);
                    break;
                }
            }
            list.get(list.size() - 1).getChildren().add(eventGrp);
            eventGrp.setIsSelectedNotificationPrevent(false);
        }
        if (list.get(list.size() - 1).getChildren().size() > 0) {
            list.get(list.size() - 1).getChildren().get(0).updateParentSelection();
        }
    }
    model.setEventGroupModels(list);
    if (!StringHelper.isNullOrEmpty(getEntity().getEmail())) {
        model.getEmail().setEntity(getEntity().getEmail());
    } else if (items.size() > 0) {
        model.getEmail().setEntity(items.iterator().next().getMethodAddress());
    }
    model.setOldEmail(model.getEmail().getEntity());
    // $NON-NLS-1$
    UICommand tempVar = UICommand.createDefaultOkUiCommand("OnSave", this);
    model.getCommands().add(tempVar);
    // $NON-NLS-1$
    UICommand tempVar2 = UICommand.createCancelUiCommand("Cancel", this);
    model.getCommands().add(tempVar2);
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) AuditLogType(org.ovirt.engine.core.common.AuditLogType) EventNotificationEntity(org.ovirt.engine.core.common.EventNotificationEntity) MissingResourceException(java.util.MissingResourceException) ArrayList(java.util.ArrayList) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) Translator(org.ovirt.engine.ui.uicompat.Translator) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) HashSet(java.util.HashSet)

Aggregations

SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)10 ArrayList (java.util.ArrayList)4 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)2 EventSubscriber (org.ovirt.engine.core.common.businessentities.EventSubscriber)2 Role (org.ovirt.engine.core.common.businessentities.Role)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 MissingResourceException (java.util.MissingResourceException)1 AuditLogType (org.ovirt.engine.core.common.AuditLogType)1 EventNotificationEntity (org.ovirt.engine.core.common.EventNotificationEntity)1 ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 EventSubscriptionParametesBase (org.ovirt.engine.core.common.action.EventSubscriptionParametesBase)1 RoleWithActionGroupsParameters (org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters)1 RolesOperationsParameters (org.ovirt.engine.core.common.action.RolesOperationsParameters)1 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)1 EnumTranslator (org.ovirt.engine.ui.uicompat.EnumTranslator)1 Translator (org.ovirt.engine.ui.uicompat.Translator)1