Search in sources :

Example 16 with ModelTransactionCommand

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

the class InterpretModelRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("self"), label);
    pm.beginTask("Interpreting...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.interpretModel(bm);
        mtc.commit();
        if (mtc.canUndo())
            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) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 17 with ModelTransactionCommand

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

the class MergeResourcesAction method run.

@Override
public void run() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntity focusEntity = bm.wGet("focusEntity");
    Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
    IEntity result = performWorkspaceResourceSelection(shell, focusEntity);
    if (!EntityUtils.isNull(result)) {
        ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
        try {
            mtc.setLabel("add Artifacts");
            mtc.begin();
            EntityUtils.merge(focusEntity, result, createEntityComparator(), false);
            mtc.commit();
            if (mtc.canUndo()) {
                IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
                CommandStack commandStack = viewer.getEditDomain().getCommandStack();
                commandStack.execute(mtc);
            }
        } catch (RuntimeException e) {
            mtc.rollbackIfNeeded();
            throw e;
        }
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) CommandStack(org.eclipse.gef.commands.CommandStack) Shell(org.eclipse.swt.widgets.Shell) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 18 with ModelTransactionCommand

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

the class ReplaceWithClassNameAction method run.

@Override
public void run() {
    Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
    FilteredItemsSelectionDialog dialog = new OpenTypeSelectionDialog(shell, true, PlatformUI.getWorkbench().getProgressService(), null, IJavaSearchConstants.TYPE);
    dialog.setTitle("Select a class");
    dialog.setMessage("Choose a class or a compilation unit");
    dialog.setInitialPattern(StringUtils.toSimpleName(className));
    if (dialog.open() != IDialogConstants.OK_ID)
        return;
    IType primaryType = (IType) dialog.getResult()[0];
    if (primaryType == null)
        return;
    className = primaryType.getFullyQualifiedName();
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntity focusEntity = bm.wGet("focusEntity");
    IEntity replacement = GenericEntityFactory.instance.create(ed, className);
    ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
    try {
        mtc.setLabel("replace with class name");
        mtc.begin();
        focusEntity.wGetParent().wSet(focusEntity, replacement);
        mtc.commit();
        if (mtc.canUndo()) {
            IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
            CommandStack commandStack = viewer.getEditDomain().getCommandStack();
            commandStack.execute(mtc);
        }
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    }
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) CommandStack(org.eclipse.gef.commands.CommandStack) Shell(org.eclipse.swt.widgets.Shell) IEntity(org.whole.lang.model.IEntity) OpenTypeSelectionDialog(org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog) FilteredItemsSelectionDialog(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog) IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IType(org.eclipse.jdt.core.IType)

Example 19 with ModelTransactionCommand

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

the class EnvironmentPart method createFigure.

protected IFigure createFigure() {
    Environment entity = getModelEntity();
    return new EnvironmentFigure(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            Environment entity = getModelEntity();
            ModelTransactionCommand command = new ModelTransactionCommand(entity);
            try {
                command.begin();
                IBindingManager bm = entity.getBindingManager().getValue();
                if (Matcher.match(EnvironmentEntityDescriptorEnum.Bindings, entity.getBindings()))
                    entity.setBindings((BindingsModel) BindingManagerFactory.instance.createFlatScopedBindingsModel(bm));
                else
                    entity.setBindings((BindingsModel) BindingManagerFactory.instance.createFlatBindingsModel(bm));
                command.commit();
                getViewer().getEditDomain().getCommandStack().execute(command);
            } catch (Exception e) {
                command.rollbackIfNeeded();
            }
        }
    }, Matcher.matchImpl(EnvironmentEntityDescriptorEnum.ScopedBindings, entity.getBindings()));
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) ActionListener(org.eclipse.draw2d.ActionListener) ActionEvent(org.eclipse.draw2d.ActionEvent) IBindingManager(org.whole.lang.bindings.IBindingManager) Environment(org.whole.lang.environment.model.Environment) EnvironmentFigure(org.whole.lang.environment.ui.figures.EnvironmentFigure)

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