Search in sources :

Example 96 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project tdi-studio-se by Talend.

the class BusinessDiagramEditorUtil method createNewDiagramFile.

/**
     * <p>
     * This method should be called within a workspace modify operation since it creates resources.
     * </p>
     * 
     * @generated
     * @return the created file resource, or <code>null</code> if the file was not created
     */
public static final IFile createNewDiagramFile(DiagramFileCreator diagramFileCreator, IPath containerFullPath, String fileName, InputStream initialContents, String kind, Shell shell, IProgressMonitor progressMonitor) {
    TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    //$NON-NLS-1$
    progressMonitor.beginTask("Creating diagram and model files", 4);
    final IProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor, 1);
    final IFile diagramFile = diagramFileCreator.createNewFile(containerFullPath, fileName, initialContents, shell, new IRunnableContext() {

        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
            runnable.run(subProgressMonitor);
        }
    });
    final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString()));
    List affectedFiles = new ArrayList();
    affectedFiles.add(diagramFile);
    final String kindParam = kind;
    AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, //$NON-NLS-1$
    "Creating diagram and model", //$NON-NLS-1$
    affectedFiles) {

        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            BusinessProcess model = createInitialModel();
            diagramResource.getContents().add(model);
            Diagram diagram = ViewService.createDiagram(model, kindParam, BusinessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            if (diagram != null) {
                diagramResource.getContents().add(diagram);
                diagram.setName(diagramFile.getName());
                diagram.setElement(model);
            }
            try {
                diagramResource.save(Collections.EMPTY_MAP);
            } catch (IOException e) {
                BusinessDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", //$NON-NLS-1$
                e);
            }
            return CommandResult.newOKCommandResult();
        }
    };
    try {
        OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);
    } catch (ExecutionException e) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e);
    }
    try {
        //$NON-NLS-1$
        diagramFile.setCharset("UTF-8", new SubProgressMonitor(progressMonitor, 1));
    } catch (CoreException e) {
        //$NON-NLS-1$
        BusinessDiagramEditorPlugin.getInstance().logError("Unable to set charset for diagram file", e);
    }
    return diagramFile;
}
Also used : IRunnableContext(org.eclipse.jface.operation.IRunnableContext) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Diagram(org.eclipse.gmf.runtime.notation.Diagram) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 97 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project tdi-studio-se by Talend.

the class EmfEmittersPersistenceFactory method getJetProject.

/**
     * DOC mhirt Comment method "getJetProject".
     * 
     * @return
     * @throws CoreException
     */
private static IProject getJetProject() {
    IProject project = null;
    try {
        IProgressMonitor monitor = new NullProgressMonitor();
        IProgressMonitor progressMonitor = new SubProgressMonitor(monitor, 1);
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        //$NON-NLS-1$
        project = workspace.getRoot().getProject(".JETEmitters");
        if (!project.exists()) {
            project.create(new SubProgressMonitor(progressMonitor, 1));
            progressMonitor.subTask(//$NON-NLS-1$
            CodeGenPlugin.getPlugin().getString(//$NON-NLS-1$
            "_UI_JETCreatingProject_message", new Object[] { project.getName() }));
            project.open(new SubProgressMonitor(progressMonitor, 1));
        }
    } catch (CoreException e) {
        log.error(e.getMessage(), e);
        project = null;
    }
    return project;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 98 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project tdi-studio-se by Talend.

the class BuildJobManager method buildJobs.

public boolean buildJobs(String destinationPath, List<? extends IRepositoryNode> nodes, List<String> topNames, String version, String context, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType, IProgressMonitor monitor) throws Exception {
    IProgressMonitor pMonitor = new NullProgressMonitor();
    if (monitor != null) {
        pMonitor = monitor;
    }
    final List<ProcessItem> processes = getProcesses(nodes);
    if (processes.size() == 1) {
        ProcessItem item = processes.get(0);
        buildJob(destinationPath, item, version, context, exportChoiceMap, jobExportType, pMonitor);
    } else {
        int scale = 1000;
        int steps = 3;
        pMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), //$NON-NLS-1$
        steps * scale * nodes.size());
        String topName = null;
        if (topNames != null && !topNames.isEmpty()) {
            topName = topNames.get(0);
        } else {
            topName = ProjectManager.getInstance().getCurrentProject().getLabel();
        }
        File desFile = new File(destinationPath);
        //$NON-NLS-1$ //$NON-NLS-2$
        File createTempFile = File.createTempFile("building_job", "");
        createTempFile.delete();
        File tempFolder = new File(desFile.getParent() + File.separator + createTempFile.getName());
        if (tempFolder.exists()) {
            tempFolder.delete();
        }
        File tempProFolder = new File(tempFolder, topName);
        tempProFolder.mkdirs();
        for (int i = 0; i < processes.size(); i++) {
            ProcessItem processItem = processes.get(i);
            //$NON-NLS-1$
            pMonitor.setTaskName(Messages.getString("BuildJobManager.building", processItem.getProperty().getLabel()));
            IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(processItem, context, processItem.getProperty().getVersion(), exportChoiceMap, jobExportType);
            buildJobHandler.generateItemFiles(true, new SubProgressMonitor(pMonitor, scale));
            buildJobHandler.generateJobFiles(new SubProgressMonitor(pMonitor, scale));
            buildJobHandler.build(new SubProgressMonitor(pMonitor, scale));
            IFile jobTargetFile = buildJobHandler.getJobTargetFile();
            if (jobTargetFile != null && jobTargetFile.exists()) {
                // unzip to temp folder
                FilesUtils.unzip(jobTargetFile.getLocation().toPortableString(), tempProFolder.getAbsolutePath());
                String zipPath = jobTargetFile.getLocation().toPortableString();
                if (needClasspathJar(exportChoiceMap)) {
                    JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(zipPath, processItem.getProperty().getLabel());
                    creator.setTempFolder(tempFolder.getAbsolutePath());
                    creator.buildNewJar();
                }
            }
            pMonitor.worked(scale);
        }
        FilesUtils.zip(tempFolder.getAbsolutePath(), destinationPath);
        FilesUtils.deleteFile(tempFolder, true);
        pMonitor.done();
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) ZipToFile(org.talend.repository.ui.utils.ZipToFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 99 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project bndtools by bndtools.

the class NewDSComponentWizardPage method createTypeMembers.

@Override
protected void createTypeMembers(IType newType, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
    boolean doConstr = isCreateConstructors();
    boolean doInherited = isCreateInherited();
    createInheritedMethods(newType, doConstr, doInherited, imports, new SubProgressMonitor(monitor, 1));
    if (activateSignature != null && activateSignature != ActivateSignature.NoActivate) {
        StringBuilder builder;
        String content;
        final String lineDelim = "\n";
        // Generate activate method
        builder = new StringBuilder();
        builder.append("@").append(imports.addImport("org.osgi.service.component.annotations.Activate")).append(lineDelim);
        builder.append("void activate(");
        switch(activateSignature) {
            case NoActivate:
            case NoArg:
            default:
                // Nothing to do
                break;
            case ConfigMap:
                builder.append(imports.addImport("java.util.Map")).append("<").append(imports.addImport("java.lang.String")).append(",").append(imports.addImport("java.lang.Object")).append(">").append(" ").append("configProps");
                break;
            case ComponentContext:
                builder.append(imports.addImport("org.osgi.service.component.ComponentContext")).append(" ").append("componentContext");
                break;
            case BundleContext:
                builder.append(imports.addImport("org.osgi.framework.BundleContext")).append(" ").append("bundleContext");
                break;
        }
        builder.append(") {").append(lineDelim);
        content = CodeGeneration.getMethodBodyContent(newType.getCompilationUnit(), newType.getTypeQualifiedName('.'), "activate", false, "", lineDelim);
        if (content != null && content.length() > 0)
            builder.append(content);
        builder.append("}");
        newType.createMethod(builder.toString(), null, false, null);
        // Generate deactivate method
        builder = new StringBuilder();
        builder.append("@").append(imports.addImport("org.osgi.service.component.annotations.Deactivate")).append(lineDelim);
        builder.append("void deactivate() {").append(lineDelim);
        content = CodeGeneration.getMethodBodyContent(newType.getCompilationUnit(), newType.getTypeQualifiedName('.'), "activate", false, "", lineDelim);
        if (content != null && content.length() > 0)
            builder.append(content);
        builder.append("}");
        newType.createMethod(builder.toString(), null, false, null);
    }
    if (monitor != null)
        monitor.done();
}
Also used : SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 100 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project bndtools by bndtools.

the class WorkspaceReleaseJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    monitor.beginTask(Messages.releasingProjects, projectDiffs.size());
    for (ProjectDiff projectDiff : projectDiffs) {
        if (projectDiff.isRelease()) {
            RepositoryPlugin release = null;
            if (projectDiff.getReleaseRepository() != null) {
                release = Activator.getRepositoryPlugin(projectDiff.getReleaseRepository());
            }
            ReleaseContext context = new ReleaseContext(projectDiff.getProject(), projectDiff.getBaselines(), release, releaseOption);
            ReleaseJob job = new ReleaseJob(context, showMessage);
            job.setRule(ResourcesPlugin.getWorkspace().getRoot());
            job.run(new SubProgressMonitor(monitor, 1));
        }
        monitor.worked(1);
    }
    monitor.done();
    return Status.OK_STATUS;
}
Also used : ReleaseContext(bndtools.release.api.ReleaseContext) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)213 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)53 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 CoreException (org.eclipse.core.runtime.CoreException)38 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)29 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IProject (org.eclipse.core.resources.IProject)14 IResource (org.eclipse.core.resources.IResource)14 File (java.io.File)13 List (java.util.List)13 IPath (org.eclipse.core.runtime.IPath)13 IMethod (org.eclipse.jdt.core.IMethod)13 HashMap (java.util.HashMap)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11