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 277662 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java (-1 / +2 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 EntityDataModelProvider_entityNotInProjectClasspath;
57
	public static String EntityDataModelProvider_typeNotInProjectClasspath;
58
	public static String EntityDataModelProvider_invalidPKType;
58
	public static String EntityDataModelProvider_invalidArgument;
59
	public static String EntityDataModelProvider_invalidArgument;
59
	public static String REMOVE_BUTTON_LABEL;
60
	public static String REMOVE_BUTTON_LABEL;
60
    public static String DUPLICATED_ENTITY_NAMES_MESSAGE;
61
    public static String DUPLICATED_ENTITY_NAMES_MESSAGE;
(-)src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java (-1 / +2 lines)
Lines 56-62 Link Here
56
	 */
56
	 */
57
	@Override
57
	@Override
58
	protected String[] getValidationPropertyNames() {
58
	protected String[] getValidationPropertyNames() {
59
		return new String[]{IEntityDataModelProperties.ENTITY_FIELDS};
59
		return new String[]{IEntityDataModelProperties.ENTITY_FIELDS, 
60
							IEntityDataModelProperties.PK_FIELDS};
60
	}
61
	}
61
	
62
	
62
	/* Create the main composite and add to it the entity properties
63
	/* Create the main composite and add to it the entity properties
(-)src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java (-52 / +102 lines)
Lines 24-31 Link Here
24
import org.eclipse.jdt.core.JavaModelException;
24
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.search.IJavaSearchScope;
25
import org.eclipse.jdt.core.search.IJavaSearchScope;
26
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.JavaCore;
27
import org.eclipse.jface.bindings.keys.KeyStroke;
28
import org.eclipse.jface.bindings.keys.ParseException;
27
import org.eclipse.jface.dialogs.Dialog;
29
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
30
import org.eclipse.jface.dialogs.IDialogConstants;
31
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
32
import org.eclipse.jface.fieldassist.IContentProposalProvider;
33
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
34
import org.eclipse.jface.fieldassist.TextContentAdapter;
29
import org.eclipse.jface.viewers.CheckStateChangedEvent;
35
import org.eclipse.jface.viewers.CheckStateChangedEvent;
30
import org.eclipse.jface.viewers.CheckboxTableViewer;
36
import org.eclipse.jface.viewers.CheckboxTableViewer;
31
import org.eclipse.jface.viewers.DoubleClickEvent;
37
import org.eclipse.jface.viewers.DoubleClickEvent;
Lines 59-71 Link Here
59
import org.eclipse.swt.layout.GridData;
65
import org.eclipse.swt.layout.GridData;
60
import org.eclipse.swt.layout.GridLayout;
66
import org.eclipse.swt.layout.GridLayout;
61
import org.eclipse.swt.widgets.Button;
67
import org.eclipse.swt.widgets.Button;
62
import org.eclipse.swt.widgets.Combo;
63
import org.eclipse.swt.widgets.Composite;
68
import org.eclipse.swt.widgets.Composite;
64
import org.eclipse.swt.widgets.Control;
69
import org.eclipse.swt.widgets.Control;
65
import org.eclipse.swt.widgets.Label;
70
import org.eclipse.swt.widgets.Label;
66
import org.eclipse.swt.widgets.Shell;
71
import org.eclipse.swt.widgets.Shell;
67
import org.eclipse.swt.widgets.Table;
72
import org.eclipse.swt.widgets.Table;
68
import org.eclipse.swt.widgets.TableColumn;
73
import org.eclipse.swt.widgets.TableColumn;
74
import org.eclipse.swt.widgets.TableItem;
69
import org.eclipse.swt.widgets.Text;
75
import org.eclipse.swt.widgets.Text;
70
import org.eclipse.ui.dialogs.SelectionDialog;
76
import org.eclipse.ui.dialogs.SelectionDialog;
71
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
77
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
Lines 81-93 Link Here
81
	/**
87
	/**
82
	 * The possible entity types, mentioned in the specification (Chapter 2.1.1 Persistent Fields and Properties p.20)
88
	 * The possible entity types, mentioned in the specification (Chapter 2.1.1 Persistent Fields and Properties p.20)
83
	 */
89
	 */
84
	protected final static String[] VALID_TYPES = {"int", "long", "short", "char", "boolean", "byte", "double", "float", "java.lang.String",
90
	protected final static String[] VALID_TYPES = {"int", 
85
		"byte[]", "char[]",	"java.lang.Byte[]", "java.lang.Character[]", "java.math.BigDecimal", "java.math.BigInteger", "java.sql.Date", "java.sql.Time", "java.sql.Timestamp",
91
												   "long", 
86
		"java.util.Date", "java.util.Calendar"};
92
												   "short", 
93
												   "char", 
94
												   "boolean", 
95
												   "byte", 
96
												   "double", 
97
												   "float", 
98
												   "java.lang.String", 
99
												   "java.lang.Integer", 
100
												   "java.lang.Long", 
101
												   "java.lang.Short",
102
												   "java.lang.Character", 
103
												   "java.lang.Boolean", 
104
												   "java.lang.Byte", 
105
												   "java.lang.Double", 
106
												   "java.lang.Float", 
107
												   "java.math.BigDecimal", 
108
												   "java.math.BigInteger", 
109
												   "java.util.Date", 
110
												   "java.util.Calendar",
111
												   "java.sql.Date", 
112
												   "java.sql.Time", 
113
												   "java.sql.Timestamp",
114
												   "String", 
115
												   "Integer", 
116
												   "Long", 
117
												   "Short",
118
												   "Character", 
119
												   "Boolean", 
120
												   "Byte", 
121
												   "Double", 
122
												   "Float" };	
87
	
123
	
88
	  private CheckboxTableViewer mTableViewer = null;
124
	  private CheckboxTableViewer mTableViewer = null;
89
	  private Table mTableWidget = null;
125
	  private Table mTableWidget = null;
90
	  private final int PK_COLUMN = 0;
91
	  private final int NAME_COLUMN = 1;
126
	  private final int NAME_COLUMN = 1;
92
	  private final int TYPE_COLUMN = 2;
127
	  private final int TYPE_COLUMN = 2;
93
	
128
	
Lines 98-109 Link Here
98
	private Button editButton;
133
	private Button editButton;
99
	private Button removeButton;
134
	private Button removeButton;
100
	private String title = EntityWizardMsg.ENTITY_FIELDS_DIALOG_TITLE;
135
	private String title = EntityWizardMsg.ENTITY_FIELDS_DIALOG_TITLE;
101
	private String[] labelsForCombo = VALID_TYPES;
136
	private String[] typeProposals = VALID_TYPES;
102
	private String[] labelsForText = new String[]{EntityWizardMsg.TYPE_TEXT_FIELD, EntityWizardMsg.NAME_TEXT_FIELD};
137
	private String[] labelsForText = new String[]{EntityWizardMsg.TYPE_TEXT_FIELD, EntityWizardMsg.NAME_TEXT_FIELD};
103
	private IDataModel model;
138
	private IDataModel model;
104
	private String propertyName;
139
	private String propertyName;
105
	private Image labelProviderImage = null;
140
	private Image labelProviderImage = null;
106
	private DialogCallback callback;	
141
	private DialogCallback callback;	
142
	private static KeyStroke ks = null;
143
	static {
144
		try {
145
			ks = KeyStroke.getInstance("Ctrl+Space");			
146
		} catch (ParseException e1) {
147
			JptUiPlugin.log(e1);
148
		} 
149
	}
107
150
108
151
109
	/**
152
	/**
Lines 261-276 Link Here
261
	 * add new entity field
304
	 * add new entity field
262
	 */
305
	 */
263
	private void handleAddButtonSelected() {
306
	private void handleAddButtonSelected() {
264
		AddFieldDialog dialog = new AddFieldDialog(getShell(), title, labelsForCombo, labelsForText);
307
		AddFieldDialog dialog = new AddFieldDialog(getShell(), title, typeProposals, labelsForText);
265
		int result = dialog.open();
308
		int result = dialog.open();
266
		if (result == Window.CANCEL) {
309
		if (result == Window.CANCEL) {
267
			return;
310
			return;
268
		}
311
		}
269
		EntityRow entityRow = dialog.getEntityRow();
312
		EntityRow entityRow = dialog.getEntityRow();
270
		addEntityRow(entityRow);
313
		addEntityRow(entityRow);
271
		if (!entityRow.couldBeKey()) {
272
			mTableViewer.setGrayed(entityRow, true);
273
		}		
274
	}
314
	}
275
	
315
	
276
	/**
316
	/**
Lines 305-322 Link Here
305
		int index = mTableWidget.getSelectionIndex();
345
		int index = mTableWidget.getSelectionIndex();
306
		boolean isChecked = mTableViewer.getChecked(entityForEdit);
346
		boolean isChecked = mTableViewer.getChecked(entityForEdit);
307
		
347
		
308
		EditFieldDialog dialog = new EditFieldDialog(getShell(), title, labelsForCombo, labelsForText, entityForEdit);
348
		EditFieldDialog dialog = new EditFieldDialog(getShell(), title, typeProposals, labelsForText, entityForEdit);
309
		dialog.open();
349
		dialog.open();
310
		EntityRow entityRow = dialog.getEntityRow();
350
		EntityRow entityRow = dialog.getEntityRow();
311
		if (entityRow != null) {			
351
		if (entityRow != null) {			
312
			editEntityRow(index, entityRow);
352
			editEntityRow(index, entityRow);
313
			mTableViewer.setChecked(entityRow, isChecked);
353
			mTableViewer.setChecked(entityRow, isChecked);
314
			if (!entityRow.couldBeKey()) {
354
			mTableViewer.setGrayed(entityRow, false);
315
				mTableViewer.setChecked(entityRow, false);
316
				mTableViewer.setGrayed(entityRow, true);
317
			} else {				
318
				mTableViewer.setGrayed(entityRow, false);
319
			}
320
		}
355
		}
321
	}
356
	}
322
	
357
	
Lines 425-433 Link Here
425
			if (columnIndex == TYPE_COLUMN) {
460
			if (columnIndex == TYPE_COLUMN) {
426
				return entity.getFqnTypeName();
461
				return entity.getFqnTypeName();
427
			}		
462
			}		
428
			if (entity.couldBeKey()) {
463
			mTableViewer.setChecked(entity, entity.isKey());
429
				mTableViewer.setChecked(entity, entity.isKey());
430
			} 
431
			return "";
464
			return "";
432
		}
465
		}
433
466
Lines 454-470 Link Here
454
	private class PKFieldCheckStateListener implements ICheckStateListener {
487
	private class PKFieldCheckStateListener implements ICheckStateListener {
455
488
456
		public void checkStateChanged(CheckStateChangedEvent event) {
489
		public void checkStateChanged(CheckStateChangedEvent event) {
457
			Object[] checkedElements = mTableViewer.getCheckedElements();
458
			List<String> pkFields = new ArrayList<String>();
490
			List<String> pkFields = new ArrayList<String>();
459
			for (Object object : checkedElements) {
491
	        TableItem[] children = mTableViewer.getTable().getItems();
460
				EntityRow entity = (EntityRow)object;
492
	        for (int i = 0; i < children.length; i++) {
461
				if (entity.couldBeKey()) {					
493
	            TableItem item = children[i];
462
					pkFields.add(entity.getName());
494
	            EntityRow entityRow = (EntityRow)item.getData(); 
463
				} else {
495
	            entityRow.setKey(item.getChecked());
464
					mTableViewer.setChecked(entity, false);
496
				if (item.getChecked())
465
				}
497
					pkFields.add(entityRow.getName());
466
			}			
498
	        }
467
			model.setProperty(IEntityDataModelProperties.PK_FIELDS, pkFields);			
499
	        model.setProperty(IEntityDataModelProperties.PK_FIELDS, pkFields);
468
		}
500
		}
469
		
501
		
470
	}
502
	}
Lines 485-491 Link Here
485
		 * @return <code>true</code> if the values in the text fields are 
517
		 * @return <code>true</code> if the values in the text fields are 
486
		 *         valid, <code>false</code> otherwise.	 
518
		 *         valid, <code>false</code> otherwise.	 
487
		 */
519
		 */
488
		public boolean validate(Combo combo, Text[] texts);
520
		public boolean validate(Text type, Text[] texts);
489
		
521
		
490
		/**
522
		/**
491
		 * Retrieves the entity presentation object from the fields of the dialog. 
523
		 * Retrieves the entity presentation object from the fields of the dialog. 
Lines 497-503 Link Here
497
		 * @param texts	the name of the entity field	
529
		 * @param texts	the name of the entity field	
498
		 * @return the entity presentation object retrieved from the dialog
530
		 * @return the entity presentation object retrieved from the dialog
499
		 */
531
		 */
500
		public EntityRow retrieveResultStrings(Combo combo, Text[] texts);
532
		public EntityRow retrieveResultStrings(Text type, Text[] texts);
501
		
533
		
502
	}
534
	}
503
	
535
	
Lines 510-516 Link Here
510
		/**
542
		/**
511
		 * The first text field should not be empty. 
543
		 * The first text field should not be empty. 
512
		 */
544
		 */
513
		public boolean validate(Combo combo, Text[] texts) {
545
		public boolean validate(Text type, Text[] texts) {
514
			if (texts.length > 0) {
546
			if (texts.length > 0) {
515
				IStatus validateFieldNameStatus = JavaConventions
547
				IStatus validateFieldNameStatus = JavaConventions
516
						.validateFieldName(texts[0].getText(),
548
						.validateFieldName(texts[0].getText(),
Lines 520-526 Link Here
520
					return false;
552
					return false;
521
				}
553
				}
522
			}
554
			}
523
			if (combo.getText().equals("")) {
555
			if (type.getText().equals("")) {
524
				return false;
556
				return false;
525
			}
557
			}
526
			return true;
558
			return true;
Lines 531-539 Link Here
531
		 * entity field presentation
563
		 * entity field presentation
532
		 * @see org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow
564
		 * @see org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow
533
		 */
565
		 */
534
		public EntityRow retrieveResultStrings(Combo combo, Text[] texts) {
566
		public EntityRow retrieveResultStrings(Text type, Text[] texts) {
535
			EntityRow entity = new EntityRow();			
567
			EntityRow entity = new EntityRow();			
536
			entity.setFqnTypeName(combo.getText());
568
			entity.setFqnTypeName(type.getText());
537
			entity.setName(texts[0].getText());
569
			entity.setName(texts[0].getText());
538
			return entity;
570
			return entity;
539
		}
571
		}
Lines 546-568 Link Here
546
	 */
578
	 */
547
	private class AddFieldDialog extends Dialog implements ModifyListener, SelectionListener {
579
	private class AddFieldDialog extends Dialog implements ModifyListener, SelectionListener {
548
		protected String windowTitle;
580
		protected String windowTitle;
549
		protected String[] labelsForCombo;
581
		protected String[] typeProposals;
550
		protected String[] labelsForText;
582
		protected String[] labelsForText;
551
		protected Text[] texts;		
583
		protected Text[] texts;		
552
		protected EntityRow entityRow;
584
		protected EntityRow entityRow;
553
		protected Combo combo;
585
		protected Text attributeType;
586
		protected ContentProposalAdapter contentProposalAdapter; 		
554
		
587
		
555
		/**
588
		/**
556
		 * Constructs AddFieldDialog
589
		 * Constructs AddFieldDialog
557
		 * @param shell
590
		 * @param shell
558
		 * @param windowTitle dialog label
591
		 * @param windowTitle dialog label
559
		 * @param labelsForCombo the elements for the combo
592
		 * @param typeProposals the elements for the combo
560
		 * @param labelsForText name text
593
		 * @param labelsForText name text
561
		 */
594
		 */
562
		public AddFieldDialog(Shell shell, String windowTitle, String[] labelsForCombo, String[] labelsForText) {
595
		public AddFieldDialog(Shell shell, String windowTitle, String[] typeProposals, String[] labelsForText) {
563
			super(shell);
596
			super(shell);
564
			this.windowTitle = windowTitle;
597
			this.windowTitle = windowTitle;
565
			this.labelsForCombo = labelsForCombo;
598
			this.typeProposals = typeProposals;
566
			this.labelsForText  = labelsForText;
599
			this.labelsForText  = labelsForText;
567
		}
600
		}
568
		
601
		
Lines 589-599 Link Here
589
			label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
622
			label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
590
			
623
			
591
			
624
			
592
			combo = new Combo(composite, SWT.SINGLE | SWT.BORDER);// | SWT.READ_ONLY);		
625
			attributeType = new Text(composite, SWT.SINGLE | SWT.BORDER);// | SWT.READ_ONLY);		
593
			combo.setItems(labelsForCombo);
626
			//combo.setItems(labelsForCombo);
594
			data = new GridData(GridData.FILL_HORIZONTAL);
627
			data = new GridData(GridData.FILL_HORIZONTAL);
595
			data.horizontalSpan = 2;			
628
			data.horizontalSpan = 2;			
596
			combo.setLayoutData(data);
629
			attributeType.setLayoutData(data);
597
			
630
			
598
			Button browseButton = new Button(composite, SWT.PUSH);
631
			Button browseButton = new Button(composite, SWT.PUSH);
599
			browseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL);
632
			browseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL);
Lines 618-631 Link Here
618
				labelI.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
651
				labelI.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
619
				texts[i-1] = new Text(composite, SWT.SINGLE | SWT.BORDER);
652
				texts[i-1] = new Text(composite, SWT.SINGLE | SWT.BORDER);
620
				data = new GridData(GridData.FILL_HORIZONTAL);
653
				data = new GridData(GridData.FILL_HORIZONTAL);
621
				data.widthHint = 100;
654
				data.horizontalSpan = 2;		
622
				texts[i-1].setLayoutData(data);
655
				texts[i-1].setLayoutData(data);
623
			}
656
			}
624
657
625
			combo.setFocus();
658
			attributeType.setFocus();
626
			Dialog.applyDialogFont(parent);
659
			Dialog.applyDialogFont(parent);
660
			createContentProposalProvider();			
627
			return composite;
661
			return composite;
628
		}
662
		}
663
		
664
		private IContentProposalProvider createContentProposalProvider() {
665
			SimpleContentProposalProvider contProvider = new SimpleContentProposalProvider(typeProposals);
666
			contProvider.setFiltering(true);
667
			
668
			contentProposalAdapter = new ContentProposalAdapter(
669
					attributeType,
670
					new TextContentAdapter(), 
671
					contProvider,
672
					ks,
673
					new char[] {'b', 'c', 'd', 'i', 'f', 'l', 's', 'j', 'B', 'C', 'D', 'F', 'S', 'L', 'I'});
674
			contentProposalAdapter.setEnabled(true);
675
			contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
676
			return contProvider;
677
		}
678
		
629
679
630
		/**
680
		/**
631
		 * Process browsing when the Browse... button have been pressed. Allow adding of entity field
681
		 * Process browsing when the Browse... button have been pressed. Allow adding of entity field
Lines 670-676 Link Here
670
				if (type != null) {
720
				if (type != null) {
671
					superclassFullPath = type.getFullyQualifiedName();
721
					superclassFullPath = type.getFullyQualifiedName();
672
				}
722
				}
673
				combo.setText(superclassFullPath);
723
				attributeType.setText(superclassFullPath);
674
				//getControl().setCursor(null);
724
				//getControl().setCursor(null);
675
				return;
725
				return;
676
			}
726
			}
Lines 685-692 Link Here
685
		protected Control createContents(Composite parent) {
735
		protected Control createContents(Composite parent) {
686
			Composite composite = (Composite) super.createContents(parent);
736
			Composite composite = (Composite) super.createContents(parent);
687
			
737
			
688
			combo.addSelectionListener(this);
738
			attributeType.addSelectionListener(this);
689
			combo.addModifyListener(this);
739
			attributeType.addModifyListener(this);
690
			for (int i = 0; i < texts.length; i++) {
740
			for (int i = 0; i < texts.length; i++) {
691
				texts[i].addModifyListener(this);
741
				texts[i].addModifyListener(this);
692
			}
742
			}
Lines 701-707 Link Here
701
		 */
751
		 */
702
		@Override
752
		@Override
703
		protected void okPressed() {
753
		protected void okPressed() {
704
			entityRow = callback.retrieveResultStrings(combo, texts);
754
			entityRow = callback.retrieveResultStrings(attributeType, texts);
705
			super.okPressed();
755
			super.okPressed();
706
		}
756
		}
707
757
Lines 724-730 Link Here
724
		 * @see DialogCallback
774
		 * @see DialogCallback
725
		 */
775
		 */
726
		private void updateOKButton() {
776
		private void updateOKButton() {
727
			getButton(IDialogConstants.OK_ID).setEnabled(callback.validate(combo, texts));
777
			getButton(IDialogConstants.OK_ID).setEnabled(callback.validate(attributeType, texts));
728
		}
778
		}
729
		/* (non-Javadoc)
779
		/* (non-Javadoc)
730
		 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
780
		 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
Lines 762-768 Link Here
762
812
763
			Composite composite = (Composite) super.createDialogArea(parent);
813
			Composite composite = (Composite) super.createDialogArea(parent);
764
814
765
			combo.setText(entityRow.getFqnTypeName());
815
			attributeType.setText(entityRow.getFqnTypeName());
766
			texts[0].setText(entityRow.getName());
816
			texts[0].setText(entityRow.getName());
767
			
817
			
768
			return composite;
818
			return composite;
(-)src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java (-55 / +44 lines)
Lines 17-64 Link Here
17
public class EntityRow {
17
public class EntityRow {
18
18
19
	private static final String DOT = ".";
19
	private static final String DOT = ".";
20
	private static final char BRACKET_SQUARE = '[';
21
	private static final char BRACKET_ANGULAR = '<';
22
	private static final String PACKAGE_JAVA_LANG = "java.lang.";
20
	private boolean key = false;
23
	private boolean key = false;
21
	private String name = "";
24
	private String name = "";
22
	private String type = "";
25
	private String type = "";
23
	private String fqnTypeName = "";
26
	private String fqnTypeName = "";
24
	private boolean isSimpleType = false;
25
27
26
	private final static String[] PK_TYPES = {"int", "long", "short", "char", "boolean", "byte", "double", "float", 
28
	private final static String[] PK_TYPES = {"int", "long", "short", "char", "boolean", "byte", "double", "float", 
27
		"java.lang.String", "java.sql.Date", "java.util.Date", "java.lang.Integer", "java.lang.Long", "java.lang.Short",
29
		"java.lang.String", "java.sql.Date", "java.util.Date", "java.lang.Integer", "java.lang.Long", "java.lang.Short",
28
		"java.lang.Character", "java.lang.Boolean", "java.lang.Byte", "java.lang.Double", "java.lang.Float"};
30
		"java.lang.Character", "java.lang.Boolean", "java.lang.Byte", "java.lang.Double", "java.lang.Float"};
29
	
31
	
30
	private final static List<String> VALID_PK_TYPES = Arrays.asList(PK_TYPES);
32
	private final static String[] PK_TYPES_SHORT = { "String", "Integer", "Long", "Short", "Character", "Boolean", 
31
	
33
		 "Byte", "Double", "Float" };
32
	
33
	/**
34
	 * Constructs <code>EntityColumn</code>.
35
	 */
36
	public EntityRow() {
37
		super();
38
	}
39
34
40
	
35
	private final static List<String> VALID_PK_TYPES = Arrays.asList(PK_TYPES);
41
	/**
36
	private final static List<String> VALID_PK_TYPES_SHORT = Arrays.asList(PK_TYPES_SHORT);
42
	 * 
43
	 * Constructs <code>EntityColumn</code> with the following parameters
44
	 * 
45
	 * @param fqnTypeName - fully qualified name of the entity field type
46
	 * @param name - name of the entity field
47
	 * @param isKey - flag which indicates whether the entity field is primary key or part of composite primary key
48
	 */
49
	public EntityRow(String fqnTypeName, String name, boolean isKey) {
50
		super();
51
		this.fqnTypeName = type;
52
		this.name = name;
53
		this.key = isKey;
54
		if (fqnTypeName.indexOf(DOT) == -1) {
55
			type = fqnTypeName;
56
			isSimpleType = true;
57
		} else {
58
			type = getSimpleName(fqnTypeName);
59
		}
60
	}
61
	
62
	
37
	
63
	/**
38
	/**
64
	 * @return whether the presented entity field is primary key or part of composite primary key
39
	 * @return whether the presented entity field is primary key or part of composite primary key
Lines 124-129 Link Here
124
	public String getFqnTypeName() {
99
	public String getFqnTypeName() {
125
		return fqnTypeName;
100
		return fqnTypeName;
126
	}
101
	}
102
	
103
	private String removeSpaces(String str) {
104
		str = str.trim();
105
		StringBuffer sb = new StringBuffer();
106
		for (int i = 0; i < str.length(); i++) {
107
			char c = str.charAt(i);
108
			if (!Character.isWhitespace(c)) 
109
				sb.append(c);
110
		}
111
		return sb.toString();
112
	}
113
	
114
	private String getBasicFQN(String fqn) {
115
		String res;
116
		int bsIndex = fqn.indexOf(BRACKET_SQUARE);
117
		int baIndex = fqn.indexOf(BRACKET_ANGULAR);
118
		if (bsIndex == -1) {
119
			if (baIndex == -1) res = fqn;
120
			else res = fqn.substring(0, baIndex);
121
		} else {
122
			if (baIndex == -1) res = fqn.substring(0, bsIndex);
123
			else res = fqn.substring(0, Math.max(bsIndex, baIndex));
124
		}
125
		return res;
126
	}
127
127
128
	/**
128
	/**
129
	 * Sets the fully qualified type name of the entity field
129
	 * Sets the fully qualified type name of the entity field
Lines 131-160 Link Here
131
	 * @param fqnTypeName
131
	 * @param fqnTypeName
132
	 */
132
	 */
133
	public void setFqnTypeName(String fqnTypeName) {
133
	public void setFqnTypeName(String fqnTypeName) {
134
		this.fqnTypeName = fqnTypeName;
134
		fqnTypeName = removeSpaces(fqnTypeName);
135
		if (fqnTypeName.indexOf(DOT) == -1) {
135
		String fqnBasicTypeName = getBasicFQN(fqnTypeName);
136
			setType(fqnTypeName);
136
		if (fqnBasicTypeName.indexOf(DOT) == -1) {
137
			setSimpleType(true);
137
			if (VALID_PK_TYPES_SHORT.contains(fqnBasicTypeName)) {
138
				this.fqnTypeName = PACKAGE_JAVA_LANG + fqnTypeName;
139
				setType(fqnTypeName);
140
			} else {
141
				this.fqnTypeName = fqnTypeName;
142
				setType(fqnTypeName);
143
			}			
138
		} else {
144
		} else {
145
			this.fqnTypeName = fqnTypeName;
139
			setType(getSimpleName(fqnTypeName));
146
			setType(getSimpleName(fqnTypeName));
140
		}
147
		}		
141
		
142
	}
143
144
	/**
145
	 * @return is the type of the entity field is primitive type
146
	 */
147
	public boolean isSimpleType() {
148
		return isSimpleType;
149
	}
150
151
	/**
152
	 * Sets the flag which indicate the type of the entity field as primitive type
153
	 * 
154
	 * @param isSimpleType
155
	 */
156
	public void setSimpleType(boolean isSimpleType) {
157
		this.isSimpleType = isSimpleType;
158
	}
148
	}
159
149
160
	/**
150
	/**
Lines 173-179 Link Here
173
	 */
163
	 */
174
	private String getSimpleName(String fullyName) {
164
	private String getSimpleName(String fullyName) {
175
		return fullyName.substring(fullyName.lastIndexOf(DOT) + 1);
165
		return fullyName.substring(fullyName.lastIndexOf(DOT) + 1);
176
177
	}
166
	}
178
167
179
	@Override
168
	@Override
(-)src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java (-4 / +10 lines)
Lines 266-276 Link Here
266
	private String checkInputElementsTypeExistence(List<EntityRow> inputElements) {
266
	private String checkInputElementsTypeExistence(List<EntityRow> inputElements) {
267
		IStatus validateFieldTypeStatus=Status.OK_STATUS;
267
		IStatus validateFieldTypeStatus=Status.OK_STATUS;
268
		for (EntityRow entityRow: inputElements) {
268
		for (EntityRow entityRow: inputElements) {
269
			
269
			if (entityRow.isKey() && !entityRow.couldBeKey()) {
270
				String message = MessageFormat.format(
271
						EntityWizardMsg.EntityDataModelProvider_invalidPKType, new Object[]{entityRow.getFqnTypeName()});
272
				validateFieldTypeStatus = new Status(IStatus.ERROR,
273
						JptUiPlugin.PLUGIN_ID, message);
274
				break;				
275
			}
270
			String sig = Signature.createTypeSignature(entityRow.getFqnTypeName() ,true);
276
			String sig = Signature.createTypeSignature(entityRow.getFqnTypeName() ,true);
271
			if (sig == null) {
277
			if (sig == null) {
272
				String message = MessageFormat.format(
278
				String message = MessageFormat.format(
273
						EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
279
						EntityWizardMsg.EntityDataModelProvider_typeNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
274
				validateFieldTypeStatus = new Status(IStatus.ERROR,
280
				validateFieldTypeStatus = new Status(IStatus.ERROR,
275
						JptUiPlugin.PLUGIN_ID, message);
281
						JptUiPlugin.PLUGIN_ID, message);
276
				break;
282
				break;
Lines 296-302 Link Here
296
				}
302
				}
297
				if (type == null) {
303
				if (type == null) {
298
					String message = MessageFormat.format(
304
					String message = MessageFormat.format(
299
							EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
305
							EntityWizardMsg.EntityDataModelProvider_typeNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
300
					validateFieldTypeStatus = new Status(IStatus.ERROR,
306
					validateFieldTypeStatus = new Status(IStatus.ERROR,
301
							JptUiPlugin.PLUGIN_ID, message);
307
							JptUiPlugin.PLUGIN_ID, message);
302
					break;
308
					break;
Lines 314-320 Link Here
314
				}
320
				}
315
				if (type == null) {
321
				if (type == null) {
316
					String message = MessageFormat.format(
322
					String message = MessageFormat.format(
317
							EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
323
							EntityWizardMsg.EntityDataModelProvider_typeNotInProjectClasspath, new Object[]{entityRow.getFqnTypeName()});
318
					validateFieldTypeStatus = new Status(IStatus.ERROR,
324
					validateFieldTypeStatus = new Status(IStatus.ERROR,
319
							JptUiPlugin.PLUGIN_ID, message);
325
							JptUiPlugin.PLUGIN_ID, message);
320
					break;
326
					break;
(-)property_files/jpt_ui_entity_wizard.properties (-1 / +2 lines)
Lines 52-56 Link Here
52
APPLY_CHANGES_TO_PERSISTENCE_XML=Apply changes to persistence XML
52
APPLY_CHANGES_TO_PERSISTENCE_XML=Apply changes to persistence XML
53
ADD_MAPPED_SUPERCLASS_TO_XML=Add mapped superclass to XML
53
ADD_MAPPED_SUPERCLASS_TO_XML=Add mapped superclass to XML
54
ADD_ENTITY_TO_XML=Add entity to XML
54
ADD_ENTITY_TO_XML=Add entity to XML
55
EntityDataModelProvider_entityNotInProjectClasspath=''{0}'' does not exist on the project classpath
55
EntityDataModelProvider_typeNotInProjectClasspath=''{0}'' does not exist on the project classpath
56
EntityDataModelProvider_invalidPKType=''{0}'' is not a valid primary key type
56
EntityDataModelProvider_invalidArgument=Invalid argument ''{0}''
57
EntityDataModelProvider_invalidArgument=Invalid argument ''{0}''

Return to bug 277662