Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-05-13 19:40:04 +0000
committerChristian W. Damus2014-05-13 19:42:23 +0000
commit258d199d1361280c45a44e5fef241f8f3112734f (patch)
tree076da6037ecd50207a9c2a6f1311c102073325cc /plugins/views
parent2da0a56b7c2d60edf43642ef2f27e2443c96f4a9 (diff)
downloadorg.eclipse.papyrus-258d199d1361280c45a44e5fef241f8f3112734f.tar.gz
org.eclipse.papyrus-258d199d1361280c45a44e5fef241f8f3112734f.tar.xz
org.eclipse.papyrus-258d199d1361280c45a44e5fef241f8f3112734f.zip
434635: [Model Explorer] Preference for "Link with Editor"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434635 Implement memento-based persistence for the link-with-editor and alphabetical-sorting toggle buttons in the Model Explorer tool bar. Fix the initial calculation of the toggle state of the advance view tool bar item and implement calculation of the toggle state of the show-diagrams tool bar item. All of these toggle states are shared across all Model Explorer pages (the user perceives the Model Explorer as one view, not a bunch of pages).
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml4
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPage.java14
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java48
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java125
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/SharedModelExplorerState.java200
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementHandler.java59
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementState.java85
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java57
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/ITreeViewerSorting.java26
9 files changed, 556 insertions, 62 deletions
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 faac864f1d2..07e86308581 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/plugin.xml
@@ -232,6 +232,10 @@
<!-- Command declaration : Sort elements command -->
<command categoryId="org.eclipse.papyrus.editor.category" defaultHandler="org.eclipse.papyrus.views.modelexplorer.handler.SortElementHandler" description="Sort elements" id="org.eclipse.papyrus.views.modelexplorer.sortelement" name="Sort elements">
+ <state
+ class="org.eclipse.papyrus.views.modelexplorer.handler.SortElementState:org.eclipse.papyrus.views.modelexplorer.modelexplorer"
+ id="org.eclipse.ui.commands.toggleState">
+ </state>
</command>
<!-- Command declaration : Delete element command -->
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPage.java
index d7359defbc9..1b4818fbcbd 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPage.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPage.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 LIFL & CEA LIST.
+ * Copyright (c) 2010, 2014 LIFL, CEA LIST, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 434635
*
*****************************************************************************/
@@ -30,6 +31,8 @@ import org.eclipse.ui.IWorkbenchPart;
*/
public class ModelExplorerPage extends ViewPartPage {
+ private SharedModelExplorerState state;
+
/**
* Constructor.
*
@@ -47,8 +50,10 @@ public class ModelExplorerPage extends ViewPartPage {
*/
@Override
protected IViewPart createViewer(IWorkbenchPart part) {
- // Part is of the right type because of call to isImportant()
- return new ModelExplorerView((IMultiDiagramEditor)part);
+ // Part is of the right type because of call to isImportant()
+ ModelExplorerView result = new ModelExplorerView((IMultiDiagramEditor)part);
+ result.setSharedState(state);
+ return result;
}
/**
@@ -75,4 +80,7 @@ public class ModelExplorerPage extends ViewPartPage {
return ((ModelExplorerView)getViewer()).getControl();
}
+ void setSharedState(SharedModelExplorerState state) {
+ this.state = state;
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java
index c7a130377b5..b527500c691 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 LIFL & CEA LIST.
+ * Copyright (c) 2010, 2014 LIFL, CEA LIST, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -10,6 +10,7 @@
* Contributors:
* Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
* Ansgar Radermacher (CEA) ansgar.radermacher@cea.fr - Added support for IGotoMarker
+ * Christian W. Damus (CEA) - bug 434635
*
*****************************************************************************/
@@ -21,9 +22,13 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.MultiViewPageBookView;
-import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.ViewPartPage;
+import org.eclipse.papyrus.views.modelexplorer.sorting.DefaultTreeViewerSorting;
+import org.eclipse.papyrus.views.modelexplorer.sorting.ITreeViewerSorting;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IGotoMarker;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.views.properties.IPropertySheetPage;
@@ -44,6 +49,15 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements
/** ID of the view, as given in the plugin.xml file */
public static final String VIEW_ID = "org.eclipse.papyrus.views.modelexplorer.modelexplorer"; //$NON-NLS-1$
+ private final SharedModelExplorerState state = new SharedModelExplorerState();
+
+ @Override
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ super.init(site, memento);
+
+ state.load(memento);
+ }
+
/**
* {@inheritDoc}
*/
@@ -52,7 +66,8 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements
// part is of type IMultiDiagramEditor (because of isImportant() )
- ViewPartPage page = new ModelExplorerPage();
+ ModelExplorerPage page = new ModelExplorerPage();
+ page.setSharedState(state);
// Init the page, and so the View
initPage(page, part);
@@ -65,7 +80,7 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements
* {@inheritDoc}
*/
@Override
- public Object getAdapter(Class adapter) {
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
if(IPropertySheetPage.class == adapter) {
// Do not test if tabbedPropertySheetPage is null before calling new
@@ -73,6 +88,24 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements
return new TabbedPropertySheetPage(this);
}
+ if(adapter == ITreeViewerSorting.class) {
+ return new DefaultTreeViewerSorting() {
+
+ @Override
+ public void setSorted(boolean sorted) {
+ // Update the shared state
+ if(state != null) {
+ state.setAlphaSorted(sorted);
+ }
+ }
+
+ @Override
+ public boolean isSorted() {
+ return state != null && state.isAlphaSorted();
+ }
+ };
+ }
+
return super.getAdapter(adapter);
}
@@ -105,4 +138,11 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements
}
}
}
+
+ @Override
+ public void saveState(IMemento memento) {
+ state.save(memento);
+
+ super.saveState(memento);
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
index bd5e0f697b7..7f2a6262cf1 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
@@ -11,6 +11,7 @@
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - post refreshes for transaction commit asynchronously (CDO)
* Christian W. Damus (CEA) - bug 429826
+ * Christian W. Damus (CEA) - bug 434635
*
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer;
@@ -74,6 +75,7 @@ import org.eclipse.papyrus.infra.services.navigation.service.NavigableElement;
import org.eclipse.papyrus.infra.services.navigation.service.NavigationService;
import org.eclipse.papyrus.infra.widgets.editors.SelectionMenu;
import org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement;
+import org.eclipse.papyrus.views.modelexplorer.SharedModelExplorerState.StateChangedEvent;
import org.eclipse.papyrus.views.modelexplorer.listener.DoubleClickListener;
import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem;
@@ -95,6 +97,7 @@ import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewSite;
@@ -105,6 +108,8 @@ import org.eclipse.ui.internal.navigator.NavigatorContentService;
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.navigator.CommonViewerSorter;
+import org.eclipse.ui.navigator.IExtensionActivationListener;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
@@ -121,6 +126,10 @@ import com.google.common.collect.Lists;
*/
public class ModelExplorerView extends CommonNavigator implements IRevealSemanticElement, IEditingDomainProvider, IPageLifeCycleEventsListener {
+ private SharedModelExplorerState sharedState;
+
+ private SharedModelExplorerState.StateChangedListener sharedStateListener;
+
/**
* The context of the LabelProviderService used by this view
*
@@ -214,8 +223,6 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
throw new IllegalArgumentException("The part should have a ServiceRegistry.");
}
- setLinkingEnabled(true);
-
// Get required services from ServicesRegistry
try {
saveAndDirtyService = serviceRegistry.getService(ISaveAndDirtyService.class);
@@ -367,6 +374,15 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
break;
}
}
+ contentService.dispose(); // No longer need this
+
+ viewer.getNavigatorContentService().getActivationService().addExtensionActivationListener(new IExtensionActivationListener() {
+
+ public void onExtensionActivation(String aViewerId, String[] theNavigatorExtensionIds, boolean isActive) {
+ sharedState.updateNavigatorContentExtensions(theNavigatorExtensionIds, isActive);
+ }
+ });
+
ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);
return viewer;
@@ -484,6 +500,10 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
} catch (ServiceException ex) {
//Ignore
}
+
+ if(sharedState != null) {
+ initSharedState(sharedState);
+ }
}
@Override
@@ -757,6 +777,19 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
if(this.getCommonViewer() != null) {
syncRefresh();
}
+
+ // Self-listen for property changes
+ addPropertyListener(new IPropertyListener() {
+
+ public void propertyChanged(Object source, int propId) {
+ switch(propId) {
+ case IS_LINKING_ENABLED_PROPERTY:
+ // Propagate to other instances
+ sharedState.setLinkingEnabled(isLinkingEnabled());
+ break;
+ }
+ }
+ });
}
/**
@@ -791,6 +824,10 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
return;
}
+ if((sharedStateListener != null) && (sharedState != null)) {
+ sharedState.removeListener(sharedStateListener);
+ }
+
try {
ISashWindowsContainer sashWindowsContainer = serviceRegistry.getService(ISashWindowsContainer.class);
if(sashWindowsContainer != null) {
@@ -972,11 +1009,11 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
* in the good order. This is a lot faster than going through the whole tree
* using getChildren of the ContentProvider since our Viewer uses a Hashtable
* to keep track of the revealed elements.
- *
+ *
* However we need to use a dedicated MatchingItem to do the matching,
* and a specific comparer in our viewer so than the equals of MatchingItem is
* used in priority.
- *
+ *
* Please refer to MatchingItem for more infos.
*/
EObject previousParent = null;
@@ -1110,4 +1147,84 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
}
};
}
+
+ void setSharedState(SharedModelExplorerState state) {
+ if(this.sharedState != null) {
+ this.sharedState.removeListener(getSharedStateListener());
+ }
+
+ this.sharedState = state;
+
+ if(state != null) {
+ state.addListener(getSharedStateListener());
+ initSharedState(state);
+ }
+ }
+
+ void initSharedState(SharedModelExplorerState state) {
+ setLinkingEnabled(state.isLinkingEnabled());
+ setAlphaSorted(state.isAlphaSorted());
+ }
+
+ void setAlphaSorted(boolean sorted) {
+ CommonViewer viewer = getCommonViewer();
+ if((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
+ if(sorted) {
+ viewer.setSorter(new CommonViewerSorter());
+ if(viewer instanceof CustomCommonViewer) {
+ ((CustomCommonViewer)viewer).getDropAdapter().setFeedbackEnabled(false);
+ }
+ } else {
+ viewer.setSorter(null);
+ if(viewer instanceof CustomCommonViewer) {
+ ((CustomCommonViewer)viewer).getDropAdapter().setFeedbackEnabled(true);
+ }
+ }
+ }
+ }
+
+ SharedModelExplorerState.StateChangedListener getSharedStateListener() {
+ if(sharedStateListener == null) {
+ sharedStateListener = new SharedModelExplorerState.StateChangedListener() {
+
+ private volatile Runnable contentUpdate;
+
+ public void sharedStateChanged(StateChangedEvent event) {
+ switch(event.getEventType()) {
+ case StateChangedEvent.LINKING_ENABLED:
+ setLinkingEnabled(event.getSource().isLinkingEnabled());
+ break;
+ case StateChangedEvent.ALPHA_SORTED:
+ setAlphaSorted(event.getSource().isAlphaSorted());
+ break;
+ case StateChangedEvent.CONTENT_EXTENSIONS:
+ if(contentUpdate == null) {
+ getCommonViewer().getControl().getDisplay().asyncExec(getContentUpdate());
+ }
+ break;
+ }
+ }
+
+ private Runnable getContentUpdate() {
+ if(contentUpdate == null) {
+ contentUpdate = new Runnable() {
+
+ public void run() {
+ CommonViewer viewer = getCommonViewer();
+ if((viewer != null) && (viewer.getControl() != null) && !viewer.getControl().isDisposed()) {
+ viewer.getNavigatorContentService().getActivationService().activateExtensions(sharedState.getNavigatorContentExtensions(), true);
+ }
+
+ // I am no longer pending
+ contentUpdate = null;
+ }
+ };
+ }
+ return contentUpdate;
+ }
+ };
+ }
+
+ return sharedStateListener;
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/SharedModelExplorerState.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/SharedModelExplorerState.java
new file mode 100644
index 00000000000..9fc03832116
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/SharedModelExplorerState.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.views.modelexplorer;
+
+import java.util.Arrays;
+import java.util.EventListener;
+import java.util.EventObject;
+import java.util.Set;
+
+import org.eclipse.core.commands.common.EventManager;
+import org.eclipse.ui.IMemento;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+
+/**
+ * Shared persistent state (especially of tool-bar toggle actions) of the Model Explorer view pages.
+ */
+class SharedModelExplorerState extends EventManager {
+
+ private static final String LINKING_MEMENTO = "linkWithEditor"; //$NON-NLS-1$
+
+ private static final String ENABLED_ATTR = "enabled"; //$NON-NLS-1$
+
+ private static final String SORTING_MEMENTO = "sorting"; //$NON-NLS-1$
+
+ private static final String ALPHA_SORTED_ATTR = "alphaSorted"; //$NON-NLS-1$
+
+ private boolean linkingEnabled;
+
+ private boolean alphaSorted;
+
+ /** The active content extensions are persisted by the Common Navigator Framework, so we don't have to. */
+ private Set<String> navigatorContentExtensions = Sets.newHashSet();
+
+ SharedModelExplorerState() {
+ super();
+ }
+
+ public void setLinkingEnabled(boolean linkingEnabled) {
+ boolean oldValue = this.linkingEnabled;
+ this.linkingEnabled = linkingEnabled;
+
+ if(oldValue != linkingEnabled) {
+ fireStateChanged(StateChangedEvent.LINKING_ENABLED);
+ }
+ }
+
+ public boolean isLinkingEnabled() {
+ return linkingEnabled;
+ }
+
+ public void setAlphaSorted(boolean alphaSorted) {
+ boolean oldValue = this.alphaSorted;
+ this.alphaSorted = alphaSorted;
+
+ if(oldValue != alphaSorted) {
+ fireStateChanged(StateChangedEvent.ALPHA_SORTED);
+ }
+ }
+
+ public boolean isAlphaSorted() {
+ return alphaSorted;
+ }
+
+ public void updateNavigatorContentExtensions(String[] contentExtensionIDs, boolean activate) {
+ Set<String> oldValue = ImmutableSet.copyOf(this.navigatorContentExtensions);
+
+ if(activate) {
+ this.navigatorContentExtensions.addAll(Arrays.asList(contentExtensionIDs));
+ } else {
+ this.navigatorContentExtensions.removeAll(Arrays.asList(contentExtensionIDs));
+ }
+
+ if(!oldValue.equals(this.navigatorContentExtensions)) {
+ fireStateChanged(StateChangedEvent.CONTENT_EXTENSIONS);
+ }
+ }
+
+ public String[] getNavigatorContentExtensions() {
+ return Iterables.toArray(navigatorContentExtensions, String.class);
+ }
+
+ void load(IMemento memento) {
+ readLinking(memento);
+ readSorting(memento);
+ // Persistence of CNF content extensions is handled by that framework
+ }
+
+ public void save(IMemento memento) {
+ writeLinking(memento);
+ writeSorting(memento);
+ // Persistence of CNF content extensions is handled by that framework
+ }
+
+ private void readLinking(IMemento memento) {
+ IMemento linking = memento.getChild(LINKING_MEMENTO);
+ if(linking != null) {
+ Boolean enabled = linking.getBoolean(ENABLED_ATTR);
+ this.linkingEnabled = (enabled != null) && enabled.booleanValue();
+ }
+ }
+
+ private void writeLinking(IMemento memento) {
+ IMemento linking = memento.getChild(LINKING_MEMENTO);
+ if(linking == null) {
+ linking = memento.createChild(LINKING_MEMENTO);
+ }
+ linking.putBoolean(ENABLED_ATTR, isLinkingEnabled());
+ }
+
+ private void readSorting(IMemento memento) {
+ IMemento sorting = memento.getChild(SORTING_MEMENTO);
+ if(sorting != null) {
+ Boolean sorted = sorting.getBoolean(ALPHA_SORTED_ATTR);
+ this.alphaSorted = (sorted != null) && sorted.booleanValue();
+ }
+ }
+
+ private void writeSorting(IMemento memento) {
+ IMemento sorting = memento.getChild(SORTING_MEMENTO);
+ if(sorting == null) {
+ sorting = memento.createChild(SORTING_MEMENTO);
+ }
+ sorting.putBoolean(ALPHA_SORTED_ATTR, isAlphaSorted());
+ }
+
+ public void addListener(StateChangedListener listener) {
+ addListenerObject(listener);
+ }
+
+ public void removeListener(StateChangedListener listener) {
+ removeListenerObject(listener);
+ }
+
+ void fireStateChanged(int eventType) {
+ if(isListenerAttached()) {
+ StateChangedEvent event = new StateChangedEvent(this, eventType);
+ Object[] listeners = getListeners();
+ for(int i = 0; i < listeners.length; i++) {
+ try {
+ ((StateChangedListener)listeners[i]).sharedStateChanged(event);
+ } catch (Exception e) {
+ Activator.log.error("Uncaught exception in shared state listener.", e);
+ }
+ }
+ }
+ }
+
+ //
+ // Nested types
+ //
+
+ static class StateChangedEvent extends EventObject {
+
+ public static final int LINKING_ENABLED = 1;
+
+ public static final int ALPHA_SORTED = 2;
+
+ public static final int CONTENT_EXTENSIONS = 3;
+
+ private static final long serialVersionUID = 1L;
+
+ private final int type;
+
+ StateChangedEvent(SharedModelExplorerState source, int type) {
+ super(source);
+ this.type = type;
+ }
+
+ @Override
+ public SharedModelExplorerState getSource() {
+ return (SharedModelExplorerState)super.getSource();
+ }
+
+ public int getEventType() {
+ return type;
+ }
+ }
+
+ /**
+ * Call-back interface for notification of changes in the shared Model Explorer state.
+ */
+ static interface StateChangedListener extends EventListener {
+
+ void sharedStateChanged(StateChangedEvent event);
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementHandler.java
index 5189beb6901..a20ad573ad3 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 2014 CEA LIST and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 434635
*
*****************************************************************************/
@@ -17,17 +18,12 @@ package org.eclipse.papyrus.views.modelexplorer.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.papyrus.views.modelexplorer.Activator;
-import org.eclipse.papyrus.views.modelexplorer.CustomCommonViewer;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
-import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.MultiViewPageBookView;
+import org.eclipse.papyrus.views.modelexplorer.sorting.DefaultTreeViewerSorting;
+import org.eclipse.papyrus.views.modelexplorer.sorting.ITreeViewerSorting;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ToolItem;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
-import org.eclipse.ui.navigator.CommonViewerSorter;
/**
@@ -40,53 +36,14 @@ public class SortElementHandler extends AbstractHandler {
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
if(Activator.getDefault().getCustomizationManager() != null) {
- TreeViewer selectedTreeViewer = getSelectedTreeViewer(event);
- if(selectedTreeViewer == null) {
- return null;
- }
+ final boolean isSorted = ((ToolItem)((Event)event.getTrigger()).widget).getSelection();
- if(((ToolItem)((Event)event.getTrigger()).widget).getSelection()) {
-
-
- selectedTreeViewer.setSorter(new CommonViewerSorter());
- if(selectedTreeViewer instanceof CustomCommonViewer) {
- ((CustomCommonViewer)selectedTreeViewer).getDropAdapter().setFeedbackEnabled(false);
- }
- } else {
- selectedTreeViewer.setSorter(null);
- if(selectedTreeViewer instanceof CustomCommonViewer) {
- ((CustomCommonViewer)selectedTreeViewer).getDropAdapter().setFeedbackEnabled(true);
- }
- }
-
- getSelectedTreeViewer(event).refresh();
+ getTreeViewerSorting(event).setSorted(isSorted);
}
return null;
}
- /**
- * used to obtain the tree viewer of the model explorer
- *
- * @param event
- * @return
- */
- protected TreeViewer getSelectedTreeViewer(ExecutionEvent event) {
- // Try to get the active part
- IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
-
- if(activePart instanceof TreeViewer) {
- return (TreeViewer)activePart;
- }
-
- if(activePart instanceof MultiViewPageBookView) {
- MultiViewPageBookView pageBookView = (MultiViewPageBookView)activePart;
- IViewPart viewPart = pageBookView.getActiveView();
- if(viewPart instanceof ModelExplorerView) {
- return ((ModelExplorerView)viewPart).getCommonViewer();
- }
- }
-
- // Not found
- return null;
+ protected ITreeViewerSorting getTreeViewerSorting(ExecutionEvent event) {
+ return DefaultTreeViewerSorting.getSorting(HandlerUtil.getActivePart(event));
}
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementState.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementState.java
new file mode 100644
index 00000000000..f833919d477
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/SortElementState.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.views.modelexplorer.handler;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.State;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.views.modelexplorer.Activator;
+import org.eclipse.papyrus.views.modelexplorer.sorting.DefaultTreeViewerSorting;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The computed toggle state of the Sort Elements action.
+ */
+public class SortElementState extends State implements IExecutableExtension {
+
+ private String viewID;
+
+ public SortElementState() {
+ super();
+ }
+
+ @Override
+ public Object getValue() {
+ IWorkbench bench = PlatformUI.getWorkbench();
+ IWorkbenchWindow window = bench.getActiveWorkbenchWindow();
+ if(window == null) {
+ // Not actually active?
+ if(bench.getWorkbenchWindowCount() > 0) {
+ window = bench.getWorkbenchWindows()[0];
+ }
+ }
+
+ IWorkbenchPage page = (window == null) ? null : window.getActivePage();
+ IViewPart viewPart = (page == null) ? null : page.findView(viewID);
+
+ return DefaultTreeViewerSorting.getSorting(viewPart).isSorted();
+ }
+
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ viewID = getViewID(config, propertyName, data);
+
+ if(viewID == null) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No viewID specified in SortElementState extension.")); //$NON-NLS-1$
+ }
+ }
+
+ static String getViewID(IConfigurationElement config, String propertyName, Object data) {
+ String result = null;
+
+ if(data instanceof String) {
+ // It's the view ID
+ result = (String)data;
+ } else {
+ // It's a parameter map
+ Map<?, ?> parameters = (Map<?, ?>)data;
+ Object value = parameters.get("viewID");
+ if(value instanceof String) {
+ result = (String)value;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java
new file mode 100644
index 00000000000..7800d99d0c8
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/DefaultTreeViewerSorting.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.views.modelexplorer.sorting;
+
+import org.eclipse.ui.IWorkbenchPart;
+
+
+
+/**
+ * A default implementation (as a no-op) of the tree-viewer sorting adapter.
+ */
+public class DefaultTreeViewerSorting implements ITreeViewerSorting {
+
+ public DefaultTreeViewerSorting() {
+ super();
+ }
+
+ /**
+ * Obtains the tree-viewer sorting adapter for a workbench part, or a no-op default if the part provides none.
+ *
+ * @param part
+ * a workbench part (may be {@code null}
+ *
+ * @return the sorting adapter (never {@code null})
+ */
+ public static ITreeViewerSorting getSorting(IWorkbenchPart part) {
+ ITreeViewerSorting result = null;
+
+ if(part != null) {
+ result = (ITreeViewerSorting)part.getAdapter(ITreeViewerSorting.class);
+ }
+
+ if(result == null) {
+ result = new DefaultTreeViewerSorting();
+ }
+
+ return result;
+ }
+
+ public void setSorted(boolean sorted) {
+ // Pass
+ }
+
+ public boolean isSorted() {
+ return false;
+ }
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/ITreeViewerSorting.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/ITreeViewerSorting.java
new file mode 100644
index 00000000000..2e278baa115
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/sorting/ITreeViewerSorting.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014 CEA 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:
+ * Christian W. Damus (CEA) - Initial API and implementation
+ *
+ */
+package org.eclipse.papyrus.views.modelexplorer.sorting;
+
+
+/**
+ * An optional adapter interface for sorting of the tree view of a workbench view.
+ */
+public interface ITreeViewerSorting {
+
+ /** Sets whether the part's tree is sorted (whatever that means to the part). */
+ void setSorted(boolean sorted);
+
+ /** Queries whether the part's tree is sorted. */
+ boolean isSorted();
+}

Back to the top