Skip to content
Snippets Groups Projects
Commit a2750351 authored by Simon Barner's avatar Simon Barner
Browse files

- Redo partial workaround for #1491 since it is still required and also fixes / works around 2203

refs 1491,2203
parent e24fba0f
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,8 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
......@@ -104,6 +106,9 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe
/** Dialog setting ID for the link with editor action flag. */
private static final String LINK_WITH_EDITOR_FLAG = "navigatorSettingLinkWithEditor";
/** Element used to ensure that the selection of the {@link NavigatorViewPart} is not empty. */
private EObject backupElementToBeSelected;
/** Stores the UI update job. */
private final UIJob updateUI = new UIJob("Update Model Navigator") {
@Override
......@@ -114,6 +119,28 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe
IActionService.INSTANCE.refresh();
viewer.refresh();
// Ensure that the selection of the {@link NavigatorViewPart} is not empty. Otherwise
// undo/redo (and also other global commands) is not enabled when model elements are
// added directly using the context menu of the model navigator.
ISelection selection = viewer.getSelection();
if(selection instanceof TreeSelection && !selection.isEmpty()) {
Object firstSelectedElement = ((TreeSelection)selection).getFirstElement();
if(firstSelectedElement instanceof EObject) {
// Preserve container of current element. This is required to determine a valid
// model element in case the next operation is to delete the currently selected
// element
backupElementToBeSelected = ((EObject)firstSelectedElement).eContainer();
}
} else if(backupElementToBeSelected != null) {
// Selection would be empty. Use backup element to force selection to the container
// of the element that has been selected last.
viewer.setSelection(new TreeSelection(new TreePath(
new Object[] {backupElementToBeSelected})));
backupElementToBeSelected = null;
}
firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
return Status.OK_STATUS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment