Search in sources :

Example 1 with ResponsibleUsersLabelProvider

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

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 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 AccessListElement (org.netxms.client.AccessListElement)1 NXCSession (org.netxms.client.NXCSession)1 AbstractUserObject (org.netxms.client.users.AbstractUserObject)1 ResponsibleUsersComparator (org.netxms.ui.eclipse.objectmanager.propertypages.helpers.ResponsibleUsersComparator)1 ResponsibleUsersLabelProvider (org.netxms.ui.eclipse.objectmanager.propertypages.helpers.ResponsibleUsersLabelProvider)1 SelectUserDialog (org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1