use of org.netxms.client.AccessListElement in project netxms by netxms.
the class AccessListLabelProvider method getColumnText.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
@Override
public String getColumnText(Object element, int columnIndex) {
switch(columnIndex) {
case 0:
return getText(element);
case 1:
AccessListElement e = (AccessListElement) element;
StringBuilder sb = new StringBuilder(4);
sb.append(((e.getAccessRights() & GraphSettings.ACCESS_READ) != 0) ? 'R' : '-');
sb.append(((e.getAccessRights() & GraphSettings.ACCESS_WRITE) != 0) ? 'W' : '-');
return sb.toString();
}
return null;
}
use of org.netxms.client.AccessListElement in project netxms by netxms.
the class TemplateGraphView method saveGraph.
/**
* Save this graph as predefined
*/
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten) {
SaveGraphDlg dlg = new SaveGraphDlg(getSite().getShell(), graphName, errorMessage, canBeOverwritten);
int result = dlg.open();
if (result == Window.CANCEL)
return;
final GraphSettings gs = new GraphSettings(0, session.getUserId(), 0, new ArrayList<AccessListElement>(0));
gs.setName(dlg.getName());
gs.setFlags(GraphSettings.GRAPH_FLAG_TEMPLATE);
if (result == SaveGraphDlg.OVERRIDE) {
new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.saveGraph(gs, canBeOverwritten);
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveSettingsError;
}
}.start();
} else {
new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
try {
session.saveGraph(gs, canBeOverwritten);
} catch (NXCException e) {
if (e.getErrorCode() == RCC.OBJECT_ALREADY_EXISTS) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExist, true);
}
});
} else {
if (e.getErrorCode() == RCC.ACCESS_DENIED) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false);
}
});
} else {
throw e;
}
}
}
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveError;
}
}.start();
}
}
use of org.netxms.client.AccessListElement 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;
}
use of org.netxms.client.AccessListElement 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.AccessListElement in project netxms by netxms.
the class TemplateGraph method createAccessCheck.
/**
* Create access control check box.
*
* @param parent Parent composite
* @param name Name of the access right
* @param bitMask Bit mask for access right
*/
private void createAccessCheck(final Composite parent, final String name, final Integer bitMask) {
final Button check = new Button(parent, SWT.CHECK);
check.setText(name);
check.setEnabled(false);
check.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) userList.getSelection();
AccessListElement element = (AccessListElement) sel.getFirstElement();
int rights = element.getAccessRights();
if (check.getSelection())
rights |= bitMask;
else
rights &= ~bitMask;
element.setAccessRights(rights);
userList.update(element, null);
}
});
accessChecks.put(bitMask, check);
}
Aggregations