use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class ConnectionPointComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result;
// $NON-NLS-1$
int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
switch(column) {
case HostSearchResults.COLUMN_SEQUENCE:
result = (Integer) ((ConnectionPoint) e1).getData() - (Integer) ((ConnectionPoint) e2).getData();
break;
case HostSearchResults.COLUMN_NODE:
case HostSearchResults.COLUMN_INTERFACE:
case HostSearchResults.COLUMN_MAC_ADDRESS:
case HostSearchResults.COLUMN_SWITCH:
case HostSearchResults.COLUMN_PORT:
result = labelProvider.getColumnText(e1, column).compareToIgnoreCase(labelProvider.getColumnText(e2, column));
break;
case HostSearchResults.COLUMN_IP_ADDRESS:
Interface iface1 = (Interface) session.findObjectById(((ConnectionPoint) e1).getLocalInterfaceId(), Interface.class);
Interface iface2 = (Interface) session.findObjectById(((ConnectionPoint) e2).getLocalInterfaceId(), Interface.class);
InetAddress a1 = ((ConnectionPoint) e1).getLocalIpAddress();
InetAddress a2 = ((ConnectionPoint) e2).getLocalIpAddress();
if ((a1 == null) && (iface1 != null))
a1 = iface1.getFirstUnicastAddress();
if ((a2 == null) && (iface2 != null))
a2 = iface2.getFirstUnicastAddress();
result = ComparatorHelper.compareInetAddresses(a1, a2);
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class SelectSnmpTrapDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
final Composite dialogArea = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
dialogArea.setLayout(layout);
filterText = new FilterText(dialogArea, SWT.NONE, null, false);
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
filterText.setLayoutData(gd);
final String[] names = { Messages.get().SelectSnmpTrapDialog_ColOID, Messages.get().SelectSnmpTrapDialog_ColEvent, Messages.get().SelectSnmpTrapDialog_ColDescription };
final int[] widths = { 350, 250, 400 };
viewer = new SortableTableViewer(dialogArea, names, widths, COLUMN_OID, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new TrapListLabelProvider());
viewer.setComparator(new SnmpTrapComparator());
viewer.setInput(trapList.toArray());
filter = new SnmpTrapFilter();
viewer.addFilter(filter);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.heightHint = 450;
viewer.getControl().setLayoutData(gd);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filter.setFilterString(filterText.getText());
viewer.refresh();
}
});
return dialogArea;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class Dot1xStatusView method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
final String[] names = { Messages.get().Dot1xStatusView_ColDevice, Messages.get().Dot1xStatusView_ColSlotPort, Messages.get().Dot1xStatusView_ColInterface, Messages.get().Dot1xStatusView_ColPAE, Messages.get().Dot1xStatusView_ColBackend };
final int[] widths = { 250, 60, 180, 150, 150 };
viewer = new SortableTableViewer(parent, names, widths, 1, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new Dot1xPortListLabelProvider());
viewer.setComparator(new Dot1xPortComparator());
// $NON-NLS-1$
WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), "Dot1xStatusView");
viewer.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
// $NON-NLS-1$
WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), "Dot1xStatusView");
}
});
createActions();
contributeToActionBars();
createPopupMenu();
refresh();
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class TableItemComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
// $NON-NLS-1$
final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
final DataType format = (column < formats.length) ? formats[column] : DataType.STRING;
final String value1 = ((TableRow) e1).get(column).getValue();
final String value2 = ((TableRow) e2).get(column).getValue();
int result;
switch(format) {
case STRING:
result = value1.compareToIgnoreCase(value2);
break;
case INT32:
try {
result = Integer.parseInt(value1) - Integer.parseInt(value2);
} catch (NumberFormatException e) {
result = 0;
}
break;
case UINT32:
case INT64:
case UINT64:
case COUNTER32:
case COUNTER64:
try {
result = Long.signum(Long.parseLong(value1) - Long.parseLong(value2));
} catch (NumberFormatException e) {
result = 0;
}
break;
case FLOAT:
try {
result = (int) Math.signum(Double.parseDouble(value1) - Double.parseDouble(value2));
} catch (NumberFormatException e) {
result = 0;
}
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class ServerJobComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case ServerJobManager.COLUMN_STATUS:
result = ((ServerJob) e1).getStatus() - ((ServerJob) e2).getStatus();
break;
case ServerJobManager.COLUMN_NODE:
AbstractObject object1 = session.findObjectById(((ServerJob) e1).getNodeId());
AbstractObject object2 = session.findObjectById(((ServerJob) e2).getNodeId());
// $NON-NLS-1$
String name1 = (object1 != null) ? object1.getObjectName() : "<unknown>";
// $NON-NLS-1$
String name2 = (object2 != null) ? object2.getObjectName() : "<unknown>";
result = name1.compareToIgnoreCase(name2);
break;
case ServerJobManager.COLUMN_DESCRIPTION:
result = ((ServerJob) e1).getDescription().compareToIgnoreCase(((ServerJob) e2).getDescription());
break;
case ServerJobManager.COLUMN_MESSAGE:
result = ((ServerJob) e1).getFailureMessage().compareToIgnoreCase(((ServerJob) e2).getFailureMessage());
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Aggregations