Search in sources :

Example 6 with SortableTableViewer

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

the class LastValuesComparator 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;
    DciValue v1 = (DciValue) e1;
    DciValue v2 = (DciValue) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case LastValuesWidget.COLUMN_ID:
            result = (int) (v1.getId() - v2.getId());
            break;
        case LastValuesWidget.COLUMN_DESCRIPTION:
            result = v1.getDescription().compareToIgnoreCase(v2.getDescription());
            break;
        case LastValuesWidget.COLUMN_VALUE:
            result = compareValue(v1, v2);
            break;
        case LastValuesWidget.COLUMN_TIMESTAMP:
            result = v1.getTimestamp().compareTo(v2.getTimestamp());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : DciValue(org.netxms.client.datacollection.DciValue) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 7 with SortableTableViewer

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

the class DciComparator 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;
    DataCollectionObject dci1 = (DataCollectionObject) e1;
    DataCollectionObject dci2 = (DataCollectionObject) e2;
    // $NON-NLS-1$
    int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    switch(column) {
        case DataCollectionEditor.COLUMN_ID:
            result = (int) (dci1.getId() - dci2.getId());
            break;
        case DataCollectionEditor.COLUMN_DESCRIPTION:
            result = dci1.getDescription().compareToIgnoreCase(dci2.getDescription());
            break;
        case DataCollectionEditor.COLUMN_PARAMETER:
            result = dci1.getName().compareToIgnoreCase(dci2.getName());
            break;
        case DataCollectionEditor.COLUMN_INTERVAL:
            result = (int) (dci1.getComparablePollingInterval() - dci2.getComparablePollingInterval());
            break;
        case DataCollectionEditor.COLUMN_RETENTION:
            result = (int) (dci1.getComparableRetentionTime() - dci2.getComparableRetentionTime());
            break;
        case DataCollectionEditor.COLUMN_ORIGIN:
        case DataCollectionEditor.COLUMN_DATATYPE:
        case DataCollectionEditor.COLUMN_STATUS:
        case DataCollectionEditor.COLUMN_TEMPLATE:
            final String text1 = labelProvider.getColumnText(e1, column);
            final String text2 = labelProvider.getColumnText(e2, column);
            if (text1 != null && text2 != null) {
                result = text1.compareToIgnoreCase(text2);
            } else {
                if (text1 == null) {
                    if (text2 == null) {
                        result = 0;
                    } else {
                        result = -1;
                    }
                } else {
                    result = 1;
                }
            }
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 8 with SortableTableViewer

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

the class PackageManager 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().PackageManager_ColumnID, Messages.get().PackageManager_ColumnName, Messages.get().PackageManager_ColumnVersion, Messages.get().PackageManager_ColumnPlatform, Messages.get().PackageManager_ColumnFile, Messages.get().PackageManager_ColumnDescription };
    final int[] widths = { 70, 120, 90, 120, 150, 400 };
    viewer = new SortableTableViewer(parent, names, widths, COLUMN_ID, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new PackageLabelProvider());
    viewer.setComparator(new PackageComparator());
    createActions();
    contributeToActionBars();
    createPopupMenu();
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            actionDeploy.setEnabled(selection.size() == 1);
            actionRemove.setEnabled(selection.size() > 0);
        }
    });
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().PackageManager_OpenDatabase, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                session.lockPackageDatabase();
            } catch (NXCException e) {
                // New versions may not require package DB lock
                if (e.getErrorCode() != RCC.NOT_IMPLEMENTED)
                    throw e;
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    refresh();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().PackageManager_OpenError;
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) PackageComparator(org.netxms.ui.eclipse.agentmanager.views.helpers.PackageComparator) 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) PackageLabelProvider(org.netxms.ui.eclipse.agentmanager.views.helpers.PackageLabelProvider) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 9 with SortableTableViewer

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

the class AccessControl method createContents.

@Override
protected Control createContents(Composite parent) {
    session = ConsoleSharedData.getSession();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    editor = (AlarmCategoryEditor) getElement().getAdapter(AlarmCategoryEditor.class);
    category = editor.getObjectAsItem();
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { "Login Name" };
    final int[] columnWidths = { 300 };
    userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    userList.setContentProvider(new ArrayContentProvider());
    userList.setLabelProvider(new WorkbenchLabelProvider());
    userList.setComparator(new UserComparator());
    GridData 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(dialogArea, 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("Add...");
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(AccessControl.this.getShell(), AbstractUserObject.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) accessMap.put(user.getId(), user);
                userList.setInput(accessMap.values().toArray(new AbstractUserObject[accessMap.size()]));
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText("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 selecion = (IStructuredSelection) userList.getSelection();
            Iterator<AbstractUserObject> iterator = selecion.iterator();
            while (iterator.hasNext()) {
                AbstractUserObject element = iterator.next();
                accessMap.remove(element.getId());
            }
            userList.setInput(accessMap.values().toArray());
        }
    });
    userList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteButton.setEnabled(!userList.getSelection().isEmpty());
        }
    });
    // Initial data
    for (long userId : category.getAccessControl()) {
        final AbstractUserObject user = session.findUserDBObjectById(userId);
        if (user != null) {
            accessMap.put(user.getId(), user);
        }
    }
    userList.setInput(accessMap.values().toArray());
    return dialogArea;
}
Also used : SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) AbstractUserObject(org.netxms.client.users.AbstractUserObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 10 with SortableTableViewer

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

the class ServerFileManager 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();
    content = new Composite(parent, SWT.NONE);
    content.setLayout(new FormLayout());
    // Create filter area
    filterText = new FilterText(content, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    final String[] columnNames = { Messages.get().ViewServerFile_FileName, Messages.get().ViewServerFile_FileType, Messages.get().ViewServerFile_FileSize, Messages.get().ViewServerFile_ModificationDate };
    final int[] columnWidths = { 300, 150, 300, 300 };
    viewer = new SortableTableViewer(content, columnNames, columnWidths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ServerFileLabelProvider());
    viewer.setComparator(new ServerFileComparator());
    filter = new ServerFileFilter();
    viewer.addFilter(filter);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionDelete.setEnabled(selection.size() > 0);
            }
        }
    });
    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.getTable().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);
    filterText.setCloseAction(actionShowFilter);
    // Set initial focus to filter input line
    if (initShowFilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
    refreshFileList();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ServerFileLabelProvider(org.netxms.ui.eclipse.filemanager.views.helpers.ServerFileLabelProvider) ServerFileComparator(org.netxms.ui.eclipse.filemanager.views.helpers.ServerFileComparator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ServerFileFilter(org.netxms.ui.eclipse.filemanager.views.helpers.ServerFileFilter) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) FilterText(org.netxms.ui.eclipse.widgets.FilterText) FormAttachment(org.eclipse.swt.layout.FormAttachment)

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