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;
}
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();
}
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;
}
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;
}
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);
}
Aggregations