409762 - Table gen does not work for Package Explorer
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java
index fb28512..563b94c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateDDLHandler.java
@@ -12,6 +12,7 @@
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
@@ -46,7 +47,8 @@
 	}
 
 	private JpaProject adaptSelection(Object selectedObject) {
-		return PlatformTools.getAdapter(selectedObject, JpaProject.class);
+		IProject project = PlatformTools.getAdapter(selectedObject, IProject.class);
+		return project == null ? null : PlatformTools.getAdapter(project, JpaProject.class);
 	}
 
 	private JpaPlatformUi getJpaPlatformUi(JpaProject project) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java
index 0a81ef4..770829d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java
@@ -13,7 +13,6 @@
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
@@ -47,18 +46,8 @@
 		}
 	}
 
-	protected IProject projectFromSelection(Object selection) {
-		if (selection instanceof IProject) { //IProject when selecting in the Project Explorer
-			return (IProject) selection;
-		}
-		if (selection instanceof IJavaProject) { //IJavaProject when selecting in the Package Explorer
-			return ((IJavaProject) selection).getProject();
-		}
-		return null;
-	}
-
 	private JpaProject jpaProjectFromSelection(Object selectedObject) {
-		IProject project = this.projectFromSelection(selectedObject);
+		IProject project = PlatformTools.getAdapter(selectedObject, IProject.class);
 		return project == null ? null : PlatformTools.getAdapter(project, JpaProject.class);
 	}