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 (-8 / +37 lines)
Lines 15-25 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.jdt.ui.IJavaElementSearchConstants;
19
import org.eclipse.jdt.ui.JavaUI;
20
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.jdt.core.IPackageFragmentRoot;
21
import org.eclipse.jdt.core.IPackageFragmentRoot;
19
import org.eclipse.jdt.core.IType;
22
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.core.search.IJavaSearchConstants;
23
import org.eclipse.jdt.core.JavaConventions;
24
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
25
import org.eclipse.jdt.core.search.IJavaSearchScope;
22
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
26
import org.eclipse.jdt.core.JavaCore;
23
import org.eclipse.jface.dialogs.Dialog;
27
import org.eclipse.jface.dialogs.Dialog;
24
import org.eclipse.jface.dialogs.IDialogConstants;
28
import org.eclipse.jface.dialogs.IDialogConstants;
25
import org.eclipse.jface.viewers.CheckStateChangedEvent;
29
import org.eclipse.jface.viewers.CheckStateChangedEvent;
Lines 37-42 Link Here
37
import org.eclipse.jface.viewers.TableViewer;
41
import org.eclipse.jface.viewers.TableViewer;
38
import org.eclipse.jface.viewers.Viewer;
42
import org.eclipse.jface.viewers.Viewer;
39
import org.eclipse.jface.window.Window;
43
import org.eclipse.jface.window.Window;
44
import org.eclipse.jpt.ui.JptUiPlugin;
40
import org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow;
45
import org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow;
41
import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties;
46
import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties;
42
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
47
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
Lines 62-67 Link Here
62
import org.eclipse.swt.widgets.Table;
67
import org.eclipse.swt.widgets.Table;
63
import org.eclipse.swt.widgets.TableColumn;
68
import org.eclipse.swt.widgets.TableColumn;
64
import org.eclipse.swt.widgets.Text;
69
import org.eclipse.swt.widgets.Text;
70
import org.eclipse.ui.dialogs.SelectionDialog;
65
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
71
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
66
72
67
/**
73
/**
Lines 512-518 Link Here
512
		 */
518
		 */
513
		public boolean validate(Combo combo, Text[] texts) {
519
		public boolean validate(Combo combo, Text[] texts) {
514
			if (texts.length > 0) {
520
			if (texts.length > 0) {
515
				return texts[0].getText().trim().length() > 0;
521
				IStatus validateFieldNameStatus = JavaConventions
522
						.validateFieldName(texts[0].getText(),
523
								JavaCore.VERSION_1_5,
524
								JavaCore.VERSION_1_5);
525
				if (!validateFieldNameStatus.isOK()) {
526
					return false;
527
				}
516
			}
528
			}
517
			return true;
529
			return true;
518
		}
530
		}
Lines 621-627 Link Here
621
		/**
633
		/**
622
		 * Process browsing when the Browse... button have been pressed. Allow adding of entity field
634
		 * Process browsing when the Browse... button have been pressed. Allow adding of entity field
623
		 * with arbitrary type.
635
		 * with arbitrary type.
624
		 * @see org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog
625
		 */
636
		 */
626
		private void handleChooseEntityTypeButtonPressed() {
637
		private void handleChooseEntityTypeButtonPressed() {
627
			//getControl().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT));
638
			//getControl().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT));
Lines 631-645 Link Here
631
			}
642
			}
632
643
633
			// this eliminates the non-exported classpath entries
644
			// this eliminates the non-exported classpath entries
634
			final IJavaSearchScope scope = TypeSearchEngine.createJavaSearchScopeForAProject(packRoot.getJavaProject(), true, true);
645
			final IJavaSearchScope scope = TypeSearchEngine.createJavaSearchScopeForAProject(packRoot.getJavaProject(), true, true); 
635
646
			
636
			// This includes all entries on the classpath.
647
			// This includes all entries on the classpath.
637
			FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false, null/*getWizard().getContainer()*/, scope, IJavaSearchConstants.TYPE);
648
			SelectionDialog dialog=null;
649
			try{
650
				dialog = JavaUI
651
						.createTypeDialog(
652
								getShell(),
653
								null,
654
								scope,
655
								IJavaElementSearchConstants.CONSIDER_ALL_TYPES,
656
								false);
657
			} catch (JavaModelException e) {
658
				JptUiPlugin.getPlugin().getLog().log(e.getStatus());
659
				return;
660
			}
661
			
638
			dialog.setTitle(EntityWizardMsg.TYPE_DIALOG_TITLE);
662
			dialog.setTitle(EntityWizardMsg.TYPE_DIALOG_TITLE);
639
			dialog.setMessage(EntityWizardMsg.TYPE_DIALOG_DESCRIPTION);
663
			dialog.setMessage(EntityWizardMsg.TYPE_DIALOG_DESCRIPTION);
640
664
641
			if (dialog.open() == Window.OK) {
665
			if (dialog.open() == Window.OK) {
642
				IType type = (IType) dialog.getFirstResult();
666
				IType type;
667
				Object[] result = dialog.getResult();
668
		        if (result == null || result.length == 0) {
669
		        	type = null;
670
				}
671
		        else type = (IType) result[0];
643
				String superclassFullPath = IEntityDataModelProperties.EMPTY_STRING;
672
				String superclassFullPath = IEntityDataModelProperties.EMPTY_STRING;
644
				if (type != null) {
673
				if (type != null) {
645
					superclassFullPath = type.getFullyQualifiedName();
674
					superclassFullPath = type.getFullyQualifiedName();
(-)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