Search in sources :

Example 1 with PerunAttributeFriendlyNameCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell in project perun by CESNET.

the class GetServiceRequiredAttributes method getTable.

/**
 * Returns table widget with required attributes for service
 *
 * @return table widget
 */
public CellTable<AttributeDefinition> getTable() {
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<AttributeDefinition>(list);
    // Cell table
    table = new PerunTable<AttributeDefinition>(list);
    // remove row count change handler
    table.removeRowCountChangeHandler();
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<AttributeDefinition> columnSortHandler = new ListHandler<AttributeDefinition>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<AttributeDefinition>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("Service has no required attribute.");
    // checkbox column column
    table.addCheckBoxColumn();
    // ID COLUMN
    table.addIdColumn("Attribute ID");
    // FRIENDLY NAME COLUMN
    final Column<AttributeDefinition, AttributeDefinition> friendlyNameColumn = JsonUtils.addColumn(new PerunAttributeFriendlyNameCell(), new JsonUtils.GetValue<AttributeDefinition, AttributeDefinition>() {

        public AttributeDefinition getValue(AttributeDefinition object) {
            return object;
        }
    }, null);
    /*
		// NAMESPACE COLUMN
		TextColumn<AttributeDefinition> namespaceColumn = new TextColumn<AttributeDefinition>() {
		public String getValue(AttributeDefinition attrDef) {
		return String.valueOf(attrDef.getNamespace());
		}
		};
		*/
    // ENTITY COLUMN
    TextColumn<AttributeDefinition> entityColumn = new TextColumn<AttributeDefinition>() {

        public String getValue(AttributeDefinition attrDef) {
            return attrDef.getEntity();
        }
    };
    // DEFINITION COLUMN
    TextColumn<AttributeDefinition> definitionColumn = new TextColumn<AttributeDefinition>() {

        public String getValue(AttributeDefinition attrDef) {
            return attrDef.getDefinition();
        }
    };
    // TYPE COLUMN
    TextColumn<AttributeDefinition> typeColumn = new TextColumn<AttributeDefinition>() {

        public String getValue(AttributeDefinition attrDef) {
            return String.valueOf(renameContent(attrDef.getType()));
        }
    };
    // SORTING
    /*
			 namespaceColumn.setSortable(true);
			 columnSortHandler.setComparator(namespaceColumn, new Comparator<AttributeDefinition>() {
			 public int compare(AttributeDefinition o1, AttributeDefinition o2) {
			 return o1.getNamespace().compareToIgnoreCase(o2.getNamespace());
			 }
			 });
			 */
    friendlyNameColumn.setSortable(true);
    columnSortHandler.setComparator(friendlyNameColumn, new Comparator<AttributeDefinition>() {

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

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

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
        }
    });
    typeColumn.setSortable(true);
    columnSortHandler.setComparator(typeColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getType().compareToIgnoreCase(o2.getType());
        }
    });
    table.setColumnWidth(friendlyNameColumn, 250.0, Unit.PX);
    table.setColumnWidth(entityColumn, 120.0, Unit.PX);
    table.setColumnWidth(definitionColumn, 120.0, Unit.PX);
    table.setColumnWidth(typeColumn, 120.0, Unit.PX);
    // Add the columns.
    table.addColumn(friendlyNameColumn, "Name");
    // attributesTable.addColumn(namespaceColumn, "Namespace");
    table.addColumn(entityColumn, "Entity");
    table.addColumn(definitionColumn, "Definition");
    table.addColumn(typeColumn, "Value type");
    table.addDescriptionColumn();
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) PerunAttributeFriendlyNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 2 with PerunAttributeFriendlyNameCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell in project perun by CESNET.

the class GetAttributesDefinition method getTable.

/**
 * Returns table widget with attributes definitions
 *
 * @return table widget
 */
public CellTable<AttributeDefinition> getTable() {
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<AttributeDefinition>(list);
    // Cell table
    table = new PerunTable<AttributeDefinition>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<AttributeDefinition> columnSortHandler = new ListHandler<AttributeDefinition>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<AttributeDefinition>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No attribute defined in Perun.");
    // checkbox column column
    if (checkable) {
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Attr ID", tableFieldUpdater, 100);
    // FRIENDLY NAME COLUMN
    final Column<AttributeDefinition, AttributeDefinition> friendlyNameColumn = JsonUtils.addColumn(new PerunAttributeFriendlyNameCell((tableFieldUpdater != null) ? "customClickableTextCell" : ""), new JsonUtils.GetValue<AttributeDefinition, AttributeDefinition>() {

        public AttributeDefinition getValue(AttributeDefinition object) {
            return object;
        }
    }, (tableFieldUpdater != null) ? new FieldUpdater<AttributeDefinition, AttributeDefinition>() {

        @Override
        public void update(int index, AttributeDefinition object, AttributeDefinition value) {
            // pass field updater to original one
            if (tableFieldUpdater != null)
                tableFieldUpdater.update(index, object, value.getFriendlyName());
        }
    } : null);
    // ENTITY COLUMN
    final Column<AttributeDefinition, String> entityColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {

        public String getValue(AttributeDefinition object) {
            return object.getEntity();
        }
    }, tableFieldUpdater);
    // DEFINITION COLUMN
    final Column<AttributeDefinition, String> definitionColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {

        public String getValue(AttributeDefinition object) {
            return object.getDefinition();
        }
    }, tableFieldUpdater);
    // TYPE COLUMN
    final Column<AttributeDefinition, String> typeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {

        public String getValue(AttributeDefinition object) {
            if (object.getType() != null) {
                return object.getType().substring(object.getType().lastIndexOf(".") + 1);
            }
            return "";
        }
    }, tableFieldUpdater);
    // UNIQUE COLUMN
    final Column<AttributeDefinition, String> uniqueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<AttributeDefinition, String>() {

        public String getValue(AttributeDefinition object) {
            return String.valueOf(object.isUnique());
        }
    }, tableFieldUpdater);
    // DESCRIPTION COLUMN
    final Column<AttributeDefinition, String> descriptionColumn = new Column<AttributeDefinition, String>(new TextInputCell()) {

        public String getValue(AttributeDefinition attrDef) {
            if (attrDef.getDescription() == null) {
                return "";
            } else {
                return attrDef.getDescription();
            }
        }
    };
    descriptionColumn.setFieldUpdater(new FieldUpdater<AttributeDefinition, String>() {

        @Override
        public void update(int i, final AttributeDefinition attributeDefinition, final String s) {
            attributeDefinition.setDescription(s.trim());
            selectionModel.setSelected(attributeDefinition, true);
        }
    });
    // DISPLAY NAME COLUMN
    final Column<AttributeDefinition, String> displayNameColumn = new Column<AttributeDefinition, String>(new TextInputCell()) {

        public String getValue(AttributeDefinition attrDef) {
            return attrDef.getDisplayName();
        }
    };
    displayNameColumn.setFieldUpdater(new FieldUpdater<AttributeDefinition, String>() {

        @Override
        public void update(int i, final AttributeDefinition attributeDefinition, final String s) {
            attributeDefinition.setDisplayName(s.trim());
            selectionModel.setSelected(attributeDefinition, true);
        }
    });
    friendlyNameColumn.setSortable(true);
    columnSortHandler.setComparator(friendlyNameColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
        }
    });
    entityColumn.setSortable(true);
    columnSortHandler.setComparator(entityColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getEntity().compareToIgnoreCase(o2.getEntity());
        }
    });
    definitionColumn.setSortable(true);
    columnSortHandler.setComparator(definitionColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
        }
    });
    typeColumn.setSortable(true);
    columnSortHandler.setComparator(typeColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return o1.getType().compareToIgnoreCase(o2.getType());
        }
    });
    uniqueColumn.setSortable(true);
    columnSortHandler.setComparator(uniqueColumn, new Comparator<AttributeDefinition>() {

        public int compare(AttributeDefinition o1, AttributeDefinition o2) {
            return String.valueOf(o1.isUnique()).compareToIgnoreCase(String.valueOf(o2.isUnique()));
        }
    });
    // Add the column sort handler.
    table.setColumnWidth(friendlyNameColumn, 250.0, Unit.PX);
    table.setColumnWidth(entityColumn, 100.0, Unit.PX);
    table.setColumnWidth(definitionColumn, 100.0, Unit.PX);
    table.setColumnWidth(typeColumn, 100.0, Unit.PX);
    table.setColumnWidth(uniqueColumn, 100.0, Unit.PX);
    // Add the columns.
    table.addColumn(friendlyNameColumn, "Name");
    // attributesTable.addColumn(namespaceColumn, "Namespace");
    table.addColumn(entityColumn, "Entity");
    table.addColumn(definitionColumn, "Definition");
    table.addColumn(typeColumn, "Type");
    table.addColumn(uniqueColumn, "Unique");
    if (editable) {
        table.addColumn(displayNameColumn, "Display name");
        table.addColumn(descriptionColumn, "Description");
    }
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) TextInputCell(com.google.gwt.cell.client.TextInputCell) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) PerunAttributeFriendlyNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell) Column(com.google.gwt.user.cellview.client.Column)

Aggregations

ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)2 PerunAttributeFriendlyNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 TextInputCell (com.google.gwt.cell.client.TextInputCell)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1