Search in sources :

Example 1 with AccessListLabelProvider

use of org.netxms.ui.eclipse.objectmanager.propertypages.helpers.AccessListLabelProvider 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

Iterator (java.util.Iterator)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 AccessListElement (org.netxms.client.AccessListElement)1 AbstractUserObject (org.netxms.client.users.AbstractUserObject)1 AccessListComparator (org.netxms.ui.eclipse.objectmanager.propertypages.helpers.AccessListComparator)1 AccessListLabelProvider (org.netxms.ui.eclipse.objectmanager.propertypages.helpers.AccessListLabelProvider)1 SelectUserDialog (org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1