Search in sources :

Example 21 with SortableTableViewer

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

the class DataSources method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    config = (ChartConfig) getElement().getAdapter(ChartConfig.class);
    if (config instanceof GraphSettings)
        graphIsTemplate = ((GraphSettings) config).isTemplate();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    dciList = new ArrayList<ChartDciConfig>();
    for (ChartDciConfig dci : config.getDciList()) dciList.add(new ChartDciConfig(dci));
    labelProvider = new DciListLabelProvider(dciList);
    labelProvider.resolveDciNames(dciList);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().DataSources_ColPosition, Messages.get().DataSources_ColNode, Messages.get().DataSources_ColParameter, Messages.get().DataSources_ColLabel, Messages.get().DataSources_ColColor };
    final int[] columnWidths = { 40, 130, 200, 150, 50 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(labelProvider);
    viewer.disableSorting();
    viewer.setInput(dciList.toArray());
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    gridData.horizontalSpan = 2;
    viewer.getControl().setLayoutData(gridData);
    /* buttons on left side */
    Composite leftButtons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginLeft = 0;
    leftButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gridData);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().DataSources_Up);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    upButton.setLayoutData(rd);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    upButton.setEnabled(false);
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().DataSources_Down);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    downButton.setLayoutData(rd);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    downButton.setEnabled(false);
    /* buttons on right side */
    Composite rightButtons = new Composite(dialogArea, SWT.NONE);
    buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    rightButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    rightButtons.setLayoutData(gridData);
    addButton = new Button(rightButtons, SWT.PUSH);
    addButton.setText(Messages.get().DataSources_Add);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            addItem();
        }
    });
    editButton = new Button(rightButtons, SWT.PUSH);
    editButton.setText(Messages.get().DataSources_Modify);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    editButton.setLayoutData(rd);
    editButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            editItem();
        }
    });
    editButton.setEnabled(false);
    deleteButton = new Button(rightButtons, SWT.PUSH);
    deleteButton.setText(Messages.get().DataSources_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteItems();
        }
    });
    deleteButton.setEnabled(false);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editButton.notifyListeners(SWT.Selection, new Event());
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            editButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
            upButton.setEnabled(selection.size() == 1);
            downButton.setEnabled(selection.size() == 1);
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) GraphSettings(org.netxms.client.datacollection.GraphSettings) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DciListLabelProvider(org.netxms.ui.eclipse.perfview.propertypages.helpers.DciListLabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 22 with SortableTableViewer

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

the class AccessListComparator 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) {
    ITableLabelProvider lp = (ITableLabelProvider) ((SortableTableViewer) viewer).getLabelProvider();
    // $NON-NLS-1$
    int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    String text1 = lp.getColumnText(e1, column);
    String text2 = lp.getColumnText(e2, column);
    if (text1 == null)
        // $NON-NLS-1$
        text1 = "";
    if (text2 == null)
        // $NON-NLS-1$
        text2 = "";
    int result = text1.compareToIgnoreCase(text2);
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 23 with SortableTableViewer

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

the class PredefinedGraph method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    settings = (GraphSettings) getElement().getAdapter(GraphSettings.class);
    acl = new HashMap<Long, AccessListElement>(settings.getAccessList().size());
    for (AccessListElement e : settings.getAccessList()) acl.put(e.getUserId(), new AccessListElement(e));
    // Initiate loading of user manager plugin if it was not loaded before
    // $NON-NLS-1$
    Platform.getAdapterManager().loadAdapter(new AccessListElement(0, 0), "org.eclipse.ui.model.IWorkbenchAdapter");
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    name = new LabeledText(dialogArea, SWT.NONE, SWT.BORDER);
    name.setLabel(Messages.get().PredefinedGraph_Name);
    name.setText(settings.getName());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    name.setLayoutData(gd);
    Group users = new Group(dialogArea, SWT.NONE);
    users.setText(Messages.get().PredefinedGraph_UsersAndGroups);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    users.setLayoutData(gd);
    layout = new GridLayout();
    users.setLayout(layout);
    final String[] columnNames = { Messages.get().PredefinedGraph_LoginName, Messages.get().PredefinedGraph_Rights };
    final int[] columnWidths = { 150, 100 };
    userList = new SortableTableViewer(users, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    userList.setContentProvider(new ArrayContentProvider());
    userList.setLabelProvider(new AccessListLabelProvider());
    userList.setComparator(new AccessListComparator());
    userList.setInput(acl.values().toArray());
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    userList.getControl().setLayoutData(gd);
    Composite buttons = new Composite(users, SWT.NONE);
    FillLayout buttonsLayout = new FillLayout();
    buttonsLayout.spacing = WidgetHelper.INNER_SPACING;
    buttons.setLayout(buttonsLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.widthHint = 184;
    buttons.setLayoutData(gd);
    final Button addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().PredefinedGraph_Add);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(PredefinedGraph.this.getShell(), AbstractUserObject.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) acl.put(user.getId(), new AccessListElement(user.getId(), 0));
                userList.setInput(acl.values().toArray());
            }
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().PredefinedGraph_Delete);
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) userList.getSelection();
            Iterator<AccessListElement> it = sel.iterator();
            while (it.hasNext()) {
                AccessListElement element = it.next();
                acl.remove(element.getUserId());
            }
            userList.setInput(acl.values().toArray());
        }
    });
    Group rights = new Group(dialogArea, SWT.NONE);
    rights.setText(Messages.get().PredefinedGraph_AccessRights);
    rights.setLayout(new RowLayout(SWT.VERTICAL));
    gd = new GridData();
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    rights.setLayoutData(gd);
    createAccessCheck(rights, Messages.get().PredefinedGraph_Read, GraphSettings.ACCESS_READ);
    createAccessCheck(rights, Messages.get().PredefinedGraph_Modify, GraphSettings.ACCESS_WRITE);
    userList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.size() == 1) {
                enableAllChecks(true);
                AccessListElement element = (AccessListElement) sel.getFirstElement();
                int rights = element.getAccessRights();
                for (int i = 0, mask = 1; i < 16; i++, mask <<= 1) {
                    Button check = accessChecks.get(mask);
                    if (check != null) {
                        check.setSelection((rights & mask) == mask);
                    }
                }
            } else {
                enableAllChecks(false);
            }
            deleteButton.setEnabled(sel.size() > 0);
        }
    });
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) AccessListComparator(org.netxms.ui.eclipse.perfview.propertypages.helpers.AccessListComparator) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) AbstractUserObject(org.netxms.client.users.AbstractUserObject) FillLayout(org.eclipse.swt.layout.FillLayout) AccessListElement(org.netxms.client.AccessListElement) AccessListLabelProvider(org.netxms.ui.eclipse.perfview.propertypages.helpers.AccessListLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 24 with SortableTableViewer

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

the class TemplateGraph method createContents.

/* (non-Javadoc)
    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createContents(Composite parent) {
    settings = (GraphSettings) getElement().getAdapter(GraphSettings.class);
    acl = new HashMap<Long, AccessListElement>(settings.getAccessList().size());
    for (AccessListElement e : settings.getAccessList()) acl.put(e.getUserId(), new AccessListElement(e));
    // Initiate loading of user manager plugin if it was not loaded before
    // $NON-NLS-1$
    Platform.getAdapterManager().loadAdapter(new AccessListElement(0, 0), "org.eclipse.ui.model.IWorkbenchAdapter");
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    name = new LabeledText(dialogArea, SWT.NONE, SWT.BORDER);
    name.setLabel(Messages.get().PredefinedGraph_Name);
    name.setText(settings.getName());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    name.setLayoutData(gd);
    Group users = new Group(dialogArea, SWT.NONE);
    users.setText(Messages.get().PredefinedGraph_UsersAndGroups);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    users.setLayoutData(gd);
    layout = new GridLayout();
    users.setLayout(layout);
    final String[] columnNames = { Messages.get().PredefinedGraph_LoginName, Messages.get().PredefinedGraph_Rights };
    final int[] columnWidths = { 150, 100 };
    userList = new SortableTableViewer(users, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    userList.setContentProvider(new ArrayContentProvider());
    userList.setLabelProvider(new AccessListLabelProvider());
    userList.setComparator(new AccessListComparator());
    userList.setInput(acl.values().toArray());
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    userList.getControl().setLayoutData(gd);
    Composite buttons = new Composite(users, SWT.NONE);
    FillLayout buttonsLayout = new FillLayout();
    buttonsLayout.spacing = WidgetHelper.INNER_SPACING;
    buttons.setLayout(buttonsLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.widthHint = 184;
    buttons.setLayoutData(gd);
    final Button addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().PredefinedGraph_Add);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(TemplateGraph.this.getShell(), AbstractUserObject.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) acl.put(user.getId(), new AccessListElement(user.getId(), 0));
                userList.setInput(acl.values().toArray());
            }
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().PredefinedGraph_Delete);
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) userList.getSelection();
            Iterator<AccessListElement> it = sel.iterator();
            while (it.hasNext()) {
                AccessListElement element = it.next();
                acl.remove(element.getUserId());
            }
            userList.setInput(acl.values().toArray());
        }
    });
    Group rights = new Group(dialogArea, SWT.NONE);
    rights.setText(Messages.get().PredefinedGraph_AccessRights);
    rights.setLayout(new RowLayout(SWT.VERTICAL));
    gd = new GridData();
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    rights.setLayoutData(gd);
    createAccessCheck(rights, Messages.get().PredefinedGraph_Read, GraphSettings.ACCESS_READ);
    createAccessCheck(rights, Messages.get().PredefinedGraph_Modify, GraphSettings.ACCESS_WRITE);
    userList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.size() == 1) {
                enableAllChecks(true);
                AccessListElement element = (AccessListElement) sel.getFirstElement();
                int rights = element.getAccessRights();
                for (int i = 0, mask = 1; i < 16; i++, mask <<= 1) {
                    Button check = accessChecks.get(mask);
                    if (check != null) {
                        check.setSelection((rights & mask) == mask);
                    }
                }
            } else {
                enableAllChecks(false);
            }
            deleteButton.setEnabled(sel.size() > 0);
        }
    });
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) AccessListComparator(org.netxms.ui.eclipse.perfview.propertypages.helpers.AccessListComparator) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) AbstractUserObject(org.netxms.client.users.AbstractUserObject) FillLayout(org.eclipse.swt.layout.FillLayout) AccessListElement(org.netxms.client.AccessListElement) AccessListLabelProvider(org.netxms.ui.eclipse.perfview.propertypages.helpers.AccessListLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 25 with SortableTableViewer

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

the class MappingTableListComparator 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;
    MappingTableDescriptor d1 = (MappingTableDescriptor) e1;
    MappingTableDescriptor d2 = (MappingTableDescriptor) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case MappingTables.COLUMN_ID:
            result = d1.getId() - d2.getId();
            break;
        case MappingTables.COLUMN_NAME:
            result = d1.getName().compareToIgnoreCase(d2.getName());
            break;
        case MappingTables.COLUMN_DESCRIPTION:
            result = d1.getDescription().compareToIgnoreCase(d2.getDescription());
            break;
        case MappingTables.COLUMN_FLAGS:
            result = d1.getFlags() - d2.getFlags();
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : MappingTableDescriptor(org.netxms.client.mt.MappingTableDescriptor) 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