diff options
8 files changed, 221 insertions, 12 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF index 1551672f28..9f3d9a6f19 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF @@ -27,7 +27,8 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)", org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)", org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)", org.eclipse.jpt.common.ui;bundle-version="[1.0.0,2.0.0)", - org.eclipse.jpt.jpa.gen;bundle-version="[2.1.0, 3.0.0)" + org.eclipse.jpt.jpa.gen;bundle-version="[2.1.0,3.0.0)", + org.eclipse.ui.ide;bundle-version="[3.8.0,4.0.0)" Export-Package: org.eclipse.jpt.jpa.eclipselink.ui, org.eclipse.jpt.jpa.eclipselink.ui.internal;x-internal:=true, org.eclipse.jpt.jpa.eclipselink.ui.internal.commands;x-internal:=true, diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties index 1e9d36ab95..b2eac7d4c8 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/property_files/eclipselink_ui_dynamic_entity_gen.properties @@ -11,3 +11,4 @@ GenerateDynamicEntitiesWizard_generateEntities=Generate Dynamic Entities GenerateDynamicEntitiesWizard_defaultTablePage_domainJavaClass=Dynamic class defaults +GenerateDynamicEntitiesWizard_defaultTablePage_xmlMappingFile=XML Mapping File: diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java index 8dd186679a..174641216d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/DynamicDefaultTableGenerationWizardPage.java @@ -9,18 +9,44 @@ *******************************************************************************/ package org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.gen; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; import org.eclipse.jpt.jpa.core.JpaProject; +import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource; +import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin; +import org.eclipse.jpt.jpa.eclipselink.ui.internal.wizards.SelectEcliplseLinkMappingFileDialog; import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds; +import org.eclipse.jpt.jpa.ui.internal.JptUiMessages; +import org.eclipse.jpt.jpa.ui.internal.jface.XmlMappingFileViewerFilter; +import org.eclipse.jpt.jpa.ui.internal.wizards.SelectJpaOrmMappingFileDialog; +import org.eclipse.jpt.jpa.ui.internal.wizards.entity.EntityWizardMsg; import org.eclipse.jpt.jpa.ui.internal.wizards.gen.DefaultTableGenerationWizardPage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; 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.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; public class DynamicDefaultTableGenerationWizardPage extends DefaultTableGenerationWizardPage { + private Label xmlMappingFileLabel; + private Text xmlMappingFileText; + private Button xmlMappingFileBrowseButton; + public DynamicDefaultTableGenerationWizardPage(JpaProject jpaProject) { super(jpaProject); } @@ -35,8 +61,9 @@ public class DynamicDefaultTableGenerationWizardPage extends composite.setLayout(layout); this.getHelpSystem().setHelp(composite, JpaHelpContextIds.GENERATE_ENTITIES_WIZARD_CUSTOMIZE_DEFAULT_ENTITY_GENERATION); - defaultTableGenPanel = new DynamicTableGenPanel(composite, 4, true, this); + createXmlMappingFileGroup(composite); createDomainJavaClassesPropertiesGroup(composite, 4); + defaultTableGenPanel = new DynamicTableGenPanel(composite, 4, true, this); setControl(composite); @@ -59,4 +86,96 @@ public class DynamicDefaultTableGenerationWizardPage extends createPackageControls(parent, columns); } + private void createXmlMappingFileGroup(Composite parent) { + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout(3, false)); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + this.xmlMappingFileLabel = new Label(composite, SWT.LEFT); + this.xmlMappingFileLabel.setText(JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_defaultTablePage_xmlMappingFile); + this.xmlMappingFileLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + + this.xmlMappingFileText = new Text(composite, SWT.SINGLE | SWT.BORDER); + this.xmlMappingFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + this.xmlMappingFileText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + handleXmlMappingFileTextModified(); + } + }); + + this.xmlMappingFileBrowseButton = new Button(composite, SWT.PUSH); + this.xmlMappingFileBrowseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL); + GridData browseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + browseButtonData.horizontalSpan = 1; + this.xmlMappingFileBrowseButton.setLayoutData(browseButtonData); + this.xmlMappingFileBrowseButton.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + handleXmlMappingFileButtonPressed(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + }); + } + + private void handleXmlMappingFileTextModified() { + this.getCustomizer().setXmlMappingFile(this.xmlMappingFileText.getText()); +// validate(); + } + + private void handleXmlMappingFileButtonPressed() { + + ViewerFilter filter = getDialogViewerFilter(this.jpaProject); + ITreeContentProvider contentProvider = new WorkbenchContentProvider(); + ILabelProvider labelProvider = new WorkbenchLabelProvider(); + SelectJpaOrmMappingFileDialog dialog = new SelectEcliplseLinkMappingFileDialog(getShell(), this.jpaProject.getProject(), labelProvider, contentProvider); + dialog.setTitle(JptUiMessages.SelectJpaOrmMappingFileDialog_title); + dialog.setMessage(JptUiMessages.SelectJpaOrmMappingFileDialog_message); + dialog.addFilter(filter); + + String ormFileName = this.xmlMappingFileText.getText(); + JpaXmlResource resource = jpaProject.getMappingFileXmlResource(new Path(ormFileName)); + IFile initialSelection = (resource != null) ? resource.getFile() : null; + dialog.setInput(this.jpaProject.getProject()); + + if (initialSelection != null) { + dialog.setInitialSelection(initialSelection); + } + if (dialog.open() == Window.OK) { + String chosenName = dialog.getChosenName(); + this.xmlMappingFileText.setText(chosenName); + this.getCustomizer().setXmlMappingFile(chosenName); + } +// validate(); + } + + protected ViewerFilter getDialogViewerFilter(JpaProject jpaProject) { + return new XmlMappingFileViewerFilter(jpaProject, JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE); + } + + public void setVisible(boolean visible){ + super.setVisible(visible); + if(visible){ + this.xmlMappingFileText.setText(this.getCustomizer().getXmlMappingFile()); +// validate(); + } + } + +// private void validate() { +// String errorMessage = null; +// JpaXmlResource ormXmlResource = getOrmXmlResource(); +// if (ormXmlResource == null) { +// errorMessage = JptUiMessages.JpaMakePersistentWizardPage_mappingFileDoesNotExistError; +// } +// setErrorMessage(errorMessage); +// setPageComplete(errorMessage == null); +// } + + protected JpaXmlResource getOrmXmlResource() { + return this.jpaProject.getMappingFileXmlResource(new Path(this.xmlMappingFileText.getText())); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java index 6892705edb..cd7a5f9de5 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/GenerateDynamicEntitiesFromSchemaWizard.java @@ -59,7 +59,7 @@ public class GenerateDynamicEntitiesFromSchemaWizard extends GenerateEntitiesFro protected String getCustomizationFileName() { ConnectionProfile profile = getProjectConnectionProfile(); String connection = profile == null ? "" : profile.getName(); - String name = "org.eclipse.jpt.entitygen.dynamic" + (connection == null ? "" :connection.replace(' ', '-')); //$NON-NLS-1$ + String name = "org.eclipse.jpt.jpa.gen.dynamic." + (connection == null ? "" :connection.replace(' ', '-')); //$NON-NLS-1$ Schema schema = getDefaultSchema(); if ( schema!= null ) { name += "." + schema.getName();//$NON-NLS-1$ @@ -72,6 +72,11 @@ public class GenerateDynamicEntitiesFromSchemaWizard extends GenerateEntitiesFro OverwriteConfirmer overwriteConfirmer) { WorkspaceJob genEntitiesJob = new GenerateEntitiesJob(this.jpaProject, getCustomizer(), overwriteConfirmer, true); genEntitiesJob.schedule(); + + //TODO need to open file after generation +// JpaXmlResource jpaXmlResource = this.jpaProject.getMappingFileXmlResource(new Path(getCustomizer().getXmlMappingFile())); +// OpenXmlMappingFileJob openXmlMappingFileJob = new OpenXmlMappingFileJob(this.jpaProject, jpaXmlResource, getShell()); +// openXmlMappingFileJob.schedule(); } @Override @@ -81,4 +86,55 @@ public class GenerateDynamicEntitiesFromSchemaWizard extends GenerateEntitiesFro this.setWindowTitle(JptJpaEclipseLinkUiEntityGenMessages.GenerateDynamicEntitiesWizard_generateEntities); } +// public static class OpenXmlMappingFileJob extends WorkspaceJob { +// final JpaProject jpaProject; +// final JpaXmlResource jpaXmlResource; +// final Shell shell; +// +// public OpenXmlMappingFileJob(JpaProject jpaProject, JpaXmlResource jpaXmlResource, Shell shell) { +// super("Open XML File"); +// this.jpaProject = jpaProject; +// this.jpaXmlResource = jpaXmlResource; +// this.shell = shell; +// IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); +// this.setRule(ruleFactory.modifyRule(jpaProject.getProject())); +// } +// +// @Override +// public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { +// try { +// postPerformFinish(this.jpaProject,this.jpaXmlResource, this.shell); +// } catch (InvocationTargetException e) { +// throw new CoreException(new Status(IStatus.ERROR, JptJpaEclipseLinkUiPlugin.PLUGIN_ID, "error", e)); +// } +// return Status.OK_STATUS; +// } +// +// private void postPerformFinish(JpaProject jpaProject, JpaXmlResource jpaXmlResource, Shell shell) throws InvocationTargetException { +// try { +// IFile file = jpaXmlResource.getFile(); +// openEditor(file, shell); +// } +// catch (Exception cantOpen) { +// throw new InvocationTargetException(cantOpen); +// } +// } +// +// private void openEditor(final IFile file, Shell shell) { +// if (file != null) { +// shell.getDisplay().asyncExec(new Runnable() { +// public void run() { +// try { +// IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); +// IDE.openEditor(page, file, true); +// } +// catch (PartInitException e) { +// JptJpaUiPlugin.log(e); +// } +// } +// }); +// } +// } +// } + } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java index 2e220cf0f1..8434698e73 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/wizards/gen/JptJpaEclipseLinkUiEntityGenMessages.java @@ -19,6 +19,7 @@ public class JptJpaEclipseLinkUiEntityGenMessages { //Default table gen properties public static String GenerateDynamicEntitiesWizard_defaultTablePage_domainJavaClass; + public static String GenerateDynamicEntitiesWizard_defaultTablePage_xmlMappingFile; static { NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java index 5f647bbbc6..8770ca2b4e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java @@ -98,6 +98,11 @@ public abstract class ORMGenCustomizer implements java.io.Serializable private boolean mUpdatePersistenceXml = true; + //EclipseLink mapping file default name + private static final String DEFAULT_XML_MAPPING_FILE = "META-INF/eclipselink-orm.xml"; + private static final String XML_MAPPING_FILE = "xmlMappingFileName"; + + //----------------------------------------- //---- abstract methods //----------------------------------------- @@ -354,6 +359,23 @@ public abstract class ORMGenCustomizer implements java.io.Serializable public String genFetchXml(ORMGenTable table) { return ""; } + + /** + * XML Mapping File Path + */ + public void setXmlMappingFile(String xmlMappingFile) { + setProperty(XML_MAPPING_FILE, xmlMappingFile, null, null); + } + + /** + * XML Mapping File Path + */ + public String getXmlMappingFile() { + String xmlMappingFile = getProperty(XML_MAPPING_FILE, null, null); + return xmlMappingFile == null ? DEFAULT_XML_MAPPING_FILE : xmlMappingFile; //$NON-NLS-1$ + } + + /** * Called when the table user selection is changed in the * generation wizard. diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java index b4c1f56d2c..eab0594a7d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java @@ -355,11 +355,20 @@ public class PackageGenerator { protected void generateXmlMappingFile(List<String> tableNames, String templateDirPath, IProgressMonitor monitor) throws Exception { - try { - IProject project = jpaProject.getProject(); - IContainer container = ((ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class)).getDefaultResourceLocation(); - IFile xmlFile = container.getFile(new Path("/eclipselink-orm.xml")); //$NON-NLS-1$ - + try { + String xmlMappingFileLocation = this.customizer.getXmlMappingFile(); + JpaXmlResource xmlResource = this.jpaProject.getMappingFileXmlResource(new Path(xmlMappingFileLocation)); + IFile xmlFile; + if (xmlResource != null) { + xmlFile = xmlResource.getFile(); + } + else{ + //TODO This is a temp hack for M6 use default location if writing to a new mapping file + IProject project = jpaProject.getProject(); + IContainer container = ((ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class)).getDefaultResourceLocation(); + xmlFile = container.getFile(new Path(xmlMappingFileLocation.substring(xmlMappingFileLocation.lastIndexOf("/")))); //$NON-NLS-1$ + } + if (xmlFile.exists()) { if (this.overwriteConfirmer != null && !this.overwriteConfirmer.overwrite(xmlFile.getName())) { return; diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java index 058a2f6f00..a4a94bf17d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DefaultTableGenerationWizardPage.java @@ -59,12 +59,12 @@ import org.eclipse.ui.help.IWorkbenchHelpSystem; @SuppressWarnings("restriction") public class DefaultTableGenerationWizardPage extends NewTypeWizardPage { - private JpaProject jpaProject; + protected JpaProject jpaProject; /*the instance used to get/set the default properties.*/ - private ORMGenTable defaultsTable; + protected ORMGenTable defaultsTable; - private ORMGenCustomizer customizer; + protected ORMGenCustomizer customizer; protected TableGenPanel defaultTableGenPanel ; @@ -319,7 +319,7 @@ public class DefaultTableGenerationWizardPage extends NewTypeWizardPage { return ret; } - private ORMGenCustomizer getCustomizer() { + protected ORMGenCustomizer getCustomizer() { GenerateEntitiesFromSchemaWizard wizard = (GenerateEntitiesFromSchemaWizard) this.getWizard(); return wizard.getCustomizer(); } |