Search in sources :

Example 1 with ModelTransactionCommand

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

the class ReplaceWithResourceAction method run.

@Override
public void run() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntity focusEntity = bm.wGet("focusEntity");
    ResourceKind resourceKind = getResourceKind(focusEntity);
    Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
    boolean selectionPerformed = false;
    switch(resourceKind) {
        case WORKSPACE:
            selectionPerformed = performWorkspaceResourceSelection(shell, focusEntity);
            break;
        case CLASSPATH:
            selectionPerformed = performClasspathResourceSelection(shell, focusEntity);
            break;
        case FILE_SYSTEM:
        case URL:
            selectionPerformed = performFilesystemSelection(shell, focusEntity, resourceKind == ResourceKind.URL);
            break;
    }
    if (!selectionPerformed)
        return;
    IEntity replacement = GenericEntityFactory.instance.create(ed, path);
    ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
    try {
        mtc.setLabel("replace with class name");
        mtc.begin();
        performReplace(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) IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 2 with ModelTransactionCommand

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

the class HistoryCommandStack method toModelTransactionCommand.

protected ModelTransactionCommand toModelTransactionCommand(Command command) {
    ModelTransactionCommand mtCommand = new ModelTransactionCommand();
    try {
        mtCommand.setModel(getModel());
        mtCommand.setLabel(command.getLabel());
        mtCommand.begin();
        command.execute();
        mtCommand.commit();
        return mtCommand;
    } catch (Exception e) {
        mtCommand.rollbackIfNeeded();
    }
    return mtCommand;
}
Also used : ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand)

Example 3 with ModelTransactionCommand

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

the class E4FindReplaceDialog method doReplaceAll.

protected void doReplaceAll() {
    IEntity self = selection.wGet("self");
    iterator.reset(self);
    if (!findNext(true))
        return;
    boolean state = enableSelectionTracking(false);
    IEntity replacement = replaceViewer.getEntityContents();
    IEntity lastReplaced = null;
    ModelTransactionCommand command = new ModelTransactionCommand();
    command.setModel(getFoundEntity());
    try {
        command.begin();
        do {
            lastReplaced = EntityUtils.clone(replacement);
            Matcher.substitute(lastReplaced, bindings, false);
            iterator.set(lastReplaced);
        } while (findNext(true));
        command.commit();
    } catch (Exception e) {
        command.rollbackIfNeeded();
    } finally {
        clearFoundEntity();
    }
    IEntityPartViewer viewer = (IEntityPartViewer) selection.wGetValue("viewer");
    viewer.getCommandStack().execute(command);
    Control control = viewer.getControl();
    if (lastReplaced != null) {
        final IEntity revealEntity = lastReplaced;
        control.getDisplay().asyncExec(new Runnable() {

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

Example 4 with ModelTransactionCommand

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

the class FragmentModelTransactionHandler method execute.

@Execute
public void execute(@Named(FRAGMENT_XWL_PARAMETER_ID) String fragmentXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, IEntityPartViewer viewer) throws Exception {
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(fragmentXwl, predicateXwl, bm);
        mtc.setLabel(getLabel(bm));
        mtc.begin();
        run(bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } 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) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 5 with ModelTransactionCommand

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

the class NormalizeModelRunnable 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("Normalizing...", IOperationProgressMonitor.TOTAL_WORK);
    try {
        mtc.begin();
        HandlersBehavior.normalizeModel(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)

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