Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-10-04 17:28:19 -0400
committerkmoore2010-10-04 17:28:19 -0400
commit38e9d885feb5f0cfff83bcdda33f40a8e278f6ca (patch)
tree61bd87b15c44b2e362fcda1fbdb03170927cee4d
parent0f5dde45230dac5926f4e9ded52948784ab2a43e (diff)
downloadwebtools.dali-38e9d885feb5f0cfff83bcdda33f40a8e278f6ca.tar.gz
webtools.dali-38e9d885feb5f0cfff83bcdda33f40a8e278f6ca.tar.xz
webtools.dali-38e9d885feb5f0cfff83bcdda33f40a8e278f6ca.zip
182849 - Add multi-select right-click menu to Java class selection to make an Entity
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/plugin.properties8
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/plugin.xml39
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties22
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MakePersistentAction.java142
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizard.java78
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizardPage.java597
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java82
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java69
9 files changed, 972 insertions, 76 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/plugin.properties b/jpa/plugins/org.eclipse.jpt.ui/plugin.properties
index 800439e8f1..33f99933b5 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.ui/plugin.properties
@@ -38,23 +38,23 @@ newJpaEntityFromTableWizardDesc = Create JPA Entities from database tables
upgradeToLatestVersion = Upgrade Document Version
jpaStructureViewCommandCategory = JPA Structure View
-addPersistentClass = Add Class ...
+addPersistentClass = Add Class...
removePersistentClass = Remove Class
addPersistentAttributeToXml = Add Attribute to XML
-addPersistentAttributeToXmlAndMap = Add Attribute to XML and Map ...
+addPersistentAttributeToXmlAndMap = Add Attribute to XML and Map...
removePersistentAttributeFromXml = Remove Attribute from XML
mapAs=Map As
mapAsMnemonic=M
mapAsParameterName=mapping key
mapAsSpecifiedMappingParameterName=specified mapping key
mapAsDefaultMappingParameterName=default mapping key
-convertJavaProjectToJpaCommandName=Convert to JPA Project ...
+convertJavaProjectToJpaCommandName=Convert to JPA Project...
jpaMenuName = JPA Tools
generateEntities = Generate Entities from Tables...
generateDDL = Generate Tables from Entities...
synchronizeClasses = Synchronize Class List
-
+makePersistent = Make Persistent...
persistenceEditor=Persistence XML Editor
jpaProblemSeveritiesPageName=Errors/Warnings
diff --git a/jpa/plugins/org.eclipse.jpt.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.ui/plugin.xml
index cad9ef928a..3a91871fdc 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.ui/plugin.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.2"?> <!--
+<?eclipse version="3.2"?>
+<!--
Copyright (c) 2007, 2010 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
@@ -403,6 +404,16 @@
property="org.eclipse.wst.common.project.facet.core.projectFacet"
value="jpt.jpa"/>
</adapt>
+ <and>
+ <adapt
+ type="org.eclipse.core.resources.IResource">
+ <test
+ property="org.eclipse.wst.common.project.facet.core.projectFacet"
+ value="jpt.jpa"/>
+ </adapt>
+ <adapt
+ type="org.eclipse.jdt.core.IJavaElement"/>
+ </and>
</or>
</iterate>
</with>
@@ -884,6 +895,32 @@
</objectContribution>
<objectContribution
+ id="org.eclipse.jpt.ui.MakePersistent"
+ objectClass="org.eclipse.jdt.core.IJavaElement"
+ adaptable="true">
+
+ <enablement>
+ <test property="org.eclipse.jdt.core.inSourceFolder" value="true"/>
+ </enablement>
+
+ <action
+ class="org.eclipse.jpt.ui.internal.actions.MakePersistentAction"
+ enablesFor="*"
+ id="org.eclipse.jpt.ui.generateEntities"
+ label="%makePersistent"
+ menubarPath="org.eclipse.jpt.ui.menu.JpaTools/content">
+ <enablement>
+ <or>
+ <objectClass name="org.eclipse.jdt.core.ICompilationUnit"/>
+ <objectClass name="org.eclipse.jdt.core.IType"/>
+ <objectClass name="org.eclipse.jdt.core.IPackageFragment"/>
+ <objectClass name="org.eclipse.jdt.core.IPackageFragmentRoot"/>
+ </or>
+ </enablement>
+ </action>
+ </objectContribution>
+
+ <objectContribution
id="org.eclipse.jpt.ui.persistenceXmlFileActions"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="persistence.xml">
diff --git a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties
index 71ab6d288b..1b72771a4b 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties
+++ b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties
@@ -40,8 +40,8 @@ AddRemovePane_RemoveButtonText=Remove
ClassChooserPane_dialogMessage=&Enter type name prefix or pattern (*, ?, or camel case):
ClassChooserPane_dialogTitle=Class Selection
-convertToJpa_convertingProject="Converting project to faceted form ..."
-convertToJpa_detectingTechnologies="Detecting existing technologies ..."
+convertToJpa_convertingProject="Converting project to faceted form..."
+convertToJpa_detectingTechnologies="Detecting existing technologies..."
DatabaseSchemaWizardPage_title=Database Schema
DatabaseSchemaWizardPage_desc=Select a database schema
@@ -91,7 +91,7 @@ JpaFacetWizardPage_title=JPA Facet
JpaFacetWizardPage_description=Configure JPA settings.
JpaFacetWizardPage_platformLabel=&Platform
JpaFacetWizardPage_connectionLabel=&Connection
-JpaFacetWizardPage_connectionLink=<a>Add connection ...</a>
+JpaFacetWizardPage_connectionLink=<a>Add connection...</a>
JpaFacetWizardPage_connectLink=<a>Connect</a>
JpaFacetWizardPage_connectedText=<a>Connected</a>
JpaFacetWizardPage_addDriverLibraryLabel=&Add driver library to build path
@@ -103,8 +103,8 @@ JpaFacetWizardPage_defaultSchemaLabel=&Schema:
JpaFacetWizardPage_jpaImplementationLabel=JPA implementation
JpaFacetWizardPage_userServerLibLabel=Implementation provided by server runtime
JpaFacetWizardPage_specifyLibLabel=Implementation library:
-JpaFacetWizardPage_jpaPrefsLink=<a>Configure default JPA implementation library ...</a>
-JpaFacetWizardPage_userLibsLink=<a>Configure user libraries ...</a>
+JpaFacetWizardPage_jpaPrefsLink=<a>Configure default JPA implementation library...</a>
+JpaFacetWizardPage_userLibsLink=<a>Configure user libraries...</a>
JpaFacetWizardPage_persistentClassManagementLabel=Persistent class management
JpaFacetWizardPage_discoverClassesButton=Discover annotated classes a&utomatically
JpaFacetWizardPage_listClassesButton=Annotated classes must be &listed in persistence.xml
@@ -115,6 +115,18 @@ JpaFacetWizardPage_none=<None>
JpaLibraryProviderInstallPanel_includeLibraries=&Include libraries with this application
+JpaMakePersistentWizardPage_title=Make Persistent...
+JpaMakePersistentWizardPage_message=Make the selected Java classes persistent by selecting Java annotations or mapping file
+JpaMakePersistentWizardPage_annotateInJavaRadioButton=Annotate in &Java
+JpaMakePersistentWizardPage_mappingFileRadioButton=Add to &ORM mapping file
+JpaMakePersistentWizardPage_mappingFileLabel=Mapping File:
+JpaMakePersistentWizardPage_mappingFileBrowseButton=B&rowse...
+JpaMakePersistentWizardPage_typeTableColumn=Type
+JpaMakePersistentWizardPage_mappingTableColumn=Mapping
+JpaMakePersistentWizardPage_listInPersistenceXmlCheckBox=&List in persistence.xml
+JpaMakePersistentWizardPage_selectedTypesPersistentError=All selected types are already persistent
+JpaMakePersistentWizardPage_mappingFileDoesNotExistError=The ORM mapping file does not exist
+
JpaPreferencesPage_Description=Expand the tree to edit preferences for a specific feature.
JpaProblemSeveritiesPage_Description=Select the severity level for the following optional Java Persistence validation problems:
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java
index 9d0f818bff..06789e5b2c 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java
@@ -99,6 +99,17 @@ public class JptUiMessages {
public static String JpaFacetWizardPage_userLibsLink;
public static String JpaFacetWizardPage_userServerLibLabel;
public static String JpaLibraryProviderInstallPanel_includeLibraries;
+ public static String JpaMakePersistentWizardPage_title;
+ public static String JpaMakePersistentWizardPage_message;
+ public static String JpaMakePersistentWizardPage_annotateInJavaRadioButton;
+ public static String JpaMakePersistentWizardPage_mappingFileRadioButton;
+ public static String JpaMakePersistentWizardPage_mappingFileLabel;
+ public static String JpaMakePersistentWizardPage_mappingFileBrowseButton;
+ public static String JpaMakePersistentWizardPage_typeTableColumn;
+ public static String JpaMakePersistentWizardPage_mappingTableColumn;
+ public static String JpaMakePersistentWizardPage_listInPersistenceXmlCheckBox;
+ public static String JpaMakePersistentWizardPage_selectedTypesPersistentError;
+ public static String JpaMakePersistentWizardPage_mappingFileDoesNotExistError;
public static String JpaStructureView_linkWithEditorDesc;
public static String JpaStructureView_linkWithEditorText;
public static String JpaStructureView_linkWithEditorTooltip;
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MakePersistentAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MakePersistentAction.java
new file mode 100644
index 0000000000..7fcc503f65
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MakePersistentAction.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+* Copyright (c) 2010 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.ui.internal.actions;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+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.ui.JptUiPlugin;
+import org.eclipse.jpt.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 Map<IProject, List<IType>> selectedTypes;
+
+ public MakePersistentAction() {
+ super();
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // do nothing
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ // Action is contributed for IType, ICompilationUnit, IPackageFragment, and IPackageFragmentRoot that is a source folder
+ this.selectedTypes = this.buildSelectedTypes((StructuredSelection) selection);
+ }
+
+ protected Map<IProject, List<IType>> buildSelectedTypes(StructuredSelection structuredSelection) {
+ Map<IProject, List<IType>> types = new HashMap<IProject, List<IType>>();
+
+ for (Object selection : structuredSelection.toList()) {
+ switch (((IJavaElement) selection).getElementType()) {
+ case IJavaElement.TYPE :
+ addSelectedType((IType) selection, types);
+ break;
+ case IJavaElement.COMPILATION_UNIT :
+ addSelectedType((ICompilationUnit) selection, types);
+ break;
+ case IJavaElement.PACKAGE_FRAGMENT :
+ addSelectedType((IPackageFragment) selection, types);
+ break;
+ case IJavaElement.PACKAGE_FRAGMENT_ROOT :
+ addSelectedType((IPackageFragmentRoot) selection, types);
+ break;
+ default :
+ break;
+ }
+ }
+ return types;
+ }
+
+ private void addSelectedType(IPackageFragmentRoot packageFragmentRoot, Map<IProject, List<IType>> types) {
+ for (IJavaElement pkgFragment : getPackageFragments(packageFragmentRoot)) {
+ addSelectedType((IPackageFragment) pkgFragment, types);
+ }
+ }
+
+ private void addSelectedType(IPackageFragment packageFragment, Map<IProject, List<IType>> types) {
+ for (ICompilationUnit compUnit : getCompilationUnits(packageFragment)) {
+ addSelectedType(compUnit, types);
+ }
+ }
+
+ private void addSelectedType(ICompilationUnit compilationUnit, Map<IProject, List<IType>> types) {
+ addSelectedType(getPrimaryType(compilationUnit), types);
+ }
+
+ private void addSelectedType(IType primaryType, Map<IProject, List<IType>> typesMap) {
+ IProject project = primaryType.getJavaProject().getProject();
+ List<IType> types = typesMap.get(project);
+ if (types == null) {
+ types = new ArrayList<IType>();
+ typesMap.put(project, types);
+ }
+ if (!types.contains(primaryType)) {
+ types.add(primaryType);
+ }
+ }
+
+ private ICompilationUnit[] getCompilationUnits(IPackageFragment packageFragment) {
+ try {
+ return packageFragment.getCompilationUnits();
+ }
+ catch (JavaModelException e) {
+ JptUiPlugin.log(e);
+ }
+ return new ICompilationUnit[0];
+ }
+
+ private IJavaElement[] getPackageFragments(IPackageFragmentRoot packageFragmentRoot) {
+ try {
+ return packageFragmentRoot.getChildren();
+ }
+ catch (JavaModelException e) {
+ JptUiPlugin.log(e);
+ }
+ return new IJavaElement[0];
+ }
+
+ private IType getPrimaryType(ICompilationUnit compilationUnit) {
+ return compilationUnit.findPrimaryType();
+ }
+
+ public void run(IAction action) {
+ for (List<IType> types : this.selectedTypes.values()) {
+ //open the wizard once for each selected project
+ JpaMakePersistentWizard wizard = new JpaMakePersistentWizard(types);
+ WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard);
+ dialog.create();
+ dialog.open();
+ }
+ }
+
+ private Shell getCurrentShell() {
+ return Display.getCurrent().getActiveShell();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizard.java
new file mode 100644
index 0000000000..dafca92be9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizard.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.ui.internal.wizards;
+
+import java.util.List;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.context.persistence.Persistence;
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.ui.JptUiPlugin;
+import org.eclipse.jpt.ui.internal.JptUiIcons;
+
+public class JpaMakePersistentWizard extends Wizard {
+
+ public static final String HELP_CONTEXT_ID = JptUiPlugin.PLUGIN_ID + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
+
+
+ final List<IType> selectedTypes;
+
+ private JpaMakePersistentWizardPage makePersistentWizardPage;
+
+ protected final ResourceManager resourceManager;
+
+ public JpaMakePersistentWizard(List<IType> selectedTypes) {
+ super();
+ this.selectedTypes = selectedTypes;
+ this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
+ this.setWindowTitle("Make Persistent");
+ this.setDefaultPageImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.ENTITY_WIZ_BANNER));
+ }
+
+ @Override
+ public void addPages() {
+ setForcePreviousAndNextButtons(true);
+
+ JpaProject jpaProject = JptCorePlugin.getJpaProject(this.selectedTypes.get(0).getResource().getProject());
+ this.makePersistentWizardPage = new JpaMakePersistentWizardPage(jpaProject, this.selectedTypes, HELP_CONTEXT_ID);
+ this.addPage(this.makePersistentWizardPage);
+ return;
+ }
+
+ @Override
+ public boolean performFinish() {
+ this.makePersistentWizardPage.performFinish();
+ return true;
+ }
+
+ protected PersistenceUnit getPersistenceUnit(JpaProject jpaProject) {
+ PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
+ if (persistenceXml != null) {
+ Persistence persistence = persistenceXml.getPersistence();
+ if (persistence != null && persistence.persistenceUnitsSize() > 0) {
+ return persistence.persistenceUnits().next();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void dispose() {
+ this.resourceManager.dispose();
+ super.dispose();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizardPage.java
new file mode 100644
index 0000000000..be566c7131
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaMakePersistentWizardPage.java
@@ -0,0 +1,597 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.ui.internal.wizards;
+
+import java.io.IOException;
+import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.ui.JavaElementComparator;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.JpaResourceType;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.PersistentType;
+import org.eclipse.jpt.core.context.java.JavaTypeMappingDefinition;
+import org.eclipse.jpt.core.context.orm.EntityMappings;
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
+import org.eclipse.jpt.ui.JpaPlatformUi;
+import org.eclipse.jpt.ui.details.MappingUiDefinition;
+import org.eclipse.jpt.ui.internal.JptUiMessages;
+import org.eclipse.jpt.ui.internal.jface.XmlMappingFileViewerFilter;
+import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry;
+import org.eclipse.jpt.ui.internal.utility.swt.SWTTools;
+import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
+import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
+import org.eclipse.jpt.utility.internal.model.value.AspectPropertyValueModelAdapter;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+public class JpaMakePersistentWizardPage extends WizardPage {
+
+ // sizing constants
+ private final static int TABLE_HEIGHT = 250;
+ private final static int TABLE_WIDTH = 300;
+
+ private static String MAKE_PERSISTENT_PAGE_NAME = "MakePersistent"; //$NON-NLS-1$
+ private TableViewer classTableViewer;
+ private final String helpContextId;
+
+ private final Type[] selectedTypes;
+
+ private final JpaProject jpaProject;
+ private JpaResourceType jpaResourceType;
+
+ private final WritablePropertyValueModel<Boolean> annotateInJavaModel;
+
+ private boolean isFirstCheck = true;
+ private final WritablePropertyValueModel<String> mappingFileModel;
+
+ private final WritablePropertyValueModel<Boolean> listInPersistenceXmlModel;
+
+ protected JpaMakePersistentWizardPage(final JpaProject jpaProject, final List<IType> selectedTypes, final String helpContextId) {
+ super(MAKE_PERSISTENT_PAGE_NAME);
+ this.jpaProject = jpaProject;
+
+ this.selectedTypes = this.buildTypes(selectedTypes);
+ this.jpaResourceType = JptCorePlugin.JAVA_SOURCE_RESOURCE_TYPE;
+ this.helpContextId = helpContextId;
+ this.annotateInJavaModel = new SimplePropertyValueModel<Boolean>(Boolean.TRUE);
+ this.mappingFileModel = new SimplePropertyValueModel<String>();
+ this.listInPersistenceXmlModel = new SimplePropertyValueModel<Boolean>(Boolean.valueOf(!this.jpaProject.discoversAnnotatedClasses()));
+ this.setTitle(JptUiMessages.JpaMakePersistentWizardPage_title);
+ this.setMessage(JptUiMessages.JpaMakePersistentWizardPage_message);
+ }
+
+ protected Type[] buildTypes(final List<IType> selectedTypes) {
+ return CollectionTools.list(
+ new TransformationIterable<IType, Type>(nonPersistentTypes(selectedTypes)) {
+ @Override
+ protected Type transform(IType jdtType) {
+ return new Type(jdtType);
+ }
+ }).toArray(new Type[] {});
+ }
+
+ /**
+ * Return all ITypes that are not already persistent.
+ * Any root structure nodes means the type is already annotated,
+ * listed in persistence.xml, or listed in a mapping file
+ */
+ protected Iterable<IType> nonPersistentTypes(final List<IType> selectedTypes) {
+ return new FilteringIterable<IType>(selectedTypes) {
+ @Override
+ protected boolean accept(IType jdtType) {
+ return getJpaProject().getJpaFile((IFile) jdtType.getResource()).rootStructureNodesSize() == 0;
+ }
+ };
+ }
+
+ protected JpaProject getJpaProject() {
+ return this.jpaProject;
+ }
+
+ protected JpaPlatformUi getJpaPlatformUi() {
+ String platformId = this.getJpaProject().getJpaPlatform().getId();
+ return JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ int nColumns= 1;
+ GridLayout layout = new GridLayout();
+ layout.numColumns = nColumns;
+ composite.setLayout(layout);
+ Button javaAnnotationButton = new Button(composite, SWT.RADIO);
+ javaAnnotationButton.setText(JptUiMessages.JpaMakePersistentWizardPage_annotateInJavaRadioButton);
+ javaAnnotationButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ JpaMakePersistentWizardPage.this.annotateInJavaModel.setValue(Boolean.TRUE);
+ JpaMakePersistentWizardPage.this.jpaResourceType = JptCorePlugin.JAVA_SOURCE_RESOURCE_TYPE;
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ this.widgetSelected(e);
+ }
+ });
+
+ Button mappingFileButton = new Button(composite, SWT.RADIO);
+ mappingFileButton.setText(JptUiMessages.JpaMakePersistentWizardPage_mappingFileRadioButton);
+ Composite mappingFileComposite = this.createMappingFileControl(composite);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.grabExcessHorizontalSpace = true;
+ mappingFileComposite.setLayoutData(data);
+
+ mappingFileButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ JpaMakePersistentWizardPage.this.annotateInJavaModel.setValue(Boolean.FALSE);
+ if (JpaMakePersistentWizardPage.this.isFirstCheck) {
+ JpaMakePersistentWizardPage.this.mappingFileModel.setValue(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString());
+ JpaMakePersistentWizardPage.this.isFirstCheck = false;
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ this.widgetSelected(e);
+ }
+ });
+
+
+ this.classTableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ this.classTableViewer.getTable().setLinesVisible(true);
+ this.classTableViewer.getTable().setHeaderVisible(true);
+ this.classTableViewer.setContentProvider(new TypeContentProvider());
+ this.classTableViewer.setComparator(new TypeComparator());
+ this.createTypeTableColumn();
+ this.createMappingTableColumn();
+ this.classTableViewer.setInput(this.selectedTypes);
+
+ data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ data.heightHint = TABLE_HEIGHT;
+ data.widthHint = TABLE_WIDTH;
+ this.classTableViewer.getTable().setLayoutData(data);
+
+ final Button persistenceXmlCheckBox = new Button(composite, SWT.CHECK);
+ persistenceXmlCheckBox.setText(JptUiMessages.JpaMakePersistentWizardPage_listInPersistenceXmlCheckBox);
+ SWTTools.bind(this.listInPersistenceXmlModel, persistenceXmlCheckBox);
+ SWTTools.controlVisibleState(this.annotateInJavaModel, persistenceXmlCheckBox);
+
+ setControl(composite);
+
+ this.validate();
+ }
+
+ private Composite createMappingFileControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ layout.marginLeft = 10;
+ composite.setLayout(layout);
+
+ Label mappingFileLabel = new Label(composite, SWT.None);
+ mappingFileLabel.setText(JptUiMessages.JpaMakePersistentWizardPage_mappingFileLabel);
+
+ Text mappingFileText = this.createText(composite, 1);
+ SWTTools.bind(this.mappingFileModel, mappingFileText);
+ this.mappingFileModel.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaXmlResource ormXmlResource = getOrmXmlResource();
+ if (ormXmlResource == null) {
+ jpaResourceType = JptCorePlugin.ORM_XML_1_0_RESOURCE_TYPE; //just default to 1.0 orm resource type
+ }
+ else {
+ jpaResourceType = ormXmlResource.getResourceType();
+ }
+ validate();
+ }
+ });
+
+ Button browseButton = new Button(composite, SWT.PUSH);
+ browseButton.setText(JptUiMessages.JpaMakePersistentWizardPage_mappingFileBrowseButton);
+ browseButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ mappingFileBrowseButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Do nothing
+ }
+ });
+
+ SWTTools.controlEnabledState(new ListInOrmMappingFileModel(this.annotateInJavaModel), mappingFileLabel, mappingFileText, browseButton);
+
+ return composite;
+ }
+
+ private Text createText(Composite container, int span) {
+ Text text = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = span;
+ gd.grabExcessHorizontalSpace = true;
+ text.setLayoutData(gd);
+ return text;
+ }
+
+ private void mappingFileBrowseButtonPressed() {
+ ViewerFilter filter = buildMappingFileDialogViewerFilter();
+ ITreeContentProvider contentProvider = new WorkbenchContentProvider();
+ ILabelProvider labelProvider = new WorkbenchLabelProvider();
+ SelectJpaOrmMappingFileDialog dialog = new SelectJpaOrmMappingFileDialog(getShell(), labelProvider, contentProvider);
+ dialog.setTitle(EntityWizardMsg.MAPPING_XML_TITLE);
+ dialog.setMessage(EntityWizardMsg.CHOOSE_MAPPING_XML_MESSAGE);
+ dialog.addFilter(filter);
+
+ JpaXmlResource resource = this.jpaProject.getMappingFileXmlResource(new Path(getMappingFileLocation()));
+ IFile initialSelection = (resource != null) ? resource.getFile() : null;
+ dialog.setInput(this.jpaProject.getProject());
+
+ if (initialSelection != null) {
+ dialog.setInitialSelection(initialSelection);
+ }
+ if (dialog.open() == Window.OK) {
+ this.mappingFileModel.setValue(dialog.getChosenName());
+ //this.model.validateProperty(IEntityDataModelProperties.XML_NAME);
+ }
+ }
+
+ /**
+ * This method create filter for the browse/add alternative mapping XML
+ * @return new instance of viewer filter for the SelectMappingXMLDialog
+ */
+ protected ViewerFilter buildMappingFileDialogViewerFilter() {
+ return new XmlMappingFileViewerFilter(this.jpaProject);
+ }
+
+ protected void createTypeTableColumn() {
+ TableViewerColumn column = new TableViewerColumn(this.classTableViewer, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText(JptUiMessages.JpaMakePersistentWizardPage_typeTableColumn);
+ column.setLabelProvider(this.buildTypeColumnLabelProvider());
+ }
+
+ protected ColumnLabelProvider buildTypeColumnLabelProvider() {
+ return new TypeColumnLabelProvider();
+ }
+
+ protected void createMappingTableColumn() {
+ TableViewerColumn column;
+ column = new TableViewerColumn(this.classTableViewer, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText(JptUiMessages.JpaMakePersistentWizardPage_mappingTableColumn);
+
+ column.setEditingSupport(new EditingSupport(this.classTableViewer) {
+ @Override
+ protected Object getValue(Object element) {
+ return getMappingUiDefinition(((Type) element).mappingKey);
+ }
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ ((Type) element).setMappingKey(((MappingUiDefinition<?, ?>) value).getKey());
+ getViewer().update(element, null);
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ final ComboBoxViewerCellEditor comboCellEditor =
+ new ComboBoxViewerCellEditor((Composite) JpaMakePersistentWizardPage.this.classTableViewer.getControl());
+
+ comboCellEditor.setLabelProvider(buildMappingComboCellEditorLabelProvider());
+ comboCellEditor.setContentProvider(buildMappingComboCellEditorContentProvider());
+ comboCellEditor.setInput(element);
+ return comboCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+
+ column.setLabelProvider(buildMappingColumnLabelProvider());
+ }
+
+ //The ComboBoxViewerCellEditor does not support the image, so no reason to implement getImage(Object)
+ protected ColumnLabelProvider buildMappingComboCellEditorLabelProvider() {
+ return new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return ((MappingUiDefinition<?, ?>) element).getLabel();
+ }
+ };
+ }
+
+ protected IStructuredContentProvider buildMappingComboCellEditorContentProvider() {
+ return new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return CollectionTools.collection(((Type) inputElement).typeMappingUiDefinitions()).toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ //do nothing
+ }
+
+ public void dispose() {
+ //do nothing
+ }
+ };
+ }
+
+ protected ColumnLabelProvider buildMappingColumnLabelProvider() {
+ return new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ MappingUiDefinition<? extends PersistentType, ?> mappingUiDefinition = getMappingUiDefinition(((Type) element).mappingKey);
+ return mappingUiDefinition.getLabel();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ MappingUiDefinition<? extends PersistentType, ?> mappingUiDefinition = getMappingUiDefinition(((Type) element).mappingKey);
+ return mappingUiDefinition.getImage();
+ }
+ };
+ }
+
+ protected MappingUiDefinition<? extends PersistentType, ?> getMappingUiDefinition(String mappingKey) {
+ for (MappingUiDefinition<? extends PersistentType, ?> provider : typeMappingUiDefinitions(this.jpaResourceType)) {
+ if (provider.getKey() == mappingKey) {
+ return provider;
+ }
+ }
+ throw new IllegalArgumentException();
+ }
+
+ protected Iterable<String> typeMappingKeys(Iterable<? extends MappingUiDefinition<? extends PersistentType, ?>> mappingUiDefinitions) {
+ return new TransformationIterable<MappingUiDefinition<? extends PersistentType, ?>, String>(mappingUiDefinitions) {
+ @Override
+ protected String transform(MappingUiDefinition<? extends PersistentType, ?> next) {
+ return next.getKey();
+ }
+ };
+ }
+
+ protected Iterable<? extends MappingUiDefinition<? extends PersistentType, ?>> typeMappingUiDefinitions(JpaResourceType jpaResourceType) {
+ return CollectionTools.iterable(getJpaPlatformUi().typeMappingUiDefinitions(jpaResourceType));
+ }
+
+ protected void validate() {
+ String errorMessage = null;
+ if (this.selectedTypes.length == 0) {
+ errorMessage = JptUiMessages.JpaMakePersistentWizardPage_selectedTypesPersistentError;
+ }
+ else if (this.isAddToOrmMappingFile() && getOrmXmlResource() == null) {
+ errorMessage = JptUiMessages.JpaMakePersistentWizardPage_mappingFileDoesNotExistError;
+ }
+ setErrorMessage(errorMessage);
+ setPageComplete(errorMessage == null);
+ }
+
+ @Override
+ public final void performHelp() {
+ PlatformUI.getWorkbench().getHelpSystem().displayHelp( this.helpContextId );
+ }
+
+ protected void performFinish() {
+ boolean modifiedPersistenceXml = false;
+ for (Type type : this.selectedTypes) {
+ modifiedPersistenceXml |= type.makePersistent();
+ }
+ if (modifiedPersistenceXml) {
+ try {
+ this.getJpaProject().getPersistenceXmlResource().save(null);
+ }
+ catch (IOException e) {
+ //ignore, file just won't get saved
+ }
+ }
+ }
+
+ protected JpaXmlResource getOrmXmlResource() {
+ return getJpaProject().getMappingFileXmlResource(new Path(getMappingFileLocation()));
+ }
+
+ protected boolean isListInPersistenceXml() {
+ return this.listInPersistenceXmlModel.getValue().booleanValue();
+ }
+
+ protected boolean isAnnotateInJavaModel() {
+ return this.annotateInJavaModel.getValue().booleanValue();
+ }
+
+ protected boolean isAddToOrmMappingFile() {
+ return !isAnnotateInJavaModel();
+ }
+
+ protected String getMappingFileLocation() {
+ return this.mappingFileModel.getValue();
+ }
+
+ private class Type {
+
+ private final IType jdtType;
+
+ private String mappingKey;
+
+ protected Type(IType jdtType) {
+ super();
+ this.jdtType = jdtType;
+ this.mappingKey = MappingKeys.ENTITY_TYPE_MAPPING_KEY;
+ }
+
+ protected void setMappingKey(String mappingKey) {
+ this.mappingKey = mappingKey;
+ }
+
+ protected boolean makePersistent() {
+ if (JpaMakePersistentWizardPage.this.isAnnotateInJavaModel()) {
+ PersistenceUnit persistenceUnit = this.getPersistenceUnit();
+ JavaResourcePersistentType persistentType = getJavaResourcePersistentType();
+ persistentType.addAnnotation(getJavaTypeMappingDefinition(this.mappingKey).getAnnotationName());
+ if (JpaMakePersistentWizardPage.this.isListInPersistenceXml()) {
+ if (persistenceUnit != null) {
+ persistenceUnit.addSpecifiedClassRef(persistentType.getQualifiedName());
+ return true;
+ }
+ }
+ }
+ else {
+ JpaXmlResource ormXmlResource = getOrmXmlResource();
+ final EntityMappings entityMappings = this.getEntityMappings();
+ ormXmlResource.modify(new Runnable() {
+ public void run() {
+ entityMappings.addPersistentType(Type.this.mappingKey, Type.this.jdtType.getFullyQualifiedName());
+ }
+ });
+ }
+ return false;
+ }
+
+// private void addAnnotation() {
+// try {
+// jdtType.getCompilationUnit().becomeWorkingCopy(null);
+// getJavaResourcePersistentType().addAnnotation(getJavaTypeMappingDefinition(this.mappingKey).getAnnotationName());
+// }
+// catch (JavaModelException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+//
+// finally {
+// //discardWorkingCopy must be called every time becomeWorkingCopy is called.
+//// this.compilationUnit.getBuffer().setContents(doc.get());
+//// this.compilationUnit.commitWorkingCopy(true, null); // true="force"
+// try {
+// jdtType.getCompilationUnit().discardWorkingCopy();
+// }
+// catch (JavaModelException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// }
+// }
+
+ protected Iterable<? extends MappingUiDefinition<? extends PersistentType, ?>> typeMappingUiDefinitions() {
+ return CollectionTools.iterable(getJpaPlatformUi().typeMappingUiDefinitions(jpaResourceType));
+ }
+
+ protected JavaTypeMappingDefinition getJavaTypeMappingDefinition(String mappingKey) {
+ return getJpaProject().getJpaPlatform().getJavaTypeMappingDefinition(mappingKey);
+ }
+
+ protected JavaResourcePersistentType getJavaResourcePersistentType() {
+ return getJpaProject().getJavaResourcePersistentType(this.jdtType.getFullyQualifiedName());
+ }
+
+ protected EntityMappings getEntityMappings() {
+ JpaXmlResource xmlResource = getOrmXmlResource();
+ return (EntityMappings) getJpaProject().getJpaFile(xmlResource.getFile()).rootStructureNodes().next();
+ }
+
+ protected PersistenceUnit getPersistenceUnit() {
+ //TODO getPersistence() can be null? or there might not be persistence units?
+ return getJpaProject().getRootContextNode().getPersistenceXml().getPersistence().persistenceUnits().next();
+ }
+ }
+
+ private final class TypeContentProvider implements IStructuredContentProvider
+ {
+ public Object[] getElements(Object inputElement){
+ return (Type[]) inputElement;
+ }
+
+ public void dispose(){}
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput){}
+
+ }
+
+ private final class TypeColumnLabelProvider extends ColumnLabelProvider
+ {
+ private final JavaElementLabelProvider javaElementLabelProvider =
+ new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_POST_QUALIFIED
+ | JavaElementLabelProvider.SHOW_SMALL_ICONS
+ | JavaElementLabelProvider.SHOW_OVERLAY_ICONS);
+
+ @Override
+ public String getText(Object element) {
+ return this.javaElementLabelProvider.getText(((Type) element).jdtType);
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return this.javaElementLabelProvider.getImage(((Type) element).jdtType);
+ }
+ }
+
+ private final class TypeComparator extends ViewerComparator {
+ private final JavaElementComparator javaElementComparator = new JavaElementComparator();
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ return this.javaElementComparator.compare(viewer, ((Type) e1).jdtType, ((Type) e2).jdtType);
+ }
+ }
+
+ static class ListInOrmMappingFileModel
+ extends AspectPropertyValueModelAdapter<Boolean, Boolean>
+ {
+ ListInOrmMappingFileModel(PropertyValueModel<Boolean> annotateInJavaModel) {
+ super(annotateInJavaModel);
+ }
+
+ @Override
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(!this.subject.booleanValue());
+ }
+
+ @Override
+ protected void engageSubject_() {/*nothing*/}
+ @Override
+ protected void disengageSubject_() {/*nothing*/}
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java
new file mode 100644
index 0000000000..1eef3bd0a6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.ui.internal.wizards;
+
+import java.io.File;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jpt.ui.JptUiPlugin;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+
+public class SelectJpaOrmMappingFileDialog extends ElementTreeSelectionDialog
+{
+ private static final String META_INF = "META-INF";//$NON-NLS-1$
+ private static final String EMPTY = "";//$NON-NLS-1$
+ private static final char SLASH = '/';
+
+ private String xmlName = EMPTY;
+
+
+ public SelectJpaOrmMappingFileDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
+ super(parent, labelProvider, contentProvider);
+ }
+
+
+ /**
+ * @return the name of the alternative mapping XML
+ */
+ public String getChosenName() {
+ String result = EMPTY;
+ Object element = getFirstResult();
+ if (element instanceof IContainer) {
+ IContainer container = (IContainer) element;
+ result = container.getFullPath().toString() + File.separatorChar + this.xmlName;
+ } else {
+ IFile f = (IFile) element;
+ result = f.getFullPath().toOSString();
+ }
+ result = removeRedundantSegmentFromName(result);
+ return result;
+ }
+
+ @Override
+ /*
+ * @see ElementTreeSelectionDialog#updateOKStatus(Composite)
+ */
+ protected void updateOKStatus() {
+ super.updateOKStatus();
+ TreeSelection selection = (TreeSelection)getTreeViewer().getSelection();
+ IResource selectedResource = (IResource) selection.getFirstElement();
+ if (selectedResource instanceof IFile) {
+ updateStatus(new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""));
+ }
+ else {
+ updateStatus(new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""));
+ }
+ }
+
+ /**
+ * This method is for internal purposes only
+ * @param input non formated path to the mapping XML
+ * @return the formated path to the mapping XML
+ */
+ private String removeRedundantSegmentFromName(String input) {
+ String output = input.substring(input.indexOf(META_INF));
+ output = output.replace(File.separatorChar, SLASH);
+ return output;
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java
index 149aa20fce..501a707a52 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java
@@ -11,22 +11,17 @@
***********************************************************************/
package org.eclipse.jpt.ui.internal.wizards.entity;
-import java.io.File;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
@@ -35,9 +30,9 @@ import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.internal.utility.jdt.JDTTools;
import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
-import org.eclipse.jpt.ui.JptUiPlugin;
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
import org.eclipse.jpt.ui.internal.jface.XmlMappingFileViewerFilter;
+import org.eclipse.jpt.ui.internal.wizards.SelectJpaOrmMappingFileDialog;
import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties;
import org.eclipse.jpt.utility.internal.ArrayTools;
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
@@ -54,10 +49,8 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.help.IWorkbenchHelpSystem;
import org.eclipse.ui.model.WorkbenchContentProvider;
@@ -68,9 +61,8 @@ import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
public class EntityClassWizardPage
extends NewJavaClassWizardPage {
- private static final String META_INF = "META-INF";//$NON-NLS-1$
private static final String EMPTY = "";//$NON-NLS-1$
- private static final char SLASH = '/';
+
private static final String SINGLE_TABLE = "SINGLE_TABLE";//$NON-NLS-1$
private static final String TABLE_PER_CLASS = "TABLE_PER_CLASS";//$NON-NLS-1$
private static final String JOINED = "JOINED";//$NON-NLS-1$
@@ -328,7 +320,7 @@ public class EntityClassWizardPage
ViewerFilter filter = getDialogViewerFilter(jpaProject);
ITreeContentProvider contentProvider = new WorkbenchContentProvider();
ILabelProvider labelProvider = new WorkbenchLabelProvider();
- SelectMappingXMLDialog dialog = new SelectMappingXMLDialog(getShell(), labelProvider, contentProvider);
+ SelectJpaOrmMappingFileDialog dialog = new SelectJpaOrmMappingFileDialog(getShell(), labelProvider, contentProvider);
dialog.setTitle(EntityWizardMsg.MAPPING_XML_TITLE);
dialog.setMessage(EntityWizardMsg.CHOOSE_MAPPING_XML_MESSAGE);
dialog.addFilter(filter);
@@ -379,61 +371,6 @@ public class EntityClassWizardPage
return (project.isAccessible() && JpaFacet.isInstalled(project));
}
- private class SelectMappingXMLDialog extends ElementTreeSelectionDialog
- {
- private String xmlName = EMPTY;
-
-
- public SelectMappingXMLDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
- super(parent, labelProvider, contentProvider);
- }
-
-
- /**
- * @return the name of the alternative mapping XML
- */
- public String getChosenName() {
- String result = EMPTY;
- Object element = getFirstResult();
- if (element instanceof IContainer) {
- IContainer container = (IContainer) element;
- result = container.getFullPath().toString() + File.separatorChar + xmlName;
- } else {
- IFile f = (IFile) element;
- result = f.getFullPath().toOSString();
- }
- result = removeRedundantSegmentFromName(result);
- return result;
- }
-
- @Override
- /*
- * @see ElementTreeSelectionDialog#updateOKStatus(Composite)
- */
- protected void updateOKStatus() {
- super.updateOKStatus();
- TreeSelection selection = (TreeSelection)getTreeViewer().getSelection();
- IResource selectedResource = (IResource) selection.getFirstElement();
- if (selectedResource instanceof IFile) {
- updateStatus(new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""));
- }
- else {
- updateStatus(new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""));
- }
- }
-
- /**
- * This method is for internal purposes only
- * @param input non formated path to the mapping XML
- * @return the formated path to the mapping XML
- */
- private String removeRedundantSegmentFromName(String input) {
- String output = input.substring(input.indexOf(META_INF));
- output = output.replace(File.separatorChar, SLASH);
- return output;
- }
- }
-
protected final IWorkbenchHelpSystem getHelpSystem() {
return PlatformUI.getWorkbench().getHelpSystem();
}

Back to the top