use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.
the class AccessControl method createContents.
@Override
protected Control createContents(Composite parent) {
session = ConsoleSharedData.getSession();
Composite dialogArea = new Composite(parent, SWT.NONE);
editor = (AlarmCategoryEditor) getElement().getAdapter(AlarmCategoryEditor.class);
category = editor.getObjectAsItem();
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
final String[] columnNames = { "Login Name" };
final int[] columnWidths = { 300 };
userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
userList.setContentProvider(new ArrayContentProvider());
userList.setLabelProvider(new WorkbenchLabelProvider());
userList.setComparator(new UserComparator());
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
userList.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 widgetSelected(SelectionEvent e) {
SelectUserDialog dlg = new SelectUserDialog(AccessControl.this.getShell(), AbstractUserObject.class);
if (dlg.open() == Window.OK) {
AbstractUserObject[] selection = dlg.getSelection();
for (AbstractUserObject user : selection) accessMap.put(user.getId(), user);
userList.setInput(accessMap.values().toArray(new AbstractUserObject[accessMap.size()]));
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
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 selecion = (IStructuredSelection) userList.getSelection();
Iterator<AbstractUserObject> iterator = selecion.iterator();
while (iterator.hasNext()) {
AbstractUserObject element = iterator.next();
accessMap.remove(element.getId());
}
userList.setInput(accessMap.values().toArray());
}
});
userList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
deleteButton.setEnabled(!userList.getSelection().isEmpty());
}
});
// Initial data
for (long userId : category.getAccessControl()) {
final AbstractUserObject user = session.findUserDBObjectById(userId);
if (user != null) {
accessMap.put(user.getId(), user);
}
}
userList.setInput(accessMap.values().toArray());
return dialogArea;
}
use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.
the class Members 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 = (UserGroup) getElement().getAdapter(UserGroup.class);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
final String[] columnNames = { Messages.get().Members_LoginName };
final int[] columnWidths = { 300 };
userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
userList.setContentProvider(new ArrayContentProvider());
userList.setLabelProvider(new WorkbenchLabelProvider());
userList.setComparator(new UserComparator());
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
userList.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(Members.this.getShell(), AbstractUserObject.class);
if (dlg.open() == Window.OK) {
AbstractUserObject[] selection = dlg.getSelection();
for (AbstractUserObject user : selection) members.put(user.getId(), user);
userList.setInput(members.values().toArray(new AbstractUserObject[members.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) userList.getSelection();
Iterator<AbstractUserObject> it = sel.iterator();
while (it.hasNext()) {
AbstractUserObject element = it.next();
members.remove(element.getId());
}
userList.setInput(members.values().toArray());
}
});
userList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
deleteButton.setEnabled(!userList.getSelection().isEmpty());
}
});
// Initial data
for (long userId : object.getMembers()) {
final AbstractUserObject user = session.findUserDBObjectById(userId);
if (user != null) {
members.put(user.getId(), user);
}
}
userList.setInput(members.values().toArray());
return dialogArea;
}
use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.
the class UserManagementView method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = ConsoleSharedData.getSession();
final String[] names = { Messages.get().UserManagementView_Name, Messages.get().UserManagementView_Type, Messages.get().UserManagementView_FullName, Messages.get().UserManagementView_Description, Messages.get().UserManagementView_Source, Messages.get().UserManagementView_Authentication, Messages.get().UserManagementView_GUID, "LDAP DN", "Last Login", "Created" };
final int[] widths = { 100, 80, 180, 250, 80, 170, 250, 400, 250, 250 };
viewer = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new UserLabelProvider());
viewer.setComparator(new UserComparator());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null) {
actionEditUser.setEnabled(selection.size() == 1);
actionChangePassword.setEnabled((selection.size() == 1) && (selection.getFirstElement() instanceof User));
actionDeleteUser.setEnabled(selection.size() > 0);
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
actionEditUser.run();
}
});
makeActions();
contributeToActionBars();
createPopupMenu();
// Listener for server's notifications
sessionListener = new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if (n.getCode() == SessionNotification.USER_DB_CHANGED) {
viewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
viewer.setInput(session.getUserDatabaseObjects());
if (editNewUser && (n.getSubCode() == SessionNotification.USER_DB_OBJECT_CREATED)) {
editNewUser = false;
viewer.setSelection(new StructuredSelection(n.getObject()), true);
actionEditUser.run();
}
}
});
}
}
};
// Request server to lock user database, and on success refresh view
new ConsoleJob(Messages.get().UserManagementView_OpenJobName, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.lockUserDatabase();
databaseLocked = true;
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.setInput(session.getUserDatabaseObjects());
session.addListener(sessionListener);
}
});
}
@Override
protected void jobFailureHandler() {
runInUIThread(new Runnable() {
@Override
public void run() {
UserManagementView.this.getViewSite().getPage().hideView(UserManagementView.this);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().UserManagementView_OpenJobError;
}
}.start();
}
use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator in project netxms by netxms.
the class SelectUserDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
session = ConsoleSharedData.getSession();
Composite dialogArea = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
dialogArea.setLayout(layout);
new Label(dialogArea, SWT.NONE).setText(Messages.get().SelectUserDialog_AvailableUsers);
final String[] columnNames = { Messages.get().SelectUserDialog_LoginName };
final int[] columnWidths = { 250 };
userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | (multiSelection ? SWT.MULTI : 0) | SWT.FULL_SELECTION);
userList.setContentProvider(new ArrayContentProvider());
userList.setLabelProvider(new WorkbenchLabelProvider());
userList.setComparator(new UserComparator());
userList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
SelectUserDialog.this.okPressed();
}
});
userList.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return classFilter.isInstance(element);
}
});
userList.setInput(session.getUserDatabaseObjects());
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.heightHint = 300;
userList.getControl().setLayoutData(gd);
return dialogArea;
}
use of org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator 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;
}
Aggregations