Search in sources :

Example 1 with AccessListComparator

use of org.netxms.ui.eclipse.perfview.propertypages.helpers.AccessListComparator 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 2 with AccessListComparator

use of org.netxms.ui.eclipse.perfview.propertypages.helpers.AccessListComparator 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)

Aggregations

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