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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations