Search in sources :

Example 6 with Column

use of com.google.gwt.user.cellview.client.Column in project rstudio by rstudio.

the class ModifyKeyboardShortcutsWidget method editableTextColumn.

private Column<KeyboardShortcutEntry, String> editableTextColumn(String name, final ValueGetter<KeyboardShortcutEntry> getter) {
    EditTextCell editTextCell = new EditTextCell() {

        @Override
        public void onBrowserEvent(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> updater) {
            // handler.
            if (event.getType().equals("keyup") && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                parent.getFirstChildElement().blur();
                return;
            }
            super.onBrowserEvent(context, parent, value, event, updater);
        }
    };
    Column<KeyboardShortcutEntry, String> column = new Column<KeyboardShortcutEntry, String>(editTextCell) {

        @Override
        public String getValue(KeyboardShortcutEntry binding) {
            return getter.getValue(binding);
        }
    };
    column.setFieldUpdater(new FieldUpdater<KeyboardShortcutEntry, String>() {

        @Override
        public void update(int index, KeyboardShortcutEntry binding, String value) {
            KeySequence keys = KeySequence.fromShortcutString(value);
            // adding a new key sequence.
            if (keys.equals(binding.getOriginalKeySequence())) {
                changes_.remove(binding);
                binding.restoreOriginalKeySequence();
            } else {
                KeyboardShortcutEntry newBinding = new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys, binding.getCommandType(), true, binding.getContext());
                changes_.put(binding, newBinding);
                binding.setKeySequence(keys);
            }
            table_.setKeyboardSelectedColumn(0);
            updateData(dataProvider_.getList());
        }
    });
    column.setSortable(true);
    table_.addColumn(column, new TextHeader(name));
    return column;
}
Also used : EditTextCell(com.google.gwt.cell.client.EditTextCell) Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) TextHeader(com.google.gwt.user.cellview.client.TextHeader) JsArrayString(com.google.gwt.core.client.JsArrayString) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 7 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class JsonUtils method addCustomCellColumn.

/**
	 * Returns a column with Object as value which is rendered by custom Cell
	 *
	 * @param <R> the row type
	 * @param cell the cell used to render the column
	 * @param fieldUpdater Field updater - on click action
	 */
public static <R> Column<R, R> addCustomCellColumn(Cell<R> cell, final FieldUpdater<R, String> fieldUpdater) {
    Column<R, R> column = new Column<R, R>(cell) {

        @Override
        public R getValue(R object) {
            return object;
        }

        @Override
        public String getCellStyleNames(Cell.Context context, R object) {
            if (fieldUpdater != null) {
                return super.getCellStyleNames(context, object) + " pointer";
            } else {
                return super.getCellStyleNames(context, object);
            }
        }
    };
    if (fieldUpdater != null) {
        FieldUpdater<R, R> tableFieldUpdater2 = new FieldUpdater<R, R>() {

            public void update(int index, R object, R value) {
                GeneralObject go = (GeneralObject) value;
                fieldUpdater.update(index, object, go.getName());
            }
        };
        column.setFieldUpdater(tableFieldUpdater2);
    }
    return column;
}
Also used : FieldUpdater(com.google.gwt.cell.client.FieldUpdater) Column(com.google.gwt.user.cellview.client.Column) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 8 with Column

use of com.google.gwt.user.cellview.client.Column 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);
    // 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());
        }
    });
    // 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);
    // Add the columns.
    table.addColumn(friendlyNameColumn, "Name");
    // attributesTable.addColumn(namespaceColumn, "Namespace");
    table.addColumn(entityColumn, "Entity");
    table.addColumn(definitionColumn, "Definition");
    table.addColumn(typeColumn, "Type");
    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)

Example 9 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class GetRequiredAttributes 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 tab index
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // checkbox 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");
    // 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.
    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 10 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class GetAllGroupsWithHierarchy method getTable.

/**
	 * Returns table with groups in hierarchical structure and with custom field updater
	 *
	 * @return table widget
	 */
public CellTable<Group> getTable() {
    // retrieve data
    retrieveData();
    dataProvider = new ListDataProvider<Group>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    table.setVisibleRange(0, 1000);
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
    // Updates the selection model = when selection changed, highlights the group children
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        public void onSelectionChange(SelectionChangeEvent event) {
            highlightRowsWhenChanged();
        }
    });
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // Checkbox column. This table will uses a checkbox column for
    // selection.
    Column<Group, Group> checkBoxColumn = new Column<Group, Group>(new PerunCheckboxCell<Group>(true, false, coreGroupsCheckable)) {

        @Override
        public Group getValue(Group object) {
            // Get the value from the selection model.
            object.setChecked(selectionModel.isSelected(object));
            return object;
        }
    };
    // Create ID column.
    Column<Group, String> idColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Group, String>() {

        public String getValue(Group g) {
            return String.valueOf(g.getId());
        }
    }, tableFieldUpdater);
    // Name column
    Column<Group, Group> nameColumn = new Column<Group, Group>(new PerunGroupCell()) {

        @Override
        public Group getValue(Group object) {
            return object;
        }
    };
    nameColumn.setFieldUpdater(new FieldUpdater<Group, Group>() {

        public void update(int index, Group object, Group value) {
            tableFieldUpdater.update(index, object, value.getName());
        }
    });
    // Create description column.
    Column<Group, String> descriptionColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Group, String>() {

        public String getValue(Group group) {
            return group.getDescription();
        }
    }, tableFieldUpdater);
    // updates the columns size
    table.setColumnWidth(checkBoxColumn, 40.0, Unit.PX);
    table.setColumnWidth(idColumn, 80.0, Unit.PX);
    // Add the columns.
    table.addColumn(checkBoxColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    table.addColumn(idColumn, "ID");
    table.addColumn(nameColumn, "Name");
    table.addColumn(descriptionColumn, "Description");
    return table;
}
Also used : Group(cz.metacentrum.perun.webgui.model.Group) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) Column(com.google.gwt.user.cellview.client.Column) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) PerunGroupCell(cz.metacentrum.perun.webgui.widgets.cells.PerunGroupCell)

Aggregations

Column (com.google.gwt.user.cellview.client.Column)51 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)28 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)18 Header (com.google.gwt.user.cellview.client.Header)15 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)14 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)10 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)10 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)9 TextCell (com.google.gwt.cell.client.TextCell)8 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)8 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 TextColumn (com.google.gwt.user.cellview.client.TextColumn)6 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)6 Attribute (cz.metacentrum.perun.webgui.model.Attribute)6 Group (cz.metacentrum.perun.webgui.model.Group)6 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)6 ImageResource (com.google.gwt.resources.client.ImageResource)5 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)5