summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2013-01-10 15:37:10 (EST)
committerKaren Butzke2013-01-10 15:37:10 (EST)
commitdfa236dcc4a38ae158b0b52e92a9a80aa77f581d (patch)
tree14ac1fbf7f111280774ca8c7bba1e404e9162c07
parentafff18832f37a8a826a0678397d96a9a83c79517 (diff)
downloadwebtools.dali-dfa236dcc4a38ae158b0b52e92a9a80aa77f581d.zip
webtools.dali-dfa236dcc4a38ae158b0b52e92a9a80aa77f581d.tar.gz
webtools.dali-dfa236dcc4a38ae158b0b52e92a9a80aa77f581d.tar.bz2
Generate Entities not from the Package Explorer (an IJavaProject selected). This functionality was lost in the conversion to the handler framework. Deleted old *Action classes
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateDDLAction.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateEntitiesAction.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java156
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java91
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java242
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/handlers/GenerateEntitiesHandler.java21
6 files changed, 17 insertions, 546 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateDDLAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateDDLAction.java
deleted file mode 100644
index f6aca3b..0000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateDDLAction.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.actions;
-
-import org.eclipse.jpt.jpa.core.JpaProject;
-
-/**
- * GenerateDDLAction
- */
-public class GenerateDDLAction extends ProjectAction {
-
- public GenerateDDLAction() {
- super();
- }
-
- @Override
- protected void execute(JpaProject project) {
- this.getJpaPlatformUi(project).generateDDL(project, this.getCurrentSelection());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateEntitiesAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateEntitiesAction.java
deleted file mode 100644
index 3836338..0000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/GenerateEntitiesAction.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2007, 2009 Oracle. 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:
-* Oracle - initial API and implementation
-*******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.actions;
-
-import org.eclipse.jpt.jpa.core.JpaProject;
-
-/**
- * GenerateEntitiesAction
- */
-public class GenerateEntitiesAction extends ProjectAction {
- public GenerateEntitiesAction() {
- super();
- }
-
- @Override
- protected void execute(JpaProject project) {
- this.getJpaPlatformUi(project).generateEntities(project, this.getCurrentSelection());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java
deleted file mode 100644
index 9a9a08b..0000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2010, 2012 Oracle. 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:
-* Oracle - initial API and implementation
-*******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.actions;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.wizards.JpaMakePersistentWizard;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-public class MakePersistentAction
- implements IObjectActionDelegate
-{
- private ISelection selection;
-
- public MakePersistentAction() {
- super();
- }
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- // do nothing
- }
-
- public void selectionChanged(IAction action, ISelection sel) {
- this.selection = sel;
- }
-
- public void run(IAction action) {
- for (Map.Entry<IProject, Set<IType>> entry : this.buildSelectedTypes().entrySet()) {
- IProject project = entry.getKey();
- Set<IType> types = entry.getValue();
- JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
- if (jpaProject != null) {
- // open the wizard once for each selected project
- JpaMakePersistentWizard wizard = new JpaMakePersistentWizard(jpaProject, types);
- WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard);
- dialog.create();
- dialog.open();
- }
- }
- }
-
- /**
- * Return a map containing lists of types, keyed by project.
- * <p>
- * The action is contributed for:<ul>
- * <li>{@link IType}
- * <li>{@link ICompilationUnit}
- * <li>{@link IPackageFragment}
- * <li>{@link IPackageFragmentRoot} that is a source folder
- * </ul>
- */
- private Map<IProject, Set<IType>> buildSelectedTypes() {
- if ( ! (this.selection instanceof StructuredSelection)) {
- return Collections.emptyMap();
- }
- HashMap<IProject, Set<IType>> types = new HashMap<IProject, Set<IType>>();
- for (Object sel : ((StructuredSelection) this.selection).toList()) {
- switch (((IJavaElement) sel).getElementType()) {
- case IJavaElement.PACKAGE_FRAGMENT_ROOT :
- this.addSelectedTypes((IPackageFragmentRoot) sel, types);
- break;
- case IJavaElement.PACKAGE_FRAGMENT :
- this.addSelectedTypes((IPackageFragment) sel, types);
- break;
- case IJavaElement.COMPILATION_UNIT :
- this.addSelectedTypes((ICompilationUnit) sel, types);
- break;
- case IJavaElement.TYPE :
- this.addSelectedType((IType) sel, types);
- break;
- default :
- break;
- }
- }
- return types;
- }
-
- private void addSelectedTypes(IPackageFragmentRoot packageFragmentRoot, Map<IProject, Set<IType>> types) {
- for (IJavaElement pkgFragment : this.getPackageFragments(packageFragmentRoot)) {
- this.addSelectedTypes((IPackageFragment) pkgFragment, types);
- }
- }
-
- private IJavaElement[] getPackageFragments(IPackageFragmentRoot packageFragmentRoot) {
- try {
- return packageFragmentRoot.getChildren();
- } catch (JavaModelException ex) {
- JptJpaUiPlugin.instance().logError(ex);
- return EMPTY_JAVA_ELEMENT_ARRAY;
- }
- }
- private static final IJavaElement[] EMPTY_JAVA_ELEMENT_ARRAY = new IJavaElement[0];
-
- private void addSelectedTypes(IPackageFragment packageFragment, Map<IProject, Set<IType>> types) {
- for (ICompilationUnit compUnit : this.getCompilationUnits(packageFragment)) {
- this.addSelectedTypes(compUnit, types);
- }
- }
-
- private ICompilationUnit[] getCompilationUnits(IPackageFragment packageFragment) {
- try {
- return packageFragment.getCompilationUnits();
- } catch (JavaModelException ex) {
- JptJpaUiPlugin.instance().logError(ex);
- return EMPTY_COMPILATION_UNIT_ARRAY;
- }
- }
- private static final ICompilationUnit[] EMPTY_COMPILATION_UNIT_ARRAY = new ICompilationUnit[0];
-
- private void addSelectedTypes(ICompilationUnit compilationUnit, Map<IProject, Set<IType>> types) {
- IType primaryType = compilationUnit.findPrimaryType();
- if (primaryType != null) {
- this.addSelectedType(primaryType, types);
- }
- }
-
- private void addSelectedType(IType primaryType, Map<IProject, Set<IType>> typesMap) {
- IProject project = primaryType.getJavaProject().getProject();
- Set<IType> types = typesMap.get(project);
- if (types == null) {
- types = new HashSet<IType>();
- typesMap.put(project, types);
- }
- types.add(primaryType);
- }
-
- private Shell getCurrentShell() {
- return Display.getCurrent().getActiveShell();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java
deleted file mode 100644
index 12ba0fd..0000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2012 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.actions;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-/**
- * Override any of the #execute() methods.
- */
-public abstract class ProjectAction
- implements IObjectActionDelegate
-{
- private ISelection currentSelection;
-
-
- public ProjectAction() {
- super();
- }
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- // do nothing
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- this.currentSelection = selection;
- }
-
- protected IStructuredSelection getCurrentSelection() {
- if (this.currentSelection instanceof IStructuredSelection) {
- return (IStructuredSelection) this.currentSelection;
- }
- return null;
- }
-
- public void run(IAction action) {
- if (this.currentSelection instanceof IStructuredSelection) {
- for (Object each : ((IStructuredSelection) this.currentSelection).toArray()) {
- this.execute(each);
- }
- }
- }
-
- protected void execute(Object selection) {
- IProject project = this.projectFromSelection(selection);
- if (project != null) {
- this.execute(project);
- }
- }
-
- protected IProject projectFromSelection(Object selection) {
- if (selection instanceof IProject) {
- return (IProject) selection;
- }
- if (selection instanceof IJavaProject) {
- return ((IJavaProject) selection).getProject();
- }
- return null;
- }
-
- protected JpaPlatformUi getJpaPlatformUi(JpaProject project) {
- return (JpaPlatformUi) project.getJpaPlatform().getAdapter(JpaPlatformUi.class);
- }
-
- protected void execute(IProject project) {
- JpaProject jpaProject = this.getJpaProject(project);
- if (jpaProject != null) {
- this.execute(jpaProject);
- }
- }
-
- protected JpaProject getJpaProject(IProject project) {
- return (JpaProject) project.getAdapter(JpaProject.class);
- }
-
- protected abstract void execute(JpaProject project);
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java
deleted file mode 100644
index 90ecd1c..0000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. 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:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.actions;
-
-import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jpt.common.core.resource.xml.JptXmlResource;
-import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor;
-import org.eclipse.jpt.common.utility.command.Command;
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JpaProjectManager;
-import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-
-/**
- * This action is contributed for:<ul>
- * <li>any {@link IFile} named <code>"persistence.xml"</code>
- * <li>any instance of {@link PersistenceXml}
- * </ul>
- */
-public class SynchronizeClassesAction
- implements IObjectActionDelegate
-{
- private IFile persistenceXmlFile;
-
-
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- // no-op for now
- }
-
- /**
- * Determine whether we can calculate the <code>persistence.xml</code> file
- * from the current selection and save it for use in {@link #run(IAction)}.
- */
- public void selectionChanged(IAction action, ISelection selection) {
- // There is always only one element in the actual selection.
- Object sel = ((StructuredSelection) selection).getFirstElement();
- this.persistenceXmlFile = this.buildPersistenceXmlFile(sel);
- }
-
- private IFile buildPersistenceXmlFile(Object selection) {
- if (selection instanceof IFile) {
- return (IFile) selection;
- }
- if (selection instanceof PersistenceXml) {
- return (IFile) ((PersistenceXml) selection).getResource();
- }
- return null;
- }
-
- public void run(IAction action) {
- try {
- IRunnableWithProgress runnable = new SyncRunnable(this.persistenceXmlFile);
- this.buildProgressMonitorDialog().run(true, true, runnable); // true => fork; true => cancellable
- } catch (InvocationTargetException ex) {
- JptJpaUiPlugin.instance().logError(ex);
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- JptJpaUiPlugin.instance().logError(ex);
- }
- }
-
- private ProgressMonitorDialog buildProgressMonitorDialog() {
- return new ProgressMonitorDialog(null);
- }
-
-
- // ********** sync runnable **********
-
- /**
- * This is dispatched to the progress monitor dialog.
- */
- /* CU private */ static class SyncRunnable
- implements IRunnableWithProgress
- {
- private IFile persistenceXmlFile;
-
- SyncRunnable(IFile persistenceXmlFile) {
- super();
- this.persistenceXmlFile = persistenceXmlFile;
- }
-
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- try {
- this.run_(monitor);
- } catch (CoreException ex) {
- throw new InvocationTargetException(ex);
- }
- }
-
- private void run_(IProgressMonitor monitor) throws CoreException {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- // lock the entire project, since we might modify the metamodel classes
- ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.persistenceXmlFile.getProject());
- workspace.run(
- new SyncWorkspaceRunnable(this.persistenceXmlFile),
- rule,
- IWorkspace.AVOID_UPDATE,
- monitor
- );
- }
- }
-
-
- // ********** sync workspace runnable **********
-
- /**
- * This is dispatched to the Eclipse workspace.
- */
- /* CU private */ static class SyncWorkspaceRunnable
- implements IWorkspaceRunnable
- {
- private IFile persistenceXmlFile;
-
- SyncWorkspaceRunnable(IFile persistenceXmlFile) {
- super();
- this.persistenceXmlFile = persistenceXmlFile;
- }
-
- public void run(IProgressMonitor monitor) throws CoreException {
- if (monitor.isCanceled()) {
- return;
- }
- SubMonitor sm = SubMonitor.convert(monitor, JptUiMessages.SynchronizingClasses_TaskName, 20);
-
- JpaProject jpaProject = this.getJpaProject();
- if (jpaProject == null) {
- return;
- }
-
- JptXmlResource resource = jpaProject.getPersistenceXmlResource();
- if (resource == null) {
- // the resource can be null if the persistence.xml file has an invalid content type
- return;
- }
-
- if (sm.isCanceled()) {
- return;
- }
- sm.worked(1);
-
- PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
- if (persistenceXml == null) {
- return; // unlikely...
- }
-
- Persistence persistence = persistenceXml.getRoot();
- if (persistence == null) {
- return; // unlikely...
- }
-
- PersistenceUnit persistenceUnit = (persistence.getPersistenceUnitsSize() == 0) ?
- persistence.addPersistenceUnit() :
- persistence.getPersistenceUnit(0);
- if (sm.isCanceled()) {
- return;
- }
- sm.worked(1);
-
- Command syncCommand = new SyncCommand(persistenceUnit, sm.newChild(17));
- try {
- this.getJpaProjectManager().execute(syncCommand, SynchronousUiCommandExecutor.instance());
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt(); // skip save?
- throw new RuntimeException(ex);
- }
-
- resource.save();
- sm.worked(1);
- }
-
- private JpaProjectManager getJpaProjectManager() {
- return (JpaProjectManager) this.getWorkspace().getAdapter(JpaProjectManager.class);
- }
-
- private IProject getProject() {
- return this.persistenceXmlFile.getProject();
- }
-
- private JpaProject getJpaProject() {
- return (JpaProject) this.getProject().getAdapter(JpaProject.class);
- }
-
- private IWorkspace getWorkspace() {
- return this.persistenceXmlFile.getWorkspace();
- }
- }
-
-
- // ********** sync command **********
-
- /**
- * This is dispatched to the JPA project manager.
- */
- /* CU private */ static class SyncCommand
- implements Command
- {
- private final PersistenceUnit persistenceUnit;
- private final IProgressMonitor monitor;
-
- SyncCommand(PersistenceUnit persistenceUnit, IProgressMonitor monitor) {
- super();
- this.persistenceUnit = persistenceUnit;
- this.monitor = monitor;
- }
-
- public void execute() {
- this.persistenceUnit.synchronizeClasses(this.monitor);
- }
-
- @Override
- public String toString() {
- return ObjectTools.toString(this, this.persistenceUnit);
- }
- }
-}
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 8e46c02..e7403e4 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
@@ -12,6 +12,8 @@ package org.eclipse.jpt.jpa.ui.internal.handlers;
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.jdt.core.IJavaProject;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
@@ -30,10 +32,10 @@ public class GenerateEntitiesHandler extends AbstractHandler
if (selection instanceof IStructuredSelection) {
Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
- jpaProject = this.adaptSelection(selectedObject);
+ jpaProject = this.jpaProjectFromSelection(selectedObject);
}
if (jpaProject != null) {
- this.generateEntities(jpaProject, (IStructuredSelection)selection);
+ this.generateEntities(jpaProject, (IStructuredSelection) selection);
}
return null;
}
@@ -42,8 +44,19 @@ public class GenerateEntitiesHandler extends AbstractHandler
this.getJpaPlatformUi(project).generateEntities(project, selection);
}
- private JpaProject adaptSelection(Object selectedObject) {
- return PlatformTools.getAdapter(selectedObject, JpaProject.class);
+ 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);
+ return project == null ? null : PlatformTools.getAdapter(project, JpaProject.class);
}
private JpaPlatformUi getJpaPlatformUi(JpaProject project) {