Search in sources :

Example 1 with SessionNotification

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

the class SessionStore method registerSession.

/**
 * @param s
 */
public synchronized SessionToken registerSession(final NXCSession session) {
    if (sessionManager == null) {
        sessionManager = new Thread(new Runnable() {

            @Override
            public void run() {
                sessionManagerThread();
            }
        }, "Session Manager");
        sessionManager.setDaemon(true);
        sessionManager.start();
    }
    final SessionToken token = new SessionToken(session);
    sessions.put(token.getGuid(), token);
    session.addListener(new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
                log.info("Received disconnect notification for session " + token.getGuid());
                session.disconnect();
                unregisterSession(token.getGuid());
            }
        }
    });
    log.info("Session " + token.getGuid() + " registered");
    return token;
}
Also used : SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Example 2 with SessionNotification

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

the class EventProcessingPolicyEditor 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();
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    // $NON-NLS-1$
    filterEnabled = settings.getBoolean("EventProcessingPolicyEditor.filterEnabled");
    // Initiate loading of required plugins if they was not loaded yet
    try {
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new ServerAction(0), "org.eclipse.ui.model.IWorkbenchAdapter");
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(session.getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
    } catch (Exception e) {
    }
    // $NON-NLS-1$
    imageStop = Activator.getImageDescriptor("icons/stop.png").createImage();
    // $NON-NLS-1$
    imageAlarm = Activator.getImageDescriptor("icons/alarm.png").createImage();
    // $NON-NLS-1$
    imageSituation = Activator.getImageDescriptor("icons/situation.gif").createImage();
    // $NON-NLS-1$
    imageExecute = Activator.getImageDescriptor("icons/execute.png").createImage();
    // $NON-NLS-1$
    imageTerminate = Activator.getImageDescriptor("icons/terminate.png").createImage();
    imageCollapse = SharedIcons.COLLAPSE.createImage();
    imageExpand = SharedIcons.EXPAND.createImage();
    imageEdit = SharedIcons.EDIT.createImage();
    parent.setLayout(new FormLayout());
    // Create filter area
    filterControl = new FilterText(parent, SWT.NONE);
    filterControl.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterControl.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
        }
    });
    scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
    dataArea = new Composite(scroller, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    dataArea.setLayout(layout);
    dataArea.setBackground(BACKGROUND_COLOR);
    scroller.setContent(dataArea);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);
    scroller.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle r = scroller.getClientArea();
            scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterControl);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    scroller.setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterControl.setLayoutData(fd);
    normalFont = JFaceResources.getDefaultFont();
    boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            processSessionNotification(n);
        }
    };
    session.addListener(sessionListener);
    selection = new TreeSet<RuleEditor>(new Comparator<RuleEditor>() {

        @Override
        public int compare(RuleEditor arg0, RuleEditor arg1) {
            return arg0.getRuleNumber() - arg1.getRuleNumber();
        }
    });
    createActions();
    contributeToActionBars();
    openEventProcessingPolicy();
    activateContext();
    // Set initial focus to filter input line
    if (filterEnabled)
        filterControl.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ServerAction(org.netxms.client.ServerAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) EventTemplate(org.netxms.client.events.EventTemplate) Rectangle(org.eclipse.swt.graphics.Rectangle) Comparator(java.util.Comparator) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FilterText(org.netxms.ui.eclipse.widgets.FilterText) SessionListener(org.netxms.client.SessionListener) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor) ControlEvent(org.eclipse.swt.events.ControlEvent) ServerAction(org.netxms.client.ServerAction) SessionNotification(org.netxms.client.SessionNotification) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 3 with SessionNotification

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

the class ApplicationWorkbenchAdvisor method doLogin.

/**
 * Show login dialog and perform login
 */
private void doLogin() {
    boolean success = false;
    final Properties properties = new AppPropertiesLoader().load();
    String password = "";
    // $NON-NLS-1$
    boolean autoLogin = (Application.getParameter("auto") != null);
    String ssoTicket = Application.getParameter("ticket");
    if (ssoTicket != null) {
        autoLogin = true;
        // $NON-NLS-1$
        String server = Application.getParameter("server");
        if (server == null)
            // $NON-NLS-1$ //$NON-NLS-2$
            server = properties.getProperty("server", "127.0.0.1");
        success = connectToServer(server, null, ssoTicket);
    } else if (autoLogin) {
        // $NON-NLS-1$
        String server = Application.getParameter("server");
        if (server == null)
            // $NON-NLS-1$ //$NON-NLS-2$
            server = properties.getProperty("server", "127.0.0.1");
        // $NON-NLS-1$
        String login = Application.getParameter("login");
        if (login == null)
            login = "guest";
        // $NON-NLS-1$
        password = Application.getParameter("password");
        if (password == null)
            password = "";
        success = connectToServer(server, login, password);
    }
    if (!autoLogin || !success) {
        Window loginDialog;
        do {
            loginDialog = BrandingManager.getInstance().getLoginForm(Display.getCurrent().getActiveShell(), properties);
            if (loginDialog.open() != Window.OK)
                continue;
            password = ((LoginForm) loginDialog).getPassword();
            success = connectToServer(// $NON-NLS-1$ //$NON-NLS-2$
            properties.getProperty("server", "127.0.0.1"), ((LoginForm) loginDialog).getLogin(), password);
        } while (!success);
    }
    if (success) {
        final NXCSession session = (NXCSession) RWT.getUISession().getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
        final Display display = Display.getCurrent();
        session.addListener(new SessionListener() {

            private final Object MONITOR = new Object();

            @Override
            public void notificationHandler(final SessionNotification n) {
                if ((n.getCode() == SessionNotification.CONNECTION_BROKEN) || (n.getCode() == SessionNotification.SERVER_SHUTDOWN) || (n.getCode() == SessionNotification.SESSION_KILLED)) {
                    display.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            RWT.getUISession().setAttribute("NoPageReload", Boolean.TRUE);
                            PlatformUI.getWorkbench().close();
                            String productName = BrandingManager.getInstance().getProductName();
                            String msg = (n.getCode() == SessionNotification.CONNECTION_BROKEN) ? String.format(Messages.get().ApplicationWorkbenchAdvisor_ConnectionLostMessage, productName) : ((n.getCode() == SessionNotification.SESSION_KILLED) ? "Communication session was terminated by system administrator" : String.format(Messages.get().ApplicationWorkbenchAdvisor_ServerShutdownMessage, productName));
                            JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
                            if (executor != null)
                                executor.execute("document.body.innerHTML='" + "<div style=\"position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: none; background-color: white;\">" + "<p style=\"margin-top: 30px; margin-left: 30px; color: #800000; font-family: \"Segoe UI\", Verdana, Arial, sans-serif; font-weight: bold; font-size: 2em;\">" + msg + "</p><br/>" + "<button style=\"margin-left: 30px\" onclick=\"location.reload(true)\">RELOAD</button>" + "</div>';");
                            synchronized (MONITOR) {
                                MONITOR.notifyAll();
                            }
                        }
                    });
                    synchronized (MONITOR) {
                        try {
                            MONITOR.wait(5000);
                        } catch (InterruptedException e) {
                        }
                    }
                    ((UISessionImpl) RWT.getUISession(display)).shutdown();
                }
            }
        });
        try {
            RWT.getSettingStore().loadById(session.getUserName() + "@" + session.getServerId());
        } catch (IOException e) {
        }
        // Suggest user to change password if it is expired
        if (session.isPasswordExpired()) {
            final PasswordExpiredDialog dlg = new PasswordExpiredDialog(null, session.getGraceLogins());
            while (true) {
                if (dlg.open() != Window.OK)
                    return;
                final String currentPassword = password;
                IRunnableWithProgress job = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            NXCSession session = (NXCSession) RWT.getUISession(display).getAttribute(ConsoleSharedData.ATTRIBUTE_SESSION);
                            session.setUserPassword(session.getUserId(), dlg.getPassword(), currentPassword);
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                };
                try {
                    ProgressMonitorDialog pd = new ProgressMonitorDialog(null);
                    pd.run(false, false, job);
                    MessageDialog.openInformation(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Information, Messages.get().ApplicationWorkbenchWindowAdvisor_PasswordChanged);
                    return;
                } catch (InvocationTargetException e) {
                    MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Error, Messages.get().ApplicationWorkbenchWindowAdvisor_CannotChangePswd + e.getCause().getLocalizedMessage());
                } catch (InterruptedException e) {
                    MessageDialog.openError(null, Messages.get().ApplicationWorkbenchWindowAdvisor_Exception, e.toString());
                }
            }
        }
    }
}
Also used : Window(org.eclipse.jface.window.Window) NXCSession(org.netxms.client.NXCSession) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) PasswordExpiredDialog(org.netxms.ui.eclipse.console.dialogs.PasswordExpiredDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SessionListener(org.netxms.client.SessionListener) LoginForm(org.netxms.ui.eclipse.console.api.LoginForm) SessionNotification(org.netxms.client.SessionNotification) Display(org.eclipse.swt.widgets.Display)

Example 4 with SessionNotification

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

the class DashboardView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    selectionProvider = new IntermediateSelectionProvider();
    getSite().setSelectionProvider(selectionProvider);
    ConsoleJob job = new ConsoleJob(Messages.get().DashboardView_GetEffectiveRights, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            readOnly = ((dashboard.getEffectiveRights() & UserAccessRights.OBJECT_ACCESS_MODIFY) == 0);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DashboardView_GetEffectiveRightsError;
        }
    };
    job.start();
    // FIXME: rewrite waiting
    try {
        job.join();
    } catch (InterruptedException e) {
    }
    parentComposite = parent;
    dbc = new DashboardControl(parent, SWT.NONE, dashboard, this, selectionProvider, false);
    if (!readOnly) {
        dbcModifyListener = new DashboardModifyListener() {

            @Override
            public void save() {
                actionSave.setEnabled(false);
                firePropertyChange(PROP_DIRTY);
            }

            @Override
            public void modify() {
                actionSave.setEnabled(true);
                firePropertyChange(PROP_DIRTY);
            }
        };
        dbc.setModifyListener(dbcModifyListener);
    }
    activateContext();
    createActions();
    contributeToActionBars();
    clientListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() == SessionNotification.OBJECT_CHANGED && dashboard.getObjectId() == n.getSubCode()) {
                parentComposite.getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        rebuildDashboard(true);
                    }
                });
            }
        }
    };
    session.addListener(clientListener);
}
Also used : IntermediateSelectionProvider(org.netxms.ui.eclipse.tools.IntermediateSelectionProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DashboardControl(org.netxms.ui.eclipse.dashboard.widgets.DashboardControl) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DashboardModifyListener(org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardModifyListener) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification)

Example 5 with SessionNotification

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

the class AbstractNetworkMapView method createPartControl.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.part.ViewPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public final void createPartControl(Composite parent) {
    FillLayout layout = new FillLayout();
    parent.setLayout(layout);
    viewer = new ExtendedGraphViewer(parent, SWT.NONE);
    viewer.setContentProvider(new MapContentProvider(viewer));
    labelProvider = new MapLabelProvider(viewer);
    viewer.setLabelProvider(labelProvider);
    viewer.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    try {
        // $NON-NLS-1$
        alwaysFitLayout = settings.getBoolean(viewId + ".alwaysFitLayout");
    } catch (Exception e) {
    }
    // Zoom level restore and save
    try {
        // $NON-NLS-1$
        viewer.zoomTo(settings.getDouble(viewId + ".zoom"));
    } catch (NumberFormatException e) {
    }
    viewer.getGraphControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            IDialogSettings settings = Activator.getDefault().getDialogSettings();
            // $NON-NLS-1$
            settings.put(viewId + ".zoom", viewer.getZoom());
        }
    });
    getSite().setSelectionProvider(this);
    ISelectionChangedListener listener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            if (bendpointEditor != null) {
                bendpointEditor.stop();
                bendpointEditor = null;
            }
            currentSelection = transformSelection(e.getSelection());
            if (currentSelection.size() == 1) {
                int selectionType = analyzeSelection(currentSelection);
                if (selectionType == SELECTION_OBJECTS) {
                    AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
                    actionOpenDrillDownObject.setEnabled(object.getDrillDownObjectId() != 0);
                } else {
                    actionOpenDrillDownObject.setEnabled(false);
                    if (selectionType == SELECTION_LINKS) {
                        NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
                        actionLockLink.setChecked(link.isLocked());
                        if (!link.isLocked() && link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS) {
                            bendpointEditor = new BendpointEditor(link, (GraphConnection) viewer.getGraphControl().getSelection().get(0), viewer);
                        }
                    }
                }
            } else {
                actionOpenDrillDownObject.setEnabled(false);
            }
            if (selectionListeners.isEmpty())
                return;
            SelectionChangedEvent event = new SelectionChangedEvent(AbstractNetworkMapView.this, currentSelection);
            for (ISelectionChangedListener l : selectionListeners) {
                l.selectionChanged(event);
            }
        }
    };
    viewer.addPostSelectionChangedListener(listener);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            int selectionType = analyzeSelection(currentSelection);
            if (selectionType == SELECTION_EMPTY)
                return;
            if (selectionType == SELECTION_OBJECTS) {
                AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
                if (object instanceof Rack) {
                    openRackView(Long.toString(object.getObjectId()));
                    return;
                }
                for (DoubleClickHandlerData h : doubleClickHandlers) {
                    if ((h.enabledFor == null) || (h.enabledFor.isInstance(object))) {
                        if (h.handler.onDoubleClick(object)) {
                            return;
                        }
                    }
                }
            } else if (((NetworkMapLink) currentSelection.getFirstElement()).isLocked() && selectionType == SELECTION_LINKS) {
                openLinkDci();
            }
            // Default behavior
            actionOpenDrillDownObject.run();
        }
    });
    sessionListener = new SessionListener() {

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

                    @Override
                    public void run() {
                        onObjectChange((AbstractObject) n.getObject());
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    if (automaticLayoutEnabled) {
        setLayoutAlgorithm(layoutAlgorithm, true);
    } else {
        viewer.setLayoutAlgorithm(new ManualLayout());
    }
    activateContext();
    registerDoubleClickHandlers();
    setupMapControl();
    refreshMap();
}
Also used : ExtendedGraphViewer(org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer) DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MapLabelProvider(org.netxms.ui.eclipse.networkmaps.views.helpers.MapLabelProvider) Rack(org.netxms.client.objects.Rack) MapContentProvider(org.netxms.ui.eclipse.networkmaps.views.helpers.MapContentProvider) GraphConnection(org.eclipse.gef4.zest.core.widgets.GraphConnection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SessionNotification(org.netxms.client.SessionNotification) NetworkMapLink(org.netxms.client.maps.NetworkMapLink) BendpointEditor(org.netxms.ui.eclipse.networkmaps.views.helpers.BendpointEditor) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Point(org.eclipse.draw2d.geometry.Point) ManualLayout(org.netxms.ui.eclipse.networkmaps.algorithms.ManualLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) AbstractObject(org.netxms.client.objects.AbstractObject) SessionListener(org.netxms.client.SessionListener)

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