Search in sources :

Example 16 with GeneralObject

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

the class PerunTable method addIdColumn.

/**
	 * Adds the default ID column to the table
	 *
	 * @param title Use the element name width ID: VO ID, Attribute ID, ...
	 * @param tableFieldUpdater
	 * @param width Width of the column in PX
	 */
public void addIdColumn(String title, FieldUpdater<T, String> tableFieldUpdater, int width) {
    // if not to show
    if (!JsonUtils.isExtendedInfoVisible()) {
        return;
    }
    if (tableFieldUpdater == null) {
        TextColumn<T> idColumn = new TextColumn<T>() {

            @Override
            public String getValue(T obj) {
                GeneralObject go = obj.cast();
                return String.valueOf(go.getId());
            }
        };
        // sort type column
        idColumn.setSortable(true);
        this.columnSortHandler.setComparator(idColumn, new GeneralComparator<T>(GeneralComparator.Column.ID));
        // adding columns
        this.addColumn(idColumn, title);
        // custom width
        this.setColumnWidth(idColumn, width, Unit.PX);
        return;
    }
    /* CLICKABLE */
    if (hyperlinksAllowed) {
        Column<T, T> idColumn = JsonUtils.addCustomCellColumn(new HyperlinkCell<T>("id"), tableFieldUpdater);
        idColumn.setSortable(true);
        // adding columns
        this.addColumn(idColumn, title);
        // comparator
        this.columnSortHandler.setComparator(idColumn, new GeneralComparator<T>(GeneralComparator.Column.ID));
        // custom width
        this.setColumnWidth(idColumn, width, Unit.PX);
        return;
    }
    // hyperlinks not allowed
    Column<T, String> idColumn = JsonUtils.addColumn(new JsonUtils.GetValue<T, String>() {

        public String getValue(T object) {
            GeneralObject go = object.cast();
            return String.valueOf(go.getId());
        }
    }, tableFieldUpdater);
    idColumn.setSortable(true);
    // adding columns
    this.addColumn(idColumn, title);
    // comparator
    this.columnSortHandler.setComparator(idColumn, new GeneralComparator<T>(GeneralComparator.Column.ID));
    // custom width
    this.setColumnWidth(idColumn, width, Unit.PX);
}
Also used : JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 17 with GeneralObject

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

the class AddRemoveItemsTable method buildWidget.

/**
	 * Rebuild widget GUI
	 */
private void buildWidget() {
    FlexTable ft = new FlexTable();
    ft.setStyleName("perun-table");
    widget.clear();
    widget.add(ft);
    if (list.isEmpty()) {
        ft.setHTML(0, 0, "<strong>No items found.</strong>");
        ft.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
    }
    int row = 0;
    int column = 0;
    for (final T object : list) {
        GeneralObject go = object.cast();
        String name = "";
        if ("User".equalsIgnoreCase(go.getObjectType())) {
            User u = go.cast();
            name = u.getFullNameWithTitles();
        } else if ("RichUser".equalsIgnoreCase(go.getObjectType())) {
            User u = go.cast();
            name = u.getFullNameWithTitles();
        } else if ("RichMember".equalsIgnoreCase(go.getObjectType())) {
            RichMember m = go.cast();
            name = m.getUser().getFullNameWithTitles();
        } else {
            name = ((GeneralObject) object).getName();
        }
        CustomButton rb = new CustomButton("", "Remove item", SmallIcons.INSTANCE.deleteIcon());
        rb.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent clickEvent) {
                removeItem(object);
            }
        });
        if (vertical) {
            ft.setHTML(row, 0, name);
            ft.setWidget(row, 1, rb);
            row++;
        } else {
            ft.setHTML(row, column, name);
            ft.setWidget(row, column + 1, rb);
            column = column + 2;
        }
    }
    widget.setSize("100%", "100%");
    widget.setStyleName("perun-tableScrollPanel", true);
    UiElements.runResizeCommands(true);
}
Also used : User(cz.metacentrum.perun.webgui.model.User) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) RichMember(cz.metacentrum.perun.webgui.model.RichMember)

Example 18 with GeneralObject

use of cz.metacentrum.perun.webgui.model.GeneralObject 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 19 with GeneralObject

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

the class GeneralComparator method compare.

/**
	 * Compares the two objects
	 *
	 * @param obj1 First object
	 * @param obj2 Second object
	 */
public int compare(T obj1, T obj2) {
    GeneralObject o1 = obj1.cast();
    GeneralObject o2 = obj2.cast();
    switch(this.attr) {
        case ID:
            return this.compareById(o1, o2);
        case NAME:
            return this.compareByName(o1, o2);
        case DESCRIPTION:
            return this.compareByDescription(o1, o2);
        case STATUS:
            return this.compareByStatus(o1, o2);
    }
    return 0;
}
Also used : GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 20 with GeneralObject

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

the class UrlMapper method getUrlFromList.

/**
	 * Returns a URL from the list of perun entities
	 *
	 * @param paramName
	 * @param list
	 * @return
	 */
public static <T extends JavaScriptObject> String getUrlFromList(String paramName, ArrayList<T> list) {
    String url = "";
    int i = 0;
    for (T obj : list) {
        GeneralObject go = obj.cast();
        url += paramName + "[" + i + "]=" + go.getId() + "&";
        i++;
    }
    return url.substring(0, url.length() - 1);
}
Also used : GWT(com.google.gwt.core.client.GWT) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Aggregations

GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)22 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)11 Column (com.google.gwt.user.cellview.client.Column)10 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)8 Header (com.google.gwt.user.cellview.client.Header)8 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)8 Attribute (cz.metacentrum.perun.webgui.model.Attribute)7 VoColumnProvider (cz.metacentrum.perun.webgui.json.columnProviders.VoColumnProvider)4 VirtualOrganization (cz.metacentrum.perun.webgui.model.VirtualOrganization)4 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)3 JsonUtils (cz.metacentrum.perun.webgui.json.JsonUtils)3 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)3 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)3 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Group (cz.metacentrum.perun.webgui.model.Group)2 RichMember (cz.metacentrum.perun.webgui.model.RichMember)2 User (cz.metacentrum.perun.webgui.model.User)2 GWT (com.google.gwt.core.client.GWT)1