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

- Undo last commit to NavigatorViewPart (old (partial) fix for #1491)

- Instead, ensure that DiagramEditorBase has the focus when a child edit part is added or removed
- This works around #2207 and also the same part of #1491 as with the old workaround
- Summing up:
   - Undo/redo of operations on the model only works if either the NavigatorViewPart or a DiagramEditorBase has the focus
   - This makes sense if the active view provides editable items itself (e.g., the GenericAnnotationView) *and* provides undo/redo (currently not the case for GenericAnnotationView).
   - For other (read-only) view (e.g., Model Markers), this behavior is confusing for the user
refs 2207,1491
parent dc617f36
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.gef.EditPartListener;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.MouseWheelHandler;
......@@ -96,6 +97,7 @@ import org.fortiss.tooling.kernel.model.ILibraryElementReference;
import org.fortiss.tooling.kernel.service.ILibraryService;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase;
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;
......@@ -246,6 +248,36 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple
(editedObject instanceof ILibraryElementReference)) {
((ScalableRootEditPart)viewer.getRootEditPart()).deactivate();
}
// Ensure that the editor gets the focus when a child edit part is added or removed in order
// to fix undo/redo (at least as long as either a DiagramEditorBase or the NavigatorViewPart
// are used to manipulate the model)
viewer.getRootEditPart().getContents().addEditPartListener(new EditPartListener() {
@Override
public void selectedStateChanged(EditPart editpart) {
// Nothing
}
@Override
public void removingChild(EditPart child, int index) {
viewer.getControl().setFocus();
}
@Override
public void partDeactivated(EditPart editpart) {
// Nothing
}
@Override
public void partActivated(EditPart editpart) {
// Nothing
}
@Override
public void childAdded(EditPart child, int index) {
viewer.getControl().setFocus();
}
});
}
/**
......@@ -415,6 +447,7 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple
((EObjectActionBase)action).refresh(element);
}
}
IActionService.INSTANCE.refresh();
}
/** {@inheritDoc} */
......
......@@ -37,8 +37,6 @@ 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;
......@@ -106,9 +104,6 @@ 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
......@@ -119,28 +114,6 @@ 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