Search in sources :

Example 11 with SortableTableViewer

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

the class DciListComparator 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 DciList.COLUMN_ID:
            result = (int) (v1.getId() - v2.getId());
            break;
        case DciList.COLUMN_PARAMETER:
            result = v1.getName().compareToIgnoreCase(v2.getName());
            break;
        case DciList.COLUMN_DESCRIPTION:
            result = v1.getDescription().compareToIgnoreCase(v2.getDescription());
            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 12 with SortableTableViewer

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

the class ScriptComparator 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;
    Script s1 = (Script) e1;
    Script s2 = (Script) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case ScriptLibrary.COLUMN_ID:
            result = Long.signum(s1.getId() - s2.getId());
            break;
        case ScriptLibrary.COLUMN_NAME:
            result = s1.getName().compareToIgnoreCase(s2.getName());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : Script(org.netxms.client.Script) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 13 with SortableTableViewer

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

the class ScriptLibrary method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = ConsoleSharedData.getSession();
    parent.setLayout(new FillLayout());
    final String[] names = { Messages.get().ScriptLibrary_ColumnId, Messages.get().ScriptLibrary_ColumnName };
    final int[] widths = { 70, 400 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ScriptLabelProvider());
    viewer.setComparator(new ScriptComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEdit.setEnabled(selection.size() == 1);
                actionRename.setEnabled(selection.size() == 1);
                actionDelete.setEnabled(selection.size() > 0);
                actionCopyName.setEnabled(selection.size() == 1);
            }
        }
    });
    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);
        }
    });
    activateContext();
    createActions();
    contributeToActionBars();
    createPopupMenu();
    refreshScriptList();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ScriptLabelProvider(org.netxms.ui.eclipse.nxsl.views.helpers.ScriptLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ScriptComparator(org.netxms.ui.eclipse.nxsl.views.helpers.ScriptComparator)

Example 14 with SortableTableViewer

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

the class ClusterResourceListComparator 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 ClusterResource r1 = (ClusterResource) e1;
    final ClusterResource r2 = (ClusterResource) e2;
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    int result;
    switch(column) {
        case ClusterTab.COLUMN_NAME:
            result = r1.getName().compareToIgnoreCase(r2.getName());
            break;
        case ClusterTab.COLUMN_VIP:
            byte[] addr1 = r1.getVirtualAddress().getAddress();
            byte[] addr2 = r2.getVirtualAddress().getAddress();
            result = 0;
            for (int i = 0; (i < addr1.length) && (result == 0); i++) {
                result = addr1[i] - addr2[i];
            }
            break;
        case ClusterTab.COLUMN_OWNER:
            result = getOwnerName(r1).compareToIgnoreCase(getOwnerName(r2));
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) ClusterResource(org.netxms.client.objects.ClusterResource)

Example 15 with SortableTableViewer

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

the class AccessControl method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    object = (AbstractObject) getElement().getAdapter(AbstractObject.class);
    AccessListElement[] origAcl = object.getAccessList();
    acl = new HashMap<Long, AccessListElement>(origAcl.length);
    for (int i = 0; i < origAcl.length; i++) acl.put(origAcl[i].getUserId(), new AccessListElement(origAcl[i]));
    // 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);
    Group users = new Group(dialogArea, SWT.NONE);
    users.setText(Messages.get().AccessControl_UsersGroups);
    GridData 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().AccessControl_ColLogin, Messages.get().AccessControl_ColRights };
    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().AccessControl_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

        @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) 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().AccessControl_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().AccessControl_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().AccessControl_AccessRead, UserAccessRights.OBJECT_ACCESS_READ);
    createAccessCheck(rights, "Read agent data", UserAccessRights.OBJECT_ACCESS_READ_AGENT);
    createAccessCheck(rights, "Read SNMP data", UserAccessRights.OBJECT_ACCESS_READ_SNMP);
    createAccessCheck(rights, Messages.get().AccessControl_AccessModify, UserAccessRights.OBJECT_ACCESS_MODIFY);
    createAccessCheck(rights, Messages.get().AccessControl_AccessCreate, UserAccessRights.OBJECT_ACCESS_CREATE);
    createAccessCheck(rights, Messages.get().AccessControl_AccessDelete, UserAccessRights.OBJECT_ACCESS_DELETE);
    createAccessCheck(rights, Messages.get().AccessControl_AccessControl, UserAccessRights.OBJECT_ACCESS_CONTROL);
    createAccessCheck(rights, Messages.get().AccessControl_AccessSendEvents, UserAccessRights.OBJECT_ACCESS_SEND_EVENTS);
    createAccessCheck(rights, Messages.get().AccessControl_AccessViewAlarms, UserAccessRights.OBJECT_ACCESS_READ_ALARMS);
    createAccessCheck(rights, Messages.get().AccessControl_AccessUpdateAlarms, UserAccessRights.OBJECT_ACCESS_UPDATE_ALARMS);
    createAccessCheck(rights, Messages.get().AccessControl_AccessTermAlarms, UserAccessRights.OBJECT_ACCESS_TERM_ALARMS);
    createAccessCheck(rights, Messages.get().AccessControl_CreateTicket, UserAccessRights.OBJECT_ACCESS_CREATE_ISSUE);
    createAccessCheck(rights, Messages.get().AccessControl_AccessPushData, UserAccessRights.OBJECT_ACCESS_PUSH_DATA);
    createAccessCheck(rights, Messages.get().AccessControl_AccessAccessControl, UserAccessRights.OBJECT_ACCESS_ACL);
    createAccessCheck(rights, Messages.get().AccessControl_DownloadFiles, UserAccessRights.OBJECT_ACCESS_DOWNLOAD);
    createAccessCheck(rights, Messages.get().AccessControl_UploadFiles, UserAccessRights.OBJECT_ACCESS_UPLOAD);
    createAccessCheck(rights, Messages.get().AccessControl_ManageFiles, UserAccessRights.OBJECT_ACCESS_MANAGE_FILES);
    createAccessCheck(rights, "Control maintenance mode", UserAccessRights.OBJECT_ACCESS_MAINTENANCE);
    createAccessCheck(rights, "Take screenshot", UserAccessRights.OBJECT_ACCESS_SCREENSHOT);
    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 < accessChecks.size(); i++, mask <<= 1) {
                    Button check = accessChecks.get(mask);
                    if (check != null) {
                        check.setSelection((rights & mask) == mask);
                    }
                }
            } else {
                enableAllChecks(false);
            }
            deleteButton.setEnabled(sel.size() > 0);
        }
    });
    checkInherit = new Button(dialogArea, SWT.CHECK);
    checkInherit.setText(Messages.get().AccessControl_InheritRights);
    if (object.getParentCount() > 0) {
        checkInherit.setSelection(object.isInheritAccessRights());
    } else {
        // For objects without parent "inherit access rights" option is meaningless
        checkInherit.setSelection(false);
        checkInherit.setEnabled(false);
    }
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) AccessListComparator(org.netxms.ui.eclipse.objectmanager.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) 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.objectmanager.propertypages.helpers.AccessListLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

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