Search in sources :

Example 11 with WorkflowProject

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

the class ConvertApplicationProperties method run.

public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.getFirstElement() instanceof IFile) {
            final IFile inputFile = (IFile) structuredSelection.getFirstElement();
            final WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(inputFile.getProject().getName());
            String ext = project == null || project.isOsgi() ? "cfg" : "properties";
            FileSaveDialog saveDialog = new FileSaveDialog(MdwPlugin.getActiveWorkbenchWindow().getShell());
            saveDialog.setFilterPath(inputFile.getParent().getRawLocation().makeAbsolute().toFile().getAbsolutePath());
            saveDialog.setFilterExtensions(new String[] { "*" + ext });
            final String filePath = saveDialog.open();
            if (filePath != null) {
                BusyIndicator.showWhile(MdwPlugin.getActiveWorkbenchWindow().getShell().getDisplay(), new Runnable() {

                    public void run() {
                        try {
                            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                            Document doc = dBuilder.parse(inputFile.getContents());
                            doc.getDocumentElement().normalize();
                            StringBuffer sb = new StringBuffer();
                            NodeList nList = doc.getElementsByTagName("PropertyGroup");
                            // for every property group
                            for (int temp = 0; temp < nList.getLength(); temp++) {
                                Node nNode = nList.item(temp);
                                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                                    Element eElement = (Element) nNode;
                                    String propertyGroupName = eElement.getAttribute("Name");
                                    // create PropertyGroup comment
                                    sb.append("\n");
                                    sb.append("#");
                                    sb.append(propertyGroupName);
                                    sb.append("\n");
                                    NodeList propertyList = eElement.getElementsByTagName("Property");
                                    // group
                                    for (int temp2 = 0; temp2 < propertyList.getLength(); temp2++) {
                                        Node nNode2 = propertyList.item(temp2);
                                        if (nNode2.getNodeType() == Node.ELEMENT_NODE) {
                                            Element eElement2 = (Element) nNode2;
                                            // format to:
                                            // propertyGroup-propertyName=elementValue
                                            sb.append(propertyGroupName);
                                            if (project == null || project.isOsgi())
                                                sb.append("-");
                                            else
                                                sb.append("/");
                                            sb.append(eElement2.getAttribute("Name"));
                                            sb.append("=");
                                            sb.append(nNode2.getTextContent());
                                            sb.append("\n");
                                        }
                                    }
                                }
                            }
                            PluginUtil.writeFile(new File(filePath), sb.toString().getBytes());
                            inputFile.getParent().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
                        } catch (Exception ex) {
                            PluginMessages.uiError(shell, ex, "Convert Application Properties", project);
                        }
                    }
                });
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) FileSaveDialog(com.centurylink.mdw.plugin.designer.dialogs.FileSaveDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Document(org.w3c.dom.Document) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 12 with WorkflowProject

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

the class ConvertPropertiesToYaml method run.

@SuppressWarnings("restriction")
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.getFirstElement() instanceof IFile) {
            final IFile inputFile = (IFile) structuredSelection.getFirstElement();
            final WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(inputFile.getProject().getName());
            BusyIndicator.showWhile(MdwPlugin.getActiveWorkbenchWindow().getShell().getDisplay(), new Runnable() {

                public void run() {
                    try {
                        Convert convert = new Convert(inputFile.getRawLocation().makeAbsolute().toFile());
                        convert.setConfigLoc(inputFile.getParent().getRawLocation().makeAbsolute().toFile().getAbsolutePath());
                        convert.run();
                        inputFile.getParent().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
                    } catch (Exception ex) {
                        PluginMessages.uiError(shell, ex, "Convert Application Properties", project);
                    }
                }
            });
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Convert(com.centurylink.mdw.cli.Convert) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 13 with WorkflowProject

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

the class MdwWorkbenchWindowAdvisor method getWorkflowProject.

private WorkflowProject getWorkflowProject(String host, String port, String contextRoot) throws DiscoveryException {
    BigInteger portInt = new BigInteger(port);
    WorkflowApplication matchingWorkflowApp = null;
    WorkflowEnvironment matchingWorkflowEnv = null;
    boolean isLocalhost = "localhost".equals(host);
    List<WorkflowApplication> workflowApps = WorkflowProjectManager.getInstance().discoverWorkflowApps();
    for (WorkflowApplication workflowApp : workflowApps) {
        if (isLocalhost) {
            // right info except host and port
            if (workflowApp.getWebContextRoot().equals(contextRoot) || (workflowApp.getServicesContextRoot() != null && workflowApp.getServicesContextRoot().equals(contextRoot))) {
                matchingWorkflowApp = workflowApp;
                matchingWorkflowEnv = workflowApp.getEnvironmentList().get(0);
                ManagedNode server = matchingWorkflowEnv.getManagedServerList().get(0);
                server.setHost(host);
                server.setPort(new BigInteger(port));
                break;
            }
        } else {
            for (WorkflowEnvironment workflowEnv : workflowApp.getEnvironmentList()) {
                for (ManagedNode server : workflowEnv.getManagedServerList()) {
                    if (server.getHost().equals(host) && server.getPort().equals(portInt)) {
                        if (matchingWorkflowEnv == null) {
                            matchingWorkflowEnv = workflowEnv;
                            matchingWorkflowApp = workflowApp;
                        } else {
                            // context root is only used to break a tie
                            if (workflowApp.getWebContextRoot().equals(contextRoot) || (workflowApp.getServicesContextRoot() != null && workflowApp.getServicesContextRoot().equals(contextRoot))) {
                                matchingWorkflowEnv = workflowEnv;
                                matchingWorkflowApp = workflowApp;
                            }
                        }
                    }
                }
            }
        }
    }
    if (matchingWorkflowApp == null)
        return null;
    return new WorkflowProject(matchingWorkflowApp, matchingWorkflowEnv);
}
Also used : WorkflowApplication(com.centurylink.mdw.workflow.WorkflowApplication) WorkflowEnvironment(com.centurylink.mdw.workflow.WorkflowEnvironment) BigInteger(java.math.BigInteger) ManagedNode(com.centurylink.mdw.workflow.ManagedNode) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject)

Example 14 with WorkflowProject

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

the class MdwWorkbenchWindowAdvisor method postWindowOpen.

public void postWindowOpen() {
    IWorkbenchPage activePage = Activator.getActivePage();
    // check for updates
    // IHandlerService handlerService = (IHandlerService)
    // activePage.getWorkbenchWindow().getService(IHandlerService.class);
    // try
    // {
    // Object result =
    // handlerService.executeCommand("org.eclipse.equinox.p2.ui.sdk.update", null);
    // System.out.println("result: " + result);
    // if (result != null)
    // System.out.println("result class: " + result.getClass().getName());
    // }
    // catch (Exception ex)
    // {
    // ex.printStackTrace();
    // }
    PluginMessages.log("MDW workbench startup...");
    if (activePage != null) {
        activePage.hideActionSet("com.centurylink.mdw.plugin.actionset.tools");
        activePage.hideActionSet("com.centurylink.mdw.plugin.actionset.dev");
        activePage.hideActionSet("com.centurylink.mdw.plugin.actionset.designerClassic");
        activePage.hideActionSet("org.eclipse.ui.edit.text.actionSet.navigation");
        activePage.hideActionSet("org.eclipse.ui.edit.text.actionSet.annotationNavigation");
        activePage.hideActionSet("org.eclipse.ui.externaltools.ExternalToolsSet");
        activePage.showActionSet("org.eclipse.search.menu");
        // make sure the process explorer view is visible
        try {
            ProcessExplorerView processExplorerView = (ProcessExplorerView) activePage.showView("mdw.views.designer.processes");
            if (mdwHost != null && mdwPort != null) {
                final Shell shell = activePage.getActivePart().getSite().getShell();
                BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {

                    public void run() {
                        try {
                            discoveryException = null;
                            projectToImport = getWorkflowProject(mdwHost, mdwPort, mdwContextRoot);
                            if (projectToImport == null)
                                throw new DiscoveryException("Unable to discover workflow app at: " + mdwHost + ":" + mdwPort);
                        } catch (DiscoveryException ex) {
                            discoveryException = ex;
                        }
                    }
                });
                if (discoveryException != null)
                    throw discoveryException;
                WorkflowProject existing = WorkflowProjectManager.getInstance().getRemoteWorkflowProject(projectToImport.getName());
                if (existing != null)
                    WorkflowProjectManager.getInstance().deleteProject(existing);
                ProgressMonitorDialog progMonDlg = new ProgressMonitorDialog(shell);
                ProjectInflator projectInflator = new ProjectInflator(projectToImport, null);
                projectInflator.inflateRemoteProject(progMonDlg);
                ProjectImporter projectImporter = new ProjectImporter(projectToImport);
                projectImporter.doImport();
                processExplorerView.handleRefresh();
                // handle preselected entity
                if (preselectType != null && preselectType.trim().length() > 0 && preselectId != null && preselectId.trim().length() > 0) {
                    if (!preselectType.equals(PRESELECT_PROCESS_INSTANCE))
                        throw new UnsupportedOperationException("Unsupported preselect type: " + preselectType);
                    BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {

                        public void run() {
                            // open the process instance
                            IWorkbenchPage page = MdwPlugin.getActivePage();
                            try {
                                WorkflowProcess instance = getProcessInstance(new Long(preselectId));
                                page.openEditor(instance, "mdw.editors.process");
                                page.showView("org.eclipse.ui.views.PropertySheet");
                            } catch (PartInitException ex) {
                                PluginMessages.uiError(ex, "Open Process Instance", projectToImport);
                            }
                        }
                    });
                }
            }
        } catch (Exception ex) {
            PluginMessages.uiError(ex, "Initialize Workspace");
        }
    }
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ProcessExplorerView(com.centurylink.mdw.plugin.designer.views.ProcessExplorerView) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) PartInitException(org.eclipse.ui.PartInitException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) ProjectImporter(com.centurylink.mdw.plugin.project.assembly.ProjectImporter) Shell(org.eclipse.swt.widgets.Shell) ProjectInflator(com.centurylink.mdw.plugin.project.assembly.ProjectInflator) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Example 15 with WorkflowProject

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

the class MdwPlugin method stop.

/**
 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
 */
public void stop(BundleContext context) throws Exception {
    try {
        for (WorkflowProject project : WorkflowProjectManager.getInstance().getWorkflowProjects()) project.clear();
        LogWatcher logWatcher = LogWatcher.instance;
        if (logWatcher != null && logWatcher.isRunning())
            logWatcher.shutdown();
        plugin = null;
    } finally {
        super.stop(context);
    }
}
Also used : LogWatcher(com.centurylink.mdw.plugin.launch.LogWatcher) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject)

Aggregations

WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)128 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)31 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)25 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)22 ArrayList (java.util.ArrayList)22 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)21 CoreException (org.eclipse.core.runtime.CoreException)19 Action (org.eclipse.jface.action.Action)19 IAction (org.eclipse.jface.action.IAction)18 IProject (org.eclipse.core.resources.IProject)17 IFile (org.eclipse.core.resources.IFile)16 PartInitException (org.eclipse.ui.PartInitException)16 IWorkbenchAction (org.eclipse.ui.actions.ActionFactory.IWorkbenchAction)16 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)12 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IOException (java.io.IOException)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)9