Search in sources :

Example 1 with ESelectionService

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

the class ReplaceWithClassNameAction method update.

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

Example 2 with ESelectionService

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

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

the class AbstractSelectionConstrainedVisibleWhen method evaluate.

@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
    ESelectionService selectionService = (ESelectionService) context.getVariable(ESelectionService.class.getName());
    Object selection = selectionService.getSelection();
    if (selection instanceof IBindingManager) {
        if (isVisible((IBindingManager) selection))
            return EvaluationResult.TRUE;
    }
    return EvaluationResult.FALSE;
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService)

Example 4 with ESelectionService

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

the class ActivateToolAction method update.

@Override
public void update() {
    setEnabled(false);
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    if (selectionService.getSelection() instanceof IBindingManager) {
        IBindingManager bm = (IBindingManager) selectionService.getSelection();
        if (bm.wIsSet("viewer"))
            setEnabled(!tool.isActive((IEntityPartViewer) bm.wGetValue("viewer")));
    }
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

Example 5 with ESelectionService

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

the class ActivateToolAction method run.

@Override
public void run() {
    ESelectionService selectionService = getContext().get(ESelectionService.class);
    IBindingManager bm = (IBindingManager) selectionService.getSelection();
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    boolean clearCaret = Tools.TEXTUAL != tool && Tools.TEXTUAL.isActive(viewer);
    if (tool.ensureActive(viewer) && clearCaret) {
        IEntity focusEntity = bm.wGet("focusEntity");
        IEntityPart focusPart = viewer.getEditPartRegistry().get(focusEntity);
        if (focusPart instanceof ITextualEntityPart) {
            ITextualEntityPart textualPart = (ITextualEntityPart) focusPart;
            textualPart.setCaretVisible(false);
            viewer.setSelection(new StructuredSelection(textualPart));
        }
    }
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

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