Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcdumoulin2012-02-15 09:21:55 -0500
committercdumoulin2012-02-15 09:21:55 -0500
commit4e744633b39b06a21a4ebb487a778224710d35cb (patch)
tree612394e53e36e19b0d6ae75eb6a22766c050012a /plugins
parent945c75a7944e4663d0ac5a58af66def2c456d5fc (diff)
downloadorg.eclipse.papyrus-4e744633b39b06a21a4ebb487a778224710d35cb.tar.gz
org.eclipse.papyrus-4e744633b39b06a21a4ebb487a778224710d35cb.tar.xz
org.eclipse.papyrus-4e744633b39b06a21a4ebb487a778224710d35cb.zip
bug 371604: [modelexplorer] The dispose() method should be called when main editor is closed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371604 - Add a new service to Papyrus: IUndoContext.class. This service allows to get the IUndoContext used to tag Papyrus command in the command stack. - Let the MultiViewPageBookView.dispose() method be called when the associated Papyrus editor is closed. - Let MultiViewPageBookView use the ServiceRegistry rather than the CoreMultiDiagramEditor class
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java12
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/undocontext/UndoContextServiceFactory.java87
-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/core/ui/pagebookview/MultiViewPageBookView.java4
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/ViewPartPage.java11
6 files changed, 198 insertions, 51 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
index 719e8a1b3c0..a3e2de783f8 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
@@ -273,6 +273,16 @@
serviceKeyRef=" org.eclipse.papyrus.infra.core.lifecycleevents.ISaveAndDirtyService">
</dependsOn>
</serviceFactory>
+ <serviceFactory
+ classname="org.eclipse.papyrus.infra.core.undocontext.UndoContextServiceFactory"
+ description="The shared IUndoContext used to tag command in the CommandStack"
+ id="org.eclipse.core.commands.operations.IUndoContext"
+ priority="1"
+ startKind="lazy">
+ <dependsOn
+ serviceKeyRef="org.eclipse.emf.transaction.TransactionalEditingDomain">
+ </dependsOn>
+ </serviceFactory>
</extension>
<extension
point="org.eclipse.ui.exportWizards">
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java
index 873bf48cb94..8a8e764c540 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/editor/CoreMultiDiagramEditor.java
@@ -203,7 +203,7 @@ public class CoreMultiDiagramEditor extends AbstractMultiPageSashEditor implemen
* TODO : move away, use a version independent of GMF, add a listener that will add
* the context to all commands modifying attached Resources (==> linked to ModelSet ?)
*/
- private EditingDomainUndoContext undoContext;
+ private IUndoContext undoContext;
/**
* Get the contentOutlineRegistry. Create it if needed.
@@ -373,16 +373,13 @@ public class CoreMultiDiagramEditor extends AbstractMultiPageSashEditor implemen
return transactionalEditingDomain;
}
- /**
+ /*
* Return context used for undo/redo.
* All papyrus views should use this context.
+ * The prefer way to get this is to use
+ * undoContext = servicesRegistry.getService(IUndoContext.class);
*/
if(IUndoContext.class == adapter) {
- if(undoContext != null) {
- return undoContext;
- }
-
- undoContext = new EditingDomainUndoContext(transactionalEditingDomain);
return undoContext;
}
@@ -530,6 +527,7 @@ public class CoreMultiDiagramEditor extends AbstractMultiPageSashEditor implemen
sashModelMngr = servicesRegistry.getService(DiSashModelMngr.class);
contentProvider = servicesRegistry.getService(ISashWindowsContentProvider.class);
saveAndDirtyService = servicesRegistry.getService(ISaveAndDirtyService.class);
+ undoContext = servicesRegistry.getService(IUndoContext.class);
} catch (ServiceException e) {
log.error("A required service is missing.", e);
// if one of the services above fail to start, the editor can't run => stop
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/undocontext/UndoContextServiceFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/undocontext/UndoContextServiceFactory.java
new file mode 100644
index 00000000000..11f398cf749
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/undocontext/UndoContextServiceFactory.java
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.undocontext;
+
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.commands.core.command.EditingDomainUndoContext;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+
+
+/**
+ * Service Factory used to create the {@link IUndoContext} used by all editors and views associated to
+ * a model (or {@link ServicesRegistry}).
+ * The {@link IUndoContext} can be retrieved from the {@link ServicesRegistry}.
+ *
+ * @author Cedric Dumoulin
+ *
+ */
+public class UndoContextServiceFactory implements IServiceFactory {
+
+ /**
+ * Undo context used to have the same undo context in all Papyrus related views and editors.
+ */
+ private EditingDomainUndoContext undoContext;
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ // Lookup TransactionalEditingDomain
+ TransactionalEditingDomain transactionalEditingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(servicesRegistry);
+ // Create the undoContext
+ undoContext = new EditingDomainUndoContext(transactionalEditingDomain);
+ }
+
+ /**
+ * Do nothing
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ public void startService() throws ServiceException {
+ }
+
+ /**
+ * Do nothing
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ public void disposeService() throws ServiceException {
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
+ *
+ * @return
+ * @throws ServiceException
+ */
+ public Object createServiceInstance() throws ServiceException {
+ return undoContext;
+ }
+
+
+}
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 5c2fba420d9..fcf6d41ad8d 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
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.views.modelexplorer;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -44,6 +45,7 @@ import org.eclipse.papyrus.infra.core.lifecycleevents.IEditorInputChangedListene
import org.eclipse.papyrus.infra.core.lifecycleevents.ISaveAndDirtyService;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageMngr;
import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement;
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
@@ -54,7 +56,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.ISaveablePart;
@@ -64,7 +65,6 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.internal.navigator.NavigatorContentService;
import org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider;
import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
@@ -85,11 +85,22 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
*/
public class ModelExplorerView extends CommonNavigator implements IRevealSemanticElement, IEditingDomainProvider {
- /** The associated EditorPart */
- private IMultiDiagramEditor editorPart;
+ /** The associated EditorPart
+ * The View is associated to the ServicesRegistry rather than to an editor.
+ * */
+// private IMultiDiagramEditor editorPart;
+
+ /**
+ * The {@link ServicesRegistry} associated to the Editor. This view is associated to the
+ * ServicesRegistry rather than to the EditorPart.
+ */
+ private ServicesRegistry serviceRegistry;
/** The save aservice associated to the editor. */
private ISaveAndDirtyService saveAndDirtyService;
+
+ /** {@link IUndoContext} used to tag command in the commandStack. */
+ private IUndoContext undoContext;
/** editing domain used to read/write the model */
private TransactionalEditingDomain editingDomain;
@@ -144,11 +155,22 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
* The part associated to this ModelExplorer
*/
public ModelExplorerView(IMultiDiagramEditor part) {
- this.editorPart = part;
+
+ if( part == null) {
+ throw new IllegalArgumentException("A part should be provided.");
+ }
+
+ // Try to get the ServicesRegistry
+ serviceRegistry = part.getServicesRegistry();
+ if( serviceRegistry == null) {
+ throw new IllegalArgumentException("The part should have a ServiceRegistry.");
+ }
+
setLinkingEnabled(true);
try {
- this.saveAndDirtyService = editorPart.getServicesRegistry().getService(ISaveAndDirtyService.class);
+ saveAndDirtyService = serviceRegistry.getService(ISaveAndDirtyService.class);
+ undoContext = serviceRegistry.getService(IUndoContext.class);
} catch (ServiceException e) {
e.printStackTrace();
}
@@ -198,7 +220,14 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
SemanticFromModelExplorer semanticGetter = new SemanticFromModelExplorer();
List<Object> path = new ArrayList<Object>();
ITreeContentProvider contentProvider = (ITreeContentProvider)getCommonViewer().getContentProvider();
- IPageMngr iPageMngr = EditorUtils.getIPageMngr();
+// IPageMngr iPageMngr = EditorUtils.getIPageMngr();
+ IPageMngr iPageMngr;
+ try {
+ iPageMngr = ServiceUtils.getInstance().getIPageMngr(serviceRegistry);
+ } catch (ServiceException e) {
+ // This shouldn't happen.
+ return Collections.emptyList();
+ }
Object[] result = iPageMngr.allPages().toArray();
List<Object> editors = Arrays.asList(result);
@@ -344,15 +373,15 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
/**
* Hook the global undo/redi actions.
*/
- private void hookGlobalHistoryHandler(IViewSite site) {
- undoHandler = new UndoActionHandler(site, null);
- redoHandler = new RedoActionHandler(site, null);
-
- IActionBars actionBars = site.getActionBars();
-
- actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoHandler);
- actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoHandler);
- }
+// private void hookGlobalHistoryHandler(IViewSite site) {
+// undoHandler = new UndoActionHandler(site, null);
+// redoHandler = new RedoActionHandler(site, null);
+//
+// IActionBars actionBars = site.getActionBars();
+//
+// actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undoHandler);
+// actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoHandler);
+// }
/**
* {@link ResourceSetListener} to listen and react to changes in the
@@ -424,8 +453,8 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
@Override
protected Object getInitialInput() {
- if(editorPart != null) {
- return editorPart.getServicesRegistry();
+ if(serviceRegistry != null) {
+ return serviceRegistry;
} else {
return super.getInitialInput();
}
@@ -437,14 +466,13 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
*/
private void activate() {
- if(editorPart != null) {
try {
- this.editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(editorPart.getServicesRegistry());
+ this.editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(serviceRegistry);
// this.editingDomain = EditorUtils.getTransactionalEditingDomain(editorPart.getServicesRegistry());
// Set Viewer input if it already exist
if(getCommonViewer() != null) {
- getCommonViewer().setInput(editorPart.getServicesRegistry());
+ getCommonViewer().setInput(serviceRegistry);
}
editingDomain.addResourceSetListener(resourceSetListener);
} catch (ServiceException e) {
@@ -462,7 +490,6 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
// redoHandler.setContext(undoContext);
// redoHandler.update();
// }
- }
if(this.getCommonViewer() != null) {
refresh();
}
@@ -470,24 +497,12 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
}
/**
- * Get the undo context associated to the part.
- *
- * @param part
- * @return
- */
- private IUndoContext getUndoContext(IMultiDiagramEditor part) {
- return (IUndoContext)part.getAdapter(IUndoContext.class);
- }
-
- /**
* Deactivate the Model Explorer.
*/
private void deactivate() {
// deactivate global handler
- if(editorPart != null) {
if(Activator.log.isDebugEnabled()) {
- Activator.log.debug("deactivate " + editorPart.getTitle()); //$NON-NLS-1$
- }
+ Activator.log.debug("deactivate ModelExplorerView" ); //$NON-NLS-1$
// Stop Listenning to isDirty flag
saveAndDirtyService.removeInputChangedListener(editorInputChangedListener);
@@ -501,9 +516,9 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
}
- editorPart = null;
if(editingDomain != null) {
editingDomain.removeResourceSetListener(resourceSetListener);
+ editingDomain = null;
}
}
@@ -512,9 +527,33 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
*/
@Override
public void dispose() {
+
+ // Stop if we are already disposed
+ if( isDisposed() ) {
+ return;
+ }
+
deactivate();
+
+ saveAndDirtyService = null;
+ undoContext = null;
+ editingDomain = null;
+ serviceRegistry = null;
+
super.dispose();
+ // Clean up properties to help GC
+
+ }
+
+ /**
+ * Return true if the component is already disposed.
+ *
+ * @return
+ */
+ public boolean isDisposed() {
+ // use editorPart as flag
+ return saveAndDirtyService == null;
}
/**
@@ -547,19 +586,19 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
return getPropertySheetPage();
}
- if(IUndoContext.class.equals(adapter)) {
- // Return the IUndoContext of the currently selected editor.
- if(editorPart != null) {
- return editorPart.getAdapter(IUndoContext.class);
- }
-
- // Let the parent return the adapter.
+ if(IUndoContext.class == adapter) {
+ // Return the IUndoContext of associated model.
+ return undoContext;
}
if(ISaveablePart.class.equals(adapter)) {
return saveAndDirtyService;
}
+ if(ServicesRegistry.class == adapter) {
+ return serviceRegistry;
+ }
+
return super.getAdapter(adapter);
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/MultiViewPageBookView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/MultiViewPageBookView.java
index 838c8386cee..c74c7a09268 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/MultiViewPageBookView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/MultiViewPageBookView.java
@@ -85,7 +85,9 @@ public abstract class MultiViewPageBookView extends PageBookView {
*/
@Override
protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
- // Nothing to do
+
+ // Dispose the associated page.
+ pageRecord.page.dispose();
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/ViewPartPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/ViewPartPage.java
index 1a35a1be7f3..92b2ab2d6e0 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/ViewPartPage.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/core/ui/pagebookview/ViewPartPage.java
@@ -140,4 +140,15 @@ public abstract class ViewPartPage extends Page implements IAdaptable {
return null;
}
+ /**
+ * Dispose the page, and its associated viewer.
+ * @see org.eclipse.ui.part.Page#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ modelExplorer.dispose();
+ super.dispose();
+ modelExplorer = null;
+ }
}

Back to the top