Commit 2340c41e authored by Simon Barner's avatar Simon Barner
Browse files

Enable "select all elements" (CTRL+A) in model navigator

* If an element is already selected in the model navigator, CTRL+A
  selects all of its siblings.* This also applies for FileProjects.
* Realization
  * Add INavigatorService::setCurrentSelection()
  * SelectionUtils.setSelection() now synchronizes the selection in the
    currently active (diagram) editor and the model navigator

Issue-Ref: 3084
Issue-Url: https://af3-developer.fortiss.org/issues/3084

Signed-off-by: Simon Barner's avatarSimon Barner <barner@fortiss.org>
parent aae82e60
......@@ -7,6 +7,6 @@ EditPartFactoryService.java e23ecf38cac145540d5dd30d2be820794a45397e GREEN
MarkerService.java 0c24285bfde05aea3ac27a31099885a18bf85f14 GREEN
ModelEditorBindingService.java ce63dd6ed8c244fe13f1ca6e071e14f7f8b09cd7 GREEN
ModelElementHandlerService.java 1eb55dcbe656377f28055713fec83fb6ff0137ab GREEN
NavigatorService.java e18ba261ef21a39065371e15ce4f03e980b23f68 GREEN
NavigatorService.java aefe0c434c541e9eab354f13bbb31b8513e46b3c YELLOW
ToolingKernelUIInternal.java 38903445a9084b7908716a00f41621dfb3126fca GREEN
TutorialUIService.java c2e5dd68ac985dbbcc337b6cb51b6342f1cca78f GREEN
......@@ -31,6 +31,7 @@ import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.ISaveablesLifecycleListener;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.Saveable;
......@@ -133,10 +134,21 @@ public class NavigatorService implements INavigatorService, IPersistencyServiceL
return navigatorViewPart;
}
/** Returns the {@link #navigatorViewPart}'s {@link ISelectionProvider}. */
private ISelectionProvider getSelectionProvider() {
return navigatorViewPart.getSite().getSelectionProvider();
}
/** {@inheritDoc} */
@Override
public ISelection getCurrentSelection() {
return navigatorViewPart.getSite().getSelectionProvider().getSelection();
return getSelectionProvider().getSelection();
}
/** {@inheritDoc} */
@Override
public void setCurrentSelection(ISelection selection) {
getSelectionProvider().setSelection(selection);
}
/** {@inheritDoc} */
......
......@@ -4,5 +4,5 @@ DeleteAction.java 788b5df59525e069365c4f272b39e0892133e9b9 GREEN
PasteAction.java f834f26660a664f138c19d82ace7b17ecc18603f GREEN
RedoAction.java d91086533289a4175e7f5ee949b31a0edc86672a GREEN
RenameAction.java f469d30cab3f692e2e0112c8f89c622ee0fa8db6 GREEN
SelectAllAction.java f9f0267bf2471ba2350823a38d9f4de642a33747 GREEN
SelectAllAction.java 023c7a94f30a1c9ba0c846c7635a0d2de98dc868 YELLOW
UndoAction.java 123dc8105fcbe8033a4680a1634aea2699045e62 GREEN
......@@ -15,12 +15,22 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal.actions;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.setSelection;
import java.util.List;
import org.conqat.ide.commons.ui.ui.WorkbenchUtils;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionFactory;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
import org.fortiss.tooling.kernel.ui.internal.views.NavigatorViewPart;
/**
* Action for selecting all elements in the currently active editor. the currently selected model
......@@ -39,9 +49,30 @@ public class SelectAllAction extends EObjectActionBase<EObject> {
/** {@inheritDoc} */
@Override
public void run() {
EObject target = getTarget();
if(target != null) {
setSelection(target.eContents());
if(target == null) {
return;
}
IWorkbenchPart activePart = WorkbenchUtils.getActiveWorkbenchPage().getActivePart();
List<EObject> objs = emptyList();
if(activePart instanceof ExtendableMultiPageEditor) {
// If an editor is active editor, select all children of the currently edited object
objs = target.eContents();
} else if(activePart instanceof NavigatorViewPart) {
// If the model navigator is active ...
if(target.eContainer() != null) {
// ... select all siblings of the currently selected object,
objs = target.eContainer().eContents();
} else {
// ... or the root elements of all projects in case the root element of a
// project is selected
List<ITopLevelElement> topLevelElems =
IPersistencyService.getInstance().getTopLevelElements();
objs = topLevelElems.stream().map(t -> t.getRootModelElement()).collect(toList());
}
}
setSelection(objs);
}
}
......@@ -6,5 +6,5 @@ IEditPartFactoryService.java c448bff63fb81f57037c9f1dc5319859c12d0c4d GREEN
IMarkerService.java a415c01cc184c0afc25aad341ebe663987484e06 GREEN
IModelEditorBindingService.java e000fb7faf558d1201c5c26e449e0019b4ec24b0 GREEN
IModelElementHandlerService.java c04c2876ccb8b3f8597c8e443f9c7c3db0945430 GREEN
INavigatorService.java 3d22db9a182c3e5a115471654c9b370f3b4f007c GREEN
INavigatorService.java 8d2ffeb6f075d3abea904b84d8a40090d97837fd YELLOW
ITutorialUIService.java 72707c60c3d23d8ffc5c579cb9b022bb614eb094 GREEN
......@@ -49,6 +49,9 @@ public interface INavigatorService {
/** Returns the current navigator selection. */
ISelection getCurrentSelection();
/** Programmatically sets the current navigator selection. */
void setCurrentSelection(ISelection selection);
/**
* Returns whether the given {@link ContextMenuContextProvider} is equal to
* the navigator view part. An {@link IContextMenuContributor} may use this
......
......@@ -7,7 +7,7 @@ EObjectSelectionUtils.java 928280b5dd3bb634debc1ac3be9f15b4e45f2683 GREEN
KernelUIUtils.java b038a28a44e17e5bca4d71f5dee70ee92e5324b9 GREEN
ObservableUtils.java 2ffced494a86bd7e8f8eb8882aec38b06f0f2818 GREEN
PropertiesConstantUtils.java 59b1a1e4d594bb98db3aa396f2ff6474ba405920 GREEN
SelectionUtils.java 5ed163fa2111a8b5a5769f276def37e95369b980 YELLOW
SelectionUtils.java 3d6a80c9c9c62db53515a1f885c70f6fc3296f54 YELLOW
TutorialUIServiceUtils.java 416970bb9bd305acee064e2ac199df39cc98b475 GREEN
UndoRedoImpl.java f218500875bda0ef52f4cc2ccdf452825e6751f7 GREEN
WidgetsFactory.java e92285bee3189ecf1a3fbaede3c4ffb237fc81ed GREEN
......@@ -27,6 +27,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.fortiss.tooling.kernel.ui.service.INavigatorService;
/**
* Utility methods for dealing with selections.
......@@ -115,12 +116,17 @@ public class SelectionUtils {
}
/**
* Programmatically sets the objects to be selected in the currently active editor.
* Programmatically sets the objects to be selected in the currently active editor (NOP if there
* is none) and the model navigator.
*
* @param eObjects
* {@link EObject}s to be selected.
*/
public static void setSelection(List<EObject> eObjects) {
ISelection selection = new StructuredSelection(eObjects);
INavigatorService ns = INavigatorService.getInstance();
ns.setCurrentSelection(selection);
IEditorPart activeEditor = getActiveEditor();
if(activeEditor == null) {
return;
......@@ -136,6 +142,6 @@ public class SelectionUtils {
return;
}
selectionProvider.setSelection(new StructuredSelection(eObjects));
selectionProvider.setSelection(selection);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment