use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.
the class WholePluginProjectWizard method performFinish.
public boolean performFinish() {
// outside WorkspaceModifyOperation.execute() due to a concurrency bug of OSGI
final IBindingManager params = BindingManagerFactory.instance.createArguments();
params.wDefValue("projectName", newProjectCreationPage.getProjectName());
params.wDefValue("pluginId", newProjectCreationPage.getPluginId());
params.wDefValue("pluginVersion", newProjectCreationPage.getPluginVersion());
params.wDefValue("pluginName", newProjectCreationPage.getPluginName());
params.wDefValue("pluginProvider", newProjectCreationPage.getPluginProvider());
if (!newProjectCreationPage.useDefaults())
params.wDefValue("locationURI", newProjectCreationPage.getLocationURI());
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor progressMonitor) {
try {
progressMonitor.beginTask("Generating...", IOperationProgressMonitor.TOTAL_WORK);
params.wDefValue("progressMonitor", new OperationProgressMonitorAdapter(progressMonitor));
IEntity projectTemplate = ProjectsArtifactsTemplateManager.instance().create("WholePluginProject");
projectTemplate = BehaviorUtils.evaluate(projectTemplate, 1, params);
Matcher.removeVars(projectTemplate, false);
ArtifactsGeneratorOperation.generate(projectTemplate, params);
} catch (Exception exception) {
E4CompatibilityPlugin.log(exception);
} finally {
progressMonitor.done();
}
}
};
try {
getContainer().run(false, false, operation);
} catch (Exception exception) {
E4CompatibilityPlugin.log(exception);
return false;
}
if (project != null) {
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(project);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
}
return true;
}
use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.
the class WholeProjectWizard method performFinish.
public boolean performFinish() {
// outside WorkspaceModifyOperation.execute() due to a concurrency bug of OSGI
final IBindingManager params = BindingManagerFactory.instance.createArguments();
params.wDefValue("projectName", projectName);
if (!newProjectCreationPage.useDefaults())
params.wDefValue("locationURI", newProjectCreationPage.getLocationURI());
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor progressMonitor) {
try {
progressMonitor.beginTask("Generating...", IOperationProgressMonitor.TOTAL_WORK);
params.wDefValue("progressMonitor", new OperationProgressMonitorAdapter(progressMonitor));
IEntity projectTemplate = ProjectsArtifactsTemplateManager.instance().create("WholeProject");
projectTemplate = BehaviorUtils.evaluate(projectTemplate, 1, params);
Matcher.removeVars(projectTemplate, false);
ArtifactsGeneratorOperation.generate(projectTemplate, params);
} catch (Exception exception) {
E4CompatibilityPlugin.log(exception);
} finally {
progressMonitor.done();
}
}
};
try {
getContainer().run(false, false, operation);
} catch (Exception exception) {
E4CompatibilityPlugin.log(exception);
return false;
}
if (project != null) {
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(project);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
}
return true;
}
use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.
the class AbstractRunnableWithProgress method run.
@Override
public void run(IProgressMonitor monitor) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
try {
final IOperationProgressMonitor pm = new OperationProgressMonitorAdapter(monitor);
bm.wDefValue("progressMonitor", pm);
run(pm);
} catch (Exception e) {
E4Utils.suspendOrReportException(context, SuspensionKind.ERROR, "Model operation error", "Error while executing " + label + " operation", e, bm);
} finally {
monitor.done();
if (isTransactional())
context.get(UISynchronize.class).syncExec(() -> viewer.getEditDomain().setDisabled(false));
}
return;
}
use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.
the class JavaModelGeneratorAction method generate.
public static void generate(IProgressMonitor monitor, final IEntity program, IBindingManager bm) throws InterruptedException, CoreException {
IPackageFragmentRoot packageFragmentRoot = JDTUtils.getPackageFragmentRoot(bm.wStringValue("sourceLocationName"));
IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
IWorkspace workspace = context.get(IWorkspace.class);
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
monitor.beginTask("Generating...", 100);
final IOperationProgressMonitor operationProgressMonitor = new OperationProgressMonitorAdapter(monitor);
bm.wDefValue("progressMonitor", operationProgressMonitor);
operationProgressMonitor.beginTask("models", 10, IOperationProgressMonitor.TOTAL_WORK);
final List<CompilationUnit> cuList = JavaCompilerOperation.compile(program, bm);
operationProgressMonitor.endTask();
operationProgressMonitor.beginTask("classes", 90, cuList.size());
if (packageFragmentRoot != null && !cuList.isEmpty()) {
Iterator<CompilationUnit> i = new ArrayList<CompilationUnit>(cuList).iterator();
while (i.hasNext()) {
try {
CompilationUnit cu = i.next();
operationProgressMonitor.beginTask(JDTUtils.getTypeName(cu), 1);
JDTUtils.save(cu, packageFragmentRoot, null);
operationProgressMonitor.endTask();
} catch (JavaModelException e) {
throw new RuntimeException(e);
}
if (operationProgressMonitor.isCanceled())
throw new OperationCanceledException();
}
}
operationProgressMonitor.endTask();
}
};
workspace.run(operation, workspace.getRoot(), IResource.NONE, monitor);
}
use of org.whole.lang.operations.OperationProgressMonitorAdapter in project whole by wholeplatform.
the class WholeOperationLaunchConfigurationDelegate method launch.
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
if (!"run".equals(mode))
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "Only 'run' mode supported by this launcher", null));
String operationId = configuration.getAttribute(OPERATION_ID, (String) null);
if (operationId == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No operation selected", null));
String targetModelPath = configuration.getAttribute(TARGET_MODEL_PATH, (String) null);
if (targetModelPath == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No target model selected", null));
String targetModelPersistence = configuration.getAttribute(TARGET_MODEL_PERSISTENCE, (String) null);
if (targetModelPersistence == null)
throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No persistence selected", null));
try {
monitor.beginTask("Executing " + operationId + " operation...", 100);
if (monitor.isCanceled())
return;
IOperationProgressMonitor operationProgressMonitor = new OperationProgressMonitorAdapter(monitor);
IFile targetModelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(targetModelPath));
IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
ResourceUtils.defineResourceBindings(bindings, targetModelFile);
IBindingScope scope = LaunchConfigurationUtils.loadBindingScope(configuration);
bindings.wEnterScope(scope, true);
IPersistenceKit persistenceKit = ReflectionFactory.getPersistenceKit(targetModelPersistence);
IEntity model = persistenceKit.readModel(new IFilePersistenceProvider(targetModelFile));
IOperationLauncher operationLauncher = OperationLauncherRegistry.instance.getOperationLauncher(operationId);
InputStream is = System.in;
OutputStream os = System.out;
if (configuration.getAttribute(CONSOLE_VIEW, false)) {
IOConsole ioConsole = WholeConsoleFactory.getIOConsole();
is = ioConsole.getInputStream();
os = ioConsole.newOutputStream();
}
operationLauncher.launch(model, bindings, is, os, operationProgressMonitor);
if (configuration.getAttribute(PERSIST_CHANGES, false))
persistenceKit.writeModel(model, new IFilePersistenceProvider(targetModelFile));
} catch (Throwable t) {
WholePlugin.log(t);
} finally {
monitor.done();
}
}
Aggregations