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) {
object = (AbstractObject) getElement().getAdapter(AbstractObject.class);
AccessListElement[] origAcl = object.getAccessList();
acl = new HashMap<Long, AccessListElement>(origAcl.length);
for (int i = 0; i < origAcl.length; i++) acl.put(origAcl[i].getUserId(), new AccessListElement(origAcl[i]));
// 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);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
dialogArea.setLayout(layout);
Group users = new Group(dialogArea, SWT.NONE);
users.setText(Messages.get().AccessControl_UsersGroups);
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
users.setLayoutData(gd);
layout = new GridLayout();
users.setLayout(layout);
final String[] columnNames = { Messages.get().AccessControl_ColLogin, Messages.get().AccessControl_ColRights };
final int[] columnWidths = { 150, 100 };
userList = new SortableTableViewer(users, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
userList.setContentProvider(new ArrayContentProvider());
userList.setLabelProvider(new AccessListLabelProvider());
userList.setComparator(new AccessListComparator());
userList.setInput(acl.values().toArray());
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(users, 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().AccessControl_Add);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@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) acl.put(user.getId(), new AccessListElement(user.getId(), 0));
userList.setInput(acl.values().toArray());
}
}
});
final Button deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().AccessControl_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<AccessListElement> it = sel.iterator();
while (it.hasNext()) {
AccessListElement element = it.next();
acl.remove(element.getUserId());
}
userList.setInput(acl.values().toArray());
}
});
Group rights = new Group(dialogArea, SWT.NONE);
rights.setText(Messages.get().AccessControl_AccessRights);
rights.setLayout(new RowLayout(SWT.VERTICAL));
gd = new GridData();
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
rights.setLayoutData(gd);
createAccessCheck(rights, Messages.get().AccessControl_AccessRead, UserAccessRights.OBJECT_ACCESS_READ);
createAccessCheck(rights, "Read agent data", UserAccessRights.OBJECT_ACCESS_READ_AGENT);
createAccessCheck(rights, "Read SNMP data", UserAccessRights.OBJECT_ACCESS_READ_SNMP);
createAccessCheck(rights, Messages.get().AccessControl_AccessModify, UserAccessRights.OBJECT_ACCESS_MODIFY);
createAccessCheck(rights, Messages.get().AccessControl_AccessCreate, UserAccessRights.OBJECT_ACCESS_CREATE);
createAccessCheck(rights, Messages.get().AccessControl_AccessDelete, UserAccessRights.OBJECT_ACCESS_DELETE);
createAccessCheck(rights, Messages.get().AccessControl_AccessControl, UserAccessRights.OBJECT_ACCESS_CONTROL);
createAccessCheck(rights, Messages.get().AccessControl_AccessSendEvents, UserAccessRights.OBJECT_ACCESS_SEND_EVENTS);
createAccessCheck(rights, Messages.get().AccessControl_AccessViewAlarms, UserAccessRights.OBJECT_ACCESS_READ_ALARMS);
createAccessCheck(rights, Messages.get().AccessControl_AccessUpdateAlarms, UserAccessRights.OBJECT_ACCESS_UPDATE_ALARMS);
createAccessCheck(rights, Messages.get().AccessControl_AccessTermAlarms, UserAccessRights.OBJECT_ACCESS_TERM_ALARMS);
createAccessCheck(rights, Messages.get().AccessControl_CreateTicket, UserAccessRights.OBJECT_ACCESS_CREATE_ISSUE);
createAccessCheck(rights, Messages.get().AccessControl_AccessPushData, UserAccessRights.OBJECT_ACCESS_PUSH_DATA);
createAccessCheck(rights, Messages.get().AccessControl_AccessAccessControl, UserAccessRights.OBJECT_ACCESS_ACL);
createAccessCheck(rights, Messages.get().AccessControl_DownloadFiles, UserAccessRights.OBJECT_ACCESS_DOWNLOAD);
createAccessCheck(rights, Messages.get().AccessControl_UploadFiles, UserAccessRights.OBJECT_ACCESS_UPLOAD);
createAccessCheck(rights, Messages.get().AccessControl_ManageFiles, UserAccessRights.OBJECT_ACCESS_MANAGE_FILES);
createAccessCheck(rights, "Control maintenance mode", UserAccessRights.OBJECT_ACCESS_MAINTENANCE);
createAccessCheck(rights, "Take screenshot", UserAccessRights.OBJECT_ACCESS_SCREENSHOT);
userList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.size() == 1) {
enableAllChecks(true);
AccessListElement element = (AccessListElement) sel.getFirstElement();
int rights = element.getAccessRights();
for (int i = 0, mask = 1; i < accessChecks.size(); i++, mask <<= 1) {
Button check = accessChecks.get(mask);
if (check != null) {
check.setSelection((rights & mask) == mask);
}
}
} else {
enableAllChecks(false);
}
deleteButton.setEnabled(sel.size() > 0);
}
});
checkInherit = new Button(dialogArea, SWT.CHECK);
checkInherit.setText(Messages.get().AccessControl_InheritRights);
if (object.getParentCount() > 0) {
checkInherit.setSelection(object.isInheritAccessRights());
} else {
// For objects without parent "inherit access rights" option is meaningless
checkInherit.setSelection(false);
checkInherit.setEnabled(false);
}
return dialogArea;
}
use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.
the class ResponsibleUsers method applyChanges.
/**
* Apply changes
*
* @param isApply true if update operation caused by "Apply" button
*/
protected void applyChanges(final boolean isApply) {
if (isApply)
setValid(false);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
List<Long> userIds = new ArrayList<Long>(userList.size());
for (AbstractUserObject o : userList) userIds.add(o.getId());
md.setResponsibleUsers(userIds);
new ConsoleJob(String.format(Messages.get().AccessControl_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.modifyObject(md);
}
@Override
protected void jobFinalize() {
if (isApply) {
runInUIThread(new Runnable() {
@Override
public void run() {
ResponsibleUsers.this.setValid(true);
}
});
}
}
@Override
protected String getErrorMessage() {
return Messages.get().AccessControl_JobError;
}
}.start();
}
use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.
the class UserFieldEditor method selectUser.
/**
*/
protected void selectUser() {
final SelectUserDialog dialog = new SelectUserDialog(getShell(), User.class);
if (dialog.open() == Window.OK) {
final AbstractUserObject[] selection = dialog.getSelection();
if (selection.length > 0) {
final AbstractUserObject user = selection[0];
this.user = user;
text.setText(user.getName());
text.setImage(labelProvider.getImage(user));
} else {
this.user = null;
text.setText(EMPTY_SELECTION_TEXT);
text.setImage(null);
}
}
}
use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.
the class ScheduleLabelProvider method getColumnText.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
@Override
public String getColumnText(Object element, int columnIndex) {
final ReportingJob job = (ReportingJob) element;
switch(columnIndex) {
case ReportExecutionForm.SCHEDULE_START_TIME:
// $NON-NLS-1$
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
String HHmm = timeFormat.format(job.getStartTime().getTime() / 1000);
switch(job.getType()) {
case ReportingJob.TYPE_ONCE:
return RegionalSettings.getDateTimeFormat().format(job.getStartTime().getTime() / 1000);
case ReportingJob.TYPE_DAILY:
return HHmm;
case ReportingJob.TYPE_MONTHLY:
// $NON-NLS-1$
String result = "";
for (int i = 0; i < 31; i++) {
if (((job.getDaysOfMonth() >> i) & 0x01) != 0)
// $NON-NLS-1$ //$NON-NLS-2$
result = String.valueOf(31 - i) + (result.length() > 0 ? "," : "") + result;
}
// $NON-NLS-1$
return HHmm + " - " + result;
case ReportingJob.TYPE_WEEKLY:
// $NON-NLS-1$
String result1 = "";
for (int i = 0; i < 7; i++) {
if (((job.getDaysOfWeek() >> i) & 0x01) != 0)
// $NON-NLS-1$ //$NON-NLS-2$
result1 = dayOfWeek[7 - (i + 1)] + (result1.length() > 0 ? "," : "") + result1;
}
// $NON-NLS-1$
return HHmm + " - " + result1;
default:
return Messages.get().ScheduleLabelProvider_Error;
}
case ReportExecutionForm.SCHEDULE_TYPE:
switch(job.getType()) {
case ReportingJob.TYPE_ONCE:
return Messages.get().ScheduleLabelProvider_Once;
case ReportingJob.TYPE_DAILY:
return Messages.get().ScheduleLabelProvider_Daily;
case ReportingJob.TYPE_MONTHLY:
return Messages.get().ScheduleLabelProvider_Monthly;
case ReportingJob.TYPE_WEEKLY:
return Messages.get().ScheduleLabelProvider_Weekly;
default:
return Messages.get().ScheduleLabelProvider_Error;
}
case ReportExecutionForm.SCHEDULE_OWNER:
AbstractUserObject user = ((NXCSession) ConsoleSharedData.getSession()).findUserDBObjectById(job.getUserId());
// $NON-NLS-1$ //$NON-NLS-2$
return (user != null) ? user.getName() : ("[" + job.getUserId() + "]");
case ReportExecutionForm.SCHEDULE_COMMENTS:
return job.getComments();
}
// $NON-NLS-1$
return "<INTERNAL ERROR>";
}
use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.
the class PredefinedGraph method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
settings = (GraphSettings) getElement().getAdapter(GraphSettings.class);
acl = new HashMap<Long, AccessListElement>(settings.getAccessList().size());
for (AccessListElement e : settings.getAccessList()) acl.put(e.getUserId(), new AccessListElement(e));
// 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);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 2;
dialogArea.setLayout(layout);
name = new LabeledText(dialogArea, SWT.NONE, SWT.BORDER);
name.setLabel(Messages.get().PredefinedGraph_Name);
name.setText(settings.getName());
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = 2;
name.setLayoutData(gd);
Group users = new Group(dialogArea, SWT.NONE);
users.setText(Messages.get().PredefinedGraph_UsersAndGroups);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
users.setLayoutData(gd);
layout = new GridLayout();
users.setLayout(layout);
final String[] columnNames = { Messages.get().PredefinedGraph_LoginName, Messages.get().PredefinedGraph_Rights };
final int[] columnWidths = { 150, 100 };
userList = new SortableTableViewer(users, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
userList.setContentProvider(new ArrayContentProvider());
userList.setLabelProvider(new AccessListLabelProvider());
userList.setComparator(new AccessListComparator());
userList.setInput(acl.values().toArray());
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(users, 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().PredefinedGraph_Add);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
SelectUserDialog dlg = new SelectUserDialog(PredefinedGraph.this.getShell(), AbstractUserObject.class);
if (dlg.open() == Window.OK) {
AbstractUserObject[] selection = dlg.getSelection();
for (AbstractUserObject user : selection) acl.put(user.getId(), new AccessListElement(user.getId(), 0));
userList.setInput(acl.values().toArray());
}
}
});
final Button deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().PredefinedGraph_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<AccessListElement> it = sel.iterator();
while (it.hasNext()) {
AccessListElement element = it.next();
acl.remove(element.getUserId());
}
userList.setInput(acl.values().toArray());
}
});
Group rights = new Group(dialogArea, SWT.NONE);
rights.setText(Messages.get().PredefinedGraph_AccessRights);
rights.setLayout(new RowLayout(SWT.VERTICAL));
gd = new GridData();
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
rights.setLayoutData(gd);
createAccessCheck(rights, Messages.get().PredefinedGraph_Read, GraphSettings.ACCESS_READ);
createAccessCheck(rights, Messages.get().PredefinedGraph_Modify, GraphSettings.ACCESS_WRITE);
userList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.size() == 1) {
enableAllChecks(true);
AccessListElement element = (AccessListElement) sel.getFirstElement();
int rights = element.getAccessRights();
for (int i = 0, mask = 1; i < 16; i++, mask <<= 1) {
Button check = accessChecks.get(mask);
if (check != null) {
check.setSelection((rights & mask) == mask);
}
}
} else {
enableAllChecks(false);
}
deleteButton.setEnabled(sel.size() > 0);
}
});
return dialogArea;
}
Aggregations