Search in sources :

Example 61 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class ScheduleTableEntryComparator 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;
    ScheduledTask task1 = (ScheduledTask) e1;
    ScheduledTask task2 = (ScheduledTask) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case ScheduledTaskView.SCHEDULE_ID:
            result = (int) (task1.getId() - task2.getId());
            break;
        case ScheduledTaskView.CALLBACK_ID:
            result = task1.getScheduledTaskId().compareToIgnoreCase(task2.getScheduledTaskId());
            break;
        case ScheduledTaskView.OBJECT:
            AbstractObject obj1 = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(task1.getObjectId());
            AbstractObject obj2 = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(task2.getObjectId());
            String name1 = (obj1 != null) ? obj1.getObjectName() : "Unknown";
            String name2 = (obj2 != null) ? obj2.getObjectName() : "Unknown";
            result = name1.compareToIgnoreCase(name2);
            break;
        case ScheduledTaskView.PARAMETERS:
            result = task1.getParameters().compareToIgnoreCase(task2.getParameters());
            break;
        case ScheduledTaskView.EXECUTION_TIME:
            if (task1.getSchedule().isEmpty()) {
                if (task2.getSchedule().isEmpty()) {
                    result = task1.getExecutionTime().compareTo(task2.getExecutionTime());
                    break;
                } else {
                    result = 1;
                    break;
                }
            }
            if (task2.getSchedule().isEmpty()) {
                result = -1;
            }
            result = task1.getSchedule().compareToIgnoreCase(task2.getSchedule());
            break;
        case ScheduledTaskView.LAST_EXECUTION_TIME:
            result = task1.getLastExecutionTime().compareTo(task2.getLastExecutionTime());
            break;
        case ScheduledTaskView.STATUS:
            result = task1.getStatus().compareToIgnoreCase(task2.getStatus());
            break;
        case ScheduledTaskView.OWNER:
            String user1 = "";
            String user2 = "";
            if ((task1.getFlags() & ScheduledTask.SYSTEM) > 0)
                user1 = "Internal";
            else
                user1 = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
            if ((task2.getFlags() & ScheduledTask.SYSTEM) > 0)
                user2 = "Internal";
            else
                user2 = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
            result = user1.compareTo(user2);
            break;
        case ScheduledTaskView.COMMENTS:
            result = task1.getComments().compareToIgnoreCase(task2.getComments());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractObject(org.netxms.client.objects.AbstractObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) ScheduledTask(org.netxms.client.ScheduledTask)

Example 62 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class ServerJobManager 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().ServerJobManager_ColStatus, Messages.get().ServerJobManager_ColInitiator, Messages.get().ServerJobManager_ColNode, Messages.get().ServerJobManager_ColDescription, Messages.get().ServerJobManager_ColProgress, Messages.get().ServerJobManager_ColMessage };
    final int[] widths = { 80, 100, 150, 250, 100, 300 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.DOWN, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ServerJobLabelProvider());
    viewer.setComparator(new ServerJobComparator());
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    session = (NXCSession) ConsoleSharedData.getSession();
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionCancelJob.setEnabled(selection.size() > 0);
                actionHoldJob.setEnabled(selection.size() > 0);
                actionUnholdJob.setEnabled(selection.size() > 0);
            }
        }
    });
    // Create listener for notifications received from server via client library
    clientListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() != SessionNotification.JOB_CHANGE)
                return;
            refreshJobList(false);
        }
    };
    session.addListener(clientListener);
    refreshJobList(false);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ServerJobLabelProvider(org.netxms.ui.eclipse.serverjobmanager.views.helpers.ServerJobLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) ServerJobComparator(org.netxms.ui.eclipse.serverjobmanager.views.helpers.ServerJobComparator) SessionNotification(org.netxms.client.SessionNotification)

Example 63 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class FDBComparator 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) {
    FdbEntry fdb1 = (FdbEntry) e1;
    FdbEntry fdb2 = (FdbEntry) e2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case SwitchForwardingDatabaseView.COLUMN_INTERFACE:
            result = fdb1.getInterfaceName().compareToIgnoreCase(fdb2.getInterfaceName());
            break;
        case SwitchForwardingDatabaseView.COLUMN_MAC_ADDRESS:
            result = fdb1.getAddress().compareTo(fdb2.getAddress());
            break;
        case SwitchForwardingDatabaseView.COLUMN_NODE:
            // $NON-NLS-1$
            String n1 = (fdb1.getNodeId() != 0) ? session.getObjectName(fdb1.getNodeId()) : "";
            // $NON-NLS-1$
            String n2 = (fdb2.getNodeId() != 0) ? session.getObjectName(fdb2.getNodeId()) : "";
            result = n1.compareToIgnoreCase(n2);
            break;
        case SwitchForwardingDatabaseView.COLUMN_PORT:
            result = fdb1.getPort() - fdb2.getPort();
            break;
        case SwitchForwardingDatabaseView.COLUMN_VLAN:
            result = fdb1.getVlanId() - fdb2.getVlanId();
            break;
        case SwitchForwardingDatabaseView.COLUMN_TYPE:
            result = fdb1.getType() - fdb2.getType();
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : FdbEntry(org.netxms.client.topology.FdbEntry) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 64 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class RadioInterfaceComparator 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) {
    RadioInterface rif1 = (RadioInterface) e1;
    RadioInterface rif2 = (RadioInterface) e2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case RadioInterfaces.COLUMN_AP_MAC_ADDR:
            result = rif1.getAccessPoint().getMacAddress().compareTo(rif2.getAccessPoint().getMacAddress());
            break;
        case RadioInterfaces.COLUMN_AP_MODEL:
            result = rif1.getAccessPoint().getModel().compareToIgnoreCase(rif2.getAccessPoint().getModel());
            break;
        case RadioInterfaces.COLUMN_AP_NAME:
            result = rif1.getAccessPoint().getObjectName().compareToIgnoreCase(rif2.getAccessPoint().getObjectName());
            break;
        case RadioInterfaces.COLUMN_AP_SERIAL:
            result = rif1.getAccessPoint().getSerialNumber().compareToIgnoreCase(rif2.getAccessPoint().getSerialNumber());
            break;
        case RadioInterfaces.COLUMN_AP_VENDOR:
            result = rif1.getAccessPoint().getVendor().compareToIgnoreCase(rif2.getAccessPoint().getVendor());
            break;
        case RadioInterfaces.COLUMN_CHANNEL:
            result = rif1.getChannel() - rif2.getChannel();
            break;
        case RadioInterfaces.COLUMN_INDEX:
            result = rif1.getIndex() - rif2.getIndex();
            break;
        case RadioInterfaces.COLUMN_MAC_ADDR:
            result = rif1.getMacAddress().compareTo(rif2.getMacAddress());
            break;
        case RadioInterfaces.COLUMN_NAME:
            result = rif1.getName().compareToIgnoreCase(rif2.getName());
            break;
        case RadioInterfaces.COLUMN_TX_POWER_DBM:
            result = rif1.getPowerDBm() - rif2.getPowerDBm();
            break;
        case RadioInterfaces.COLUMN_TX_POWER_MW:
            result = rif1.getPowerMW() - rif2.getPowerMW();
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) RadioInterface(org.netxms.client.topology.RadioInterface)

Example 65 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class RoutingTableComparator 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) {
    Route r1 = (Route) e1;
    Route r2 = (Route) e2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case RoutingTableView.COLUMN_DESTINATION:
            result = ComparatorHelper.compareInetAddresses(r1.getDestination(), r2.getDestination());
            if (result == 0) {
                result = r1.getPrefixLength() - r2.getPrefixLength();
            }
            break;
        case RoutingTableView.COLUMN_NEXT_HOP:
            result = ComparatorHelper.compareInetAddresses(r1.getNextHop(), r2.getNextHop());
            break;
        case RoutingTableView.COLUMN_INTERFACE:
            result = r1.getIfName().compareToIgnoreCase(r2.getIfName());
            break;
        case RoutingTableView.COLUMN_TYPE:
            result = r1.getType() - r2.getType();
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) Route(org.netxms.client.topology.Route)

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