summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCurtis Windatt2013-05-07 16:08:37 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-05-13 14:36:52 (EDT)
commitd7bf7e543636f8f570f7e1e4daedcbd9fed8645e (patch)
treedd8d853d6773783edc0d1f9bc681e17a46e7880f
parentf66c50d8e498d570d827960c675e1062becb9e5b (diff)
downloadeclipse.platform.ui-d7bf7e543636f8f570f7e1e4daedcbd9fed8645e.zip
eclipse.platform.ui-d7bf7e543636f8f570f7e1e4daedcbd9fed8645e.tar.gz
eclipse.platform.ui-d7bf7e543636f8f570f7e1e4daedcbd9fed8645e.tar.bz2
Bug 407377 - CCE when trying to close minimized view via context menuI20130513-2000refs/changes/96/12596/4
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/TrimStack.java213
1 files changed, 122 insertions, 91 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/TrimStack.java b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/TrimStack.java
index ec8ad9f..0320193 100644
--- a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/TrimStack.java
+++ b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/minmax/TrimStack.java
@@ -81,6 +81,12 @@ public class TrimStack {
private static final String RESTORE_ICON_URI = "platform:/plugin/org.eclipse.e4.ui.workbench.addons.swt/icons/full/etool16/fastview_restore.gif"; //$NON-NLS-1$
+ /**
+ * If the minimized shared editor area is empty, the editor area tool item will have this
+ * constant as its data.
+ */
+ private static final Object EMPTY_EDITOR_AREA = new Object();
+
static final String STATE_XSIZE = "XSize"; //$NON-NLS-1$
static final String STATE_YSIZE = "YSize"; //$NON-NLS-1$
@@ -420,7 +426,7 @@ public class TrimStack {
ToolItem toolItem = (ToolItem) e.widget;
MUIElement uiElement = (MUIElement) toolItem.getData();
- // Clicking on the already showing item ? NOTE: teh Selection will already have been
+ // Clicking on the already showing item ? NOTE: the selection will already have been
// turned off by the time the event arrives
if (!toolItem.getSelection()) {
partService.requestActivation();
@@ -500,7 +506,7 @@ public class TrimStack {
while (trimStackMenu.getItemCount() > 0)
trimStackMenu.getItem(0).dispose();
- // Only add the menu if hovering over a tool item (vs restore button)
+ // Only open the menu if a tool item is selected
Point point = trimStackTB.getDisplay().map(null, trimStackTB,
new Point(event.x, event.y));
ToolItem selectedToolItem = trimStackTB.getItem(point);
@@ -508,113 +514,135 @@ public class TrimStack {
return;
}
- MPart toActivate = null;
- if (minimizedElement instanceof MPartStack) {
- if (selectedToolItem.getData() instanceof MPart) {
- toActivate = (MPart) selectedToolItem.getData();
- }
+ // Are we hovering over a valid tool item (vs restore button)
+ Object data = selectedToolItem.getData();
+ if (data instanceof MPart) {
+ // A part on a stack or editor area
+ createPartMenu((MPart) data);
+ } else if (data instanceof MPerspective) {
+ // A perspective in a perspective stack (for now we just support restore)
+ createEmtpyEditorAreaMenu();
+ } else if (EMPTY_EDITOR_AREA.equals(data)) {
+ // An empty editor area
+ createEmtpyEditorAreaMenu();
}
+ }
+ });
- final MUIElement partToTag = minimizedElement;
- final MPart partToActivate = toActivate;
-
- MenuItem orientationItem = new MenuItem(trimStackMenu, SWT.CASCADE);
- orientationItem.setText(Messages.TrimStack_OrientationMenu);
- Menu orientationMenu = new Menu(orientationItem);
- orientationItem.setMenu(orientationMenu);
-
- MenuItem defaultItem = new MenuItem(orientationMenu, SWT.RADIO);
- defaultItem.setText(Messages.TrimStack_DefaultOrientationItem);
- defaultItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- boolean doRefresh = partToTag.getTags().remove(
- IPresentationEngine.ORIENTATION_HORIZONTAL);
- doRefresh |= partToTag.getTags().remove(
- IPresentationEngine.ORIENTATION_VERTICAL);
- if (isShowing && doRefresh) {
- setPaneLocation(hostPane);
- }
- }
- });
+ trimStackMenu = new Menu(trimStackTB);
+ trimStackTB.setMenu(trimStackMenu);
- MenuItem horizontalItem = new MenuItem(orientationMenu, SWT.RADIO);
- horizontalItem.setText(Messages.TrimStack_Horizontal);
- horizontalItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- if (!partToTag.getTags().contains(
- IPresentationEngine.ORIENTATION_HORIZONTAL)) {
- partToTag.getTags().remove(IPresentationEngine.ORIENTATION_VERTICAL);
- partToTag.getTags().add(IPresentationEngine.ORIENTATION_HORIZONTAL);
- if (isShowing) {
- setPaneLocation(hostPane);
- }
- }
- }
- });
+ ToolItem restoreBtn = new ToolItem(trimStackTB, SWT.PUSH);
+ restoreBtn.setToolTipText(Messages.TrimStack_RestoreText);
+ restoreBtn.setImage(getRestoreImage());
+ restoreBtn.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ minimizedElement.getTags().remove(IPresentationEngine.MINIMIZED);
+ }
+ });
- MenuItem verticalItem = new MenuItem(orientationMenu, SWT.RADIO);
- verticalItem.setText(Messages.TrimStack_Vertical);
- verticalItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- if (!partToTag.getTags().contains(IPresentationEngine.ORIENTATION_VERTICAL)) {
- partToTag.getTags().remove(IPresentationEngine.ORIENTATION_HORIZONTAL);
- partToTag.getTags().add(IPresentationEngine.ORIENTATION_VERTICAL);
- if (isShowing) {
- setPaneLocation(hostPane);
- }
- }
- }
- });
+ updateTrimStackItems();
+ }
- // Set initial orientation selection
- if (partToTag.getTags().contains(IPresentationEngine.ORIENTATION_HORIZONTAL)) {
- horizontalItem.setSelection(true);
- } else if (partToTag.getTags().contains(IPresentationEngine.ORIENTATION_VERTICAL)) {
- verticalItem.setSelection(true);
- } else {
- defaultItem.setSelection(true);
+ /**
+ * Creates a restore menu item that removes the minimized tag from the {@link #minimizedElement}
+ */
+ private void createEmtpyEditorAreaMenu() {
+ MenuItem restoreItem = new MenuItem(trimStackMenu, SWT.NONE);
+ restoreItem.setText(Messages.TrimStack_RestoreText);
+ restoreItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ minimizedElement.getTags().remove(IPresentationEngine.MINIMIZED);
+ }
+ });
+ }
+
+ /**
+ * Creates a series of menu items when a part is selected. The orientation submenu changes the
+ * layout tags on the {@link #minimizedElement}. The restore item will remove the minimized tag.
+ * The close item is not available on the editor stack, but will ask the part service to hide
+ * the part.
+ *
+ * @param selectedPart
+ * the part from the data of the selected tool item
+ */
+ private void createPartMenu(final MPart selectedPart) {
+ MenuItem orientationItem = new MenuItem(trimStackMenu, SWT.CASCADE);
+ orientationItem.setText(Messages.TrimStack_OrientationMenu);
+ Menu orientationMenu = new Menu(orientationItem);
+ orientationItem.setMenu(orientationMenu);
+
+ MenuItem defaultItem = new MenuItem(orientationMenu, SWT.RADIO);
+ defaultItem.setText(Messages.TrimStack_DefaultOrientationItem);
+ defaultItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ boolean doRefresh = minimizedElement.getTags().remove(
+ IPresentationEngine.ORIENTATION_HORIZONTAL);
+ doRefresh |= minimizedElement.getTags().remove(
+ IPresentationEngine.ORIENTATION_VERTICAL);
+ if (isShowing && doRefresh) {
+ setPaneLocation(hostPane);
}
+ }
+ });
- MenuItem restoreItem = new MenuItem(trimStackMenu, SWT.NONE);
- restoreItem.setText(Messages.TrimStack_RestoreText);
- restoreItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- minimizedElement.getTags().remove(IPresentationEngine.MINIMIZED);
- if (partToActivate != null) {
- partService.activate(partToActivate);
- }
+ MenuItem horizontalItem = new MenuItem(orientationMenu, SWT.RADIO);
+ horizontalItem.setText(Messages.TrimStack_Horizontal);
+ horizontalItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (!minimizedElement.getTags()
+ .contains(IPresentationEngine.ORIENTATION_HORIZONTAL)) {
+ minimizedElement.getTags().remove(IPresentationEngine.ORIENTATION_VERTICAL);
+ minimizedElement.getTags().add(IPresentationEngine.ORIENTATION_HORIZONTAL);
+ if (isShowing) {
+ setPaneLocation(hostPane);
}
- });
-
- // Don't allow the editor area to be closed
- if (!isEditorStack()) {
- MenuItem closeItem = new MenuItem(trimStackMenu, SWT.NONE);
- closeItem.setText(Messages.TrimStack_CloseText);
- closeItem.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- partService.hidePart((MPart) partToTag);
- }
- });
}
+ }
+ });
+ MenuItem verticalItem = new MenuItem(orientationMenu, SWT.RADIO);
+ verticalItem.setText(Messages.TrimStack_Vertical);
+ verticalItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (!minimizedElement.getTags().contains(IPresentationEngine.ORIENTATION_VERTICAL)) {
+ minimizedElement.getTags().remove(IPresentationEngine.ORIENTATION_HORIZONTAL);
+ minimizedElement.getTags().add(IPresentationEngine.ORIENTATION_VERTICAL);
+ if (isShowing) {
+ setPaneLocation(hostPane);
+ }
+ }
}
});
- if (minimizedElement instanceof MPartStack || minimizedElement instanceof MPlaceholder) {
- trimStackMenu = new Menu(trimStackTB);
- trimStackTB.setMenu(trimStackMenu);
+ // Set initial orientation selection
+ if (minimizedElement.getTags().contains(IPresentationEngine.ORIENTATION_HORIZONTAL)) {
+ horizontalItem.setSelection(true);
+ } else if (minimizedElement.getTags().contains(IPresentationEngine.ORIENTATION_VERTICAL)) {
+ verticalItem.setSelection(true);
+ } else {
+ defaultItem.setSelection(true);
}
- ToolItem restoreBtn = new ToolItem(trimStackTB, SWT.PUSH);
- restoreBtn.setToolTipText(Messages.TrimStack_RestoreText);
- restoreBtn.setImage(getRestoreImage());
- restoreBtn.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
+ MenuItem restoreItem = new MenuItem(trimStackMenu, SWT.NONE);
+ restoreItem.setText(Messages.TrimStack_RestoreText);
+ restoreItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
minimizedElement.getTags().remove(IPresentationEngine.MINIMIZED);
+ partService.activate(selectedPart);
}
});
- updateTrimStackItems();
+ // Do not allow the shared editor area to be closed
+ if (!isEditorStack()) {
+ MenuItem closeItem = new MenuItem(trimStackMenu, SWT.NONE);
+ closeItem.setText(Messages.TrimStack_CloseText);
+ closeItem.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ partService.hidePart(selectedPart);
+ }
+ });
+ }
}
@PreDestroy
@@ -710,7 +738,10 @@ public class TrimStack {
}
if (isEditorStack() && trimStackTB.getItemCount() == 1) {
- MUIElement data = getLeafPart(minimizedElement);
+ Object data = getLeafPart(minimizedElement);
+ if (data == null) {
+ data = EMPTY_EDITOR_AREA;
+ }
ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
ti.setToolTipText(Messages.TrimStack_SharedAreaTooltip);
ti.setImage(getLayoutImage());