use of org.netxms.client.TableCell in project netxms by netxms.
the class TableComparisonChartElement method updateChart.
/**
* Update chart with new data
*
* @param data
*/
private void updateChart(final Table data) {
// FIXME //$NON-NLS-1$
String instanceColumn = (config.getInstanceColumn() != null) ? config.getInstanceColumn() : "";
if (instanceColumn == null)
return;
final int icIndex = data.getColumnIndex(instanceColumn);
final int dcIndex = data.getColumnIndex(config.getDataColumn());
if ((icIndex == -1) || (dcIndex == -1))
// at least one column is missing
return;
if (config.isSortOnDataColumn()) {
data.sort(new Comparator<TableRow>() {
@Override
public int compare(TableRow row1, TableRow row2) {
TableCell c1 = row1.get(dcIndex);
TableCell c2 = row2.get(dcIndex);
String s1 = (c1 != null) ? c1.getValue() : "";
String s2 = (c2 != null) ? c2.getValue() : "";
int result = 0;
try {
double value1 = Double.parseDouble(s1);
double value2 = Double.parseDouble(s2);
result = Double.compare(value1, value2);
} catch (NumberFormatException e) {
result = s1.compareToIgnoreCase(s2);
}
return config.isSortDescending() ? -result : result;
}
});
// Sorting may reorder instances, so clear everything
instanceMap.clear();
chart.removeAllParameters();
}
boolean rebuild = false;
for (int i = 0; i < data.getRowCount(); i++) {
String instance = data.getCellValue(i, icIndex);
if (instance == null)
continue;
double value;
try {
value = Double.parseDouble(data.getCellValue(i, dcIndex));
} catch (NumberFormatException e) {
value = 0.0;
}
Integer index = instanceMap.get(instance);
if (index == null) {
if ((instanceMap.size() >= DataChart.MAX_CHART_ITEMS) || ((value == 0) && config.isIgnoreZeroValues()))
continue;
// $NON-NLS-1$
index = chart.addParameter(new GraphItem(config.getNodeId(), config.getDciId(), 0, DataType.INT32, Long.toString(config.getDciId()), instance, "%s"), 0.0);
instanceMap.put(instance, index);
rebuild = true;
}
chart.updateParameter(index, value, false);
}
if (!chartInitialized) {
chart.initializationComplete();
chartInitialized = true;
} else {
if (rebuild)
chart.rebuild();
else
chart.refresh();
}
}
use of org.netxms.client.TableCell in project netxms by netxms.
the class TableLabelProvider method getForeground.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableColorProvider#getForeground(java.lang.Object, int)
*/
@Override
public Color getForeground(Object element, int columnIndex) {
TableRow row = (TableRow) element;
if (columnIndex >= row.size())
return null;
TableCell cell = row.get(columnIndex);
return (cell.getStatus() >= 0) && (cell.getStatus() < FOREGROUND_COLORS.length) ? FOREGROUND_COLORS[cell.getStatus()] : null;
}
use of org.netxms.client.TableCell in project netxms by netxms.
the class TableLabelProvider method getBackground.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableColorProvider#getBackground(java.lang.Object, int)
*/
@Override
public Color getBackground(Object element, int columnIndex) {
TableRow row = (TableRow) element;
if (columnIndex >= row.size())
return null;
TableCell cell = row.get(columnIndex);
return (cell.getStatus() > 0) ? StatusDisplayInfo.getStatusColor(cell.getStatus()) : null;
}
use of org.netxms.client.TableCell in project netxms by netxms.
the class SummaryTableWidget method update.
/**
* Update viewer with fresh table data
*
* @param table table
*/
public void update(final Table table) {
if (!viewer.isInitialized()) {
final String[] names = table.getColumnDisplayNames();
final int[] widths = new int[names.length];
Arrays.fill(widths, 100);
viewer.createColumns(names, widths, 0, SWT.UP);
final IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
final String key = viewPart.getViewSite().getId() + ".SummaryTable." + Integer.toString(tableId);
WidgetHelper.restoreTreeViewerSettings(viewer, settings, key);
// $NON-NLS-1$
String value = settings.get(key + ".useMultipliers");
if (value != null)
useMultipliers = Boolean.parseBoolean(value);
labelProvider.setUseMultipliers(useMultipliers);
viewer.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
WidgetHelper.saveTreeViewerSettings(viewer, settings, key);
// $NON-NLS-1$
settings.put(key + ".useMultipliers", useMultipliers);
}
});
viewer.setComparator(new SummaryTableItemComparator(table));
}
labelProvider.setColumnDataTypes(table.getColumnDataTypes());
if (sortingColumnList != null && sortingColumnList.size() > 0) {
List<SortItem> sortItem = new ArrayList<SortItem>();
for (int i = 0; i < sortingColumnList.size(); i++) {
boolean isDesc = sortingColumnList.get(i).charAt(0) == '>' ? true : false;
int index = table.getColumnIndex(sortingColumnList.get(i).substring(1));
if (index >= 0) {
sortItem.add(new SortItem(index, isDesc));
}
}
// find index of columns to compare and desc or asc
final List<SortItem> sortItemFin = sortItem;
table.sort(new Comparator<TableRow>() {
public int compare(TableRow row1, TableRow row2) {
// compare lines
int result = 0;
int i = 0;
while (result == 0 && i < sortItemFin.size()) {
result = compareItem(row1, row2, sortItemFin.get(i).colIndex, sortItemFin.get(i).isDesc);
i++;
}
return result;
}
private int compareItem(TableRow row1, TableRow row2, int index, boolean sortDesc) {
TableCell c1 = row1.get(index);
TableCell c2 = row2.get(index);
String s1 = (c1 != null) ? c1.getValue() : "";
String s2 = (c2 != null) ? c2.getValue() : "";
int result = 0;
try {
double value1 = Double.parseDouble(s1);
double value2 = Double.parseDouble(s2);
result = Double.compare(value1, value2);
} catch (NumberFormatException e) {
result = s1.compareToIgnoreCase(s2);
}
return sortDesc ? -result : result;
}
});
viewer.setComparator(null);
}
if (showLineCount > 0)
viewer.setInput(table.getFirstRows(showLineCount));
else
viewer.setInput(table);
viewer.expandAll();
}
Aggregations