Search in sources :

Example 41 with NXCSession

use of org.netxms.client.NXCSession 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 42 with NXCSession

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

the class AlarmCategorySelector method setCategoryId.

/**
 * Set category Id
 *
 * @param categoryId
 */
public void setCategoryId(List<Long> categoryId) {
    if (this.categoryId.equals(categoryId))
        // Nothing to change
        return;
    if (categoryId != null && !categoryId.isEmpty()) {
        if (categoryId.get(0) == 0) {
            setText("<none>");
        } else {
            List<AlarmCategory> categories = ((NXCSession) ConsoleSharedData.getSession()).findMultipleAlarmCategories(categoryId);
            if (categories != null) {
                StringBuilder sb = new StringBuilder();
                this.categoryId.clear();
                for (AlarmCategory c : categories) {
                    sb.append(c.getName() + ";");
                    this.categoryId.add(c.getId());
                }
                setText(sb.toString());
            } else {
                setText("<unknown>");
            }
        }
    } else {
        setText("<none>");
    }
    fireModifyListeners();
}
Also used : NXCSession(org.netxms.client.NXCSession) AlarmCategory(org.netxms.client.events.AlarmCategory)

Example 43 with NXCSession

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

the class AlarmComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    TableColumn sortColumn = ((TableViewer) viewer).getTable().getSortColumn();
    if (sortColumn == null)
        return 0;
    int rc;
    switch(// $NON-NLS-1$
    (Integer) sortColumn.getData("ID")) {
        case AlarmList.COLUMN_SEVERITY:
            rc = ((Alarm) e1).getCurrentSeverity().compareTo(((Alarm) e2).getCurrentSeverity());
            break;
        case AlarmList.COLUMN_STATE:
            rc = Integer.signum(((Alarm) e1).getState() - ((Alarm) e2).getState());
            break;
        case AlarmList.COLUMN_SOURCE:
            AbstractObject obj1 = ConsoleSharedData.getSession().findObjectById(((Alarm) e1).getSourceObjectId());
            AbstractObject obj2 = ConsoleSharedData.getSession().findObjectById(((Alarm) e2).getSourceObjectId());
            String name1 = (obj1 != null) ? obj1.getObjectName() : Messages.get().AlarmComparator_Unknown;
            String name2 = (obj2 != null) ? obj2.getObjectName() : Messages.get().AlarmComparator_Unknown;
            rc = name1.compareToIgnoreCase(name2);
            break;
        case AlarmList.COLUMN_MESSAGE:
            rc = ((Alarm) e1).getMessage().compareToIgnoreCase(((Alarm) e2).getMessage());
            break;
        case AlarmList.COLUMN_COUNT:
            rc = Integer.signum(((Alarm) e1).getRepeatCount() - ((Alarm) e2).getRepeatCount());
            break;
        case AlarmList.COLUMN_CREATED:
            rc = ((Alarm) e1).getCreationTime().compareTo(((Alarm) e2).getCreationTime());
            break;
        case AlarmList.COLUMN_LASTCHANGE:
            rc = ((Alarm) e1).getLastChangeTime().compareTo(((Alarm) e2).getLastChangeTime());
            break;
        case AlarmList.COLUMN_ZONE:
            NXCSession session = ConsoleSharedData.getSession();
            if (session.isZoningEnabled()) {
                ZoneMember o1 = session.findObjectById(((Alarm) e1).getSourceObjectId(), ZoneMember.class);
                ZoneMember o2 = session.findObjectById(((Alarm) e2).getSourceObjectId(), ZoneMember.class);
                String n1 = (o1 != null) ? o1.getZoneName() : "";
                String n2 = (o2 != null) ? o2.getZoneName() : "";
                rc = n1.compareToIgnoreCase(n2);
            } else {
                rc = 0;
            }
            break;
        default:
            rc = 0;
            break;
    }
    int dir = ((TableViewer) viewer).getTable().getSortDirection();
    return (dir == SWT.UP) ? rc : -rc;
}
Also used : NXCSession(org.netxms.client.NXCSession) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) ZoneMember(org.netxms.client.objects.ZoneMember) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 44 with NXCSession

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

the class SendSMS method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (window == null)
        return;
    final SendSMSDialog dlg = new SendSMSDialog(window.getShell());
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SendSMS_JobTitle + dlg.getPhoneNumber(), window.getActivePage().getActivePart(), Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.sendSMS(dlg.getPhoneNumber(), dlg.getMessage());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    final String message = Messages.get().SendSMS_DialogTextPrefix + dlg.getPhoneNumber() + Messages.get().SendSMS_DialogTextSuffix;
                    MessageDialogHelper.openInformation(window.getShell(), Messages.get().SendSMS_DialogTitle, message);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SendSMS_SendError + dlg.getPhoneNumber();
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SendSMSDialog(org.netxms.ui.eclipse.console.dialogs.SendSMSDialog)

Example 45 with NXCSession

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

the class RegionalSettings method getTimeFormat.

/**
 * Get formatter for time only
 *
 * @return
 */
public static DateFormat getTimeFormat() {
    RegionalSettings instance = getInstance();
    DateFormat df;
    switch(instance.dateTimeFormat) {
        case DATETIME_FORMAT_SERVER:
            NXCSession session = ConsoleSharedData.getSession();
            df = new SimpleDateFormat(session.getTimeFormat());
            break;
        case DATETIME_FORMAT_CUSTOM:
            try {
                df = new SimpleDateFormat(instance.timeFormatString);
            } catch (IllegalArgumentException e) {
                df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
            }
            break;
        default:
            df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
            break;
    }
    TimeZone tz = ConsoleSharedData.getTimeZone();
    if (tz != null)
        df.setTimeZone(tz);
    return df;
}
Also used : TimeZone(java.util.TimeZone) NXCSession(org.netxms.client.NXCSession) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10