Search in sources :

Example 11 with ESelectionService

use of org.eclipse.e4.ui.workbench.modeling.ESelectionService 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 12 with ESelectionService

use of org.eclipse.e4.ui.workbench.modeling.ESelectionService in project whole by wholeplatform.

the class MergeResourcesAction method update.

@Override
public void update() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    if (selectionService.getSelection() instanceof IBindingManager) {
        IBindingManager bm = (IBindingManager) selectionService.getSelection();
        setEnabled(HandlersBehavior.isValidFocusEntityPart(bm));
    } else
        setEnabled(false);
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService)

Example 13 with ESelectionService

use of org.eclipse.e4.ui.workbench.modeling.ESelectionService 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 14 with ESelectionService

use of org.eclipse.e4.ui.workbench.modeling.ESelectionService in project whole by wholeplatform.

the class ReplaceWithResourceAction method update.

@Override
public void update() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    if (selectionService.getSelection() instanceof IBindingManager) {
        IBindingManager bm = (IBindingManager) selectionService.getSelection();
        setEnabled(HandlersBehavior.isValidFocusEntityPart(bm));
    } else
        setEnabled(false);
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService)

Aggregations

ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)14 IBindingManager (org.whole.lang.bindings.IBindingManager)13 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)7 IEntity (org.whole.lang.model.IEntity)6 Shell (org.eclipse.swt.widgets.Shell)4 CommandStack (org.eclipse.gef.commands.CommandStack)3 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)3 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Named (javax.inject.Named)1 Bookmark (name.abuchen.portfolio.model.Bookmark)1 SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)1 DesktopAPI (name.abuchen.portfolio.ui.util.DesktopAPI)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)1 IServiceConstants (org.eclipse.e4.ui.services.IServiceConstants)1