Search in sources :

Example 6 with User

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

the class General method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    final String newName = new String(textName.getText());
    final String newDescription = new String(textDescription.getText());
    // $NON-NLS-1$
    final String newFullName = (object instanceof User) ? textFullName.getText() : "";
    // $NON-NLS-1$
    final String newXmppId = (object instanceof User) ? textXmppId.getText() : "";
    if (newName.equals(initialName) && newDescription.equals(initialDescription) && newFullName.equals(initialFullName) && newXmppId.equals(initialXmppId))
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    new ConsoleJob(Messages.get().General_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            initialName = newName;
            initialFullName = newFullName;
            initialDescription = newDescription;
            initialXmppId = newXmppId;
            int fields = AbstractUserObject.MODIFY_LOGIN_NAME | AbstractUserObject.MODIFY_DESCRIPTION;
            object.setName(newName);
            object.setDescription(newDescription);
            if (object instanceof User) {
                ((User) object).setFullName(newFullName);
                ((User) object).setXmppId(newXmppId);
                fields |= AbstractUserObject.MODIFY_FULL_NAME | AbstractUserObject.MODIFY_XMPP_ID;
            }
            session.modifyUserDBObject(object, fields);
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        General.this.setValid(true);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().General_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) User(org.netxms.client.users.User) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 7 with User

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

Aggregations

User (org.netxms.client.users.User)7 AbstractUserObject (org.netxms.client.users.AbstractUserObject)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 NXCSession (org.netxms.client.NXCSession)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 GroupMarker (org.eclipse.jface.action.GroupMarker)1 Separator (org.eclipse.jface.action.Separator)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1