Commit e332be9b authored by Hernan Ponce de Leon's avatar Hernan Ponce de Leon
Browse files

Merge branch '3084' into 'master'

3084

See merge request !23
parents 1cdf74d2 6d56c78f
AdvancedTreeViewerEditorBase.java 34e37880adc67c3ee45bcb74ed7572d3360bcc0f GREEN
AllocationDiagramEditorBase.java fa544546f73eea1150d90b7257b0e6bce82c288c GREEN
CommonDiagramEditorBase.java f0a243caa6fc7c66434ffb4028628c6d6aa657fd GREEN
CommonDiagramEditorBase.java 284c1fa70771c0f4a9393f6911f44561ea0c3a44 GREEN
ConstraintBasedProcessEditor.java 06891ab7f5c5eb7549e8aee0d3760ea5a534d99d GREEN
ConstraintBasedProcessEditorHelper.java 651e909b90fe1b777206c35ca91a36630365435e GREEN
DiagramEditorBase.java 09663ce095074d1a8eef086284eea0a7776e0431 GREEN
......
......@@ -15,6 +15,7 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor;
import static org.conqat.ide.commons.ui.selection.SelectionUtils.checkAndPickFirstSafe;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_ENABLED;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_ORIGIN;
import static org.eclipse.gef.SnapToGrid.PROPERTY_GRID_SPACING;
......@@ -38,7 +39,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.conqat.ide.commons.ui.selection.SelectionUtils;
import org.eclipse.core.runtime.Platform;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
......@@ -107,6 +107,7 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
import org.fortiss.tooling.kernel.ui.service.IActionService;
import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
import org.fortiss.tooling.kernel.ui.service.IEditPartFactoryService;
import org.fortiss.tooling.kernel.ui.util.SelectionUtils;
/**
* <p>
......@@ -201,10 +202,22 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
/** Selection listener used to update selection actions. */
private final ISelectionListener selectionListener = new ISelectionListener() {
/** Flag to avoid infinite recursion. */
private boolean inSelectionListener = false;
/** {@inheritDoc} */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
EditPart ep = SelectionUtils.checkAndPickFirstSafe(selection, EditPart.class);
if(inSelectionListener) {
return;
}
inSelectionListener = true;
List<EObject> eObjects = getEObjectElements(selection);
// Synchronize selection of model element navigator
SelectionUtils.setSelection(eObjects, true, false);
EditPart ep = checkAndPickFirstSafe(selection, EditPart.class);
if(ep != null) {
Control control = ep.getViewer().getControl();
Object model = ep.getModel();
......@@ -224,6 +237,7 @@ abstract class CommonDiagramEditorBase<T extends EObject> extends GEFEditorBase<
control.setToolTipText(hint);
}
updateActions(selectionActions);
inSelectionListener = false;
}
};
......
......@@ -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 GREEN
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 GREEN
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);
}
}
......@@ -9,4 +9,4 @@ MarkerViewPart.java cbb650271b6877af205421b7cb11f930440a7ef9 GREEN
NavigatorNewMenu.java a35e391960d1dacbe7f77982e53e1891e9382d5a GREEN
NavigatorTreeContentProvider.java 1bdefa28c5e2c2619cabbcd1946269a52db34e6c GREEN
NavigatorTreeContentSorter.java 76fc94e441ac1a8f2c5ae573f0e2b1e6fa73c31a GREEN
NavigatorViewPart.java 76a5f5c0a8c891dfcd4aa98d9d3459e4b7af9b17 GREEN
NavigatorViewPart.java 1fd73a2d717304556bd86fbbb0f98aad4e7d354f GREEN
......@@ -70,6 +70,7 @@ import org.fortiss.tooling.kernel.ui.service.IActionService;
import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
import org.fortiss.tooling.kernel.ui.service.INavigatorService;
import org.fortiss.tooling.kernel.ui.util.PropertiesConstantUtils;
import org.fortiss.tooling.kernel.ui.util.SelectionUtils;
/**
* {@link ViewPart} of the model navigator provided by the tooling kernel.
......@@ -300,6 +301,9 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe
@Override
public void selectionChanged(SelectionChangedEvent event) {
IActionService.getInstance().refresh();
// Set selection of active editor
SelectionUtils.setSelection(getSelectedModelElementList(), false, true);
// fire upon viewer selection change
firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
}
......
......@@ -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 GREEN
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 d685e3707dfc6ca2fdc10be3bb3a2bc031b7cfe4 GREEN
SelectionUtils.java 136096917a2357678c54339543a14fc3a63edf6d GREEN
TutorialUIServiceUtils.java 416970bb9bd305acee064e2ac199df39cc98b475 GREEN
UndoRedoImpl.java f218500875bda0ef52f4cc2ccdf452825e6751f7 GREEN
WidgetsFactory.java e92285bee3189ecf1a3fbaede3c4ffb237fc81ed GREEN
......@@ -15,6 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.util;
import static org.conqat.ide.commons.ui.ui.WorkbenchUtils.getActiveEditor;
import java.util.ArrayList;
import java.util.List;
......@@ -25,9 +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.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.fortiss.tooling.kernel.ui.service.INavigatorService;
/**
* Utility methods for dealing with selections.
......@@ -116,24 +116,40 @@ 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) {
IWorkbenchWindow activeWorkbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(activeWorkbenchWindow == null) {
return;
setSelection(eObjects, true, true);
}
/**
* 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.
* @param updateNavigator
* Flag whether to update the model navigator
* @param updateActiveEditor
* Flag whether to update the currently active editor.
*/
public static void setSelection(List<EObject> eObjects, boolean updateNavigator,
boolean updateActiveEditor) {
ISelection selection = new StructuredSelection(eObjects);
if(updateNavigator) {
INavigatorService ns = INavigatorService.getInstance();
ns.setCurrentSelection(selection);
}
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if(activePage == null) {
if(!updateActiveEditor) {
return;
}
IEditorPart activeEditor = activePage.getActiveEditor();
IEditorPart activeEditor = getActiveEditor();
if(activeEditor == null) {
return;
}
......@@ -148,6 +164,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