Search in sources :

Example 56 with SortableTableViewer

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;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) InetAddress(java.net.InetAddress) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) Interface(org.netxms.client.objects.Interface) ConnectionPoint(org.netxms.client.topology.ConnectionPoint)

Example 57 with SortableTableViewer

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SnmpTrapFilter(org.netxms.ui.eclipse.serverconfig.dialogs.helpers.SnmpTrapFilter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TrapListLabelProvider(org.netxms.ui.eclipse.serverconfig.dialogs.helpers.TrapListLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SnmpTrapComparator(org.netxms.ui.eclipse.serverconfig.dialogs.helpers.SnmpTrapComparator) FilterText(org.netxms.ui.eclipse.widgets.FilterText)

Example 58 with SortableTableViewer

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();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Dot1xPortComparator(org.netxms.ui.eclipse.switchmanager.views.helpers.Dot1xPortComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Dot1xPortListLabelProvider(org.netxms.ui.eclipse.switchmanager.views.helpers.Dot1xPortListLabelProvider)

Example 59 with SortableTableViewer

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;
}
Also used : DataType(org.netxms.client.constants.DataType) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 60 with SortableTableViewer

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;
}
Also used : ServerJob(org.netxms.client.server.ServerJob) AbstractObject(org.netxms.client.objects.AbstractObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Aggregations

SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)97 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)66 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)43 Composite (org.eclipse.swt.widgets.Composite)43 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridData (org.eclipse.swt.layout.GridData)38 GridLayout (org.eclipse.swt.layout.GridLayout)38 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)29 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)28 Button (org.eclipse.swt.widgets.Button)28 SelectionListener (org.eclipse.swt.events.SelectionListener)27 DisposeEvent (org.eclipse.swt.events.DisposeEvent)26 DisposeListener (org.eclipse.swt.events.DisposeListener)26 RowLayout (org.eclipse.swt.layout.RowLayout)24 RowData (org.eclipse.swt.layout.RowData)20 Event (org.eclipse.swt.widgets.Event)14 FillLayout (org.eclipse.swt.layout.FillLayout)12 Iterator (java.util.Iterator)11