Search in sources :

Example 1 with IOperationProgressMonitor

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();
}
Also used : IModelsEntity(org.whole.lang.models.model.IModelsEntity) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor)

Example 2 with IOperationProgressMonitor

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);
}
Also used : ActionCallIterator(org.whole.lang.actions.iterators.ActionCallIterator) IEntity(org.whole.lang.model.IEntity) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor)

Example 3 with IOperationProgressMonitor

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();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITransactionScope(org.whole.lang.bindings.ITransactionScope) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) Method(java.lang.reflect.Method) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) OperationCanceledException(org.whole.lang.operations.OperationCanceledException)

Example 4 with IOperationProgressMonitor

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;
}
Also used : OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with IOperationProgressMonitor

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);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaModelException(org.eclipse.jdt.core.JavaModelException) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspace(org.eclipse.core.resources.IWorkspace) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter)

Aggregations

IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)6 OperationProgressMonitorAdapter (org.whole.lang.operations.OperationProgressMonitorAdapter)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IEntity (org.whole.lang.model.IEntity)2 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 Status (org.eclipse.core.runtime.Status)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 IOConsole (org.eclipse.ui.console.IOConsole)1 ActionCallIterator (org.whole.lang.actions.iterators.ActionCallIterator)1