[517503] Fix command stack not working in some contexts
Doing a command in aird editor's models block that does not provide an
affected object now update the command stack correctly.
Bug: 517503
Change-Id: I250c08f0f2763e99c72c9f5497d4c17fea917f39
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
index 739a084..9adb3bf 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
@@ -105,6 +105,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchSite;
@@ -479,7 +480,15 @@
// Try to select the last affected objects.
Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();
if (mostRecentCommand != null) {
- setSelectionToViewer(mostRecentCommand.getAffectedObjects());
+ Collection<?> affectedObjects = mostRecentCommand.getAffectedObjects();
+ if (!affectedObjects.isEmpty()) {
+ setSelectionToViewer(affectedObjects);
+ } else {
+ Tree tree = treeViewer.getTree();
+ if (!tree.isDisposed() && tree.getItems().length > 0 && !tree.getItem(0).isDisposed()) {
+ setSelectionToViewer(Lists.newArrayList(tree.getItem(0).getData()));
+ }
+ }
actionBars.updateActionBars();
}
}