Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-03-28 05:07:24 -0400
committerCamille Letavernier2014-03-28 05:07:24 -0400
commitea02f32388d5c2450fbab1d14c5081dc34321f73 (patch)
treeade6a0337b7d16f4c24f25c5115ce3507e2cf7ff /plugins
parent4f1af28df69e9ba9a6181f719367e8114cfface7 (diff)
downloadorg.eclipse.papyrus-ea02f32388d5c2450fbab1d14c5081dc34321f73.tar.gz
org.eclipse.papyrus-ea02f32388d5c2450fbab1d14c5081dc34321f73.tar.xz
org.eclipse.papyrus-ea02f32388d5c2450fbab1d14c5081dc34321f73.zip
431418: NPE in ServiceUtilsForActionHandlers.getServiceRegistry() again
https://bugs.eclipse.org/bugs/show_bug.cgi?id=431418
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java40
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/WorkbenchPartHelper.java30
2 files changed, 42 insertions, 28 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java
index c5c582f3aaf..4a83992a32c 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/ServiceUtilsForActionHandlers.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2010 LIFL & CEA LIST.
*
- *
+ *
* 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
@@ -15,6 +15,7 @@
package org.eclipse.papyrus.infra.core.utils;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.lifecycleevents.ILifeCycleEventsProvider;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
@@ -23,8 +24,8 @@ import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServiceNotFoundException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.tools.util.WorkbenchPartHelper;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
/**
* Set of utility methods for accessing core Services. This class provide
@@ -34,9 +35,9 @@ import org.eclipse.ui.PlatformUI;
* All methods from this class rely on the Eclipse Active Editor, which should
* be an instance of {@link IMultiDiagramEditor}. If this is not the case,
* methods throw an exception {@link ServiceException}.
- *
+ *
* @author cedric dumoulin
- *
+ *
* @deprecated 0.10: Use org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers instead
*/
@Deprecated
@@ -50,7 +51,7 @@ public class ServiceUtilsForActionHandlers {
/**
* Get the singleton instance of the class.
- *
+ *
* @return
*/
public static final ServiceUtilsForActionHandlers getInstance() {
@@ -59,33 +60,26 @@ public class ServiceUtilsForActionHandlers {
/**
* Get the service registry from the specified parameter.
- *
+ *
* @param from
* @return
*/
public ServicesRegistry getServiceRegistry() throws ServiceException {
-
- IEditorPart editor;
- try {
- editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ IEditorPart editor = WorkbenchPartHelper.getCurrentActiveEditorPart();
+ if(editor != null) {
ServicesRegistry serviceRegistry = (ServicesRegistry)editor.getAdapter(ServicesRegistry.class);
if(serviceRegistry != null) {
return serviceRegistry;
}
- } catch (NullPointerException e) {
- // Can't get the active editor
- throw new ServiceNotFoundException("Can't get the current Eclipse Active Editor. No ServiceRegistry found.");
}
-
// Not found
throw new ServiceNotFoundException("Can't get the ServiceRegistry from current Eclipse Active Editor");
-
}
/**
* Gets the {@link TransactionalEditingDomain} registered in the {@link ServicesRegistry}.
- *
+ *
* @return
* @throws ServiceException
* If an error occurs while getting the requested service.
@@ -96,11 +90,11 @@ public class ServiceUtilsForActionHandlers {
/**
* Gets the {@link IPageMngr} registered in the {@link ServicesRegistry}.
- *
+ *
* @return
* @throws ServiceException
* If an error occurs while getting the requested service.
- *
+ *
* @deprecated Use {@link #getIPageManager} instead
*/
@Deprecated
@@ -110,7 +104,7 @@ public class ServiceUtilsForActionHandlers {
/**
* Gets the {@link IPageManager} registered in the {@link ServicesRegistry}.
- *
+ *
* @return
* @throws ServiceException
* If an error occurs while getting the requested service.
@@ -121,7 +115,7 @@ public class ServiceUtilsForActionHandlers {
/**
* Gets the {@link IPageMngr} registered in the {@link ServicesRegistry}.
- *
+ *
* @return
* @throws ServiceException
* If an error occurs while getting the requested service.
@@ -132,7 +126,7 @@ public class ServiceUtilsForActionHandlers {
/**
* Gets the {@link ILifeCycleEventsProvider} registered in the {@link ServicesRegistry}.
- *
+ *
* @param from
* @return
* @throws ServiceException
@@ -144,7 +138,7 @@ public class ServiceUtilsForActionHandlers {
/**
* Gets the {@link ISashWindowsContainer} registered in the {@link ServicesRegistry}.
- *
+ *
* @param from
* @return
* @throws ServiceException
@@ -156,7 +150,7 @@ public class ServiceUtilsForActionHandlers {
/**
* Gets the {@link IEditorPart} of the currently nested active editor.
- *
+ *
* @param from
* @return
* @throws ServiceException
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/WorkbenchPartHelper.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/WorkbenchPartHelper.java
index 9b1bde932e9..81c7fa66a41 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/WorkbenchPartHelper.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/WorkbenchPartHelper.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2012 CEA LIST.
*
- *
+ *
* 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
@@ -13,6 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.tools.util;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
@@ -20,9 +21,9 @@ import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
- *
+ *
* a helper for the Eclipse workbench part
- *
+ *
*/
public class WorkbenchPartHelper {
@@ -31,9 +32,9 @@ public class WorkbenchPartHelper {
}
/**
- *
+ *
* @return
- * the current editor or <code>null</code> if not found
+ * the current IWorkbenchPart or <code>null</code> if not found
*/
public static final IWorkbenchPart getCurrentActiveWorkbenchPart() {
final IWorkbench workbench = PlatformUI.getWorkbench();
@@ -48,4 +49,23 @@ public class WorkbenchPartHelper {
}
return null;
}
+
+ /**
+ *
+ * @return
+ * the current IEditorPart or <code>null</code> if not found
+ */
+ public static final IEditorPart getCurrentActiveEditorPart() {
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ if(workbench != null) {
+ final IWorkbenchWindow activeWorkbench = workbench.getActiveWorkbenchWindow();
+ if(activeWorkbench != null) {
+ final IWorkbenchPage activePage = activeWorkbench.getActivePage();
+ if(activePage != null) {
+ return activePage.getActiveEditor();
+ }
+ }
+ }
+ return null;
+ }
}

Back to the top