Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-03-11 09:49:35 +0000
committercletavernie2013-03-11 09:49:35 +0000
commit8cd1c426af18794be64779e0948d8aa5d1d7b957 (patch)
tree4939fb3e16c7e27b8df88b0e3047d747bc420866
parentefae6fd7b1c5b39dfc129c1ad86b5562705c702f (diff)
downloadorg.eclipse.papyrus-8cd1c426af18794be64779e0948d8aa5d1d7b957.tar.gz
org.eclipse.papyrus-8cd1c426af18794be64779e0948d8aa5d1d7b957.tar.xz
org.eclipse.papyrus-8cd1c426af18794be64779e0948d8aa5d1d7b957.zip
401493: Closing and repopening Properties view causes NPE and renders the view unusable
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401493 402873: [Core] ServiceUtilsForActionHandler is deprecated and should not be used anymore https://bugs.eclipse.org/bugs/show_bug.cgi?id=402873
-rw-r--r--plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractCommandHandler.java95
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java7
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java11
3 files changed, 15 insertions, 98 deletions
diff --git a/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractCommandHandler.java b/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractCommandHandler.java
index 22eed69833a..f802bb377a2 100644
--- a/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractCommandHandler.java
+++ b/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer/src/org/eclipse/papyrus/uml/modelexplorer/handler/AbstractCommandHandler.java
@@ -14,9 +14,6 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.modelexplorer.handler;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -27,8 +24,7 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.facet.infra.browser.uicore.internal.model.LinkItem;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
-import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers;
import org.eclipse.papyrus.uml.modelexplorer.Activator;
import org.eclipse.papyrus.views.modelexplorer.CommandContext;
import org.eclipse.papyrus.views.modelexplorer.ICommandContext;
@@ -62,91 +58,6 @@ public abstract class AbstractCommandHandler extends AbstractHandler {
/**
* <pre>
- * Get the selected element, the first selected element if several are selected or null
- * if no selection or the selection is not an {@link EObject}.
- *
- * @return selected {@link EObject} or null
- * </pre>
- *
- * @deprecated
- */
- @Deprecated
- protected EObject getSelectedElement() {
- EObject eObject = null;
-
- // Get current selection
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- Object selection = (activeWorkbenchWindow != null) ? activeWorkbenchWindow.getSelectionService().getSelection() : null;
-
- // Treat non-null selected object (try to adapt and return EObject)
- if(selection != null) {
-
- // Get first element if the selection is an IStructuredSelection
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- selection = structuredSelection.getFirstElement();
- }
-
- // Treat non-null selected object (try to adapt and return EObject)
- if(selection instanceof IAdaptable) {
- selection = ((IAdaptable)selection).getAdapter(EObject.class);
- }
-
- Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(selection);
- if(businessObject instanceof EObject) {
- eObject = (EObject)businessObject;
- }
-
- }
- return eObject;
- }
-
- /**
- * <pre>
- * Parse current selection and extract the list of {@link EObject} from
- * this selection.
- *
- * This also tries to adapt selected element into {@link EObject}
- * (for example to get the {@link EObject} from a selection in the ModelExplorer).
- *
- * @return a list of currently selected {@link EObject}
- * </pre>
- *
- * @deprecated
- */
- @Deprecated
- protected List<EObject> getSelectedElements() {
-
- List<EObject> selectedEObjects = new ArrayList<EObject>();
-
- // Get current selection
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- Object selection = (activeWorkbenchWindow != null) ? activeWorkbenchWindow.getSelectionService().getSelection() : null;
-
- // Treat non-null selected object (try to adapt and return EObject)
- if(selection != null) {
-
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- for(Object current : structuredSelection.toArray()) {
- // Adapt current selection to EObject
- if(current instanceof IAdaptable) {
- selectedEObjects.add((EObject)((IAdaptable)current).getAdapter(EObject.class));
- }
- }
- } else { // Not a IStructuredSelection
- // Adapt current selection to EObject
- if(selection instanceof IAdaptable) {
- selectedEObjects.add((EObject)((IAdaptable)selection).getAdapter(EObject.class));
- }
- }
- }
-
- return selectedEObjects;
- }
-
- /**
- * <pre>
* Parse current selection and extract the command context (can be null).
*
* @return the command context based on current selection
@@ -219,10 +130,10 @@ public abstract class AbstractCommandHandler extends AbstractHandler {
try {
- ServiceUtilsForActionHandlers util = ServiceUtilsForActionHandlers.getInstance();
+ ServiceUtilsForHandlers util = ServiceUtilsForHandlers.getInstance();
creationcommand = getCommand();
- util.getTransactionalEditingDomain().getCommandStack().execute(creationcommand);
+ util.getTransactionalEditingDomain(event).getCommandStack().execute(creationcommand);
return creationcommand.getResult();
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 bb87ea9fa8e..f4344cd4ab4 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
@@ -115,7 +115,7 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
* The {@link ServicesRegistry} associated to the Editor. This view is associated to the
* ServicesRegistry rather than to the EditorPart.
*/
- private ServicesRegistry serviceRegistry;
+ private final ServicesRegistry serviceRegistry;
/** The save aservice associated to the editor. */
private ISaveAndDirtyService saveAndDirtyService;
@@ -368,7 +368,7 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
super.createPartControl(aParent);
getCommonViewer().setSorter(null);
((CustomCommonViewer)getCommonViewer()).getDropAdapter().setFeedbackEnabled(true);
- getCommonViewer().addDoubleClickListener(new DoubleClickListener());
+ getCommonViewer().addDoubleClickListener(new DoubleClickListener(serviceRegistry));
Tree tree = getCommonViewer().getTree();
Activator.getDefault().getCustomizationManager().installCustomPainter(tree);
@@ -583,7 +583,6 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
saveAndDirtyService = null;
undoContext = null;
editingDomain = null;
- serviceRegistry = null;
super.dispose();
@@ -611,7 +610,7 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
final IMultiDiagramEditor multiDiagramEditor = ServiceUtils.getInstance().getService(IMultiDiagramEditor.class, serviceRegistry);
if(multiDiagramEditor != null) {
- if(propertySheetPage == null) {
+ if(propertySheetPage == null || propertySheetPage.getControl() == null || propertySheetPage.getControl().isDisposed()) {
if(multiDiagramEditor instanceof ITabbedPropertySheetPageContributor) {
ITabbedPropertySheetPageContributor contributor = (ITabbedPropertySheetPageContributor)multiDiagramEditor;
this.propertySheetPage = new TabbedPropertySheetPage(contributor);
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java
index d3456e50981..fca88c9c006 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/listener/DoubleClickListener.java
@@ -26,7 +26,8 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForSelection;
import org.eclipse.papyrus.views.modelexplorer.Activator;
@@ -38,6 +39,12 @@ import org.eclipse.papyrus.views.modelexplorer.Messages;
*/
public class DoubleClickListener implements IDoubleClickListener {
+ private final ServicesRegistry servicesRegistry;
+
+ public DoubleClickListener(ServicesRegistry servicesRegistry) {
+ this.servicesRegistry = servicesRegistry;
+ }
+
/**
*
* @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
@@ -48,7 +55,7 @@ public class DoubleClickListener implements IDoubleClickListener {
final IPageManager pageManager;
//get the page Manager
try {
- pageManager = ServiceUtilsForActionHandlers.getInstance().getIPageManager();
+ pageManager = ServiceUtils.getInstance().getIPageManager(servicesRegistry);
} catch (Exception e) {
Activator.log.error(Messages.DoubleClickListener_Error_NoLoadManagerToOpen, e);
return;

Back to the top