diff options
author | Christian W. Damus | 2014-12-09 19:42:17 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-12-09 19:42:17 +0000 |
commit | 3e12822539a86ddeb420c5c72deaf62b20bc5644 (patch) | |
tree | a9c62df83fef3399a206d0632d71f588ff1fe11f | |
parent | c8845c7a6a656723119ff2020a301e6b21c3b6aa (diff) | |
download | org.eclipse.papyrus-3e12822539a86ddeb420c5c72deaf62b20bc5644.tar.gz org.eclipse.papyrus-3e12822539a86ddeb420c5c72deaf62b20bc5644.tar.xz org.eclipse.papyrus-3e12822539a86ddeb420c5c72deaf62b20bc5644.zip |
454536: [Properties View] Impossible to display the properties pages after reopening of a project
https://bugs.eclipse.org/bugs/show_bug.cgi?id=454536
Don't delegate provision of property pages to the nested Model Explorer pages that the Properties view cannot track.
Implement a new dynamic undo-context delegation scheme to maintain the memory-leak fix for which the property pages were originally delegated.
4 files changed, 94 insertions, 57 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/operation/DelegatingUndoContext.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/operation/DelegatingUndoContext.java index bb4a632bd2a..561e98bc68f 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/operation/DelegatingUndoContext.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/operation/DelegatingUndoContext.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 CEA LIST and others. + * Copyright (c) 2014 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * CEA LIST - Initial API and implementation + * Christian W. Damus - bug 454536 * *****************************************************************************/ @@ -15,6 +16,9 @@ package org.eclipse.papyrus.infra.core.operation; import org.eclipse.core.commands.operations.IUndoContext; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; + /** * An undo context that dynamically delegates to another. * Use this with caution: it is important that the semantics of an undo context @@ -33,11 +37,13 @@ public class DelegatingUndoContext implements IUndoContext { @Override public String getLabel() { + IUndoContext delegate = getDelegate(); return (delegate == null) ? "" : delegate.getLabel(); } @Override public boolean matches(IUndoContext context) { + IUndoContext delegate = getDelegate(); return (delegate == null) ? false : delegate.matches(context); } @@ -48,4 +54,37 @@ public class DelegatingUndoContext implements IUndoContext { public IUndoContext getDelegate() { return delegate; } + + // + // Nested types + // + + /** + * A specialized delegating undo context that dynamically computes its delegate. + */ + public static class Dynamic extends DelegatingUndoContext { + private Supplier<IUndoContext> delegateSupplier; + + /** + * Initializes me with a supplier that dynamically determines my undo-context delegate. + * + * @param delegateSupplier + * my dynamic delegate supplier + */ + public Dynamic(Supplier<IUndoContext> delegateSupplier) { + super(); + + this.delegateSupplier = delegateSupplier; + } + + @Override + public IUndoContext getDelegate() { + return delegateSupplier.get(); + } + + @Override + public void setDelegate(IUndoContext delegate) { + delegateSupplier = Suppliers.ofInstance(delegate); + } + } }
\ No newline at end of file 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 819c8c6c5cf..d9eafdb9713 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,7 +1,6 @@ /*****************************************************************************
* Copyright (c) 2010, 2014 LIFL, CEA LIST, Christian W. Damus, 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
@@ -11,6 +10,7 @@ * Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 434635
* Christian W. Damus - bug 450536
+ * Christian W. Damus - bug 454536
*
*****************************************************************************/
@@ -22,8 +22,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
/**
@@ -36,25 +34,8 @@ public class ModelExplorerPage extends ViewPartPage { private SharedModelExplorerState state;
- private final ITabbedPropertySheetPageContributor propertySheetContributor;
- private IPropertySheetPage propertySheet;
-
- public ModelExplorerPage(ITabbedPropertySheetPageContributor propertySheetContributor) {
+ public ModelExplorerPage() {
super();
-
- this.propertySheetContributor = propertySheetContributor;
- }
-
- @Override
- public void dispose() {
- try {
- if (propertySheet != null) {
- propertySheet.dispose();
- }
- } finally {
- propertySheet = null;
- super.dispose();
- }
}
/**
@@ -99,24 +80,4 @@ public class ModelExplorerPage extends ViewPartPage { void setSharedState(SharedModelExplorerState state) {
this.state = state;
}
-
- @Override
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- Object result;
-
- if (adapter == IPropertySheetPage.class) {
- result = getPropertySheetPage();
- } else {
- result = super.getAdapter(adapter);
- }
-
- return result;
- }
-
- private IPropertySheetPage getPropertySheetPage() {
- if (propertySheet == null) {
- propertySheet = new ModelExplorerPropertySheetPage(propertySheetContributor);
- }
- return propertySheet;
- }
}
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 0e8b907ba4e..d73d5150db7 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,7 +1,6 @@ /***************************************************************************** * Copyright (c) 2010, 2014 LIFL, CEA LIST, Christian W. Damus, 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 @@ -14,11 +13,15 @@ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 431117 * Christian W. Damus - bug 450536 * Christian W. Damus - bug 451683 + * Christian W. Damus - bug 454536 * *****************************************************************************/ package org.eclipse.papyrus.views.modelexplorer; +import java.util.LinkedList; +import java.util.List; + import org.eclipse.core.resources.IMarker; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; @@ -34,6 +37,7 @@ 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; import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; import com.google.common.collect.Lists; @@ -52,6 +56,9 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements private final SharedModelExplorerState state = new SharedModelExplorerState(); + /** The property sheet pages. */ + private List<IPropertySheetPage> propertiesSheetPages = new LinkedList<IPropertySheetPage>(); + @Override public void init(IViewSite site, IMemento memento) throws PartInitException { super.init(site, memento); @@ -66,7 +73,7 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements // part is of type IMultiDiagramEditor (because of isImportant() ) - ModelExplorerPage page = new ModelExplorerPage(this); + ModelExplorerPage page = new ModelExplorerPage(); page.setSharedState(state); // Init the page, and so the View @@ -75,9 +82,26 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements return new PageRec(part, page); } + /** + * Retrieves the {@link IPropertySheetPage} that his Model Explorer uses. + * + * @return + */ + private IPropertySheetPage getPropertySheetPage() { + IPropertySheetPage propertySheetPage = new ModelExplorerPropertySheetPage(this); + propertiesSheetPages.add(propertySheetPage); + return propertySheetPage; + } + @Override public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + if (IPropertySheetPage.class == adapter) { + // Do not test if tabbedPropertySheetPage is null before calling new + // this is managed by Eclipse which only call current method when necessary + return getPropertySheetPage(); + } + if (adapter == ITreeViewerSorting.class) { return new DefaultTreeViewerSorting() { @@ -142,4 +166,13 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements super.partClosed(part); } + + @Override + public void dispose() { + for (IPropertySheetPage page : propertiesSheetPages) { + page.dispose(); + } + propertiesSheetPages.clear(); + super.dispose(); + } } diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java index 2913aefe76b..6b64ed8f2e2 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPropertySheetPage.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 CEA LIST and others. + * Copyright (c) 2014 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + * Christian W. Damus - bug 454536 * *****************************************************************************/ @@ -20,9 +21,10 @@ import org.eclipse.ui.IActionBars; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.operations.RedoActionHandler; import org.eclipse.ui.operations.UndoActionHandler; -import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; +import com.google.common.base.Supplier; + /** * Specific PropertySheetPage for Model Explorer view to contribute to Undo/Redo Edit menu. * @@ -30,6 +32,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; * */ class ModelExplorerPropertySheetPage extends TabbedPropertySheetPage { + private final ModelExplorerPageBookView modelExplorer; /** The undo. */ private UndoActionHandler undo = null; @@ -43,11 +46,13 @@ class ModelExplorerPropertySheetPage extends TabbedPropertySheetPage { /** * Constructor. * - * @param tabbedPropertySheetPageContributor - * the tabbed property sheet page contributor + * @param modelExplorer + * the Model Explorer view that owns me */ - public ModelExplorerPropertySheetPage(ITabbedPropertySheetPageContributor tabbedPropertySheetPageContributor) { - super(tabbedPropertySheetPageContributor); + public ModelExplorerPropertySheetPage(ModelExplorerPageBookView modelExplorer) { + super(modelExplorer); + + this.modelExplorer = modelExplorer; } /** @@ -59,8 +64,12 @@ class ModelExplorerPropertySheetPage extends TabbedPropertySheetPage { public void setActionBars(IActionBars actionBars) { super.setActionBars(actionBars); - undoContext = new DelegatingUndoContext(); - undoContext.setDelegate(AdapterUtils.adapt(getSite().getPage().getActivePart(), IUndoContext.class, null)); + undoContext = new DelegatingUndoContext.Dynamic(new Supplier<IUndoContext>() { + + public IUndoContext get() { + return AdapterUtils.adapt(modelExplorer, IUndoContext.class, null); + } + }); undo = new UndoActionHandler(getSite().getPage().getActivePart().getSite(), undoContext); redo = new RedoActionHandler(getSite().getPage().getActivePart().getSite(), undoContext); @@ -85,9 +94,4 @@ class ModelExplorerPropertySheetPage extends TabbedPropertySheetPage { super.dispose(); } - - - - - } |