Skip to content

Commit

Permalink
Bug 579418 - Model Spy > Form/List/XMI tabs > selection state lost when
Browse files Browse the repository at this point in the history
switching.

Change-Id: I7c227e6513a12e11600c2d856ebfe52910a9dfcf
Signed-off-by: Niraj Modi <[email protected]>
  • Loading branch information
niraj-modi committed Mar 25, 2022
1 parent 87a58fe commit f4c9d3b
Showing 1 changed file with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2018 BestSolution.at and others.
* Copyright (c) 2010, 2022 BestSolution.at and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -289,6 +289,7 @@ public class ModelEditor implements IGotoObject {
public static final int TAB_FORM = 0;
public static final int TAB_XMI = 1;
public static final int TAB_LIST = 2;
final String key = "org.eclipse.e4.tools.active-object-viewer"; //$NON-NLS-1$



Expand Down Expand Up @@ -486,22 +487,18 @@ void postCreate(Composite composite) {
public void widgetSelected(SelectionEvent e) {
if (editorTabFolder.getSelectionIndex() == getTabIndex(tabItemXmi)) {
emfDocumentProvider.updateFromEMF();
gotoEObject(TAB_XMI, null);
}
}
});

editorTabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// When the list tab is visible, register the IViewEObjects
// interface
// This allows external commands to interact with the view.
// Eventually, all 3 tabs, or even the ModelEditor itself, could
// implement the interface.
final String key = "org.eclipse.e4.tools.active-object-viewer"; //$NON-NLS-1$
if (listTab != null && editorTabFolder.getSelectionIndex() == getTabIndex(listTab.getTabItem())) {
else if (listTab != null && editorTabFolder.getSelectionIndex() == getTabIndex(listTab.getTabItem())) {
gotoEObject(TAB_LIST, null);
app.getContext().set(key, listTab);
} else {
gotoEObject(TAB_FORM, null);
app.getContext().set(key, null);
}
}
Expand Down Expand Up @@ -2091,9 +2088,43 @@ private String getObjectNameForCommand(Object data) {

@Override
public void gotoEObject(int targetHint, EObject object) {
// Try to find current selection if any
if (object == null) {
// do nothing
} else {
switch (targetHint) {
case TAB_FORM:
if (app.getContext().get(key) == listTab) {
Iterator<EObject> it = listTab.getSelectedEObjects().iterator();
if (it.hasNext()) {
object = it.next();
}
}
break;
case TAB_XMI:
if (app.getContext().get(key) == listTab) {
Iterator<EObject> it = listTab.getSelectedEObjects().iterator();
if (it.hasNext()) {
object = it.next();
}
} else if (app.getContext().get(key) == null) {
final Object parent = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (parent instanceof EObject) {
object = (EObject) parent;
}
}
break;
case TAB_LIST:
if (app.getContext().get(key) == null) {
final Object parent = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (parent instanceof EObject) {
object = (EObject) parent;
}
}
break;
default:
break;
}
}
if (object != null) {
switch (targetHint) {
case TAB_FORM:
// make sure tree node has been instantiated
Expand Down

0 comments on commit f4c9d3b

Please sign in to comment.