View | Details | Raw Unified | Return to bug 200268
Collapse All | Expand All

(-)property_files/jpt_ui.properties (+10 lines)
Lines 118-123 Link Here
118
MapAsComposite_unmappedTypeText=Type ''{0}'' is not mapped, click here to change the mapping type.
118
MapAsComposite_unmappedTypeText=Type ''{0}'' is not mapped, click here to change the mapping type.
119
MapAsComposite_version=version
119
MapAsComposite_version=version
120
120
121
MappingFileWizard_title=New Mapping File
122
MappingFileWizardPage_title=Mapping file
123
MappingFileWizardPage_desc=Specify mapping file location and properties
124
MappingFileWizardPage_projectLabel=Project:
125
MappingFileWizardPage_sourceFolderLabel=Source folder:
126
MappingFileWizardPage_filePathLabel=File path:
127
MappingFileWizardPage_accessLabel=Default access:
128
MappingFileWizardPage_addToPersistenceUnitButton=Add to persistence unit
129
MappingFileWizardPage_persistenceUnitLabel=Persistence unit:
130
121
NewJpaProjectWizard_title=New JPA Project
131
NewJpaProjectWizard_title=New JPA Project
122
NewJpaProjectWizard_firstPage_title=JPA Project
132
NewJpaProjectWizard_firstPage_title=JPA Project
123
NewJpaProjectWizard_firstPage_description=Configure JPA project settings.
133
NewJpaProjectWizard_firstPage_description=Configure JPA project settings.
(-)property_files/jpt_ui_entity_wizard.properties (-2 / +3 lines)
Lines 1-4 Link Here
1
###############################################################################
1
################################################################################
2
# Copyright (c) 2008 by SAP AG, Walldorf. 
2
# Copyright (c) 2008 by SAP AG, Walldorf. 
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
Lines 8-14 Link Here
8
# Contributors:
8
# Contributors:
9
#     SAP AG - initial API and implementation
9
#     SAP AG - initial API and implementation
10
#     Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation     
10
#     Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation     
11
###############################################################################
11
################################################################################
12
12
ENTITY_WIZARD_TITLE=New JPA Entity
13
ENTITY_WIZARD_TITLE=New JPA Entity
13
ADD_ENTITY_WIZARD_PAGE_TITLE=Entity class
14
ADD_ENTITY_WIZARD_PAGE_TITLE=Entity class
14
ADD_ENTITY_WIZARD_PAGE_DESCRIPTION=Specify package, class name, and inheritance properties.
15
ADD_ENTITY_WIZARD_PAGE_DESCRIPTION=Specify package, class name, and inheritance properties.
(-)src/org/eclipse/jpt/ui/internal/JptUiMessages.java (+9 lines)
Lines 113-118 Link Here
113
	public static String MapAsComposite_unmappedAttributeText;
113
	public static String MapAsComposite_unmappedAttributeText;
114
	public static String MapAsComposite_unmappedTypeText;
114
	public static String MapAsComposite_unmappedTypeText;
115
	public static String MapAsComposite_version;
115
	public static String MapAsComposite_version;
116
	public static String MappingFileWizard_title;
117
	public static String MappingFileWizardPage_title;
118
	public static String MappingFileWizardPage_desc;
119
	public static String MappingFileWizardPage_projectLabel;
120
	public static String MappingFileWizardPage_sourceFolderLabel;
121
	public static String MappingFileWizardPage_filePathLabel;
122
	public static String MappingFileWizardPage_accessLabel;
123
	public static String MappingFileWizardPage_addToPersistenceUnitButton;
124
	public static String MappingFileWizardPage_persistenceUnitLabel;
116
	public static String NewJpaProjectWizard_firstPage_description;
125
	public static String NewJpaProjectWizard_firstPage_description;
117
	public static String NewJpaProjectWizard_firstPage_title;
126
	public static String NewJpaProjectWizard_firstPage_title;
118
	public static String NewJpaProjectWizard_title;
127
	public static String NewJpaProjectWizard_title;
(-)plugin.xml (-19 / +19 lines)
Lines 474-480 Link Here
474
			name="%jpaWizardCategoryName"/>
474
			name="%jpaWizardCategoryName"/>
475
		
475
		
476
		<wizard
476
		<wizard
477
			id="org.eclipse.jpt.jpaProject"
477
			id="org.eclipse.jpt.ui.wizard.newJpaProject"
478
			name="%newJpaProjectWizardName"
478
			name="%newJpaProjectWizardName"
479
			icon="icons/full/etool16/new_jpaproject_wiz.gif"
479
			icon="icons/full/etool16/new_jpaproject_wiz.gif"
480
			category="org.eclipse.jpt"
480
			category="org.eclipse.jpt"
Lines 484-489 Link Here
484
			<description>%newJpaProjectWizardDesc</description>
484
			<description>%newJpaProjectWizardDesc</description>
485
		</wizard>
485
		</wizard>
486
		
486
		
487
		<wizard
488
            id="org.eclipse.jpt.ui.wizard.newEntity"
489
			name="%newJpaEntityWizardName"
490
			icon="icons/full/etool16/new_entity_wiz.gif"
491
			category="org.eclipse.jpt"
492
			class="org.eclipse.jpt.ui.internal.wizards.entity.EntityWizard">
493
			<description>%newJpaEntityWizardDesc</description>
494
		</wizard>
495
		
496
		<wizard
497
            id="org.eclipse.jpt.ui.wizard.newMappingFile"
498
			name="%newJpaMappingFileWizardName"
499
			icon="icons/full/etool16/new_jpa_file_wiz.gif"
500
			category="org.eclipse.jpt"
501
			class="org.eclipse.jpt.ui.internal.wizards.orm.MappingFileWizard">
502
			<description>%newJpaMappingFileWizardDesc</description>
503
		</wizard>
504
      
487
	</extension>
505
	</extension>
488
	
506
	
489
	
507
	
Lines 658-679 Link Here
658
		
676
		
659
	</extension>
677
	</extension>
660
 	
678
 	
661
<!-- =================================================================================== -->
662
<!-- Extension: Entity Wizard                                                       -->
663
<!-- =================================================================================== -->
664
 	
665
    <extension
666
         point="org.eclipse.ui.newWizards">
667
      <wizard
668
            category="org.eclipse.jpt"
669
            class="org.eclipse.jpt.ui.internal.wizards.entity.EntityWizard"
670
            icon="icons/full/obj16/entity.gif"
671
            id="org.eclipse.jpt.ui.internal.wizards.entity.EntityWizard"
672
            name="JPA Entity">
673
         <description>
674
			Create Entity wizard
675
         </description>
676
      </wizard>
677
   </extension>
678
 	
679
</plugin>
679
</plugin>
(-)plugin.properties (+4 lines)
Lines 29-34 Link Here
29
jpaWizardCategoryName = JPA
29
jpaWizardCategoryName = JPA
30
newJpaProjectWizardName = JPA Project
30
newJpaProjectWizardName = JPA Project
31
newJpaProjectWizardDesc = Create a JPA project
31
newJpaProjectWizardDesc = Create a JPA project
32
newJpaEntityWizardName = Entity
33
newJpaEntityWizardDesc = Create a JPA Entity 
34
newJpaMappingFileWizardName = Mapping File
35
newJpaMappingFileWizardDesc = Create a JPA Mapping File
32
36
33
jpaStructureViewCommandCategory = JPA Structure View
37
jpaStructureViewCommandCategory = JPA Structure View
34
addPersistentClass = Add Class ...
38
addPersistentClass = Add Class ...
(-)icons/full/etool16/new_jpa_file_wiz.gif (+4 lines)
Added Link Here
1
GIF87a÷ÿº—&¿¶ˆþýï¼µŠùúüÔ²iµ‘#µ’#¹²Œ®ŠýôÏýóϵ°?øùü÷ùû÷ùüàÈ?¥‚ü磦‚¦?°­’õøûõøüžyû݃ðôû;t¢óöúŸtðôú™tááÝ-j–J®¢¤›±ÇÿíòúäµVààÝ_‹”³è4[›hܟ?vžÑåìùÓ+ØÜâÍÓÜJs•_"Œ–ªˆ–¬áêøâëøâê÷âë÷ßé÷àé÷ßéø†”®†“®…“®…”®…”¯‰”¬ÿÿÿ!ù,¸HP`€‚*L À€ƒ	˜HÑÀ ˜€"E0`°@?ÀR>p!‚	(Thá‚Í›0dÐ?? …
2
:íàáÃCˆaÔ¨‡¢$
3
Š(1„UNx@A0…
4
Vˆ]Á¢ES¸àð¢í0XÄ((c†·/hÐxQ£ ?3pàÈ¡ƒÆ?}	ÚØÁ˜?Œw$èãA|©ücHÁÏ ;
(-)src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java (+215 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2008  Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *  
8
 *  Contributors: 
9
 *  	Oracle - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jpt.ui.internal.wizards.orm;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
19
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jpt.core.JptCorePlugin;
22
import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties;
23
import org.eclipse.jpt.ui.internal.JptUiMessages;
24
import org.eclipse.jpt.utility.internal.CollectionTools;
25
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
26
import org.eclipse.jst.j2ee.internal.plugin.J2EEUIMessages;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.events.SelectionAdapter;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.Button;
33
import org.eclipse.swt.widgets.Combo;
34
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.Text;
37
import org.eclipse.ui.IWorkbench;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
40
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
41
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
42
import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
43
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
44
45
public class MappingFileWizardPage extends DataModelWizardPage
46
	implements OrmFileCreationDataModelProperties
47
{
48
	private Label projectNameLabel;
49
		
50
	private Combo projectNameCombo;	
51
	
52
	private Label sourceFolderLabel;
53
	
54
	private Text sourceFolderText;
55
	
56
	private Label filePathLabel;
57
	
58
	private Text filePathText;
59
	
60
	private Label accessLabel;
61
	
62
	private Combo accessCombo;
63
	
64
	private Button addToPersistenceUnitButton;
65
	
66
	private Label persistenceUnitLabel;
67
	
68
	private Combo persistenceUnitCombo;
69
	
70
	
71
	public MappingFileWizardPage(IDataModel dataModel, String pageName) {
72
		super(dataModel, pageName);
73
		setTitle(JptUiMessages.MappingFileWizardPage_title);
74
		setDescription(JptUiMessages.MappingFileWizardPage_desc);
75
		setPageComplete(false);
76
	}
77
	
78
	
79
	@Override
80
	protected Composite createTopLevelComposite(Composite parent) {
81
		Composite composite = new Composite(parent, SWT.NULL);
82
		GridLayout layout = new GridLayout();
83
		layout.numColumns = 3;
84
		composite.setLayout(layout);
85
		GridData data = new GridData();
86
		data.verticalAlignment = GridData.FILL;
87
		data.horizontalAlignment = GridData.FILL;
88
		data.widthHint = 300;
89
		composite.setLayoutData(data);
90
		
91
		projectNameLabel = new Label(composite, SWT.NONE);
92
		projectNameLabel.setText(JptUiMessages.MappingFileWizardPage_projectLabel); //$NON-NLS-1$
93
		data = new GridData();
94
		projectNameLabel.setLayoutData(data);
95
		
96
		projectNameCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
97
		data = new GridData(GridData.FILL_HORIZONTAL);
98
		data.widthHint = 300;
99
		data.horizontalSpan = 1;
100
		projectNameCombo.setLayoutData(data);
101
		projectNameCombo.addSelectionListener(new SelectionAdapter() {
102
			public void widgetSelected(SelectionEvent e) {
103
				super.widgetSelected(e);
104
				// update source folder
105
//					if (folderText != null) {					
106
//						String sourceFolder = getDefaultJavaSourceFolder(ProjectUtilities.getProject(projectNameCombo.getText())).getFullPath().toOSString();					
107
//						if (sourceFolder != null)
108
//							folderText.setText(sourceFolder);
109
//					}
110
			}
111
		});
112
		synchHelper.synchCombo(projectNameCombo, PROJECT_NAME, null);
113
		fillProjects();
114
		new Label(composite, SWT.NONE);
115
		
116
		sourceFolderLabel = new Label(composite, SWT.NONE);
117
		sourceFolderLabel.setText(JptUiMessages.MappingFileWizardPage_sourceFolderLabel); //$NON-NLS-1$
118
		data = new GridData();
119
		sourceFolderLabel.setLayoutData(data);
120
		
121
		sourceFolderText = new Text(composite, SWT.BORDER);
122
		data = new GridData(GridData.FILL_HORIZONTAL);
123
		data.widthHint = 300;
124
		data.horizontalSpan = 1;
125
		sourceFolderText.setLayoutData(data);
126
		synchHelper.synchText(sourceFolderText, SOURCE_FOLDER, null);
127
		new Label(composite, SWT.NONE);
128
		
129
		filePathLabel = new Label(composite, SWT.NONE);
130
		filePathLabel.setText(JptUiMessages.MappingFileWizardPage_filePathLabel); //$NON-NLS-1$
131
		data = new GridData();
132
		filePathLabel.setLayoutData(data);
133
		
134
		filePathText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
135
		data = new GridData(GridData.FILL_HORIZONTAL);
136
		data.widthHint = 300;
137
		data.horizontalSpan = 1;
138
		filePathText.setLayoutData(data);
139
		synchHelper.synchText(filePathText, FILE_PATH, null);
140
		fillProjects();
141
		new Label(composite, SWT.NONE);
142
		
143
		accessLabel = new Label(composite, SWT.NONE);
144
		accessLabel.setText(JptUiMessages.MappingFileWizardPage_accessLabel); //$NON-NLS-1$
145
		data = new GridData();
146
		accessLabel.setLayoutData(data);
147
		
148
		accessCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
149
		data = new GridData(GridData.FILL_HORIZONTAL);
150
		data.widthHint = 300;
151
		data.horizontalSpan = 1;
152
		accessCombo.setLayoutData(data);
153
		new Label(composite, SWT.NONE);
154
		
155
		addToPersistenceUnitButton = new Button(composite, SWT.CHECK | SWT.BEGINNING);
156
		addToPersistenceUnitButton.setText(JptUiMessages.MappingFileWizardPage_addToPersistenceUnitButton);
157
		data = new GridData(GridData.FILL_HORIZONTAL);
158
		data.horizontalSpan = 3;
159
		addToPersistenceUnitButton.setLayoutData(data);
160
		
161
		persistenceUnitLabel = new Label(composite, SWT.NONE);
162
		persistenceUnitLabel.setText(JptUiMessages.MappingFileWizardPage_persistenceUnitLabel); //$NON-NLS-1$
163
		data = new GridData();
164
		persistenceUnitLabel.setLayoutData(data);
165
		
166
		persistenceUnitCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
167
		data = new GridData(GridData.FILL_HORIZONTAL);
168
		data.widthHint = 300;
169
		data.horizontalSpan = 1;
170
		persistenceUnitCombo.setLayoutData(data);
171
		new Label(composite, SWT.NONE);
172
		
173
//		classText.setFocus();
174
		PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, getInfopopID());
175
	    Dialog.applyDialogFont(parent);
176
		return composite;
177
	}
178
	
179
	private void fillProjects() {
180
		projectNameCombo.setItems(new String[0]);
181
		for (Iterator<IProject> stream = jpaProjects(); stream.hasNext(); ) {
182
			projectNameCombo.add(stream.next().getName());
183
		}
184
	}
185
		
186
	private Iterator<IProject> jpaProjects() {
187
		return new FilteringIterator<IProject, IProject>(CollectionTools.iterator(ProjectUtilities.getAllProjects())) {
188
			@Override
189
			protected boolean accept(IProject project) {
190
				try {
191
					return FacetedProjectFramework.hasProjectFacet(project, JptCorePlugin.FACET_ID);
192
				}
193
				catch (CoreException ce) {
194
					return false;
195
				}
196
			}
197
		};
198
	}
199
	
200
	@Override
201
	protected String[] getValidationPropertyNames() {
202
		return new String[] {
203
			PROJECT_NAME,
204
			SOURCE_FOLDER,
205
			FILE_PATH,
206
			DEFAULT_ACCESS,
207
			ADD_TO_PERSISTENCE_UNIT,
208
			PERSISTENCE_UNIT
209
		};
210
	}
211
	
212
	void init(IWorkbench workbench, IStructuredSelection selection) {
213
		
214
	}
215
}
(-)src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java (+96 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2008  Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *  
8
 *  Contributors: 
9
 *  	Oracle - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jpt.ui.internal.wizards.orm;
12
13
import java.lang.reflect.InvocationTargetException;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.runtime.Path;
17
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties;
20
import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider;
21
import org.eclipse.jpt.ui.JptUiPlugin;
22
import org.eclipse.jpt.ui.internal.JptUiMessages;
23
import org.eclipse.ui.INewWizard;
24
import org.eclipse.ui.IWorkbench;
25
import org.eclipse.ui.IWorkbenchPage;
26
import org.eclipse.ui.PartInitException;
27
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.ide.IDE;
29
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
30
import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
31
import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
32
33
public class MappingFileWizard extends DataModelWizard 
34
	implements INewWizard 
35
{
36
	private MappingFileWizardPage page;
37
	
38
	
39
	public MappingFileWizard() {
40
		this(null);
41
	}
42
	
43
	public MappingFileWizard(IDataModel dataModel) {
44
		super(dataModel);
45
		setWindowTitle(JptUiMessages.MappingFileWizard_title);
46
		//setDefaultPageImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_WIZ_BANNER));
47
	}
48
	
49
	
50
	@Override
51
	protected void doAddPages() {
52
		super.doAddPages();
53
		page = new MappingFileWizardPage(getDataModel(), "Page_1");
54
		addPage(page);
55
	}
56
	
57
	@Override
58
	protected IDataModelProvider getDefaultProvider() {
59
		return new OrmFileCreationDataModelProvider();
60
	}
61
	
62
	public void init(IWorkbench workbench, IStructuredSelection selection) {
63
		
64
	}
65
	
66
	protected void postPerformFinish() throws InvocationTargetException {      
67
        try {
68
        	String projectName = (String) getDataModel().getProperty(OrmFileCreationDataModelProperties.PROJECT_NAME);
69
        	IProject project = ProjectUtilities.getProject(projectName);
70
        	String sourceFolder = getDataModel().getStringProperty(OrmFileCreationDataModelProperties.SOURCE_FOLDER);
71
        	String filePath = getDataModel().getStringProperty(OrmFileCreationDataModelProperties.FILE_PATH);
72
        	
73
        	IFile file = project.getWorkspace().getRoot().getFile(new Path(sourceFolder).append(filePath));
74
            openEditor(file);
75
        } 
76
        catch (Exception cantOpen) {
77
        	throw new InvocationTargetException(cantOpen);
78
        } 
79
    }
80
	
81
	private void openEditor(final IFile file) {
82
        if (file != null) {
83
            getShell().getDisplay().asyncExec(new Runnable() {
84
                public void run() {
85
                    try {
86
                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
87
                        IDE.openEditor(page, file, true);
88
                    }
89
                    catch (PartInitException e) {
90
                    	JptUiPlugin.log(e);
91
                    }
92
                }
93
            });
94
        }
95
    }
96
}
(-)icons/full/etool16/new_entity_wiz.gif (+2 lines)
Added Link Here
1
GIF87a÷ÿº—&ÇÎÅY›mG?]6‚MFŒ[þýï~°?e¡ks«tµ‘#µ’#/|C}°z­Î¨ÀÚ½ÃÝÁ®ŠýôÏýóÏv«s¼Ù¸ÿÿÿ¥‚ü磦‚¦?V˜l^?dœÅ—¸Ö´Ž¼‰°Ñ­àîޞyû݃C‹ZO’[›ÃžÚêÛ]›cj£ldŸg™t0~I-{C‹¼—ÁÛÇ,zB*yA0}E3€F:„L0}G8ƒLs«ƒáîä<†O:ƒM°Í¸ÙéÝÜëß»Öôѻ´Ñ½`Ÿs;„M[™gðöò¹ÖÀh¤wÐäÕºg1ºi/»p*¾x(¿%Á„$‰ "r:Q“^v«}ÙêÛ®|;ò¬ô·öÅúÔ(üßF}¯Œ+yCCŠS]?fy¯€?µ‰Éß̺i.»p-À~%À„!-zCO’_R—aR–aºÕÀ®™MÿÿþĺŒ¯—MQ•g=†T>ˆV±Ï» ?\´²™Ž†\Ž†]?†]?†\!ù,ÜHP`€‚ PÀÀ$ˆ @,`p€ƒ?8x!	&P 0A*X¸@“&4lÈ¡ƒš@„¸ b‰K˜8qEŠ§*V¬`Qb`/.Àˆ!CFŒ4jØHzDž:vðèáã? …!R䂑#H’(Y¤‰“'/¡D‘2¥&•*V®`ɀ–-\ºxù&I1LÆ?i츌™3hÒ¨Y³†
2
é6¸y'ŽÒsHËA8ðõšØkfÓ@§N;Àï;
(-)property_files/jpa_core.properties (+8 lines)
Lines 9-14 Link Here
9
#     Oracle. - initial API and implementation
9
#     Oracle. - initial API and implementation
10
###############################################################################
10
###############################################################################
11
11
12
NONE=<None>
13
VALIDATE_PROJECT_NOT_SPECIFIED=Project must be specified
14
VALIDATE_SOURCE_FOLDER_NOT_SPECIFIED=Source folder must be specified
15
VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST=Source folder ''{0}'' does not exist
16
VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT=Source folder ''{0}'' is not in project ''{1}''
17
VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER=Source folder ''{0}'' is not an actual source folder
18
VALIDATE_ORM_FILE_ALREADY_EXISTS=File already exists at this location
19
VALIDATE_PERSISTENCE_UNIT_DOES_NOT_EXIST=Persistence unit ''{0}'' is invalid
12
VALIDATE_PLATFORM_NOT_SPECIFIED=Platform must be specified
20
VALIDATE_PLATFORM_NOT_SPECIFIED=Platform must be specified
13
VALIDATE_CONNECTION_NOT_SPECIFIED=Connection must be specified
21
VALIDATE_CONNECTION_NOT_SPECIFIED=Connection must be specified
14
VALIDATE_CONNECTION_NOT_CONNECTED=Connection must be active to get data source specific help and validation.
22
VALIDATE_CONNECTION_NOT_CONNECTED=Connection must be active to get data source specific help and validation.
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 46-51 Link Here
46
 org.eclipse.jpt.core.internal.context.orm;x-friends:="org.eclipse.jpt.ui",
46
 org.eclipse.jpt.core.internal.context.orm;x-friends:="org.eclipse.jpt.ui",
47
 org.eclipse.jpt.core.internal.context.persistence;x-friends:="org.eclipse.jpt.ui",
47
 org.eclipse.jpt.core.internal.context.persistence;x-friends:="org.eclipse.jpt.ui",
48
 org.eclipse.jpt.core.internal.facet;x-friends:="org.eclipse.jpt.ui",
48
 org.eclipse.jpt.core.internal.facet;x-friends:="org.eclipse.jpt.ui",
49
 org.eclipse.jpt.core.internal.operations,
49
 org.eclipse.jpt.core.internal.platform;x-friends:="org.eclipse.jpt.ui",
50
 org.eclipse.jpt.core.internal.platform;x-friends:="org.eclipse.jpt.ui",
50
 org.eclipse.jpt.core.internal.prefs;x-friends:="org.eclipse.jpt.ui",
51
 org.eclipse.jpt.core.internal.prefs;x-friends:="org.eclipse.jpt.ui",
51
 org.eclipse.jpt.core.internal.resource.common.translators;x-friends:="org.eclipse.jpt.ui",
52
 org.eclipse.jpt.core.internal.resource.common.translators;x-friends:="org.eclipse.jpt.ui",
(-)src/org/eclipse/jpt/core/internal/JptCoreMessages.java (+16 lines)
Lines 20-25 Link Here
20
		NLS.initializeMessages(BUNDLE_NAME, JptCoreMessages.class);
20
		NLS.initializeMessages(BUNDLE_NAME, JptCoreMessages.class);
21
	}
21
	}
22
	
22
	
23
	public static String NONE;
24
	
25
	public static String VALIDATE_PROJECT_NOT_SPECIFIED;
26
	
27
	public static String VALIDATE_SOURCE_FOLDER_NOT_SPECIFIED;
28
	
29
	public static String VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST;
30
	
31
	public static String VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT;
32
	
33
	public static String VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER;
34
	
35
	public static String VALIDATE_ORM_FILE_ALREADY_EXISTS;
36
	
37
	public static String VALIDATE_PERSISTENCE_UNIT_DOES_NOT_EXIST;
38
	
23
	public static String VALIDATE_PLATFORM_NOT_SPECIFIED;
39
	public static String VALIDATE_PLATFORM_NOT_SPECIFIED;
24
	
40
	
25
	public static String VALIDATE_CONNECTION_NOT_SPECIFIED;
41
	public static String VALIDATE_CONNECTION_NOT_SPECIFIED;
(-)src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProvider.java (+319 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2008  Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *  
8
 *  Contributors: 
9
 *  	Oracle - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jpt.core.internal.operations;
12
13
import java.util.Set;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IPackageFragmentRoot;
22
import org.eclipse.jdt.core.JavaCore;
23
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
24
import org.eclipse.jpt.core.JpaProject;
25
import org.eclipse.jpt.core.JptCorePlugin;
26
import org.eclipse.jpt.core.context.persistence.Persistence;
27
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
28
import org.eclipse.jpt.core.context.persistence.PersistenceXml;
29
import org.eclipse.jpt.core.internal.JptCoreMessages;
30
import org.eclipse.jpt.core.resource.orm.AccessType;
31
import org.eclipse.jpt.utility.internal.StringTools;
32
import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
33
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
34
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor;
35
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
36
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
37
38
public class OrmFileCreationDataModelProvider extends AbstractDataModelProvider
39
	implements OrmFileCreationDataModelProperties
40
{
41
	/**
42
	 * required default constructor
43
	 */
44
	public OrmFileCreationDataModelProvider() {
45
		super();
46
	}
47
	
48
	
49
	@Override
50
	public IDataModelOperation getDefaultOperation() {
51
		return new OrmFileCreationOperation(getDataModel());
52
	}
53
	
54
	@Override
55
	public Set<String> getPropertyNames() {
56
		@SuppressWarnings("unchecked")
57
		Set<String> propertyNames = super.getPropertyNames();
58
		propertyNames.add(PROJECT_NAME);
59
		propertyNames.add(SOURCE_FOLDER);
60
		propertyNames.add(FILE_PATH);
61
		propertyNames.add(DEFAULT_ACCESS);
62
		propertyNames.add(ADD_TO_PERSISTENCE_UNIT);
63
		propertyNames.add(PERSISTENCE_UNIT);
64
		return propertyNames;
65
	}
66
	
67
	@Override
68
	public Object getDefaultProperty(String propertyName) {
69
		if (propertyName.equals(SOURCE_FOLDER)) {
70
			IFolder sourceFolder = getDefaultSourceFolder();
71
			if (sourceFolder != null && sourceFolder.exists()) {
72
				return sourceFolder.getFullPath().toOSString();
73
			}
74
		}
75
		else if (propertyName.equals(FILE_PATH)) {
76
			return new Path(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH).toOSString();
77
		}
78
		else if (propertyName.equals(DEFAULT_ACCESS)) {
79
			return null;
80
		}
81
		else if (propertyName.equals(ADD_TO_PERSISTENCE_UNIT)) {
82
			return Boolean.FALSE;
83
		}
84
		else if (propertyName.equals(PERSISTENCE_UNIT)) {
85
			PersistenceUnit pUnit = getDefaultPersistenceUnit();
86
			if (pUnit != null) {
87
				return pUnit.getName();
88
			}
89
		}
90
		return super.getDefaultProperty(propertyName);
91
	}
92
	
93
	@Override
94
	public boolean propertySet(String propertyName, Object propertyValue) {
95
		boolean ok = super.propertySet(propertyName, propertyValue);
96
		if (propertyName.equals(PROJECT_NAME)) {
97
			this.model.notifyPropertyChange(SOURCE_FOLDER, IDataModel.DEFAULT_CHG);
98
		}
99
		return ok;
100
	}
101
	
102
	@Override
103
	public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
104
		if (propertyName.equals(DEFAULT_ACCESS)) {
105
			DataModelPropertyDescriptor[] accessTypes = new DataModelPropertyDescriptor[3];
106
			accessTypes[0] = new DataModelPropertyDescriptor(null, JptCoreMessages.NONE);
107
			accessTypes[1] = new DataModelPropertyDescriptor(AccessType.FIELD, AccessType.FIELD.getName());
108
			accessTypes[2] = new DataModelPropertyDescriptor(AccessType.PROPERTY, AccessType.PROPERTY.getName());
109
			return accessTypes;
110
		}
111
		else {
112
			return super.getValidPropertyDescriptors(propertyName);
113
		}
114
	}
115
	
116
	
117
	// **************** validation *********************************************
118
	
119
	@Override
120
	public IStatus validate(String propertyName) {
121
		if (propertyName.equals(PROJECT_NAME)
122
				|| propertyName.equals(SOURCE_FOLDER)
123
				|| propertyName.equals(FILE_PATH)) {
124
			return validateProjectSourceFolderAndFilePath();
125
		}
126
		else if (propertyName.equals(ADD_TO_PERSISTENCE_UNIT)
127
				|| propertyName.equals(PERSISTENCE_UNIT)) {
128
			return validatePersistenceUnit();
129
		}
130
		return super.validate(propertyName);
131
	}
132
	
133
	private IStatus validateProjectSourceFolderAndFilePath() {
134
		String projectName = (String) getProperty(PROJECT_NAME);
135
		if (StringTools.stringIsEmpty(projectName)) {
136
			return new Status(
137
				IStatus.ERROR, JptCorePlugin.PLUGIN_ID, 
138
				JptCoreMessages.VALIDATE_PROJECT_NOT_SPECIFIED);
139
		}
140
		String sourceFolderPath = getStringProperty(SOURCE_FOLDER);
141
		if (StringTools.stringIsEmpty(sourceFolderPath)) {
142
			return new Status(
143
				IStatus.ERROR, JptCorePlugin.PLUGIN_ID,
144
				JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_SPECIFIED);
145
		}
146
		if (getVerifiedSourceFolder() == null) {
147
			return new Status(
148
				IStatus.WARNING, JptCorePlugin.PLUGIN_ID,
149
				JptCoreMessages.bind(JptCoreMessages.VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST, sourceFolderPath));
150
		}
151
		if (getVerifiedSourceFolder().getProject() != getProject()) {
152
			return new Status(
153
				IStatus.WARNING, JptCorePlugin.PLUGIN_ID,
154
				JptCoreMessages.bind(
155
					JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT, 
156
					sourceFolderPath, projectName));
157
		}
158
		if (getVerifiedJavaSourceFolder() == null) {
159
			return new Status(
160
				IStatus.WARNING, JptCorePlugin.PLUGIN_ID,
161
				JptCoreMessages.bind(JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER, sourceFolderPath));
162
		}
163
		if (getExistingOrmFile() != null) {
164
			return new Status(
165
				IStatus.ERROR, JptCorePlugin.PLUGIN_ID,
166
				JptCoreMessages.VALIDATE_ORM_FILE_ALREADY_EXISTS);
167
		}
168
		return Status.OK_STATUS;
169
	}
170
	
171
	private IStatus validatePersistenceUnit() {
172
		boolean addToPUnit = getBooleanProperty(ADD_TO_PERSISTENCE_UNIT);
173
		String pUnitName = getStringProperty(PERSISTENCE_UNIT);
174
		if (addToPUnit) {
175
			if (getPersistenceUnit() == null) {
176
				return new Status(
177
					IStatus.ERROR, JptCorePlugin.PLUGIN_ID,
178
					JptCoreMessages.bind(JptCoreMessages.VALIDATE_PERSISTENCE_UNIT_DOES_NOT_EXIST, pUnitName));
179
			}
180
		}
181
		return Status.OK_STATUS;
182
	}
183
	
184
	
185
	// **************** helper methods *****************************************
186
	
187
	// Copied from ArtifactEditOperationDataModelProvider
188
	private IProject getProject() {
189
		String projectName = (String) model.getProperty(PROJECT_NAME);
190
		if (StringTools.stringIsEmpty(projectName)) {
191
			return null;
192
		}
193
		return ProjectUtilities.getProject(projectName);
194
	}
195
	
196
	private JpaProject getJpaProject() {
197
		IProject project = getProject();
198
		if (project == null) {
199
			return null;
200
		}
201
		return JptCorePlugin.getJpaProject(project);
202
	}
203
	
204
	/**
205
	 * Return a best guess java source folder for the specified project
206
	 */
207
	// Copied from NewJavaClassDataModelProvider
208
	private IFolder getDefaultSourceFolder() {
209
		IProject project = getProject();
210
		if (project == null) {
211
			return null;
212
		}
213
		IPackageFragmentRoot[] sources = J2EEProjectUtilities.getSourceContainers(project);
214
		// Try and return the first source folder
215
		if (sources.length > 0) {
216
			try {
217
				return (IFolder) sources[0].getCorrespondingResource();
218
			} catch (Exception e) {
219
				return null;
220
			}
221
		}
222
		return null;
223
	}
224
	
225
	/**
226
	 * Return an IFolder represented by the SOURCE_FOLDER property, verified
227
	 * to exist
228
	 */
229
	private IFolder getVerifiedSourceFolder() {
230
		String folderPath = getStringProperty(SOURCE_FOLDER);
231
		IProject project = getProject();
232
		if (project == null) {
233
			return null;
234
		}
235
		IFolder folder;
236
		try {
237
			folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath));
238
		}
239
		catch (IllegalArgumentException e) {
240
			return null;
241
		}
242
		if (folder == null || ! folder.exists()) {
243
			return null;
244
		}
245
		return folder;
246
	}
247
	
248
	/**
249
	 * Return the source folder, provided it is verified to be an actual java
250
	 * source folder
251
	 */
252
	private IFolder getVerifiedJavaSourceFolder() {
253
		IFolder folder = getVerifiedSourceFolder();
254
		if (folder == null) {
255
			return null;
256
		}
257
		IJavaProject jProject = JavaCore.create(getProject());
258
		if (jProject == null) {
259
			return null;
260
		}
261
		IPackageFragmentRoot packageFragmentRoot = jProject.getPackageFragmentRoot(folder);
262
		if (packageFragmentRoot == null) {
263
			return null;
264
		}
265
		return folder;
266
	}
267
	
268
	private IFile getExistingOrmFile() {
269
		IFolder folder = getVerifiedSourceFolder();
270
		if (folder == null) {
271
			return null;
272
		}
273
		String filePath = getStringProperty(FILE_PATH);
274
		IFile existingFile = folder.getFile(new Path(filePath));
275
		if (! existingFile.exists()) {
276
			return null;
277
		}
278
		return existingFile;
279
	}
280
	
281
	private PersistenceUnit getDefaultPersistenceUnit() {
282
		JpaProject jpaProject = getJpaProject();
283
		if (jpaProject == null) {
284
			return null;
285
		}
286
		PersistenceXml persistenceXml = jpaProject.getRootContext().getPersistenceXml();
287
		if (persistenceXml == null) {
288
			return null;
289
		}
290
		Persistence persistence = persistenceXml.getPersistence();
291
		if (persistence == null) {
292
			return null;
293
		}
294
		if (persistence.persistenceUnitsSize() == 0) {
295
			return null;
296
		}
297
		return persistence.persistenceUnits().next();
298
	}
299
	
300
	private PersistenceUnit getPersistenceUnit() {
301
		String pUnitName = getStringProperty(PERSISTENCE_UNIT);
302
		if (StringTools.stringIsEmpty(pUnitName)) {
303
			return null;
304
		}
305
		JpaProject jpaProject = getJpaProject();
306
		if (jpaProject == null) {
307
			return null;
308
		}
309
		PersistenceXml persistenceXml = jpaProject.getRootContext().getPersistenceXml();
310
		if (persistenceXml == null) {
311
			return null;
312
		}
313
		PersistenceUnit pUnit = persistenceXml.getPersistenceUnit();
314
		if (! pUnitName.equals(pUnit.getName())) {
315
			return null;
316
		}
317
		return pUnit;
318
	}
319
}
(-)src/org/eclipse/jpt/core/internal/operations/OrmFileCreationDataModelProperties.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2008  Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *  
8
 *  Contributors: 
9
 *  	Oracle - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jpt.core.internal.operations;
12
13
public interface OrmFileCreationDataModelProperties
14
{
15
	/**
16
	 * Required, type String, identifies the name of the project in which to create the file
17
	 */
18
	public static final String PROJECT_NAME = "OrmFileCreationDataModelProperties.PROJECT_NAME";
19
	
20
	/**
21
	 * Required, type String, identifies the fully pathed source folder in which to create the file
22
	 */
23
	public static final String SOURCE_FOLDER = "OrmFileCreationDataModelProperties.SOURCE_FOLDER";
24
	
25
	/**
26
	 * Required, type String, identifies the file path relative to the source folder
27
	 */
28
	public static final String FILE_PATH = "OrmFileCreationDataModelProperties.FILE_PATH";
29
	
30
	/**
31
	 * Optional, type AccessType, specifies the default access type (or null)
32
	 */
33
	public static final String DEFAULT_ACCESS = "OrmFileCreationDataModelProperties.DEFAULT_ACCESS";
34
	
35
	/**
36
	 * Required, type Boolean, specifies whether to add a reference to the file
37
	 * in the persistence unit
38
	 */
39
	public static final String ADD_TO_PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT";
40
	
41
	/**
42
	 * Optional (unless ADD_TO_PERSISTENCE_UNIT property is true), type String, 
43
	 * identifies the persistence unit to which to add a reference to the file
44
	 */
45
	public static final String PERSISTENCE_UNIT = "OrmFileCreationDataModelProperties.PERSISTENCE_UNIT";
46
}
(-)src/org/eclipse/jpt/core/internal/operations/OrmFileCreationOperation.java (+159 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2008  Oracle. 
3
 *  All rights reserved.  This program and the accompanying materials are 
4
 *  made available under the terms of the Eclipse Public License v1.0 which 
5
 *  accompanies this distribution, and is available at 
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *  
8
 *  Contributors: 
9
 *  	Oracle - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jpt.core.internal.operations;
12
13
import java.util.Iterator;
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFolder;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
24
import org.eclipse.jpt.core.JpaProject;
25
import org.eclipse.jpt.core.JptCorePlugin;
26
import org.eclipse.jpt.core.context.persistence.MappingFileRef;
27
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
28
import org.eclipse.jpt.core.context.persistence.PersistenceXml;
29
import org.eclipse.jpt.core.resource.orm.AccessType;
30
import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit;
31
import org.eclipse.jpt.core.resource.orm.OrmFactory;
32
import org.eclipse.jpt.core.resource.orm.OrmResource;
33
import org.eclipse.jpt.core.resource.orm.XmlEntityMappings;
34
import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults;
35
import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata;
36
import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit;
37
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
38
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
39
40
public class OrmFileCreationOperation extends AbstractDataModelOperation
41
	implements OrmFileCreationDataModelProperties
42
{
43
	public OrmFileCreationOperation(IDataModel dataModel) {
44
		super(dataModel);
45
	}
46
	
47
	
48
	@Override
49
	public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
50
		// Create source folder if it does not exist
51
		IFolder folder = createSourceFolder();
52
		// Create orm file
53
		createOrmXml(folder);
54
		// Add orm file to persistence unit if specified
55
		addOrmXmlToPersistenceXml();
56
		return OK_STATUS;
57
	}
58
	
59
	private IProject getProject() throws ExecutionException {
60
		String projectName = (String) getDataModel().getProperty(PROJECT_NAME);
61
		IProject project = ProjectUtilities.getProject(projectName);
62
		if (project == null) {
63
			throw new ExecutionException("No project name specified");
64
		}
65
		return project;
66
	}
67
	
68
	private JpaProject getJpaProject() throws ExecutionException {
69
		IProject project = getProject();
70
		JpaProject jpaProject = JptCorePlugin.getJpaProject(project);
71
		if (jpaProject == null) {
72
			throw new ExecutionException("Project does not have JPA content");
73
		}
74
		return jpaProject;
75
	}
76
	
77
	private PersistenceUnit getPersistenceUnit() throws ExecutionException {
78
		String pUnitName = getDataModel().getStringProperty(PERSISTENCE_UNIT);
79
		JpaProject jpaProject = getJpaProject();
80
		PersistenceXml persistenceXml = jpaProject.getRootContext().getPersistenceXml();
81
		if (persistenceXml == null) {
82
			throw new ExecutionException("Project does not have a persistence.xml file");
83
		}
84
		PersistenceUnit pUnit = persistenceXml.getPersistenceUnit();
85
		if (pUnit == null || ! pUnitName.equals(pUnit.getName())) {
86
			throw new ExecutionException("persistence.xml does not have persistence unit named \'" + pUnitName + "\'");
87
		}
88
		return pUnit;
89
	}
90
	
91
	/**
92
	 * This method will return the source folder as specified in the data model. 
93
	 * It will create the source folder if it does not exist. It will not add
94
	 * it as a source folder to the project build path if it is not already.
95
	 * This method may return null.
96
	 */
97
	// copied from NewJavaClassOperation
98
	private IFolder createSourceFolder() throws ExecutionException {
99
		// Get the source folder name from the data model
100
		String folderPath = model.getStringProperty(SOURCE_FOLDER);
101
		IProject project = getProject();
102
		IFolder folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath));
103
		// If folder does not exist, create the folder with the specified path
104
		if (! folder.exists()) {
105
			try {
106
				folder.create(true, true, null);
107
			} catch (CoreException e) {
108
				throw new ExecutionException("Could not create folder", e);
109
			}
110
		}
111
		// Return the source folder
112
		return folder;
113
	}
114
	
115
	@SuppressWarnings("unchecked")
116
	private void createOrmXml(IFolder folder) throws ExecutionException {
117
		String filePath = getDataModel().getStringProperty(FILE_PATH);
118
		IFile file = folder.getFile(new Path(filePath));
119
		OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForWrite(getProject());
120
		OrmResource ormResource = oae.getResource(file);
121
		XmlEntityMappings entityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings();
122
		entityMappings.setVersion("1.0");
123
		ormResource.getContents().add(entityMappings);
124
		
125
		AccessType defaultAccess = (AccessType) getDataModel().getProperty(DEFAULT_ACCESS); 
126
		if (defaultAccess != null) {
127
			XmlPersistenceUnitMetadata puMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata();
128
			entityMappings.setPersistenceUnitMetadata(puMetadata);
129
			XmlPersistenceUnitDefaults puDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults();
130
			puMetadata.setPersistenceUnitDefaults(puDefaults);
131
			puDefaults.setAccess(defaultAccess);
132
		}
133
		
134
		oae.save(null);
135
		oae.dispose();
136
	}
137
	
138
	private void addOrmXmlToPersistenceXml() throws ExecutionException {
139
		if (! getDataModel().getBooleanProperty(ADD_TO_PERSISTENCE_UNIT)) {
140
			return;
141
		}
142
		
143
		String filePath = getDataModel().getStringProperty(FILE_PATH);
144
		PersistenceUnit pUnit = getPersistenceUnit();
145
		for (Iterator<MappingFileRef> stream = pUnit.specifiedMappingFileRefs(); stream.hasNext(); ) {
146
			if (filePath.equals(stream.next().getFileName())) {
147
				return;
148
			}
149
		}
150
		MappingFileRef mfRef = pUnit.addSpecifiedMappingFileRef();
151
		mfRef.setFileName(filePath);
152
		
153
		PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(getProject());
154
		pae.getResource((IFile) pUnit.getResource());
155
		
156
		pae.save(null);
157
		pae.dispose();
158
	}
159
}

Return to bug 200268