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