use of com.google.gwt.user.cellview.client.RowStyles 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") || tsk.getStatus().equalsIgnoreCase("SENDERROR") || tsk.getStatus().equalsIgnoreCase("GENERROR")) {
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.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 (Arrays.asList("GENERROR", "SENDERROR", "ERROR").contains(row.getStatus())) {
return "rowred";
} else if (row.getStatus().equalsIgnoreCase("WARNING")) {
return "roworange";
}
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