use of org.whole.lang.operations.IOperationProgressMonitor in project whole by wholeplatform.
the class ModelsJavaModelGeneratorVisitor method visit.
public void visit(ModelDeclarations modelBody) {
IOperationProgressMonitor progressMonitor = getOperation().getProgressMonitor();
progressMonitor.beginTask("Building entities", IOperationProgressMonitor.TOTAL_WORK, modelBody.wSize());
for (int i = 0, size = modelBody.wSize(); i < size; i++) {
((IModelsEntity) modelBody.wGet(i)).accept(this);
progressMonitor.worked(1);
handleCancelRequest();
}
progressMonitor.endTask();
}
use of org.whole.lang.operations.IOperationProgressMonitor in project whole by wholeplatform.
the class HandlersBehavior method actionCall.
public static void actionCall(IBindingManager bm) {
IEntity model = bm.wGet("self");
boolean analyzing = bm.wBooleanValue("analyzing");
if (analyzing) {
// clone model if is analyzing
model = EntityUtils.clone(model);
CommonsEntityFactory.instance.createRootFragment(model.wGetAdapter(CommonsEntityDescriptorEnum.Any));
ReflectionFactory.getHistoryManager(model).setHistoryEnabled(true);
// map selected entities if analyzing
IEntity tuple = bm.wGet("selectedEntities");
int size = tuple.wSize();
for (int i = 0; i < size; i++) tuple.wSet(i, EntityUtils.mapEntity(tuple.wGet(i), model));
bm.wSet("primarySelectedEntity", EntityUtils.mapEntity(bm.wGet("primarySelectedEntity"), model));
bm.wSet("focusEntity", EntityUtils.mapEntity(bm.wGet("focusEntity"), model));
}
IEntityIterator<?> iterator = new ActionCallIterator(bm.wStringValue("functionUri"));
if (analyzing) {
iterator.setBindings(bm);
iterator.reset(model);
IEntity results = MiscEntityFactory.instance.createMisc();
for (IEntity result : iterator) {
results.wAdd(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.StageUpFragment, // CommonsEntityFactory.instance.createStageUpFragment(
EntityUtils.cloneIfParented(// TODO substitute with a no containment fragment
result)));
((IOperationProgressMonitor) bm.wGetValue("progressMonitor")).worked(1);
}
bm.setResult(results);
} else
iterator.evaluate(model, bm);
}
use of org.whole.lang.operations.IOperationProgressMonitor in project whole by wholeplatform.
the class HandlersBehavior method generateJava.
public static void generateJava(IBindingManager bm) {
ClassLoader cl = ReflectionFactory.getClassLoader(bm);
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
Class<?> generatorClass = Class.forName("org.whole.lang.ui.actions.JavaModelGeneratorAction", true, cl);
Method generateMethod = generatorClass.getMethod("generate", IProgressMonitor.class, IEntity.class, IBindingManager.class);
final IOperationProgressMonitor operationProgressMonitor = (IOperationProgressMonitor) bm.wGetValue("progressMonitor");
generateMethod.invoke(null, operationProgressMonitor.getAdapter(IProgressMonitor.class), bm.wGet("self"), bm);
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
ts.rollback();
bm.wExitScope();
}
}
use of org.whole.lang.operations.IOperationProgressMonitor 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.IOperationProgressMonitor 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);
}
Aggregations