Search in sources :

Example 51 with IEntityPartViewer

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

the class RedoHandler method execute.

@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    viewer.getEditDomain().getCommandStack().redo();
}
Also used : IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 52 with IEntityPartViewer

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

the class UndoHandler method execute.

@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    viewer.getEditDomain().getCommandStack().undo();
}
Also used : IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 53 with IEntityPartViewer

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

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

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

the class IActionRedirection method getActionRedirection.

public static IActionRedirection getActionRedirection(IBindingManager bm) {
    if (!bm.wIsSet("focusEntity"))
        return NullActionRedirection.instance();
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    IEntityPart entityPart = viewer.getEditPartRegistry().get(bm.wGet("focusEntity"));
    if (entityPart == null)
        return NullActionRedirection.instance();
    IActionRedirection actionRedirection = (IActionRedirection) entityPart.getAdapter(IActionRedirection.class);
    return actionRedirection != null ? actionRedirection : NullActionRedirection.instance();
}
Also used : IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

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