List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.centurylink.mdw.plugin.designer.wizards.ImportPackagePage.java
License:Apache License
@Override public IWizardPage getNextPage() { ImportPackageWizard wiz = (ImportPackageWizard) getWizard(); if (isDiscovery()) { preselected = null;/*from w w w.ja v a2 s .com*/ ((ImportPackageWizard) getWizard()).setHasOldImplementors(false); final String url = discoveryUrlText.getText().trim(); final boolean latestVersionsOnly = latestVersionsCheckbox.getSelection(); // display a progress dialog since this can take a while ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(getShell()); try { pmDialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Crawling for workflow assets...", 100); try { packageFolder = populateTopFolder(url, latestVersionsOnly, monitor); monitor.done(); } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { throw new InvocationTargetException(ex); } } }); } catch (InterruptedException iex) { } catch (Exception ex) { PluginMessages.uiError(getShell(), ex, "Discover Packages", getProject()); return null; } } else { BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { public void run() { try { packageFolder = populateTopFolder(null, false, null); } catch (Exception ex) { PluginMessages.uiError(getShell(), ex, "Import Packages", getProject()); } } }); } if (packageFolder == null) { return null; } else { wiz.setFolder(packageFolder); wiz.initializePackageSelectPage(preselected); return ((ImportPackageWizard) getWizard()).getImportPackageSelectPage(); } }
From source file:com.centurylink.mdw.plugin.designer.wizards.ImportPackageWizard.java
License:Apache License
@Override public boolean performFinish() { final List<WorkflowPackage> importedPackages = new ArrayList<WorkflowPackage>(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { WorkflowProject wfp = topFolder.getProject(); DesignerProxy designerProxy = wfp.getDesignerProxy(); monitor.beginTask("Import Packages", 100 * importPackageSelectPage.getSelectedPackages().size()); monitor.subTask("Importing selected packages..."); monitor.worked(10);//from www .j a v a 2s. c o m for (File pkgFile : importPackageSelectPage.getSelectedPackages()) { ProgressMonitor progressMonitor = new SwtProgressMonitor( new SubProgressMonitor(monitor, 100)); if (pkgFile.getContent() == null && pkgFile.getUrl() != null) { // download // postponed // for // discovered // assets HttpHelper httpHelper = new HttpHelper(pkgFile.getUrl()); httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout()); httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout()); pkgFile.setContent(httpHelper.get()); } String pkgFileContent = pkgFile.getContent(); Importer importer = new Importer(designerProxy.getPluginDataAccess(), wfp.isFilePersist() && wfp.isRemote() ? null : getShell()); WorkflowPackage importedPackage = importer.importPackage(wfp, pkgFileContent, progressMonitor); if (importedPackage == null) // canceled { progressMonitor.done(); break; } else { if (upgradeAssets) { progressMonitor.subTask("Upgrading activity implementors and other assets..."); designerProxy.upgradeAssets(importedPackage); } if (wfp.isFilePersist()) // file system eclipse sync wfp.getSourceProject().refreshLocal(2, null); // TODO refresh Archive in case existing package was // moved there importedPackage.addElementChangeListener(wfp); for (WorkflowProcess pv : importedPackage.getProcesses()) pv.addElementChangeListener(wfp); for (ExternalEvent ee : importedPackage.getExternalEvents()) ee.addElementChangeListener(wfp); for (ActivityImpl ai : importedPackage.getActivityImpls()) ai.addElementChangeListener(wfp); for (WorkflowAsset wa : importedPackage.getAssets()) wa.addElementChangeListener(wfp); importedPackages.add(importedPackage); if (wfp.isRemote() && wfp.isFilePersist()) { // zip and upload imported packages to server java.io.File tempDir = wfp.getTempDir(); if (!tempDir.exists()) { if (!tempDir.mkdirs()) throw new IOException("Unable to create temp directory: " + tempDir); } java.io.File zipFile = new java.io.File(tempDir + "/packages" + StringHelper.filenameDateToString(new Date()) + ".zip"); java.io.File assetDir = wfp.getAssetDir(); List<java.io.File> includes = new ArrayList<java.io.File>(); for (WorkflowPackage pkg : importedPackages) includes.add( new java.io.File(assetDir + "/" + pkg.getName().replace('.', '/'))); // TODO populate excludes with non-imported // package dirs (why, since these are not in // includes?) FileHelper.createZipFileWith(assetDir, zipFile, includes); String uploadUrl = wfp.getServiceUrl() + "/upload?overwrite=true&assetZip=true&user=" + importPackagePage.getProject().getUser().getUsername(); InputStream is = new FileInputStream(zipFile); try { ByteArrayOutputStream os = new ByteArrayOutputStream(); int read = 0; byte[] bytes = new byte[1024]; while ((read = is.read(bytes)) != -1) os.write(bytes, 0, read); String encryptedPassword = CryptUtil .encrypt(wfp.getMdwDataSource().getDbPassword()); HttpHelper httpHelper = new HttpHelper(new URL(uploadUrl), wfp.getMdwDataSource().getDbUser(), encryptedPassword); byte[] resp = httpHelper.postBytes(os.toByteArray()); PluginMessages.log("Asset download respose: " + new String(resp)); } finally { is.close(); } } } progressMonitor.done(); } wfp.getDesignerProxy().getCacheRefresh().doRefresh(true); } catch (ActionCancelledException ex) { throw new OperationCanceledException(); } catch (Exception ex) { PluginMessages.log(ex); throw new InvocationTargetException(ex); } } }; try { getContainer().run(true, true, op); for (WorkflowPackage importedPackage : importedPackages) importedPackage.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, importedPackage); if (importedPackages.size() > 0) DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), importedPackages.get(0)); return true; } catch (InterruptedException ex) { MessageDialog.openInformation(getShell(), "Import Package", "Import Cancelled"); return true; } catch (Exception ex) { PluginMessages.uiError(getShell(), ex, "Import Package", importPackagePage.getProject()); return false; } }
From source file:com.centurylink.mdw.plugin.designer.wizards.ImportProjectWizard.java
License:Apache License
@Override public boolean performFinish() { if (errorMessage != null) { MessageDialog.openError(getShell(), "Import Project", errorMessage); return false; }/*w ww . ja v a2s . c o m*/ BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { public void run() { List<IProject> existingProjects = new ArrayList<IProject>(); 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 = (Object[]) 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) { Platform.getBundle("org.eclipse.egit.ui").start(); // avoid // 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; }
From source file:com.centurylink.mdw.plugin.project.assembly.ExtensionModulesUpdater.java
License:Apache License
private void doAdd(final ExtensionModule module, final Shell shell) { try {// w w w .ja va2 s . c o m ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell); pmDialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Adding Extension Module: " + module.getName(), 105); monitor.worked(5); try { if (module.addTo(project, monitor)) project.addExtension(module); WorkflowProjectManager.getInstance().save(project); monitor.done(); } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { PluginMessages.log(ex); throw new InvocationTargetException(ex); } } }); } catch (InvocationTargetException ex) { PluginMessages.uiError(shell, ex, "Add Extension Module", project); } catch (InterruptedException ex) { PluginMessages.log(ex); MessageDialog.openWarning(shell, "Add Extension Module", "Operation cancelled"); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ExtensionModulesUpdater.java
License:Apache License
private void doRemove(final ExtensionModule module, final Shell shell) { try {//www . j a va 2 s .c o m ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell); pmDialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Removing Extension Module: " + module.getName(), 105); monitor.worked(5); try { if (module.removeFrom(project, monitor)) project.removeExtension(module); WorkflowProjectManager.getInstance().save(project); monitor.done(); } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { PluginMessages.log(ex); throw new InvocationTargetException(ex); } } }); } catch (InvocationTargetException ex) { PluginMessages.uiError(shell, ex, "Remove Extension Module", project); } catch (InterruptedException ex) { PluginMessages.log(ex); MessageDialog.openWarning(shell, "Remove Extension Module", "Operation cancelled"); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ExtensionModulesUpdater.java
License:Apache License
private void doUpdate(final ExtensionModule module, final Shell shell) { try {//from w ww . j a v a 2 s . c o m ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell); pmDialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Updating Extension Module: " + module.getName(), 105); monitor.worked(5); try { module.update(project, monitor); monitor.done(); } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { PluginMessages.log(ex); throw new InvocationTargetException(ex); } } }); } catch (InvocationTargetException ex) { PluginMessages.uiError(shell, ex, "Update Extension Module", project); } catch (InterruptedException ex) { PluginMessages.log(ex); MessageDialog.openWarning(shell, "Update Extension Module", "Operation cancelled"); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
public void initializeFrameworkJars() { final Shell shell = MdwPlugin.getShell(); ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell); try {//from w w w . j a v a 2 s . c o m pmDialog.run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Adding Framework Libraries", 100); monitor.worked(5); ProjectUpdater updater = new ProjectUpdater(getProject(), getSettings()); updater.updateFrameworkJars(monitor); try { SubProgressMonitor submon = new SubProgressMonitor(monitor, 75); addFrameworkJarsToClasspath(submon); createFrameworkSourceCodeAssociations(shell, submon); monitor.done(); } catch (CoreException ex) { throw new InvocationTargetException(ex); } } }); } catch (Exception ex) { PluginMessages.uiError(ex, "Framework Jars", getProject()); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
public void initializeWebAppJars() { if (getProject().isRemote()) return;/*from ww w . j a v a2s . c o m*/ final Shell shell = MdwPlugin.getShell(); ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell); try { pmDialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Adding WebApp Libraries", 100); monitor.worked(5); try { ProjectUpdater updater = new ProjectUpdater(getProject(), MdwPlugin.getSettings()); updater.updateWebProjectJars(monitor); createFrameworkSourceCodeAssociations(shell, monitor); } catch (CoreException ex) { PluginMessages.log(ex); } } }); } catch (Exception ex) { PluginMessages.log(ex); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectInflator.java
License:Apache License
public void inflateRemoteProject(final IRunnableContext container) { // get a project handle final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot() .getProject(workflowProject.getName()); // get a project descriptor IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); // create the new project operation IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { CreateProjectOperation op = new CreateProjectOperation(description, "MDW Remote Project"); try { PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell)); } catch (ExecutionException ex) { throw new InvocationTargetException(ex); }/*from w w w .j a va2 s . c o m*/ } }; // run the new project creation operation try { container.run(true, true, op); } catch (Exception ex) { PluginMessages.uiError(shell, ex, "Create Remote Project", workflowProject); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectInflator.java
License:Apache License
public void inflateCloudProject(final IRunnableContext container) { getProject().setCloudProject(true);// w ww. jav a 2s . co m // get a project handle final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot() .getProject(workflowProject.getName()); // get a project descriptor IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); // create the new project operation IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { Repository newRepo = null; try { if (workflowProject.getPersistType() == PersistType.Git) { File localDir = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() + "/" + workflowProject.getName()); if (workflowProject.getMdwVcsRepository().hasRemoteRepository()) { monitor.subTask("Cloning Git repository"); VcsRepository gitRepo = workflowProject.getMdwVcsRepository(); Git.cloneRepository().setURI(gitRepo.getRepositoryUrlWithCredentials()) .setDirectory(localDir).call(); } else { newRepo = new FileRepository(new File(localDir + "/.git")); newRepo.create(); } // .gitignore Generator generator = new Generator(shell); JetAccess jet = getJet("source/.ignorejet", getProject().getSourceProject(), ".gitignore", null); generator.createFile(jet, monitor); } CreateProjectOperation op = new CreateProjectOperation(description, "MDW Cloud Project"); PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shell)); } catch (Exception ex) { throw new InvocationTargetException(ex); } finally { if (newRepo != null) newRepo.close(); } } }; // run the new project creation operation try { container.run(false, false, op); ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(MdwPlugin.getShell()); pmDialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Inflating Workflow Project", 250); monitor.worked(5); // configure as Java project ProjectConfigurator projConf = new ProjectConfigurator(getProject(), MdwPlugin.getSettings()); projConf.setJava(new SubProgressMonitor(monitor, 3)); ProjectUpdater updater = new ProjectUpdater(getProject(), MdwPlugin.getSettings()); updater.updateMappingFiles(new SubProgressMonitor(monitor, 3)); // bootstrap // versions // of // the // property // files updater.updateFrameworkJars(new SubProgressMonitor(monitor, 150)); updater.updateWebProjectJars(new SubProgressMonitor(monitor, 50)); try { if (getProject().isOsgi()) projConf.addJavaProjectSourceFolder(getProject().getOsgiSettings().getSourceDir(), new SubProgressMonitor(monitor, 3)); else if (!getProject().isWar()) projConf.addJavaProjectSourceFolder("src", monitor); projConf.setJavaBuildOutputPath("build/classes", new SubProgressMonitor(monitor, 5)); projConf.addFrameworkJarsToClasspath(monitor); // add the workflow facet getProject().setSkipFacetPostInstallUpdates(true); // already // did // framework // updates IFacetedProject facetedProject = ProjectFacetsManager .create(getProject().getSourceProject(), true, new SubProgressMonitor(monitor, 3)); IProjectFacetVersion javaFacetVersion = ProjectFacetsManager.getProjectFacet("java") .getDefaultVersion(); if (Float.parseFloat(javaFacetVersion.getVersionString()) < 1.6) javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.6"); if (workflowProject.isCloudOnly()) javaFacetVersion = ProjectFacetsManager.getProjectFacet("java").getVersion("1.7"); facetedProject.installProjectFacet(javaFacetVersion, null, new SubProgressMonitor(monitor, 3)); IProjectFacetVersion mdwFacet = ProjectFacetsManager.getProjectFacet("mdw.workflow") .getDefaultVersion(); facetedProject.installProjectFacet(mdwFacet, getProject(), new SubProgressMonitor(monitor, 3)); if (workflowProject.isOsgi()) { IProjectFacet utilFacet = ProjectFacetsManager.getProjectFacet("jst.utility"); IProjectFacetVersion facetVer = utilFacet.getDefaultVersion(); IActionDefinition def = facetVer.getActionDefinition(null, IFacetedProject.Action.Type.INSTALL); Object cfg = def.createConfigObject(); facetedProject.installProjectFacet( ProjectFacetsManager.getProjectFacet("jst.utility").getDefaultVersion(), cfg, new SubProgressMonitor(monitor, 3)); } else if (workflowProject.isWar()) { // add the facet to the xml file IFile facetsFile = workflowProject.getSourceProject() .getFile(".settings/org.eclipse.wst.common.project.facet.core.xml"); if (facetsFile.exists()) { String content = new String(PluginUtil.readFile(facetsFile)); int insert = content.indexOf("</faceted-project>"); content = content.substring(0, insert) + " <installed facet=\"jst.web\" version=\"3.0\"/>\n" + content.substring(insert); PluginUtil.writeFile(facetsFile, content, new SubProgressMonitor(monitor, 3)); } } final ProjectConfigurator configurator = new ProjectConfigurator(getProject(), MdwPlugin.getSettings()); if (!workflowProject.isOsgi() && !workflowProject.isWar()) { MdwPlugin.getDisplay().syncExec(new Runnable() { public void run() { try { configurator.createFrameworkSourceCodeAssociations(MdwPlugin.getShell(), new NullProgressMonitor()); } catch (CoreException ex) { PluginMessages.log(ex); } } }); } if (workflowProject.isOsgi()) { generateOsgiArtifacts(new SubProgressMonitor(monitor, 10)); configurator.configureOsgiProject(shell, new SubProgressMonitor(monitor, 5)); } else if (workflowProject.isWar()) { generateWarCloudArtifacts(new SubProgressMonitor(monitor, 10)); configurator.addMavenNature(new SubProgressMonitor(monitor, 5)); // force // maven // refresh } } catch (Exception ex) { throw new InvocationTargetException(ex); } } }); } catch (Exception ex) { PluginMessages.uiError(ex, "Create Cloud Project", workflowProject); } }