Search in sources :

Example 21 with AbstractUserObject

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

the class UserAdapterFactory method getAdapter.

/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == IWorkbenchAdapter.class) {
        // NXCUser
        if (adaptableObject instanceof User) {
            return new IWorkbenchAdapter() {

                @Override
                public Object[] getChildren(Object o) {
                    return null;
                }

                @Override
                public ImageDescriptor getImageDescriptor(Object object) {
                    // $NON-NLS-1$
                    return Activator.getImageDescriptor("icons/user.png");
                }

                @Override
                public String getLabel(Object o) {
                    return ((User) o).getName();
                }

                @Override
                public Object getParent(Object o) {
                    return null;
                }
            };
        }
        // NXCUserGroup
        if (adaptableObject instanceof UserGroup) {
            return new IWorkbenchAdapter() {

                @Override
                public Object[] getChildren(Object o) {
                    long[] members = ((UserGroup) o).getMembers();
                    AbstractUserObject[] childrens = new User[members.length];
                    for (int i = 0; i < members.length; i++) childrens[i] = ConsoleSharedData.getSession().findUserDBObjectById(members[i]);
                    return childrens;
                }

                @Override
                public ImageDescriptor getImageDescriptor(Object object) {
                    // $NON-NLS-1$
                    return Activator.getImageDescriptor("icons/group.png");
                }

                @Override
                public String getLabel(Object o) {
                    return ((UserGroup) o).getName();
                }

                @Override
                public Object getParent(Object o) {
                    return null;
                }
            };
        }
        // AccessListElement
        if (adaptableObject instanceof AbstractAccessListElement) {
            return new IWorkbenchAdapter() {

                @Override
                public Object[] getChildren(Object o) {
                    return null;
                }

                @Override
                public ImageDescriptor getImageDescriptor(Object object) {
                    long userId = ((AbstractAccessListElement) object).getUserId();
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return Activator.getImageDescriptor((userId < 0x80000000L) ? "icons/user.png" : "icons/group.png");
                }

                @Override
                public String getLabel(Object object) {
                    long userId = ((AbstractAccessListElement) object).getUserId();
                    NXCSession session = ConsoleSharedData.getSession();
                    AbstractUserObject dbo = session.findUserDBObjectById(userId);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return (dbo != null) ? dbo.getName() : ("{" + Long.toString(userId) + "}");
                }

                @Override
                public Object getParent(Object o) {
                    return null;
                }
            };
        }
    }
    return null;
}
Also used : User(org.netxms.client.users.User) NXCSession(org.netxms.client.NXCSession) AbstractAccessListElement(org.netxms.client.users.AbstractAccessListElement) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) AbstractUserObject(org.netxms.client.users.AbstractUserObject) AbstractUserObject(org.netxms.client.users.AbstractUserObject) UserGroup(org.netxms.client.users.UserGroup)

Example 22 with AbstractUserObject

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

the class SelectUserDialog method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
    IStructuredSelection sel = (IStructuredSelection) userList.getSelection();
    if (sel.size() == 0) {
        MessageDialogHelper.openWarning(getShell(), Messages.get().SelectUserDialog_Warning, Messages.get().SelectUserDialog_WarningText);
        return;
    }
    selection = new AbstractUserObject[sel.size()];
    Iterator<AbstractUserObject> it = sel.iterator();
    for (int i = 0; it.hasNext(); i++) {
        selection[i] = it.next();
    }
    super.okPressed();
}
Also used : AbstractUserObject(org.netxms.client.users.AbstractUserObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 23 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject 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)

Example 24 with AbstractUserObject

use of org.netxms.client.users.AbstractUserObject 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) {
    Composite dialogArea = (Composite) super.createContents(parent);
    dco = editor.getObject();
    // Initiate loading of user manager plugin if it was not loaded before
    // $NON-NLS-1$ //$NON-NLS-2$
    Platform.getAdapterManager().loadAdapter(new User(""), "org.eclipse.ui.model.IWorkbenchAdapter");
    // Build internal copy of access list
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    for (Long uid : dco.getAccessList()) {
        AbstractUserObject o = session.findUserDBObjectById(uid);
        if (o != null)
            acl.add(o);
    }
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText("Restrict access to the following users");
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new AccessListLabelProvider());
    viewer.setComparator(new ObjectLabelComparator((ILabelProvider) viewer.getLabelProvider()));
    viewer.getTable().setSortDirection(SWT.UP);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    viewer.getTable().setLayoutData(gd);
    setViewerInput();
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttons.setLayout(buttonLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.verticalIndent = WidgetHelper.OUTER_SPACING - WidgetHelper.INNER_SPACING;
    buttons.setLayoutData(gd);
    buttonAdd = new Button(buttons, SWT.PUSH);
    buttonAdd.setText("Add");
    buttonAdd.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            addUser();
        }
    });
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonAdd.setLayoutData(rd);
    buttonRemove = new Button(buttons, SWT.PUSH);
    buttonRemove.setText("Remove");
    buttonRemove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeUsers();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonRemove.setLayoutData(rd);
    return dialogArea;
}
Also used : User(org.netxms.client.users.User) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ObjectLabelComparator(org.netxms.ui.eclipse.tools.ObjectLabelComparator) AbstractUserObject(org.netxms.client.users.AbstractUserObject) Label(org.eclipse.swt.widgets.Label) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) AccessListLabelProvider(org.netxms.ui.eclipse.datacollection.propertypages.helpers.AccessListLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 25 with AbstractUserObject

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

the class AccessControl method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    List<Long> list = new ArrayList<Long>(acl.size());
    for (AbstractUserObject o : acl) list.add(o.getId());
    dco.setAccessList(list);
}
Also used : ArrayList(java.util.ArrayList) AbstractUserObject(org.netxms.client.users.AbstractUserObject)

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