use of org.netxms.client.TableRow 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.TableRow 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.TableRow in project netxms by netxms.
the class AlarmLogViewer method showIssue.
/**
* Show in web browser helpdesk ticket (issue) linked to selected alarm
*/
private void showIssue() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final long id = Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue());
new ConsoleJob("Show helpdesk ticket", this, Activator.PLUGIN_ID, JOB_FAMILY) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final String url = session.getHelpdeskIssueUrl(id);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
browser.openURL(new URL(url));
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$
Activator.logError("Exception in AlarmList.showIssue (url=\"" + url + "\")", e);
MessageDialogHelper.openError(getSite().getShell(), "Error", "Internal error: unable to open web browser");
}
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot get URL for helpdesk ticket";
}
}.start();
}
use of org.netxms.client.TableRow in project netxms by netxms.
the class ObjectSelectionProvider method getSelection.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
*/
@Override
public ISelection getSelection() {
IStructuredSelection selection = (IStructuredSelection) parent.getSelection();
if ((selection == null) || selection.isEmpty())
return selection;
List<AbstractObject> objects = new ArrayList<AbstractObject>(selection.size());
for (Object o : selection.toList()) {
if (!(o instanceof TableRow))
continue;
AbstractObject object = session.findObjectById(((TableRow) o).getObjectId());
if (object != null)
objects.add(object);
}
return new StructuredSelection(objects);
}
use of org.netxms.client.TableRow 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