Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 250802 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java (-1 / +3 lines)
Lines 54-60 Link Here
54
    public static String BROWSE_BUTTON_LABEL;
54
    public static String BROWSE_BUTTON_LABEL;
55
    public static String ADD_BUTTON_LABEL;
55
    public static String ADD_BUTTON_LABEL;
56
    public static String EDIT_BUTTON_LABEL;
56
    public static String EDIT_BUTTON_LABEL;
57
    public static String REMOVE_BUTTON_LABEL;
57
	public static String EntityDataModelProvider_entityNotInProjectClasspath;
58
	public static String EntityDataModelProvider_invalidArgument;
59
	public static String REMOVE_BUTTON_LABEL;
58
    public static String DUPLICATED_ENTITY_NAMES_MESSAGE;
60
    public static String DUPLICATED_ENTITY_NAMES_MESSAGE;
59
    public static String ACCESS_TYPE;
61
    public static String ACCESS_TYPE;
60
    public static String FIELD_BASED;
62
    public static String FIELD_BASED;
(-)src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java (-1 / +10 lines)
Lines 15-24 Link Here
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.jdt.core.IPackageFragmentRoot;
19
import org.eclipse.jdt.core.IPackageFragmentRoot;
19
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.IType;
21
import org.eclipse.jdt.core.JavaConventions;
20
import org.eclipse.jdt.core.search.IJavaSearchConstants;
22
import org.eclipse.jdt.core.search.IJavaSearchConstants;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
23
import org.eclipse.jdt.core.search.IJavaSearchScope;
24
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
22
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
25
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
23
import org.eclipse.jface.dialogs.Dialog;
26
import org.eclipse.jface.dialogs.Dialog;
24
import org.eclipse.jface.dialogs.IDialogConstants;
27
import org.eclipse.jface.dialogs.IDialogConstants;
Lines 512-518 Link Here
512
		 */
515
		 */
513
		public boolean validate(Combo combo, Text[] texts) {
516
		public boolean validate(Combo combo, Text[] texts) {
514
			if (texts.length > 0) {
517
			if (texts.length > 0) {
515
				return texts[0].getText().trim().length() > 0;
518
				IStatus validateFieldNameStatus = JavaConventions
519
						.validateFieldName(texts[0].getText(),
520
								CompilerOptions.VERSION_1_5,
521
								CompilerOptions.VERSION_1_5);
522
				if (!validateFieldNameStatus.isOK()) {
523
					return false;
524
				}
516
			}
525
			}
517
			return true;
526
			return true;
518
		}
527
		}
(-)property_files/jpt_ui_entity_wizard.properties (+2 lines)
Lines 42-47 Link Here
42
BROWSE_BUTTON_LABEL=Browse...
42
BROWSE_BUTTON_LABEL=Browse...
43
ADD_BUTTON_LABEL=Add...
43
ADD_BUTTON_LABEL=Add...
44
EDIT_BUTTON_LABEL=Edit...
44
EDIT_BUTTON_LABEL=Edit...
45
EntityDataModelProvider_entityNotInProjectClasspath="{0}" does not exist on the project classpath
46
EntityDataModelProvider_invalidArgument=Invalid agrument "{0}"
45
REMOVE_BUTTON_LABEL=Remove
47
REMOVE_BUTTON_LABEL=Remove
46
DUPLICATED_ENTITY_NAMES_MESSAGE=There are duplicate names on created entity fields. Please resolve the duplication.
48
DUPLICATED_ENTITY_NAMES_MESSAGE=There are duplicate names on created entity fields. Please resolve the duplication.
47
ACCESS_TYPE=Access Type
49
ACCESS_TYPE=Access Type
(-)src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java (+142 lines)
Lines 11-24 Link Here
11
 ***********************************************************************/
11
 ***********************************************************************/
12
package org.eclipse.jpt.ui.internal.wizards.entity.data.model;
12
package org.eclipse.jpt.ui.internal.wizards.entity.data.model;
13
13
14
import java.text.MessageFormat;
14
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.List;
15
import java.util.Set;
17
import java.util.Set;
16
18
19
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IType;
18
import org.eclipse.jdt.core.JavaConventions;
24
import org.eclipse.jdt.core.JavaConventions;
25
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.Signature;
28
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
29
import org.eclipse.jpt.ui.JptUiPlugin;
19
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg;
30
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg;
20
import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation;
31
import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation;
21
import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages;
32
import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages;
33
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
22
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider;
34
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider;
23
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
35
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
24
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
36
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
Lines 170-180 Link Here
170
				String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE;				
182
				String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE;				
171
				return WTPCommonPlugin.createErrorStatus(msg);
183
				return WTPCommonPlugin.createErrorStatus(msg);
172
			}
184
			}
185
			// Ensure that the entries in the list are valid
186
			String errorMsg = checkInputElementsTypeValidation(entities);
187
			if(errorMsg != null) 
188
				return WTPCommonPlugin.createErrorStatus(errorMsg);
189
			String warningMsg = checkInputElementsTypeExistence(entities);
190
			if(warningMsg != null) 
191
				return WTPCommonPlugin.createWarningStatus(warningMsg);
192
			
173
		}
193
		}
174
		// Return OK
194
		// Return OK
175
		return WTPCommonPlugin.OK_STATUS;
195
		return WTPCommonPlugin.OK_STATUS;
176
	}
196
	}
177
	
197
	
198
	private String checkInputElementsTypeValidation(List<EntityRow> inputElements){
199
		IStatus validateFieldTypeStatus=Status.OK_STATUS;
200
		for(EntityRow entityRow: inputElements) {
201
			if (entityRow.getFqnTypeName().equals("")){
202
				validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getFqnTypeName(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5);
203
				break;
204
			}
205
			String sig = null;
206
			try {
207
				sig = Signature.createTypeSignature(entityRow.getFqnTypeName(),true);
208
			} catch (IllegalArgumentException e) {
209
				String message = MessageFormat.format(EntityWizardMsg.EntityDataModelProvider_invalidArgument, e.getLocalizedMessage());
210
				validateFieldTypeStatus = new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, message);
211
				break;
212
			}
213
			if(sig == null){
214
				validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getType(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5);
215
				break;
216
				  
217
			}
218
			Integer sigType = Signature.getTypeSignatureKind(sig);
219
			if(sigType == Signature.BASE_TYPE_SIGNATURE){
220
				continue;
221
			}
222
			else if(sigType == Signature.ARRAY_TYPE_SIGNATURE) {
223
				String elementSignature = Signature.getElementType(sig);
224
				if(Signature.getTypeSignatureKind(elementSignature) == Signature.BASE_TYPE_SIGNATURE){
225
					continue;
226
				}
227
				else {
228
					String elFullSignature = Signature.createTypeSignature(entityRow.getFqnTypeName(),true);
229
					String elSignatureType = Signature.getElementType(elFullSignature);
230
					String elSignatureTypeString = Signature.toString(elSignatureType);
231
					String elTypeSimpleName = Signature.getSimpleName(elSignatureTypeString);
232
					
233
					validateFieldTypeStatus = JavaConventions.validateFieldName(elTypeSimpleName, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5);
234
				    if(!validateFieldTypeStatus.isOK()) {
235
					break;
236
			        } 
237
		        }
238
			}
239
				else {
240
				validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getType(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5);
241
			    if(!validateFieldTypeStatus.isOK()) {
242
				break;
243
			  }
244
		 }
245
	}
246
		if(!validateFieldTypeStatus.isOK()){
247
			return validateFieldTypeStatus.getMessage();
248
		}
249
		return null;
250
	}
251
	
252
	private String checkInputElementsTypeExistence(List<EntityRow> inputElements){
253
		IStatus validateFieldTypeStatus=Status.OK_STATUS;
254
		for(EntityRow entityRow: inputElements) {
255
			
256
			String sig = Signature.createTypeSignature(entityRow.getFqnTypeName(),true);
257
			if(sig == null){
258
				String message = MessageFormat.format(
259
						EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName());
260
				validateFieldTypeStatus = new Status(IStatus.ERROR,
261
						JptUiPlugin.PLUGIN_ID, message);
262
				break;
263
			}
264
			Integer sigType = Signature.getTypeSignatureKind(sig);
265
			if(sigType == Signature.BASE_TYPE_SIGNATURE){
266
				continue;
267
			}
268
			else if(sigType == Signature.ARRAY_TYPE_SIGNATURE) {
269
				String elementSignature = Signature.getElementType(sig);
270
				if(Signature.getTypeSignatureKind(elementSignature) == Signature.BASE_TYPE_SIGNATURE){
271
					continue;
272
				}
273
				else {
274
					String qualifiedName = Signature.toString(elementSignature);
275
					IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT);
276
					IJavaProject javaProject = JavaCore.create(project);
277
					IType type=null;
278
					try {
279
						type = javaProject.findType(qualifiedName);
280
					} catch (JavaModelException e) {
281
						validateFieldTypeStatus = e.getStatus();
282
						break;
283
					}
284
					if (type == null) {
285
						String message = MessageFormat.format(
286
								EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName());
287
						validateFieldTypeStatus = new Status(IStatus.ERROR,
288
								JptUiPlugin.PLUGIN_ID, message);
289
						break;
290
					}
291
			  } 
292
		}
293
			else {
294
				IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT);
295
				IJavaProject javaProject = JavaCore.create(project);
296
				IType type=null;
297
				try {
298
					type = javaProject.findType(entityRow.getFqnTypeName());
299
				} catch (JavaModelException e) {
300
					validateFieldTypeStatus = e.getStatus();
301
					break;
302
				}
303
				if (type == null) {
304
					String message = MessageFormat.format(
305
							EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName());
306
					validateFieldTypeStatus = new Status(IStatus.ERROR,
307
							JptUiPlugin.PLUGIN_ID, message);
308
					break;
309
				}
310
			}
311
			
312
	}
313
		if(!validateFieldTypeStatus.isOK()){
314
			return validateFieldTypeStatus.getMessage();
315
		}
316
		return null;
317
	}
318
	
319
	
178
	/**
320
	/**
179
	 * This method is intended for internal use only. It provides a simple algorithm for detecting
321
	 * This method is intended for internal use only. It provides a simple algorithm for detecting
180
	 * if there are duplicate entries in a list. It will accept a null parameter. It will return
322
	 * if there are duplicate entries in a list. It will accept a null parameter. It will return

Return to bug 250802