Search in sources :

Example 26 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.

the class ResponsibleUsers method createContents.

/* (non-Javadoc)
    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createContents(Composite parent) {
    final NXCSession session = ConsoleSharedData.getSession();
    object = (AbstractObject) getElement().getAdapter(AbstractObject.class);
    userList = session.findUserDBObjectsByIds(object.getResponsibleUsers());
    // 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);
    dialogArea.setLayout(new GridLayout());
    final String[] columnNames = { "Login Name" };
    final int[] columnWidths = { 150 };
    userTable = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    userTable.setContentProvider(new ArrayContentProvider());
    userTable.setLabelProvider(new ResponsibleUsersLabelProvider());
    userTable.setComparator(new ResponsibleUsersComparator());
    userTable.setInput(userList.toArray());
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    userTable.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 widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(getShell(), AbstractUserObject.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) userList.add(user);
                userTable.setInput(userList.toArray());
            }
        }
    });
    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 selection = (IStructuredSelection) userTable.getSelection();
            Iterator<AbstractUserObject> it = selection.iterator();
            while (it.hasNext()) {
                AbstractUserObject element = it.next();
                userList.remove(element);
            }
            userTable.setInput(userList.toArray());
        }
    });
    userTable.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            deleteButton.setEnabled(!selection.isEmpty());
        }
    });
    return dialogArea;
}
Also used : ResponsibleUsersComparator(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.ResponsibleUsersComparator) SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ResponsibleUsersLabelProvider(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.ResponsibleUsersLabelProvider) 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) AccessListElement(org.netxms.client.AccessListElement) 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

AbstractUserObject (org.netxms.client.users.AbstractUserObject)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 SelectionListener (org.eclipse.swt.events.SelectionListener)9 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Button (org.eclipse.swt.widgets.Button)9 Composite (org.eclipse.swt.widgets.Composite)9 SelectUserDialog (org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog)9 Iterator (java.util.Iterator)7 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)7 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)7 FillLayout (org.eclipse.swt.layout.FillLayout)7 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)7 NXCSession (org.netxms.client.NXCSession)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 RowLayout (org.eclipse.swt.layout.RowLayout)5 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)5 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)4