Search in sources :

Example 11 with AccessListElement

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();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PropertyDialogAction(org.eclipse.ui.dialogs.PropertyDialogAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ObjectToolsComparator(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsComparator) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ObjectToolsLabelProvider(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ObjectToolsFilter(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsFilter)

Example 12 with AccessListElement

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;
}
Also used : ResponsibleUsersComparator(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.ResponsibleUsersComparator) SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ResponsibleUsersLabelProvider(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.ResponsibleUsersLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) AbstractUserObject(org.netxms.client.users.AbstractUserObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AccessListElement(org.netxms.client.AccessListElement) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 13 with AccessListElement

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);
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AccessListElement(org.netxms.client.AccessListElement) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 14 with AccessListElement

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AccessListElement(org.netxms.client.AccessListElement)

Example 15 with AccessListElement

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) SaveGraphDlg(org.netxms.ui.eclipse.perfview.dialogs.SaveGraphDlg) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Aggregations

AccessListElement (org.netxms.client.AccessListElement)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Button (org.eclipse.swt.widgets.Button)7 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)5 Composite (org.eclipse.swt.widgets.Composite)5 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)5 Iterator (java.util.Iterator)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 AbstractUserObject (org.netxms.client.users.AbstractUserObject)4 SelectUserDialog (org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 RowLayout (org.eclipse.swt.layout.RowLayout)3 Group (org.eclipse.swt.widgets.Group)3 PartInitException (org.eclipse.ui.PartInitException)3