use of org.netxms.client.users.AbstractUserObject in project netxms by netxms.
the class TemplateGraph 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(TemplateGraph.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;
}
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) {
objectTool = (ObjectToolDetails) getElement().getAdapter(ObjectToolDetails.class);
// Build internal copy of access list
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
for (Long uid : objectTool.getAccessList()) {
AbstractUserObject o = session.findUserDBObjectById(uid);
if (o != null)
acl.add(o);
}
Composite dialogArea = new Composite(parent, SWT.NONE);
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(Messages.get().AccessControl_Label);
viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new WorkbenchLabelProvider());
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);
viewer.setInput(acl.toArray());
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(Messages.get().AccessControl_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(Messages.get().AccessControl_Delete);
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());
objectTool.setAccessList(list);
}
use of org.netxms.client.users.AbstractUserObject 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.client.users.AbstractUserObject in project netxms by netxms.
the class LogLabelProvider method getColumnText.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
@Override
public String getColumnText(Object element, int columnIndex) {
final String value = ((TableRow) element).get(columnIndex).getValue();
switch(columns[columnIndex].getType()) {
case LogColumn.LC_TIMESTAMP:
try {
long timestamp = Long.parseLong(value);
Date date = new Date(timestamp * 1000);
return RegionalSettings.getDateTimeFormat().format(date);
} catch (NumberFormatException e) {
return Messages.get().LogLabelProvider_Error;
}
case LogColumn.LC_OBJECT_ID:
try {
long id = Long.parseLong(value);
if (id == 0)
// $NON-NLS-1$
return "";
AbstractObject object = session.findObjectById(id);
// $NON-NLS-1$ //$NON-NLS-2$
return (object != null) ? object.getObjectName() : ("[" + id + "]");
} catch (NumberFormatException e) {
return Messages.get().LogLabelProvider_Error;
}
case LogColumn.LC_SEVERITY:
try {
int severity = Integer.parseInt(value);
return StatusDisplayInfo.getStatusText(severity);
} catch (NumberFormatException e) {
return Messages.get().LogLabelProvider_Error;
}
case LogColumn.LC_USER_ID:
try {
long id = Long.parseLong(value);
AbstractUserObject user = session.findUserDBObjectById(id);
return (user != null) ? wbLabelProvider.getText(user) : null;
} catch (NumberFormatException e) {
return null;
}
case LogColumn.LC_EVENT_CODE:
try {
long code = Long.parseLong(value);
EventObject evo = session.findEventObjectByCode(code);
// $NON-NLS-1$ //$NON-NLS-2$
return (evo != null) ? evo.getName() : ("[" + code + "]");
} catch (NumberFormatException e) {
return null;
}
case LogColumn.LC_ALARM_STATE:
try {
int state = Integer.parseInt(value);
return ALARM_STATE_TEXTS[state & Alarm.STATE_MASK];
} catch (Exception e) {
return Messages.get().LogLabelProvider_Error;
}
case LogColumn.LC_ALARM_HD_STATE:
try {
int state = Integer.parseInt(value);
return ALARM_HD_STATE_TEXTS[state];
} catch (Exception e) {
return Messages.get().LogLabelProvider_Error;
}
case LogColumn.LC_ZONE_UIN:
try {
long uin = Long.parseLong(value);
Zone zone = session.findZone(uin);
return (zone != null) ? zone.getObjectName() : "[" + uin + "]";
} catch (NumberFormatException e) {
return null;
}
default:
return value;
}
}
Aggregations