Search in sources :

Example 31 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class CutHandler method execute.

@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && ClipboardUtils.hasTextSeletion((IEntityPartViewer) bm.wGetValue("viewer"))) {
        HandlersBehavior.copy(bm);
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity focusEntity = bm.wGet("focusEntity");
        ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
        Command command = focusPart.getCommand(TextualRequest.createDeleteRequest());
        command.setLabel(getLabel(bm) + " text");
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        commandStack.execute(command);
        return;
    }
    super.execute(bm);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Command(org.eclipse.gef.commands.Command) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 32 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer 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 33 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer 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 34 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class HandlersBehavior method selectAll.

public static void selectAll(IBindingManager bm) {
    E4Utils.syncExec(bm, () -> {
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity entityContents = viewer.getEntityContents();
        IEntityPart contents = viewer.getEditPartRegistry().get(entityContents);
        viewer.setSelection(new StructuredSelection(contents));
    });
}
Also used : IEntity(org.whole.lang.model.IEntity) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 35 with IEntityPartViewer

use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.

the class HandlersBehavior method pasteAs.

public static void pasteAs(IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    IEntity focusEntity = bm.wGet("focusEntity");
    RunnableWithResult<IImportAsModelDialog> dialogRunnable = RunnableWithResult.create(() -> {
        Shell shell = viewer.getControl().getShell();
        IEclipseContext eclipseContext = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
        IImportAsModelDialog dialog = eclipseContext.get(IImportAsModelDialogFactory.class).createImplicitElementImportAsModelDialog(shell, "Paste As", EntityUtils.isComposite(focusEntity));
        dialog.show();
        return dialog;
    });
    IImportAsModelDialog dialog = E4Utils.syncExec(bm, dialogRunnable).get();
    if (!dialog.isConfirmed())
        return;
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    RunnableWithResult<IEntity> entityRunnable = RunnableWithResult.create(() -> {
        try {
            return ClipboardUtils.parseClipboardContents(persistenceKit, bm);
        } catch (Exception e) {
            IEclipseContext context = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
            E4Utils.reportError(context, "Write Model errors", "Parse failed using the selected persistence.", e);
            return CommonsEntityFactory.instance.createResolver();
        }
    });
    IEntity entity = E4Utils.syncExec(bm, entityRunnable).get();
    boolean adding = dialog.isForceAdding();
    IEntityIterator<IEntity> iterator;
    if (bm.wIsSet("syntheticRoot")) {
        IEntity syntheticRoot = bm.wGet("syntheticRoot");
        adding |= syntheticRoot.wSize() > 1;
        if (adding && !EntityUtils.isComposite(focusEntity)) {
            adding = false;
            iterator = IteratorFactory.selfIterator();
        } else
            iterator = IteratorFactory.childReverseIterator();
        iterator.reset(syntheticRoot);
    } else {
        iterator = IteratorFactory.selfIterator();
        iterator.reset(entity);
    }
    EntityDescriptor<?> stage = dialog.getStage();
    while (iterator.hasNext()) {
        IEntity clipboardEntity = EntityUtils.clone(iterator.next());
        if (!adding) {
            if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isReplaceable(focusEntity, clipboardEntity))
                clipboardEntity = CommonsEntityFactory.instance.create(stage, clipboardEntity);
            IEntity parent = focusEntity.wGetParent();
            parent.wSet(focusEntity, clipboardEntity);
            break;
        } else {
            if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isAddable(focusEntity, clipboardEntity))
                clipboardEntity = CommonsEntityFactory.instance.create(stage, clipboardEntity);
            if (bm.wIsSet("hilightPosition"))
                focusEntity.wAdd(bm.wIntValue("hilightPosition"), clipboardEntity);
            else
                focusEntity.wAdd(clipboardEntity);
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Aggregations

IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)55 IEntity (org.whole.lang.model.IEntity)29 IBindingManager (org.whole.lang.bindings.IBindingManager)13 CommandStack (org.eclipse.gef.commands.CommandStack)12 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)11 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)8 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)8 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)7 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)6 Execute (org.eclipse.e4.core.di.annotations.Execute)6 Shell (org.eclipse.swt.widgets.Shell)5 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)5 ITransactionScope (org.whole.lang.bindings.ITransactionScope)3 IEventBroker (org.eclipse.e4.core.services.events.IEventBroker)2 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)2 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)2 Command (org.eclipse.gef.commands.Command)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Control (org.eclipse.swt.widgets.Control)2