use of org.whole.lang.operations.IOperationProgressMonitor 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