Search in sources :

Example 11 with CheckboxCell

use of com.google.gwt.cell.client.CheckboxCell in project perun by CESNET.

the class GetAttributes 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);
    if (checkable) {
        // 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);
    }
    // Create ID column.
    table.addIdColumn("Attribute ID", this.tableFieldUpdater);
    // 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 a) {
            return a.getEntity();
        }
    }, this.tableFieldUpdater);
    // Create def type column
    Column<Attribute, String> defTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute a) {
            return a.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);
    Column<Attribute, String> valueColumn;
    if (editable) {
        valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

            public String getValue(Attribute attribute) {
                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);
                }
            }
        });
    } else {
        valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

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

        public String getValue(Attribute attribute) {
            return attribute.getDescription();
        }
    }, this.tableFieldUpdater);
    // 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 description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(descriptionColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getDescription().compareToIgnoreCase(o2.getDescription());
        }
    });
    // 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());
        }
    });
    // column size
    this.table.setColumnWidth(typeColumn, 120.0, Unit.PX);
    this.table.setColumnWidth(entityColumn, 100.0, Unit.PX);
    this.table.setColumnWidth(defTypeColumn, 110.0, Unit.PX);
    this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);
    this.table.setColumnWidth(valueColumn, 200.0, Unit.PX);
    // Add the columns.
    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.addColumn(descriptionColumn, "Description");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) 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 12 with CheckboxCell

use of com.google.gwt.cell.client.CheckboxCell in project perun by CESNET.

the class GetAttributesV2 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);
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No settings found. Use 'Add' button to add new setting.");
    // because of tab index
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // checkbox column
    if (checkable) {
        // 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 selection
        table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Attribute>createCheckboxManager(0));
        table.addColumn(checkBoxColumn, checkBoxHeader);
    }
    // Create ID column.
    table.addIdColumn("Attr ID", null, 90);
    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());
    // Description column
    Column<Attribute, Attribute> descriptionColumn = JsonUtils.addColumn(new PerunAttributeDescriptionCell());
    // Value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell());
    valueColumn.setFieldUpdater(new FieldUpdater<Attribute, Attribute>() {

        public void update(int index, Attribute object, Attribute value) {
            object = value;
            selectionModel.setSelected(object, object.isAttributeValid());
        }
    });
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));
    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(descriptionColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));
    // Add sorting
    this.table.addColumnSortHandler(columnSortHandler);
    // updates the columns size
    this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);
    // Add the columns.
    this.table.addColumn(nameColumn, "Name");
    this.table.addColumn(valueColumn, "Value");
    this.table.addColumn(descriptionColumn, "Description");
    return this.table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) Attribute(cz.metacentrum.perun.webgui.model.Attribute) PerunAttributeNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell) PerunAttributeDescriptionCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell) 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 13 with CheckboxCell

use of com.google.gwt.cell.client.CheckboxCell in project perun by CESNET.

the class GetUserExtSources method getTable.

/**
	 * Return table with checkboxes containing user external sources
	 *
	 * @return table containing user ext sources
	 */
public CellTable<UserExtSource> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<UserExtSource>(list);
    // Cell table
    table = new PerunTable<UserExtSource>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<UserExtSource> columnSortHandler = new ListHandler<UserExtSource>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<UserExtSource>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // checkbox column column
    com.google.gwt.user.cellview.client.Column<UserExtSource, UserExtSource> checkBoxColumn = new com.google.gwt.user.cellview.client.Column<UserExtSource, UserExtSource>(new PerunCheckboxCell<UserExtSource>(true, false, false)) {

        @Override
        public UserExtSource getValue(UserExtSource 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, Style.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 (UserExtSource obj : list) {
                if (!obj.isPersistent()) {
                    selectionModel.setSelected(obj, value);
                }
            }
        }
    });
    table.addColumn(checkBoxColumn, checkBoxHeader);
    table.addIdColumn("UES ID", tableFieldUpdater, 100);
    // Name column
    Column<UserExtSource, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            return String.valueOf(extSource.getExtSource().getName());
        }
    }, tableFieldUpdater);
    // Login column
    Column<UserExtSource, String> loginColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            return String.valueOf(extSource.getLogin());
        }
    }, tableFieldUpdater);
    // LOA column
    Column<UserExtSource, String> loaColumn = JsonUtils.addColumn(new JsonUtils.GetValue<UserExtSource, String>() {

        public String getValue(UserExtSource extSource) {
            return String.valueOf(extSource.getLoa());
        }
    }, tableFieldUpdater);
    // sort name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new GeneralComparator<UserExtSource>(GeneralComparator.Column.NAME));
    // sort login column
    loginColumn.setSortable(true);
    columnSortHandler.setComparator(loginColumn, new Comparator<UserExtSource>() {

        public int compare(UserExtSource o1, UserExtSource o2) {
            return o1.getLogin().compareTo(o2.getLogin());
        }
    });
    // sort login column
    loaColumn.setSortable(true);
    columnSortHandler.setComparator(loaColumn, new Comparator<UserExtSource>() {

        public int compare(UserExtSource o1, UserExtSource o2) {
            return o1.getLoa() - o2.getLoa();
        }
    });
    table.addColumn(nameColumn, "External source name");
    table.addColumn(loginColumn, "ID in external source");
    table.addColumn(loaColumn, "Level of assurance");
    return table;
}
Also used : 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) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Header(com.google.gwt.user.cellview.client.Header) UserExtSource(cz.metacentrum.perun.webgui.model.UserExtSource)

Example 14 with CheckboxCell

use of com.google.gwt.cell.client.CheckboxCell 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 15 with CheckboxCell

use of com.google.gwt.cell.client.CheckboxCell in project perun by CESNET.

the class TestDataGridAttributesTabItem method draw.

public Widget draw() {
    //contentWidget.setSize("100%", "100%");
    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);
    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");
    final ArrayList<Attribute> vosList = new ArrayList<Attribute>();
    final GetAttributesV2 getVos = new GetAttributesV2(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosList.addAll(new TableSorter<Attribute>().sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
            gridTable.setRowData(vosList);
            gridTable.redraw();
        }
    });
    getVos.getUserAttributes(3411);
    getVos.retrieveData();
    gridTable.setSelectionModel(new MultiSelectionModel<Attribute>(new GeneralKeyProvider<Attribute>()));
    final SelectionModel<Attribute> selectionModel = gridTable.getSelectionModel();
    gridTable.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    Column<Attribute, Boolean> checkBoxColumn = new Column<Attribute, Boolean>(new CheckboxCell(true, true)) {

        @Override
        public Boolean getValue(Attribute object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkBoxColumn.setFieldUpdater(new FieldUpdater<Attribute, Boolean>() {

        @Override
        public void update(int i, Attribute Attribute, Boolean aBoolean) {
            selectionModel.setSelected(Attribute, aBoolean);
        }
    });
    // 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 : vosList) {
                selectionModel.setSelected(obj, value);
            }
        }
    });
    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    TextColumn<Attribute> idColumn = new TextColumn<Attribute>() {

        @Override
        public String getValue(Attribute object) {
            return String.valueOf(object.getId());
        }
    };
    if (JsonUtils.isExtendedInfoVisible()) {
        gridTable.addColumn(idColumn, "Id", "Id");
        gridTable.setColumnWidth(idColumn, "90px");
    }
    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());
    // Description column
    Column<Attribute, Attribute> descriptionColumn = JsonUtils.addColumn(new PerunAttributeDescriptionCell());
    // Value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), new FieldUpdater<Attribute, Attribute>() {

        public void update(int index, Attribute object, Attribute value) {
            object = value;
            selectionModel.setSelected(object, object.isAttributeValid());
        }
    });
    ColumnSortEvent.ListHandler<Attribute> columnSortHandler = new ColumnSortEvent.ListHandler<Attribute>(vosList);
    gridTable.addColumnSortHandler(columnSortHandler);
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));
    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(descriptionColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));
    // Add sorting
    gridTable.addColumnSortHandler(columnSortHandler);
    // updates the columns size
    gridTable.setColumnWidth(nameColumn, 200.0, Style.Unit.PX);
    gridTable.setColumnWidth(valueColumn, 420.0, Style.Unit.PX);
    gridTable.addColumn(nameColumn, "Name");
    gridTable.addColumn(valueColumn, "Value");
    gridTable.addColumn(descriptionColumn, "Description");
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new TestDataGridTabItem(), true);
        }
    }));
    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) GeneralKeyProvider(cz.metacentrum.perun.webgui.json.keyproviders.GeneralKeyProvider) PerunAttributeNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) PerunAttributeDescriptionCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) DockLayoutPanel(com.google.gwt.user.client.ui.DockLayoutPanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

CheckboxCell (com.google.gwt.cell.client.CheckboxCell)20 Column (com.google.gwt.user.cellview.client.Column)18 Header (com.google.gwt.user.cellview.client.Header)15 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)14 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)13 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)8 Attribute (cz.metacentrum.perun.webgui.model.Attribute)7 Group (cz.metacentrum.perun.webgui.model.Group)4 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)4 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)4 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)4 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)2 TextColumn (com.google.gwt.user.cellview.client.TextColumn)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 IsClickableCell (cz.metacentrum.perun.webgui.json.columnProviders.IsClickableCell)2 MemberColumnProvider (cz.metacentrum.perun.webgui.json.columnProviders.MemberColumnProvider)2 GeneralKeyProvider (cz.metacentrum.perun.webgui.json.keyproviders.GeneralKeyProvider)2