Search in sources :

Example 1 with ProjectImporter

use of com.centurylink.mdw.plugin.project.assembly.ProjectImporter 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 2 with ProjectImporter

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

the class ImportProjectWizard method performFinish.

@Override
public boolean performFinish() {
    if (errorMessage != null) {
        MessageDialog.openError(getShell(), "Import Project", errorMessage);
        return false;
    }
    BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

        public void run() {
            List<IProject> existingProjects = new ArrayList<>();
            for (WorkflowProject toImport : projectsToImport) {
                IProject existing = MdwPlugin.getWorkspaceRoot().getProject(toImport.getName());
                if (existing != null && existing.exists())
                    existingProjects.add(existing);
            }
            if (!existingProjects.isEmpty()) {
                String text = "Please confirm that the following workspace projects should be overwritten:";
                ListSelectionDialog lsd = new ListSelectionDialog(getShell(), existingProjects, new ExistingProjectContentProvider(), new ProjectLabelProvider(), text);
                lsd.setTitle("Existing Projects");
                lsd.setInitialSelections(existingProjects.toArray(new IProject[0]));
                lsd.open();
                Object[] results = lsd.getResult();
                if (results == null) {
                    cancel = true;
                    return;
                }
                for (IProject existing : existingProjects) {
                    boolean include = false;
                    for (Object included : results) {
                        if (existing.getName().equals(((IProject) included).getName()))
                            include = true;
                    }
                    if (include) {
                        WorkflowProjectManager.getInstance().deleteProject(existing);
                    } else {
                        WorkflowProject toRemove = null;
                        for (WorkflowProject wfp : projectList) {
                            if (wfp.getName().equals(existing.getName())) {
                                toRemove = wfp;
                                break;
                            }
                        }
                        if (toRemove != null)
                            projectsToImport.remove(toRemove);
                    }
                }
            }
        }
    });
    if (cancel)
        return false;
    if (projectsToImport.isEmpty()) {
        MessageDialog.openInformation(getShell(), "Import Projects", "No projects to import.");
        return true;
    }
    try {
        getContainer().run(false, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Importing MDW project(s)", 100);
                monitor.worked(20);
                try {
                    for (WorkflowProject workflowProject : projectsToImport) {
                        if (workflowProject.isFilePersist()) {
                            File projectDir = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() + "/" + workflowProject.getName());
                            projectDir.mkdir();
                            String repositoryUrl = projectsToImport.get(0).getMdwVcsRepository().getRepositoryUrl();
                            if (repositoryUrl != null && repositoryUrl.length() > 0) {
                                // avoid
                                Platform.getBundle("org.eclipse.egit.ui").start();
                                // Eclipse
                                // default
                                // Authenticator
                                workflowProject.setPersistType(PersistType.Git);
                                workflowProject.getMdwVcsRepository().setProvider(VcsRepository.PROVIDER_GIT);
                                monitor.subTask("Cloning Git repository for " + workflowProject.getLabel());
                                monitor.worked(1);
                                VcsRepository gitRepo = workflowProject.getMdwVcsRepository();
                                VersionControlGit vcsGit = new VersionControlGit();
                                String user = null;
                                String password = null;
                                if (MdwPlugin.getSettings().isUseDiscoveredVcsCredentials()) {
                                    user = gitRepo.getUser();
                                    password = gitRepo.getPassword();
                                }
                                vcsGit.connect(gitRepo.getRepositoryUrl(), user, password, projectDir);
                                vcsGit.cloneRepo();
                            } else {
                                File assetDir = new File(projectDir + "/" + workflowProject.getMdwVcsRepository().getLocalPath());
                                assetDir.mkdirs();
                            }
                            monitor.worked(40 / projectsToImport.size());
                        }
                        ProjectInflator inflator = new ProjectInflator(workflowProject, MdwPlugin.getSettings());
                        inflator.inflateRemoteProject(getContainer());
                    }
                } catch (Exception ex) {
                    throw new InvocationTargetException(ex);
                }
                ProjectImporter projectImporter = new ProjectImporter(projectsToImport);
                projectImporter.doImport();
                monitor.worked(20);
                monitor.done();
            }
        });
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Import Project");
        return false;
    }
    DesignerPerspective.openPerspective(activeWindow);
    return true;
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ProjectImporter(com.centurylink.mdw.plugin.project.assembly.ProjectImporter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectInflator(com.centurylink.mdw.plugin.project.assembly.ProjectInflator) ArrayList(java.util.ArrayList) List(java.util.List) VcsRepository(com.centurylink.mdw.plugin.project.model.VcsRepository) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog) File(java.io.File)

Aggregations

ProjectImporter (com.centurylink.mdw.plugin.project.assembly.ProjectImporter)2 ProjectInflator (com.centurylink.mdw.plugin.project.assembly.ProjectInflator)2 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)2 VersionControlGit (com.centurylink.mdw.dataaccess.file.VersionControlGit)1 DiscoveryException (com.centurylink.mdw.plugin.designer.DiscoveryException)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 ProcessExplorerView (com.centurylink.mdw.plugin.designer.views.ProcessExplorerView)1 VcsRepository (com.centurylink.mdw.plugin.project.model.VcsRepository)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1 ListSelectionDialog (org.eclipse.ui.dialogs.ListSelectionDialog)1