Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2016-09-22 14:24:13 +0000
committerGerrit Code Review @ Eclipse.org2016-09-30 07:25:32 +0000
commit62ff5b7ce50daf940e0183e675819c8936fc3c91 (patch)
tree45151f14ae40e2bda53e35a3ac783ba0515f34e9 /plugins/views
parent52b6db0337e4d0a91de8001283ae5622921dd2c0 (diff)
downloadorg.eclipse.papyrus-62ff5b7ce50daf940e0183e675819c8936fc3c91.tar.gz
org.eclipse.papyrus-62ff5b7ce50daf940e0183e675819c8936fc3c91.tar.xz
org.eclipse.papyrus-62ff5b7ce50daf940e0183e675819c8936fc3c91.zip
Bug 502003 - [Model Explorer] Expand/Collapse buttons should be work at
selected element https://bugs.eclipse.org/bugs/show_bug.cgi?id=502003 Change-Id: Ife74540571623e4eacadaca18ba72e6daab63dc6 Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/collapseall.pngbin0 -> 1265 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/expandall.pngbin0 -> 229 bytes
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml38
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Activator.java7
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CollapseAllHandler.java82
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/ExpandAllHandler.java81
6 files changed, 207 insertions, 1 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/collapseall.png b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/collapseall.png
new file mode 100644
index 00000000000..75c898936a2
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/collapseall.png
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/expandall.png b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/expandall.png
new file mode 100644
index 00000000000..354ac37cf23
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/icons/etool16/expandall.png
Binary files differ
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml
index f21882a6c8f..81b373de3a2 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml
@@ -18,6 +18,12 @@
</extension>
<extension point="org.eclipse.ui.navigator.viewer">
<viewer popupMenuId="org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup" viewerId="org.eclipse.papyrus.views.modelexplorer.modelexplorer">
+ <options>
+ <property
+ name="org.eclipse.ui.navigator.hideCollapseAllAction"
+ value="true">
+ </property>
+ </options>
</viewer>
<viewerContentBinding viewerId="org.eclipse.papyrus.views.modelexplorer.modelexplorer">
<includes>
@@ -135,6 +141,18 @@
<!-- Sort elements command -->
<command commandId="org.eclipse.papyrus.views.modelexplorer.sortelement" icon="icons/etool16/sort.gif" label="sort" style="toggle">
</command>
+ <command
+ commandId="org.eclipse.papyrus.views.modelexplorer.expandall"
+ icon="icons/etool16/expandall.png"
+ label="Expand all at selected element"
+ style="push">
+ </command>
+ <command
+ commandId="org.eclipse.papyrus.views.modelexplorer.collapseall"
+ icon="icons/etool16/collapseall.png"
+ label="Collapse all at selected element"
+ style="push">
+ </command>
</menuContribution>
<menuContribution allPopups="false" locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup">
<separator
@@ -261,7 +279,21 @@
<!-- Command declaration : Delete element command -->
<command categoryId="org.eclipse.papyrus.editor.category" defaultHandler="org.eclipse.papyrus.views.modelexplorer.handler.DeleteCommandHandler" description="Delete" id="org.eclipse.papyrus.uml.service.creation.DeleteCommand" name="Delete">
- </command>
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.views.modelexplorer.handler.ExpandAllHandler"
+ description="Expand All at selected Element"
+ id="org.eclipse.papyrus.views.modelexplorer.expandall"
+ name="Expand All at Selected Element (Ctrl+ Shift+ Numpad_Multiply)">
+ </command>
+ <command
+ categoryId="org.eclipse.papyrus.editor.category"
+ defaultHandler="org.eclipse.papyrus.views.modelexplorer.handler.CollapseAllHandler"
+ description="Collapse All at selected Element"
+ id="org.eclipse.papyrus.views.modelexplorer.collapseall"
+ name="Collapse All at Selected Element (Ctrl+ Shift+ Numpad_Divide)">
+ </command>
</extension>
@@ -472,6 +504,10 @@
</with>
</and>
</activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.views.modelexplorer.handler.ExpandAllHandler"
+ commandId="org.eclipse.ui.navigate.expandAll">
</handler>
</extension>
<extension point="org.eclipse.core.expressions.propertyTesters">
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Activator.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Activator.java
index bd3850b16e9..57e6819abb6 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Activator.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/Activator.java
@@ -26,6 +26,9 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.papyrus.infra.ui.emf.utils.ProviderHelper;
+import org.eclipse.papyrus.views.modelexplorer.handler.CollapseAllHandler;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -59,6 +62,10 @@ public class Activator extends AbstractUIPlugin {
if (System.getProperty(workaround) == null) { // Only change the value if it is not explicitly set already (Don't override user-defined value)
System.setProperty(workaround, Boolean.toString(true));
}
+
+ //Replace collapseHandler in handler service
+ IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
+ handlerService.activateHandler(org.eclipse.ui.handlers.CollapseAllHandler.COMMAND_ID, new CollapseAllHandler());
}
/**
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CollapseAllHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CollapseAllHandler.java
new file mode 100644
index 00000000000..6905ee1c2cf
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CollapseAllHandler.java
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST, ALL4TEC and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Handler to collapse all children at selected element.
+ */
+public class CollapseAllHandler extends AbstractHandler {
+
+ /**
+ * Constructor.
+ */
+ public CollapseAllHandler() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(final ExecutionEvent event) {
+
+ ModelExplorerView openedModelExplorerView = getOpenedModelExplorerView();
+
+ if (openedModelExplorerView != null) {
+ CommonViewer commonViewer = openedModelExplorerView.getCommonViewer();
+ ISelection selection = commonViewer.getSelection();
+ // If there are selected element
+ if (selection instanceof StructuredSelection && !selection.isEmpty()) {
+ // expand each selected element
+ for (Object object : ((StructuredSelection) selection).toArray()) {
+ commonViewer.collapseToLevel(object, AbstractTreeViewer.ALL_LEVELS);
+ }
+
+ } else {
+ // or collapse all
+ commonViewer.collapseAll();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the view 'ModelExplorer' if it's already opened.
+ */
+ public static ModelExplorerView getOpenedModelExplorerView() {
+ final IViewReference[] iViewModelExplorers = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getViewReferences();
+
+ for (final IViewReference iViewModelExplorer : iViewModelExplorers) {
+ final IViewPart iViewPart = iViewModelExplorer.getView(false);
+ if (iViewPart instanceof ModelExplorerPageBookView && ((MultiViewPageBookView) iViewPart).getActiveView() instanceof ModelExplorerView) {
+ return (ModelExplorerView) ((ModelExplorerPageBookView) iViewPart).getActiveView();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/ExpandAllHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/ExpandAllHandler.java
new file mode 100644
index 00000000000..749188e3627
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/ExpandAllHandler.java
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST, ALL4TEC and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
+import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Handler to expand all children at selected element.
+ */
+public class ExpandAllHandler extends AbstractHandler {
+
+ /**
+ * Constructor.
+ */
+ public ExpandAllHandler() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(final ExecutionEvent event) {
+
+ ModelExplorerView openedModelExplorerView = getOpenedModelExplorerView();
+
+ if (openedModelExplorerView != null) {
+ CommonViewer commonViewer = openedModelExplorerView.getCommonViewer();
+ ISelection selection = commonViewer.getSelection();
+ // If there are selected element
+ if (selection instanceof StructuredSelection && !selection.isEmpty()) {
+ // For each element
+ for (Object object : ((StructuredSelection) selection).toArray()) {
+ commonViewer.expandToLevel(object, AbstractTreeViewer.ALL_LEVELS);
+ }
+ } else {
+ // or expand all
+ commonViewer.expandAll();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the view 'References' if it's already opened.
+ */
+ public static ModelExplorerView getOpenedModelExplorerView() {
+ final IViewReference[] iViewModelExplorers = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getViewReferences();
+
+ for (final IViewReference iModelExplorer : iViewModelExplorers) {
+ final IViewPart iViewPart = iModelExplorer.getView(false);
+ if (iViewPart instanceof ModelExplorerPageBookView && ((MultiViewPageBookView) iViewPart).getActiveView() instanceof ModelExplorerView) {
+ return (ModelExplorerView) ((ModelExplorerPageBookView) iViewPart).getActiveView();
+ }
+ }
+ return null;
+ }
+
+}

Back to the top