Search in sources :

Example 11 with SessionListener

use of org.netxms.client.SessionListener in project netxms by netxms.

the class DashboardNavigator 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();
    final Set<Integer> classFilter = new HashSet<Integer>(2);
    classFilter.add(AbstractObject.OBJECT_DASHBOARDGROUP);
    classFilter.add(AbstractObject.OBJECT_DASHBOARD);
    objectTree = new ObjectTree(parent, SWT.NONE, ObjectTree.NONE, getRootObjects(classFilter), classFilter, false, true);
    objectTree.enableFilter(false);
    objectTree.getTreeViewer().expandToLevel(2);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    getSite().setSelectionProvider(objectTree.getTreeViewer());
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if ((n.getCode() == SessionNotification.OBJECT_CHANGED) && (n.getObject() instanceof DashboardRoot)) {
                objectTree.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refresh();
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
}
Also used : ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) DashboardRoot(org.netxms.client.objects.DashboardRoot) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification) HashSet(java.util.HashSet)

Example 12 with SessionListener

use of org.netxms.client.SessionListener in project netxms by netxms.

the class MappingTables method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    final int[] widths = { 80, 160, 80, 400 };
    final String[] names = { Messages.get().MappingTables_ColID, Messages.get().MappingTables_ColName, Messages.get().MappingTables_ColFlags, Messages.get().MappingTables_ColDescription };
    viewer = new SortableTableViewer(parent, names, widths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new MappingTableListLabelProvider());
    viewer.setComparator(new MappingTableListComparator());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editTable();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            actionEditTable.setEnabled(selection.size() == 1);
            actionDeleteTables.setEnabled(selection.size() > 0);
        }
    });
    final IDialogSettings settings = Activator.getDefault().getDialogSettings();
    // $NON-NLS-1$
    WidgetHelper.restoreTableViewerSettings(viewer, settings, "MappingTablesList");
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            WidgetHelper.saveTableViewerSettings(viewer, settings, "MappingTablesList");
        }
    });
    createActions();
    contributeToActionBars();
    createPopupMenu();
    session = ConsoleSharedData.getSession();
    refresh(0);
    final Display display = getSite().getShell().getDisplay();
    listener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() == SessionNotification.MAPPING_TABLE_UPDATED) {
                final Integer id = (int) n.getSubCode();
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refresh(id);
                    }
                });
            } else if (n.getCode() == SessionNotification.MAPPING_TABLE_DELETED) {
                final Integer id = (int) n.getSubCode();
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        mappingTables.remove(id);
                        viewer.setInput(mappingTables.values().toArray());
                    }
                });
            }
        }
    };
    session.addListener(listener);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) MappingTableListLabelProvider(org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListLabelProvider) SessionNotification(org.netxms.client.SessionNotification) MappingTableListComparator(org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListComparator) Display(org.eclipse.swt.widgets.Display)

Example 13 with SessionListener

use of org.netxms.client.SessionListener in project netxms by netxms.

the class ServerJobManager method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    final String[] names = { Messages.get().ServerJobManager_ColStatus, Messages.get().ServerJobManager_ColInitiator, Messages.get().ServerJobManager_ColNode, Messages.get().ServerJobManager_ColDescription, Messages.get().ServerJobManager_ColProgress, Messages.get().ServerJobManager_ColMessage };
    final int[] widths = { 80, 100, 150, 250, 100, 300 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.DOWN, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ServerJobLabelProvider());
    viewer.setComparator(new ServerJobComparator());
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    session = (NXCSession) ConsoleSharedData.getSession();
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionCancelJob.setEnabled(selection.size() > 0);
                actionHoldJob.setEnabled(selection.size() > 0);
                actionUnholdJob.setEnabled(selection.size() > 0);
            }
        }
    });
    // Create listener for notifications received from server via client library
    clientListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() != SessionNotification.JOB_CHANGE)
                return;
            refreshJobList(false);
        }
    };
    session.addListener(clientListener);
    refreshJobList(false);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ServerJobLabelProvider(org.netxms.ui.eclipse.serverjobmanager.views.helpers.ServerJobLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) 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) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) ServerJobComparator(org.netxms.ui.eclipse.serverjobmanager.views.helpers.ServerJobComparator) SessionNotification(org.netxms.client.SessionNotification)

Example 14 with SessionListener

use of org.netxms.client.SessionListener 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)

Example 15 with SessionListener

use of org.netxms.client.SessionListener in project netxms by netxms.

the class SummaryTablesCache method init.

/**
 * Initialize object tools cache. Should be called when connection with
 * the server already established.
 */
public static void init(NXCSession session) {
    SummaryTablesCache.session = session;
    reload();
    session.addListener(new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            switch(n.getCode()) {
                case SessionNotification.DCI_SUMMARY_TABLE_UPDATED:
                    onTableChange((int) n.getSubCode());
                    break;
                case SessionNotification.DCI_SUMMARY_TABLE_DELETED:
                    onTableDelete((int) n.getSubCode());
                    break;
            }
        }
    });
}
Also used : SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Aggregations

SessionListener (org.netxms.client.SessionListener)18 SessionNotification (org.netxms.client.SessionNotification)18 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)6 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)5 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)4 Composite (org.eclipse.swt.widgets.Composite)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 NXCSession (org.netxms.client.NXCSession)3 AbstractObject (org.netxms.client.objects.AbstractObject)3 IOException (java.io.IOException)2 Action (org.eclipse.jface.action.Action)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2