use of org.netxms.client.AccessListElement in project netxms by netxms.
the class ObjectToolsEditor method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
// Initiate loading of required plugins if they was not loaded yet
try {
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new AccessListElement(0, 0), "org.eclipse.ui.model.IWorkbenchAdapter");
} catch (Exception e) {
}
// Create interface area
objectToolsArea = new Composite(parent, SWT.BORDER);
FormLayout formLayout = new FormLayout();
objectToolsArea.setLayout(formLayout);
// Create filter
filterText = new FilterText(objectToolsArea, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterText.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
actionShowFilter.setChecked(initShowFilter);
}
});
final String[] columnNames = { Messages.get().ObjectToolsEditor_ColId, Messages.get().ObjectToolsEditor_ColName, Messages.get().ObjectToolsEditor_ColType, Messages.get().ObjectToolsEditor_ColDescr };
final int[] columnWidths = { 90, 200, 100, 200 };
viewer = new SortableTableViewer(objectToolsArea, columnNames, columnWidths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ObjectToolsLabelProvider());
filter = new ObjectToolsFilter();
viewer.addFilter(filter);
viewer.setComparator(new ObjectToolsComparator());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null) {
actionEdit.setEnabled(selection.size() == 1);
actionClone.setEnabled(selection.size() == 1);
actionDelete.setEnabled(selection.size() > 0);
actionDisable.setEnabled(containsEnabled(selection));
actionEnable.setEnabled(containsDisabled(selection));
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
actionEdit.run();
}
});
viewer.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterText);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
viewer.getControl().setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterText.setLayoutData(fd);
createActions();
contributeToActionBars();
createPopupMenu();
activateContext();
session.addListener(this);
// Set initial focus to filter input line
if (initShowFilter)
filterText.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
refreshToolList();
}
use of org.netxms.client.AccessListElement 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;
}
use of org.netxms.client.AccessListElement in project netxms by netxms.
the class AccessControl 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);
}
use of org.netxms.client.AccessListElement 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) {
if (isApply)
setValid(false);
final boolean inheritAccessRights = checkInherit.getSelection();
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
md.setACL(acl.values().toArray(new AccessListElement[acl.size()]));
md.setInheritAccessRights(inheritAccessRights);
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() {
AccessControl.this.setValid(true);
}
});
}
}
@Override
protected String getErrorMessage() {
return Messages.get().AccessControl_JobError;
}
}.start();
}
use of org.netxms.client.AccessListElement in project netxms by netxms.
the class HistoricalGraphView method saveGraph.
/**
* Save this graph as predefined
*/
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten, final boolean asTemplate) {
if (asTemplate && useMoreThanOneShoucrNode) {
String templateError = "More than one node is used for template creation.\nThis may cause undefined behaviour.";
errorMessage = errorMessage == null ? templateError : errorMessage + "\n\n" + templateError;
}
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.setConfig(settings);
if (asTemplate) {
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, asTemplate);
}
});
} else {
if (e.getErrorCode() == RCC.ACCESS_DENIED) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false, asTemplate);
}
});
} else {
throw e;
}
}
}
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveError;
}
}.start();
}
updateChart();
}
Aggregations