Search in sources :

Example 1 with ProcessConsoleRunner

use of com.centurylink.mdw.plugin.ProcessConsoleRunner in project mdw-designer by CenturyLinkCloud.

the class WorkflowElementActionHandler method launchSwing.

public void launchSwing(final WorkflowProject project, final String title, final String formName, String dataInit) {
    try {
        if (title.equals("Java VisualVM")) {
            String javaVersion = System.getProperty("java.version");
            String badVersionMsg = "Cannot launch Java VisualVM.\nRequires Java version >= 1.6.0_07.\nRunning version: " + javaVersion + ".";
            if (!javaVersion.startsWith("1.6") && !javaVersion.startsWith("1.7") && !javaVersion.startsWith("1.8")) {
                MessageDialog.openError(getShell(), "Launch Java VisualVM", badVersionMsg);
                return;
            } else if (javaVersion.startsWith("1.6")) {
                // check minor version
                String minorVer = javaVersion.substring(javaVersion.indexOf('_') + 1);
                if (Integer.parseInt(minorVer) < 7) {
                    MessageDialog.openError(getShell(), "Launch Java VisualVM", badVersionMsg);
                    return;
                }
            }
            String jdkBin = PluginUtil.getJdkBin();
            File exe = new File(jdkBin + File.separator + "jvisualvm.exe");
            if (!exe.exists()) {
                MessageDialog.openError(getShell(), "Launch Java VisualVM", "Executable not found: '" + exe + "'");
                return;
            }
            String[] cmdArr = new String[] { exe.getAbsolutePath() };
            if (project.isRemote()) {
                cmdArr = (String[]) PluginUtil.appendArrays(cmdArr, new String[] { "--openjmx", project.getServerSettings().getHost() + ":" + project.getJmxPort() });
            } else {
                cmdArr = (String[]) PluginUtil.appendArrays(cmdArr, new String[] { "--openid", String.valueOf(project.getVisualVmId()) });
            }
            new ProcessConsoleRunner(getShell().getDisplay(), cmdArr).start();
        } else if (title.equals("JConsole")) {
            String jdkBin = PluginUtil.getJdkBin();
            File exe = new File(jdkBin + File.separator + "jconsole.exe");
            if (!exe.exists()) {
                MessageDialog.openError(getShell(), "Launch JConsole", "Executable not found: '" + exe + "'");
                return;
            }
            String[] cmdArr = new String[] { exe.getAbsolutePath() };
            if (project.isRemote())
                cmdArr = (String[]) PluginUtil.appendArrays(cmdArr, new String[] { project.getServerSettings().getHost() + ":" + project.getJmxPort() });
            else {
                String serverProcId = project.getServerSettings().getServerProcessId();
                if (serverProcId != null)
                    cmdArr = (String[]) PluginUtil.appendArrays(cmdArr, new String[] { serverProcId });
            }
            new ProcessConsoleRunner(getShell().getDisplay(), cmdArr).start();
        } else {
            String request = null;
            if (dataInit != null) {
                FormDataDocument datadoc = new FormDataDocument();
                datadoc.setAttribute(FormDataDocument.ATTR_ACTION, dataInit);
                request = datadoc.format();
            }
            final String response = dataInit == null ? null : project.getDesignerProxy().getDesignerDataAccess().engineCall(request);
            EventQueue.invokeLater(new Runnable() {

                public void run() {
                    try {
                        DesignerProxy designerProxy = project.getDesignerProxy();
                        JFrame propmgr_frame = new JFrame(title);
                        FormPanel mainform = new FormPanel(propmgr_frame, designerProxy.getDesignerDataAccess(), designerProxy.getPluginDataAccess().getPrivileges());
                        mainform.setData(formName, response);
                        propmgr_frame.setVisible(true);
                    } catch (final Exception ex) {
                        if (getShell() == null) {
                            PluginMessages.log(ex);
                        } else {
                            getShell().getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    if (ex.getCause() instanceof ConnectException)
                                        MessageDialog.openError(getShell(), "Launch " + title, ex.getCause().getMessage());
                                    else
                                        PluginMessages.uiError(ex, "Launch " + title, project);
                                }
                            });
                        }
                    }
                }
            });
        }
    } catch (Exception ex) {
        if (ex.getCause() instanceof ConnectException)
            MessageDialog.openError(getShell(), "Launch " + title, ex.getCause().getMessage());
        else
            PluginMessages.uiError(ex, "Launch " + title, project);
    }
}
Also used : ProcessConsoleRunner(com.centurylink.mdw.plugin.ProcessConsoleRunner) FormPanel(com.centurylink.mdw.designer.pages.FormPanel) JFrame(javax.swing.JFrame) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(com.centurylink.mdw.plugin.designer.model.JarFile) FormDataDocument(com.centurylink.mdw.model.FormDataDocument) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ConnectException(java.net.ConnectException)

Aggregations

FormPanel (com.centurylink.mdw.designer.pages.FormPanel)1 FormDataDocument (com.centurylink.mdw.model.FormDataDocument)1 ProcessConsoleRunner (com.centurylink.mdw.plugin.ProcessConsoleRunner)1 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)1 JarFile (com.centurylink.mdw.plugin.designer.model.JarFile)1 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectException (java.net.ConnectException)1 JFrame (javax.swing.JFrame)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 PartInitException (org.eclipse.ui.PartInitException)1