Search in sources :

Example 1 with UserComparator

use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator 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 2 with UserComparator

use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.

the class Members method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    session = ConsoleSharedData.getSession();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (UserGroup) getElement().getAdapter(UserGroup.class);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().Members_LoginName };
    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(Messages.get().Members_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(Members.this.getShell(), AbstractUserObject.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) members.put(user.getId(), user);
                userList.setInput(members.values().toArray(new AbstractUserObject[members.size()]));
            }
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().Members_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<AbstractUserObject> it = sel.iterator();
            while (it.hasNext()) {
                AbstractUserObject element = it.next();
                members.remove(element.getId());
            }
            userList.setInput(members.values().toArray());
        }
    });
    userList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteButton.setEnabled(!userList.getSelection().isEmpty());
        }
    });
    // Initial data
    for (long userId : object.getMembers()) {
        final AbstractUserObject user = session.findUserDBObjectById(userId);
        if (user != null) {
            members.put(user.getId(), user);
        }
    }
    userList.setInput(members.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 3 with UserComparator

use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.

the class UserManagementView 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();
    final String[] names = { Messages.get().UserManagementView_Name, Messages.get().UserManagementView_Type, Messages.get().UserManagementView_FullName, Messages.get().UserManagementView_Description, Messages.get().UserManagementView_Source, Messages.get().UserManagementView_Authentication, Messages.get().UserManagementView_GUID, "LDAP DN", "Last Login", "Created" };
    final int[] widths = { 100, 80, 180, 250, 80, 170, 250, 400, 250, 250 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new UserLabelProvider());
    viewer.setComparator(new UserComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEditUser.setEnabled(selection.size() == 1);
                actionChangePassword.setEnabled((selection.size() == 1) && (selection.getFirstElement() instanceof User));
                actionDeleteUser.setEnabled(selection.size() > 0);
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEditUser.run();
        }
    });
    makeActions();
    contributeToActionBars();
    createPopupMenu();
    // Listener for server's notifications
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(final SessionNotification n) {
            if (n.getCode() == SessionNotification.USER_DB_CHANGED) {
                viewer.getControl().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(session.getUserDatabaseObjects());
                        if (editNewUser && (n.getSubCode() == SessionNotification.USER_DB_OBJECT_CREATED)) {
                            editNewUser = false;
                            viewer.setSelection(new StructuredSelection(n.getObject()), true);
                            actionEditUser.run();
                        }
                    }
                });
            }
        }
    };
    // Request server to lock user database, and on success refresh view
    new ConsoleJob(Messages.get().UserManagementView_OpenJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.lockUserDatabase();
            databaseLocked = true;
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(session.getUserDatabaseObjects());
                    session.addListener(sessionListener);
                }
            });
        }

        @Override
        protected void jobFailureHandler() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    UserManagementView.this.getViewSite().getPage().hideView(UserManagementView.this);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().UserManagementView_OpenJobError;
        }
    }.start();
}
Also used : UserLabelProvider(org.netxms.ui.eclipse.usermanager.views.helpers.UserLabelProvider) User(org.netxms.client.users.User) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SessionNotification(org.netxms.client.SessionNotification)

Example 4 with UserComparator

use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.

the class SelectUserDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    session = ConsoleSharedData.getSession();
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    dialogArea.setLayout(layout);
    new Label(dialogArea, SWT.NONE).setText(Messages.get().SelectUserDialog_AvailableUsers);
    final String[] columnNames = { Messages.get().SelectUserDialog_LoginName };
    final int[] columnWidths = { 250 };
    userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | (multiSelection ? SWT.MULTI : 0) | SWT.FULL_SELECTION);
    userList.setContentProvider(new ArrayContentProvider());
    userList.setLabelProvider(new WorkbenchLabelProvider());
    userList.setComparator(new UserComparator());
    userList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            SelectUserDialog.this.okPressed();
        }
    });
    userList.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return classFilter.isInstance(element);
        }
    });
    userList.setInput(session.getUserDatabaseObjects());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    userList.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) Label(org.eclipse.swt.widgets.Label) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) AbstractUserObject(org.netxms.client.users.AbstractUserObject)

Example 5 with UserComparator

use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.

the class GroupMembership method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    session = ConsoleSharedData.getSession();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (User) getElement().getAdapter(User.class);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().GroupMembership_ColName };
    final int[] columnWidths = { 300 };
    groupList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    groupList.setContentProvider(new ArrayContentProvider());
    groupList.setLabelProvider(new WorkbenchLabelProvider());
    groupList.setComparator(new UserComparator());
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    groupList.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(Messages.get().Members_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(GroupMembership.this.getShell(), UserGroup.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) groups.put(user.getId(), user);
                groupList.setInput(groups.values().toArray(new AbstractUserObject[groups.size()]));
            }
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().Members_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) groupList.getSelection();
            Iterator<AbstractUserObject> it = sel.iterator();
            while (it.hasNext()) {
                AbstractUserObject element = it.next();
                groups.remove(element.getId());
            }
            groupList.setInput(groups.values().toArray());
        }
    });
    groupList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteButton.setEnabled(!groupList.getSelection().isEmpty());
        }
    });
    // Initial data
    for (long groupId : object.getGroups()) {
        final AbstractUserObject group = session.findUserDBObjectById(groupId);
        if (group != null) {
            groups.put(group.getId(), group);
        }
    }
    groupList.setInput(groups.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) UserGroup(org.netxms.client.users.UserGroup) 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)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)5 UserComparator (org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator)5 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)4 AbstractUserObject (org.netxms.client.users.AbstractUserObject)4 Iterator (java.util.Iterator)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 Button (org.eclipse.swt.widgets.Button)3 SelectUserDialog (org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog)3 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1