use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.
the class JsonUtils method addColumn.
/**
* Returns a column with a header and with automatic cell selection
*
* @param <R> the row type
* @param getter the value getter for the cell
* @param fieldUpdater Field updater - on click action
*/
public static <R> Column<R, String> addColumn(final GetValue<R, String> getter, final FieldUpdater<R, String> fieldUpdater) {
Cell<String> cell;
if (fieldUpdater == null) {
cell = new TextCell();
} else {
cell = new CustomClickableTextCell();
}
Column<R, String> column = new Column<R, String>(cell) {
@Override
public String getValue(R object) {
return getter.getValue(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) {
column.setFieldUpdater(fieldUpdater);
}
return column;
}
use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.
the class JsonUtils method addColumn.
/**
* Returns a column with a header.
*
* @param <R> the row type
* @param <R> the cell type
* @param cell the cell used to render the column
* @param headerText the header string
* @param getValue the value getter for the cell
* @deprecated Shouldn't be used when returning the same object - use the method without Getter in parameter instead *
*/
public static <R> Column<R, R> addColumn(Cell<R> cell, String headerText, final GetValue<R, R> getValue, final FieldUpdater<R, String> tableFieldUpdater, boolean custom) {
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 (tableFieldUpdater != null) {
return super.getCellStyleNames(context, object) + " pointer";
} else {
return super.getCellStyleNames(context, object);
}
}
};
if (tableFieldUpdater != null) {
FieldUpdater<R, R> tableFieldUpdater2 = new FieldUpdater<R, R>() {
public void update(int index, R object, R value) {
GeneralObject go = (GeneralObject) value;
tableFieldUpdater.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 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;
}
use of com.google.gwt.user.cellview.client.Column 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;
}
use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.
the class VoResourcesPropagationsTabItem method draw.
public Widget draw() {
mainrow = 0;
okCounter = 0;
errorCounter = 0;
notDeterminedCounter = 0;
procesingCounter = 0;
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources state");
final TabItem tab = this;
VerticalPanel mainTab = new VerticalPanel();
mainTab.setWidth("100%");
// MAIN PANEL
final ScrollPanel firstTabPanel = new ScrollPanel();
firstTabPanel.setSize("100%", "100%");
firstTabPanel.setStyleName("perun-tableScrollPanel");
final FlexTable help = new FlexTable();
help.setCellPadding(4);
help.setWidth("100%");
final CustomButton cb = UiElements.getRefreshButton(this);
help.setWidget(0, 0, cb);
help.getFlexCellFormatter().setWidth(0, 0, "80px");
help.setHTML(0, 1, "<strong>Color notation:</strong>");
help.getFlexCellFormatter().setWidth(0, 1, "100px");
help.setHTML(0, 2, "<strong>OK</strong>");
help.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
help.getFlexCellFormatter().setWidth(0, 2, "50px");
help.getFlexCellFormatter().setStyleName(0, 2, "green");
help.setHTML(0, 3, "<strong>Error</strong>");
help.getFlexCellFormatter().setWidth(0, 3, "50px");
help.getFlexCellFormatter().setStyleName(0, 3, "red");
help.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
help.setHTML(0, 4, "<strong>Not determined</strong>");
help.getFlexCellFormatter().setWidth(0, 4, "50px");
help.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER);
help.getFlexCellFormatter().setStyleName(0, 4, "notdetermined");
/*
help.setHTML(0, 5, "<strong>Processing</strong>");
help.getFlexCellFormatter().setWidth(0, 5, "50px");
help.getFlexCellFormatter().setStyleName(0, 5, "yellow");
help.getFlexCellFormatter().setHorizontalAlignment(0, 5, HasHorizontalAlignment.ALIGN_CENTER);
*/
help.setHTML(0, 5, " ");
help.getFlexCellFormatter().setWidth(0, 6, "50%");
mainTab.add(help);
mainTab.add(new HTML("<hr size=\"2\" />"));
mainTab.add(firstTabPanel);
final FlexTable content = new FlexTable();
content.setWidth("100%");
content.setBorderWidth(0);
firstTabPanel.add(content);
content.setStyleName("propagationTable", true);
final AjaxLoaderImage im = new AjaxLoaderImage();
content.setWidget(0, 0, im);
content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
final GetAllResourcesState callback = new GetAllResourcesState(voId, new JsonCallbackEvents() {
public void onLoadingStart() {
im.loadingStart();
cb.setProcessing(true);
}
public void onError(PerunError error) {
im.loadingError(error);
cb.setProcessing(false);
}
public void onFinished(JavaScriptObject jso) {
im.loadingFinished();
cb.setProcessing(false);
content.clear();
content.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
ArrayList<ResourceState> list = JsonUtils.jsoAsList(jso);
if (list != null && !list.isEmpty()) {
list = new TableSorter<ResourceState>().sortByResourceName(list);
for (final ResourceState state : list) {
content.setHTML(mainrow, 0, new Image(LargeIcons.INSTANCE.serverGroupIcon()) + "<span class=\"now-managing\" style=\"display: inline-block; position: relative; top: -8px;\">" + state.getResource().getName() + "</span>");
ArrayList<Task> tasks = new TableSorter<Task>().sortByService(JsonUtils.<Task>jsoAsList(state.getTasks()));
if (tasks == null || tasks.isEmpty())
notDeterminedCounter++;
boolean allOk = true;
for (Task tsk : tasks) {
if (tsk.getStatus().equalsIgnoreCase("ERROR")) {
errorCounter++;
allOk = false;
break;
}
}
if (allOk && tasks != null && !tasks.isEmpty())
okCounter++;
ListDataProvider<Task> dataProvider = new ListDataProvider<Task>();
PerunTable<Task> table;
// Table data provider.
dataProvider = new ListDataProvider<Task>(tasks);
// Cell table
table = new PerunTable<Task>(tasks);
table.removeRowCountChangeHandler();
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ColumnSortEvent.ListHandler<Task> columnSortHandler = new ColumnSortEvent.ListHandler<Task>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// set empty content & loader
AjaxLoaderImage loaderImage = new AjaxLoaderImage();
loaderImage.setEmptyResultMessage("No service configuration was propagated to this resource.");
table.setEmptyTableWidget(loaderImage);
loaderImage.loadingFinished();
table.addIdColumn("Task Id");
// Service column
Column<Task, String> serviceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {
public String getValue(Task task) {
return String.valueOf(task.getExecService().getService().getName());
}
}, null);
// status column
Column<Task, String> statusColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Task, String>() {
public String getValue(Task task) {
return String.valueOf(task.getStatus());
}
}, null);
// start COLUMN
TextColumn<Task> startTimeColumn = new TextColumn<Task>() {
public String getValue(Task result) {
return result.getStartTime();
}
};
// end COLUMN
TextColumn<Task> endTimeColumn = new TextColumn<Task>() {
public String getValue(Task result) {
return result.getEndTime();
}
};
// schedule COLUMN
TextColumn<Task> scheduleColumn = new TextColumn<Task>() {
public String getValue(Task result) {
return result.getSchedule();
}
};
// Add the columns.
table.addColumn(serviceColumn, "Service");
table.addColumn(statusColumn, "Status");
table.addColumn(scheduleColumn, "Scheduled");
table.addColumn(startTimeColumn, "Started");
table.addColumn(endTimeColumn, "Ended");
// set row styles based on task state
table.setRowStyles(new RowStyles<Task>() {
public String getStyleNames(Task row, int rowIndex) {
if (row.getStatus().equalsIgnoreCase("NONE")) {
return "rowdarkgreen";
} else if (row.getStatus().equalsIgnoreCase("DONE")) {
return "rowgreen";
} else if (row.getStatus().equalsIgnoreCase("PROCESSING")) {
return "rowyellow";
} else if (row.getStatus().equalsIgnoreCase("ERROR")) {
return "rowred";
}
return "";
}
});
table.setWidth("100%");
content.setWidget(mainrow + 1, 0, table);
content.getFlexCellFormatter().setStyleName(mainrow + 1, 0, "propagationTablePadding");
mainrow++;
mainrow++;
}
}
// set counters
help.setHTML(0, 2, "<strong>Ok (" + okCounter + ")</strong>");
help.setHTML(0, 3, "<strong>Error (" + errorCounter + ")</strong>");
help.setHTML(0, 4, "<strong>Not determined (" + notDeterminedCounter + ")</strong>");
//help.setHTML(0, 5, "<strong>Processing (" + procesingCounter + ")</strong>");
}
});
// get for all facilities for VO
callback.retrieveData();
// resize perun table to correct size on screen
session.getUiElements().resizePerunTable(firstTabPanel, 400, this);
this.contentWidget.setWidget(mainTab);
return getWidget();
}
Aggregations