Search in sources :

Example 1 with UserLabelProvider

use of org.netxms.ui.eclipse.usermanager.views.helpers.UserLabelProvider in project netxms by netxms.

the class UserManagementView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = ConsoleSharedData.getSession();
    final String[] names = { Messages.get().UserManagementView_Name, Messages.get().UserManagementView_Type, Messages.get().UserManagementView_FullName, Messages.get().UserManagementView_Description, Messages.get().UserManagementView_Source, Messages.get().UserManagementView_Authentication, Messages.get().UserManagementView_GUID, "LDAP DN", "Last Login", "Created" };
    final int[] widths = { 100, 80, 180, 250, 80, 170, 250, 400, 250, 250 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new UserLabelProvider());
    viewer.setComparator(new UserComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEditUser.setEnabled(selection.size() == 1);
                actionChangePassword.setEnabled((selection.size() == 1) && (selection.getFirstElement() instanceof User));
                actionDeleteUser.setEnabled(selection.size() > 0);
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEditUser.run();
        }
    });
    makeActions();
    contributeToActionBars();
    createPopupMenu();
    // Listener for server's notifications
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(final SessionNotification n) {
            if (n.getCode() == SessionNotification.USER_DB_CHANGED) {
                viewer.getControl().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(session.getUserDatabaseObjects());
                        if (editNewUser && (n.getSubCode() == SessionNotification.USER_DB_OBJECT_CREATED)) {
                            editNewUser = false;
                            viewer.setSelection(new StructuredSelection(n.getObject()), true);
                            actionEditUser.run();
                        }
                    }
                });
            }
        }
    };
    // Request server to lock user database, and on success refresh view
    new ConsoleJob(Messages.get().UserManagementView_OpenJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.lockUserDatabase();
            databaseLocked = true;
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(session.getUserDatabaseObjects());
                    session.addListener(sessionListener);
                }
            });
        }

        @Override
        protected void jobFailureHandler() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    UserManagementView.this.getViewSite().getPage().hideView(UserManagementView.this);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().UserManagementView_OpenJobError;
        }
    }.start();
}
Also used : UserLabelProvider(org.netxms.ui.eclipse.usermanager.views.helpers.UserLabelProvider) User(org.netxms.client.users.User) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SessionNotification(org.netxms.client.SessionNotification)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SessionListener (org.netxms.client.SessionListener)1 SessionNotification (org.netxms.client.SessionNotification)1 User (org.netxms.client.users.User)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 UserComparator (org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator)1 UserLabelProvider (org.netxms.ui.eclipse.usermanager.views.helpers.UserLabelProvider)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1