use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.
the class FindSimilarPublications method getEmptyTable.
/**
* Returns table of users publications
* @return table
*/
public CellTable<Publication> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<Publication>(list);
// Cell table
table = new PerunTable<Publication>(list);
// display row-count for perun admin only
if (!session.isPerunAdmin()) {
table.removeRowCountChangeHandler();
}
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("No similar publications found.");
// show checkbox column
if (this.checkable) {
// checkbox column column
table.addCheckBoxColumn();
}
// ID COLUMN
table.addIdColumn("Publication ID", tableFieldUpdater, 60);
Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {
public ImageResource getValue(Publication object) {
if (object.getLocked() == true) {
return SmallIcons.INSTANCE.lockIcon();
} else {
return SmallIcons.INSTANCE.lockOpenIcon();
}
}
public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
// on click and for perun admin
if ("click".equals(event.getType()) && session.isPerunAdmin()) {
final ImageResource value;
if (object.getLocked() == true) {
value = SmallIcons.INSTANCE.lockOpenIcon();
object.setLocked(false);
} else {
value = SmallIcons.INSTANCE.lockIcon();
object.setLocked(true);
}
LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
}
@Override
public void onFinished(JavaScriptObject jso) {
// change picture (object already changed)
getCell().setValue(context, elem, value);
}
@Override
public void onError(PerunError error) {
// on error switch object back
if (object.getLocked() == true) {
object.setLocked(false);
getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
} else {
object.setLocked(true);
getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
}
}
});
// send request
ArrayList<Publication> list = new ArrayList<Publication>();
list.add(object);
request.lockUnlockPublications(object.getLocked(), list);
}
}
};
table.addColumn(lockedColumn, "Lock");
// TITLE COLUMN
Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getTitle();
}
}, this.tableFieldUpdater);
titleColumn.setSortable(true);
columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
table.addColumn(titleColumn, "Title");
// if display authors
if (ids.containsKey("authors")) {
if ((Integer) ids.get("authors") == 1) {
// AUTHORS COLUMN
Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getAuthorsFormatted();
}
}, this.tableFieldUpdater);
authorColumn.setSortable(true);
columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
table.addColumn(authorColumn, "Reported by");
}
}
// YEAR COLUMN
Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return String.valueOf(object.getYear());
}
}, this.tableFieldUpdater);
yearColumn.setSortable(true);
columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
table.addColumn(yearColumn, "Year");
// CATEGORY COLUMN
Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return object.getCategoryName();
}
}, this.tableFieldUpdater);
categoryColumn.setSortable(true);
columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
table.addColumn(categoryColumn, "Category");
// THANKS COLUMN
Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
String result = "";
JsArray<Thanks> thks = object.getThanks();
for (int i = 0; i < thks.length(); i++) {
result += thks.get(i).getOwnerName() + ", ";
}
if (result.length() >= 2) {
result = result.substring(0, result.length() - 2);
}
return result;
}
}, this.tableFieldUpdater);
thanksColumn.setSortable(true);
columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
table.addColumn(thanksColumn, "Thanked to");
// CITE COLUMN
Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {
public String getValue(Publication object) {
return "Cite";
}
}, new FieldUpdater<Publication, String>() {
public void update(int index, Publication object, String value) {
SimplePanel sp = new SimplePanel();
sp.add(new HTML(object.getMain()));
Confirm cf = new Confirm("Cite publication", sp, true);
cf.show();
}
;
});
table.addColumn(citaceColumn, "Cite");
return table;
}
use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.
the class GetCategories method getEmptyTable.
/**
* Returns table of users publications
* @return table
*/
public CellTable<Category> getEmptyTable() {
// Table data provider.
dataProvider = new ListDataProvider<Category>(list);
// Cell table
table = new PerunTable<Category>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<Category> columnSortHandler = new ListHandler<Category>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Category>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("No publications categories found.");
// tab index for values
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// show checkbox column
if (this.checkable) {
// checkbox column column
table.addCheckBoxColumn();
}
// ID COLUMN
table.addIdColumn("Category ID", tableFieldUpdater, 80);
table.addNameColumn(tableFieldUpdater);
// Rank COLUMN
Column<Category, String> rankColumn = JsonUtils.addColumn(new TextInputCellWithTabIndex(), new JsonUtils.GetValue<Category, String>() {
public String getValue(Category category) {
return String.valueOf(category.getRank());
}
}, new FieldUpdater<Category, String>() {
public void update(int index, Category object, String newText) {
// parsing value
try {
double value = Double.parseDouble(newText);
object.setRank(value);
selectionModel.setSelected(object, true);
} catch (NumberFormatException ex) {
selectionModel.setSelected(object, false);
session.getUiElements().setLogErrorText("Rank mismatch for category: " + object.getName() + " and value: " + newText);
}
}
});
// Sorting value column
rankColumn.setSortable(true);
columnSortHandler.setComparator(rankColumn, new Comparator<Category>() {
public int compare(Category o1, Category o2) {
// return int diff of doubles
return (int) (o1.getRank() - o2.getRank());
}
});
table.addColumn(rankColumn, "Rank");
return table;
}
use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.
the class GetRequiredAttributesV2 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 Comparator<Attribute>() {
public int compare(Attribute o1, Attribute o2) {
Collator customCollator = Collator.getInstance();
String key1 = o1.getDisplayName();
String key2 = o2.getDisplayName();
return customCollator.compare(key1, key2);
}
});
// 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;
}
use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler in project perun by CESNET.
the class GetResourceRequiredAttributesV2 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);
// 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());
// 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());
}
});
// Description column
Column<Attribute, Attribute> descriptionColumn = JsonUtils.addColumn(new PerunAttributeDescriptionCell());
// 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;
}
use of com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler 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;
}
Aggregations