Search in sources :

Example 26 with SortableTableViewer

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

the class NodeListComparator 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) {
    final AbstractNode node1 = (AbstractNode) e1;
    final AbstractNode node2 = (AbstractNode) e2;
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    int result;
    switch(column) {
        case NodesTab.COLUMN_SYS_DESCRIPTION:
            result = node1.getSystemDescription().compareToIgnoreCase(node2.getSystemDescription());
            break;
        case NodesTab.COLUMN_PLATFORM:
            result = node1.getPlatformName().compareToIgnoreCase(node2.getPlatformName());
            break;
        case NodesTab.COLUMN_AGENT_VERSION:
            result = node1.getAgentVersion().compareToIgnoreCase(node2.getAgentVersion());
            break;
        case NodesTab.COLUMN_ID:
            result = Long.signum(node1.getObjectId() - node2.getObjectId());
            break;
        case NodesTab.COLUMN_NAME:
            result = node1.getObjectName().compareToIgnoreCase(node2.getObjectName());
            break;
        case NodesTab.COLUMN_STATUS:
            result = node1.getStatus().compareTo(node2.getStatus());
            break;
        case NodesTab.COLUMN_IP_ADDRESS:
            result = ComparatorHelper.compareInetAddresses(node1.getPrimaryIP().getAddress(), node2.getPrimaryIP().getAddress());
            break;
        case NodesTab.COLUMN_RACK:
            Rack rack1 = session.findObjectById(node1.getRackId(), Rack.class);
            Rack rack2 = session.findObjectById(node2.getRackId(), Rack.class);
            if ((rack1 != null) && (rack2 != null)) {
                result = rack1.getObjectName().compareToIgnoreCase(rack2.getObjectName());
                if (result == 0) {
                    result = node1.getRackPosition() - node2.getRackPosition();
                }
            } else {
                result = Long.signum(node1.getRackId() - node2.getRackId());
            }
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : Rack(org.netxms.client.objects.Rack) AbstractNode(org.netxms.client.objects.AbstractNode) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 27 with SortableTableViewer

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

the class ObjectToolsEditor method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    // Initiate loading of required plugins if they was not loaded yet
    try {
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new AccessListElement(0, 0), "org.eclipse.ui.model.IWorkbenchAdapter");
    } catch (Exception e) {
    }
    // Create interface area
    objectToolsArea = new Composite(parent, SWT.BORDER);
    FormLayout formLayout = new FormLayout();
    objectToolsArea.setLayout(formLayout);
    // Create filter
    filterText = new FilterText(objectToolsArea, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
            actionShowFilter.setChecked(initShowFilter);
        }
    });
    final String[] columnNames = { Messages.get().ObjectToolsEditor_ColId, Messages.get().ObjectToolsEditor_ColName, Messages.get().ObjectToolsEditor_ColType, Messages.get().ObjectToolsEditor_ColDescr };
    final int[] columnWidths = { 90, 200, 100, 200 };
    viewer = new SortableTableViewer(objectToolsArea, columnNames, columnWidths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ObjectToolsLabelProvider());
    filter = new ObjectToolsFilter();
    viewer.addFilter(filter);
    viewer.setComparator(new ObjectToolsComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEdit.setEnabled(selection.size() == 1);
                actionClone.setEnabled(selection.size() == 1);
                actionDelete.setEnabled(selection.size() > 0);
                actionDisable.setEnabled(containsEnabled(selection));
                actionEnable.setEnabled(containsDisabled(selection));
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEdit.run();
        }
    });
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterText);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    viewer.getControl().setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    activateContext();
    session.addListener(this);
    // Set initial focus to filter input line
    if (initShowFilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
    refreshToolList();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PropertyDialogAction(org.eclipse.ui.dialogs.PropertyDialogAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) 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) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ObjectToolsComparator(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsComparator) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ObjectToolsLabelProvider(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ObjectToolsFilter(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsFilter)

Example 28 with SortableTableViewer

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

the class ObjectToolsComparator 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) {
    ObjectTool tool1 = (ObjectTool) e1;
    ObjectTool tool2 = (ObjectTool) e2;
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    int result;
    switch(column) {
        case ObjectToolsEditor.COLUMN_ID:
            result = Long.signum(tool1.getId() - tool2.getId());
            break;
        case ObjectToolsEditor.COLUMN_NAME:
            result = tool1.getName().compareToIgnoreCase(tool2.getName());
            break;
        case ObjectToolsEditor.COLUMN_TYPE:
            final ObjectToolsLabelProvider labelProvider = (ObjectToolsLabelProvider) ((SortableTableViewer) viewer).getLabelProvider();
            result = labelProvider.getToolTypeName(tool1).compareTo(labelProvider.getToolTypeName(tool2));
            break;
        case ObjectToolsEditor.COLUMN_DESCRIPTION:
            result = tool1.getDescription().compareToIgnoreCase(tool2.getDescription());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 29 with SortableTableViewer

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

the class SoftwareInventory method createTableViewer.

/**
 * Create viewer for table mode
 */
private void createTableViewer() {
    viewer = new SortableTableViewer(this, names, widths, 0, SWT.UP, SWT.MULTI | SWT.FULL_SELECTION);
    WidgetHelper.restoreColumnViewerSettings(viewer, Activator.getDefault().getDialogSettings(), configPrefix);
    viewer.getControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveColumnViewerSettings(viewer, Activator.getDefault().getDialogSettings(), configPrefix);
        }
    });
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new SoftwarePackageLabelProvider(false));
    viewer.setComparator(new SoftwarePackageComparator());
    if (menuManager != null) {
        Menu menu = menuManager.createContextMenu(viewer.getControl());
        viewer.getControl().setMenu(menu);
        viewPart.getSite().registerContextMenu(menuManager, viewer);
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SoftwarePackageComparator(org.netxms.ui.eclipse.objectview.widgets.helpers.SoftwarePackageComparator) SoftwarePackageLabelProvider(org.netxms.ui.eclipse.objectview.widgets.helpers.SoftwarePackageLabelProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) Menu(org.eclipse.swt.widgets.Menu) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 30 with SortableTableViewer

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

the class PersistentStorageView method createPartControl.

/* (non-Javadoc)
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
@Override
public void createPartControl(Composite parent) {
    // GridLayout layout = new GridLayout();
    // layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    // layout.marginWidth = 0;
    // layout.marginHeight = 0;
    // parent.setLayout(layout);
    final String[] setColumnNames = { "Key", "Value" };
    final int[] setColumnWidths = { 150, 200 };
    viewerSetValue = new SortableTableViewer(parent, setColumnNames, setColumnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewerSetValue.setContentProvider(new ArrayContentProvider());
    viewerSetValue.setLabelProvider(new AttributeLabelProvider());
    viewerSetValue.setComparator(new ObjectLabelComparator((ILabelProvider) viewerSetValue.getLabelProvider()));
    viewerSetValue.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int size = ((IStructuredSelection) viewerSetValue.getSelection()).size();
            actionEdit.setEnabled(size == 1);
            actionDelete.setEnabled(size > 0);
        }
    });
    createActions();
    contributeToActionBars();
    createPopupMenu();
    refresh();
}
Also used : ObjectLabelComparator(org.netxms.ui.eclipse.tools.ObjectLabelComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) AttributeLabelProvider(org.netxms.ui.eclipse.widgets.helpers.AttributeLabelProvider)

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