Search in sources :

Example 11 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class DataEntityDirectEditPolicy method getDirectEditCommand.

protected Command getDirectEditCommand(IEntity hostEntity, String value, IDataTypeParser parser) {
    ModelTransactionCommand command = new ModelTransactionCommand(hostEntity);
    try {
        command.begin();
        hostEntity.wSetValue(parser.parse(hostEntity.wGetEntityDescriptor(), value));
        command.commit();
        return command;
    } catch (Exception e) {
        command.rollbackIfNeeded();
        return UnexecutableCommand.INSTANCE;
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand)

Example 12 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class TreeDirectEditPolicy method getDirectEditCommand.

private Command getDirectEditCommand(TreeDirectEditRequest request) {
    IEntity entity = getTreeEntityPart().getModelEntity();
    ModelTransactionCommand mtc = new ModelTransactionCommand(entity);
    try {
        mtc.setLabel("edit");
        mtc.begin();
        DataTypeUtils.setFromPersistenceString(entity, request.getValue());
        mtc.commit();
        if (mtc.canUndo())
            getTreeEntityPart().getViewer().getEditDomain().getCommandStack().execute(mtc);
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
    } finally {
    }
    return null;
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity)

Example 13 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class E4FindReplaceDialog method doReplace.

protected void doReplace(boolean updateSelection) {
    if (!hasFoundEntity())
        return;
    final RootFragment replacementWrapper = CommonsEntityFactory.instance.createRootFragment(EntityUtils.clone(replaceViewer.getEntityContents()).wGetAdapter(CommonsEntityDescriptorEnum.Any));
    Matcher.substitute(replacementWrapper.getRootEntity(), bindings, false);
    ModelTransactionCommand command = new ModelTransactionCommand();
    try {
        command.setModel(getFoundEntity());
        command.begin();
        iterator.set(EntityUtils.remove(replacementWrapper.getRootEntity()));
        command.commit();
    } catch (Exception e) {
        command.rollbackIfNeeded();
    } finally {
        clearFoundEntity();
    }
    IEntityPartViewer viewer = (IEntityPartViewer) selection.wGetValue("viewer");
    viewer.getCommandStack().execute(command);
    if (updateSelection) {
        Control control = viewer.getControl();
        control.getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                boolean state = enableSelectionTracking(false);
                selectAndReveal(replacementWrapper);
                enableSelectionTracking(state);
            }
        });
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) Control(org.eclipse.swt.widgets.Control) RootFragment(org.whole.lang.commons.model.RootFragment) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 14 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class ModelTransactionHandler method execute.

@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    EntityEditDomainJob.asyncExec(getLabel(bm), viewer.getEditDomain(), (monitor) -> {
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
        ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
        try {
            bm.wEnterScope(ts);
            mtc.setLabel(getLabel(bm));
            mtc.begin();
            run(bm);
            mtc.commit();
            if (mtc.canUndo())
                commandStack.execute(mtc);
        } catch (RollbackException e) {
        // rollback done
        } catch (RuntimeException e) {
            mtc.rollbackIfNeeded();
            throw e;
        } finally {
            ts.rollback();
            bm.wExitScope();
        }
    });
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) ITransactionScope(org.whole.lang.bindings.ITransactionScope) RollbackException(org.whole.lang.lifecycle.RollbackException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 15 with ModelTransactionCommand

use of org.whole.lang.ui.commands.ModelTransactionCommand in project whole by wholeplatform.

the class ActionCallRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException {
    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));
    }
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    final CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    final ModelTransactionCommand mtc = new ModelTransactionCommand(model, label);
    pm.beginTask("executing action", 90, IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.actionCall(bm);
        mtc.commit();
        if (analyzing) {
            E4Utils.revealPart(context, RESULTS_PART_ID);
            IEventBroker eventBroker = context.get(IEventBroker.class);
            eventBroker.post(IE4UIConstants.TOPIC_UPDATE_RESULTS, bm.getResult());
        } else if (mtc.canUndo()) {
            context.get(UISynchronize.class).syncExec(new Runnable() {

                public void run() {
                    commandStack.execute(mtc);
                }
            });
        }
    } catch (OperationCanceledException e) {
        mtc.rollbackIfNeeded();
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        pm.endTask();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) IEntity(org.whole.lang.model.IEntity) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker)

Aggregations

ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)19 CommandStack (org.eclipse.gef.commands.CommandStack)12 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)11 IEntity (org.whole.lang.model.IEntity)9 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)5 Execute (org.eclipse.e4.core.di.annotations.Execute)5 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)5 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ITransactionScope (org.whole.lang.bindings.ITransactionScope)4 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)3 Shell (org.eclipse.swt.widgets.Shell)3 Control (org.eclipse.swt.widgets.Control)2 RollbackException (org.whole.lang.lifecycle.RollbackException)2 ActionEvent (org.eclipse.draw2d.ActionEvent)1 ActionListener (org.eclipse.draw2d.ActionListener)1 IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)1 IType (org.eclipse.jdt.core.IType)1 OpenTypeSelectionDialog (org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog)1 FilteredItemsSelectionDialog (org.eclipse.ui.dialogs.FilteredItemsSelectionDialog)1 RootFragment (org.whole.lang.commons.model.RootFragment)1