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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations