Search in sources :

Example 6 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor 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 7 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class AlarmSounds method createContents.

/*
    * (non-Javadoc)
    * 
    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    Combo newCombo = null;
    Button button = null;
    for (int i = 0; i < 6; i++) {
        final String soundId = (i < 5) ? StatusDisplayInfo.getStatusText(i) : "Outstanding alarm reminder";
        newCombo = WidgetHelper.createLabeledCombo(dialogArea, SWT.DROP_DOWN | SWT.READ_ONLY, soundId, WidgetHelper.DEFAULT_LAYOUT_DATA);
        newCombo.setEnabled(false);
        comboList.add(i, newCombo);
        button = new Button(dialogArea, SWT.PUSH);
        GridData gridData = new GridData();
        gridData.verticalAlignment = GridData.END;
        button.setLayoutData(gridData);
        // $NON-NLS-1$
        button.setImage(Activator.getImageDescriptor("icons/sound.png").createImage());
        final int index = i;
        button.addMouseListener(new MouseListener() {

            @Override
            public void mouseUp(MouseEvent e) {
                String fileName = comboList.get(index).getText();
                getMelodyAndDownloadIfRequired(fileName);
                JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
                File localFile = new File(workspaceUrl.getPath(), fileName);
                String id = "audio-" + fileName;
                // $NON-NLS-1$
                DownloadServiceHandler.addDownload(id, fileName, localFile, "audio/wav");
                StringBuilder js = new StringBuilder();
                js.append("var testAudio = document.createElement('audio');");
                js.append("if (testAudio.canPlayType !== undefined)");
                js.append("{");
                // $NON-NLS-1$
                js.append("var audio = new Audio('");
                js.append(DownloadServiceHandler.createDownloadUrl(id));
                // $NON-NLS-1$
                js.append("');");
                // $NON-NLS-1$
                js.append("audio.play();");
                js.append("}");
                executor.execute(js.toString());
            }

            @Override
            public void mouseDown(MouseEvent e) {
            // do noting
            }

            @Override
            public void mouseDoubleClick(MouseEvent e) {
            // do noting
            }
        });
        buttonList.add(i, button);
    }
    new UIJob(Messages.get().AlarmMelody_JobGetMelodyList) {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            try {
                // $NON-NLS-1$
                String[] s = { "wav" };
                serverFiles = session.listServerFiles(s);
            } catch (final Exception e) {
                e.printStackTrace();
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialogHelper.openError(getShell(), Messages.get().AlarmMelody_ErrorGettingMelodyList, Messages.get().AlarmMelody_ErrorGettingMelodyListDescription + e.getMessage());
                    }
                });
            }
            for (ServerFile s : serverFiles) {
                soundList.add(s.getName());
            }
            // $NON-NLS-1$
            soundList.add("");
            for (int i = 0; i < 6; i++) {
                // $NON-NLS-1$
                currentSoundList.add(i, ps.getString("ALARM_NOTIFIER.MELODY." + AlarmNotifier.SEVERITY_TEXT[i]));
            }
            soundList.addAll(currentSoundList);
            Combo newCombo = null;
            for (int i = 0; i < 6; i++) {
                newCombo = comboList.get(i);
                newCombo.setEnabled(true);
                newCombo.setItems(soundList.toArray(new String[soundList.size()]));
                newCombo.select(newCombo.indexOf(currentSoundList.get(i)));
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return dialogArea;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) ServerFile(org.netxms.client.server.ServerFile) Combo(org.eclipse.swt.widgets.Combo) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) ServerFile(org.netxms.client.server.ServerFile) File(java.io.File)

Example 8 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class DownloadServiceHandler method startDownload.

/**
 * Start download that was added previously
 *
 * @param id
 */
public static void startDownload(String id) {
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    if (executor != null) {
        StringBuilder js = new StringBuilder();
        js.append("var hiddenIFrameID = 'hiddenDownloader',");
        js.append("   iframe = document.getElementById(hiddenIFrameID);");
        js.append("if (iframe === null) {");
        js.append("   iframe = document.createElement('iframe');");
        js.append("   iframe.id = hiddenIFrameID;");
        js.append("   iframe.style.display = 'none';");
        js.append("   document.body.appendChild(iframe);");
        js.append("}");
        js.append("iframe.src = '");
        js.append(DownloadServiceHandler.createDownloadUrl(id));
        js.append("';");
        executor.execute(js.toString());
    }
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor)

Example 9 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class MobileApplicationWorkbenchWindowAdvisor method postWindowClose.

/* (non-Javadoc)
	 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowClose()
	 */
@Override
public void postWindowClose() {
    super.postWindowClose();
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    if (executor != null)
        executor.execute("location.reload(true);");
}
Also used : JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor)

Example 10 with JavaScriptExecutor

use of org.eclipse.rap.rwt.client.service.JavaScriptExecutor in project netxms by netxms.

the class AgentFileManager method copyFilePath.

/**
 * Copy full path to file to clipboard
 */
private void copyFilePath() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    String filePath = ((AgentFile) selection.getFirstElement()).getFilePath();
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    if (executor != null) {
        StringBuilder js = new StringBuilder();
        filePath = filePath.replace("\\", "\\\\");
        // Substring is made to remove first "/"
        js.append("copyTextToClipboard(\'" + filePath + "\');");
        executor.execute(js.toString());
    }
}
Also used : AgentFile(org.netxms.client.server.AgentFile) JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

JavaScriptExecutor (org.eclipse.rap.rwt.client.service.JavaScriptExecutor)17 File (java.io.File)3 IOException (java.io.IOException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NXCSession (org.netxms.client.NXCSession)2 RandomAccessFile (java.io.RandomAccessFile)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Properties (java.util.Properties)1 UUID (java.util.UUID)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 IStatus (org.eclipse.core.runtime.IStatus)1 BindingManager (org.eclipse.jface.bindings.BindingManager)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Window (org.eclipse.jface.window.Window)1 CBanner (org.eclipse.swt.custom.CBanner)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 GridData (org.eclipse.swt.layout.GridData)1