Search in sources :

Example 46 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class PerunAttributeTableWidget method save.

/**
	 * Saves the attributes
	 * If attribute with value null, asks if remove it
	 * Called recursively
	 *
	 * @param attrs
	 */
private void save(final ArrayList<Attribute> attrs) {
    // call the method
    if (saveEvent == null) {
        // ids must be set
        if (ids == null || ids.isEmpty())
            return;
        final ArrayList<Attribute> toSet = new ArrayList<Attribute>();
        final ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
        for (Attribute a : attrs) {
            Object oldValue = originalAttributes.get(a.getId());
            if (a.getValue().equals(oldValue)) {
            // do not save not changed
            } else if (a.getValueAsObject() == null) {
                toRemove.add(a);
            } else {
                toSet.add(a);
            }
        }
        if (!toSet.isEmpty()) {
            SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // for all attributes to be saved/removed
                    for (Attribute a : toSet) {
                        originalAttributes.put(a.getId(), a.getValueAsObject());
                    }
                }
            }));
            request.setAttributes(ids, toSet);
        }
        if (!toRemove.isEmpty()) {
            RemoveAttributes request2 = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // for all attributes to be saved/removed
                    for (Attribute a : toRemove) {
                        originalAttributes.put(a.getId(), a.getValueAsObject());
                    }
                }
            }));
            request2.removeAttributes(ids, toRemove);
        }
        if (toSet.isEmpty() && toRemove.isEmpty()) {
            UiElements.generateAlert("No changes", "No changes to save.");
        }
        return;
    }
    saveEvent.save(attrs);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 47 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class PreferredUnixGroupNameWidget method getAttribute.

public Attribute getAttribute(String urn) {
    // for each find
    for (Map.Entry<Attribute, PerunAttributeValueCell> entry : cells.entrySet()) {
        Attribute attrOld = entry.getKey();
        if (attrOld.getName().equals(urn)) {
            PerunAttributeValueCell valueCell = entry.getValue();
            // save the value
            Attribute attr = valueCell.getValue(attrOld);
            return attr;
        }
    }
    return null;
}
Also used : PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) Attribute(cz.metacentrum.perun.webgui.model.Attribute) Map(java.util.Map) HashMap(java.util.HashMap)

Example 48 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class GetRequiredAttributesV2 method onFinished.

/**
	 * Called, when operation finishes successfully.
	 */
public void onFinished(JavaScriptObject jso) {
    clearTable();
    for (Attribute a : JsonUtils.<Attribute>jsoAsList(jso)) {
        if (!a.getDefinition().equals("core")) {
            addToTable(a);
        }
    }
    sortTable();
    session.getUiElements().setLogText("Required attributes loaded: " + list.size());
    events.onFinished(jso);
    loaderImage.loadingFinished();
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 49 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class GetResourceRequiredAttributes method getEmptyTable.

/**
	 * Returns empty table widget with attributes
	 *
	 * @return table widget
	 */
public CellTable<Attribute> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Attribute>(list);
    // Cell table
    table = new PerunTable<Attribute>(list);
    // remove row count change handler
    table.removeRowCountChangeHandler();
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Attribute> columnSortHandler = new ListHandler<Attribute>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Attribute>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // because of tabindex
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // Name column
    Column<Attribute, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return attribute.getFriendlyName();
        }
    }, this.tableFieldUpdater);
    // Create ENTITY column
    Column<Attribute, String> entityColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute g) {
            return g.getEntity();
        }
    }, this.tableFieldUpdater);
    // Create def type column
    Column<Attribute, String> defTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute g) {
            return g.getDefinition();
        }
    }, this.tableFieldUpdater);
    // Create type column.
    Column<Attribute, String> typeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return renameContent(attribute.getType());
        }
    }, this.tableFieldUpdater);
    // Create value column.
    Column<Attribute, String> valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            if (attribute.getValue() == null)
                return "";
            return attribute.getValue();
        }
    }, new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String newText) {
            if (object.setValue(newText)) {
                selectionModel.setSelected(object, true);
            } else {
                selectionModel.setSelected(object, false);
                UiElements.cantSaveAttributeValueDialogBox(object);
            }
        }
    });
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
        }
    });
    // Sorting type column
    typeColumn.setSortable(true);
    columnSortHandler.setComparator(typeColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getType().compareToIgnoreCase(o2.getType());
        }
    });
    // Sorting value column
    valueColumn.setSortable(true);
    columnSortHandler.setComparator(valueColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getValue().compareToIgnoreCase(o2.getValue());
        }
    });
    // Sorting value column
    entityColumn.setSortable(true);
    columnSortHandler.setComparator(entityColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getEntity().compareToIgnoreCase(o2.getEntity());
        }
    });
    // Sorting value column
    defTypeColumn.setSortable(true);
    columnSortHandler.setComparator(defTypeColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
        }
    });
    // Add the columns.
    this.table.addColumnSortHandler(columnSortHandler);
    // updates the columns size
    this.table.setColumnWidth(entityColumn, 100.0, Unit.PX);
    this.table.setColumnWidth(defTypeColumn, 110.0, Unit.PX);
    this.table.setColumnWidth(typeColumn, 100.0, Unit.PX);
    this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);
    this.table.setColumnWidth(valueColumn, 200.0, Unit.PX);
    // Add the columns.
    // checkbox column column
    Column<Attribute, Attribute> checkBoxColumn = new Column<Attribute, Attribute>(new PerunCheckboxCell<Attribute>(true, false, false)) {

        @Override
        public Attribute getValue(Attribute object) {
            // Get the value from the selection model.
            GeneralObject go = object.cast();
            go.setChecked(selectionModel.isSelected(object));
            return go.cast();
        }
    };
    // updates the columns size
    table.setColumnWidth(checkBoxColumn, 40.0, Unit.PX);
    // Add the columns
    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {

        public Boolean getValue() {
            //return true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Attribute obj : list) {
                if (obj.isWritable()) {
                    selectionModel.setSelected(obj, value);
                }
            }
        }
    });
    table.addColumn(checkBoxColumn, checkBoxHeader);
    this.table.addIdColumn("Attribute ID");
    this.table.addColumn(nameColumn, "Name");
    this.table.addColumn(entityColumn, "Entity");
    this.table.addColumn(defTypeColumn, "Definition");
    this.table.addColumn(typeColumn, "Value type");
    this.table.addColumn(valueColumn, "Value");
    this.table.addDescriptionColumn();
    return this.table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Attribute(cz.metacentrum.perun.webgui.model.Attribute) Header(com.google.gwt.user.cellview.client.Header) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 50 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class GetRichAdminsWithAttributes method getTable.

/**
	 * Returns the table with member-users
	 *
	 * @return CellTable widget
	 */
public CellTable<User> getTable() {
    // Retrieves data
    this.retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<User>(list);
    // Cell table
    table = new PerunTable<User>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    if (entity.equals(PerunEntity.VIRTUAL_ORGANIZATION)) {
        loaderImage.setEmptyResultMessage("VO has no managers (try to switch to 'Groups' view).");
    } else if (entity.equals(PerunEntity.GROUP)) {
        loaderImage.setEmptyResultMessage("Group has no managers (try to switch to 'Groups' view).");
    } else if (entity.equals(PerunEntity.FACILITY)) {
        loaderImage.setEmptyResultMessage("Facility has no managers (try to switch to 'Groups' view).");
    } else if (entity.equals(PerunEntity.SECURITY_TEAM)) {
        loaderImage.setEmptyResultMessage("SecurityTeam has no members (try to switch to 'Groups' view).");
    }
    // Sorting
    ListHandler<User> columnSortHandler = new ListHandler<User>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // Table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<User>createCheckboxManager());
    // Set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // Checkbox column column
    if (checkable) {
        table.addCheckBoxColumn();
    }
    // Create User ID column.
    Column<User, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            return String.valueOf(object.getId());
        }
    }, this.tableFieldUpdater);
    userIdColumn.setSortable(true);
    columnSortHandler.setComparator(userIdColumn, new GeneralComparator<User>(GeneralComparator.Column.ID));
    table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
    if (JsonUtils.isExtendedInfoVisible()) {
        table.addColumn(userIdColumn, "User ID");
    }
    table.setHyperlinksAllowed(false);
    table.addNameColumn(tableFieldUpdater);
    // Create organization column.
    Column<User, String> organizationColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:organization");
            if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
                return at.getValue();
            }
            return "";
        }
    }, this.tableFieldUpdater);
    // Create e-mail column.
    Column<User, String> emailColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            Attribute at = object.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
            if (at != null && at.getValue() != null && !"null".equalsIgnoreCase(at.getValue())) {
                return at.getValue().replace(",", " ");
            }
            return "";
        }
    }, this.tableFieldUpdater);
    // Create name column.
    Column<User, String> loginsColumn = JsonUtils.addColumn(new JsonUtils.GetValue<User, String>() {

        public String getValue(User object) {
            return object.getLogins();
        }
    }, this.tableFieldUpdater);
    organizationColumn.setSortable(true);
    columnSortHandler.setComparator(organizationColumn, new RichUserComparator(RichUserComparator.Column.ORGANIZATION));
    emailColumn.setSortable(true);
    columnSortHandler.setComparator(emailColumn, new RichUserComparator(RichUserComparator.Column.EMAIL));
    // Add the other columns.
    table.addColumn(organizationColumn, "Organization");
    table.addColumn(emailColumn, "E-mail");
    table.addColumn(loginsColumn, "Logins");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) User(cz.metacentrum.perun.webgui.model.User) RichUserComparator(cz.metacentrum.perun.webgui.json.comparators.RichUserComparator) Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Aggregations

Attribute (cz.metacentrum.perun.webgui.model.Attribute)58 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)17 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)16 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)16 ArrayList (java.util.ArrayList)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)15 HashMap (java.util.HashMap)14 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)12 PerunError (cz.metacentrum.perun.webgui.model.PerunError)10 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)9 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)9 Map (java.util.Map)9 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)7 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)7 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)7 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)7 Column (com.google.gwt.user.cellview.client.Column)6