View | Details | Raw Unified | Return to bug 267343 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java (-289 / +329 lines)
Lines 46-55 Link Here
46
import org.eclipse.jpt.db.ConnectionAdapter;
46
import org.eclipse.jpt.db.ConnectionAdapter;
47
import org.eclipse.jpt.db.ConnectionListener;
47
import org.eclipse.jpt.db.ConnectionListener;
48
import org.eclipse.jpt.db.ConnectionProfile;
48
import org.eclipse.jpt.db.ConnectionProfile;
49
import org.eclipse.jpt.db.ConnectionProfileFactory;
49
import org.eclipse.jpt.db.ConnectionProfileListener;
50
import org.eclipse.jpt.db.ConnectionProfileListener;
50
import org.eclipse.jpt.db.Database;
51
import org.eclipse.jpt.db.Database;
51
import org.eclipse.jpt.db.JptDbPlugin;
52
import org.eclipse.jpt.db.JptDbPlugin;
52
import org.eclipse.jpt.db.Schema;
53
import org.eclipse.jpt.db.Schema;
54
import org.eclipse.jpt.db.SchemaContainer;
53
import org.eclipse.jpt.db.ui.internal.DTPUiTools;
55
import org.eclipse.jpt.db.ui.internal.DTPUiTools;
54
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
56
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
55
import org.eclipse.jpt.ui.internal.JptUiMessages;
57
import org.eclipse.jpt.ui.internal.JptUiMessages;
Lines 110-156 Link Here
110
{
112
{
111
	public static final String PROP_ID = "org.eclipse.jpt.ui.jpaProjectPropertiesPage"; //$NON-NLS-1$
113
	public static final String PROP_ID = "org.eclipse.jpt.ui.jpaProjectPropertiesPage"; //$NON-NLS-1$
112
114
113
	private WritablePropertyValueModel<IProject> projectHolder;
115
	WritablePropertyValueModel<IProject> projectHolder;
114
	
116
	
115
	private PropertyValueModel<JpaProject> jpaProjectHolder;
117
	PropertyValueModel<JpaProject> jpaProjectHolder;
116
	
118
	
117
	private Trigger trigger;
119
	Trigger trigger;
118
	
120
	
119
	private PropertyChangeListener validationListener;
121
	PropertyChangeListener validationListener;
120
	
122
	
121
	private PropertyChangeListener overrideDefaultCatalogListener;
123
	PropertyChangeListener overrideDefaultCatalogListener;
122
	
124
	
123
	private PropertyChangeListener overrideDefaultSchemaListener;
125
	PropertyChangeListener overrideDefaultSchemaListener;
124
126
125
	private PropertyChangeListener platformChangelistener;
127
	PropertyChangeListener platformChangelistener;
126
	
128
	
127
	private BufferedWritablePropertyValueModel<String> platformIdModel;
129
	BufferedWritablePropertyValueModel<String> platformIdModel;
128
	
130
	
129
	private BufferedWritablePropertyValueModel<String> connectionModel;
131
	BufferedWritablePropertyValueModel<String> connectionModel;
130
	
132
	
131
	private ListValueModel<String> connectionChoicesModel;
133
	ListValueModel<String> connectionChoicesModel;
132
	
134
	
133
	private PropertyValueModel<ConnectionProfile> connectionProfileModel;
135
	PropertyValueModel<ConnectionProfile> connectionProfileModel;
134
	
136
	
135
	private BufferedWritablePropertyValueModel<Boolean> overrideDefaultCatalogModel;
137
	PropertyValueModel<Boolean> databaseSupportsCatalogsModel;
136
	
138
	
137
	private BufferedWritablePropertyValueModel<String> defaultCatalogModel;
139
	PropertyValueModel<Boolean> databaseExistsModel;
138
	
140
	
139
	private WritablePropertyValueModel<String> combinedDefaultCatalogModel;
141
	BufferedWritablePropertyValueModel<Boolean> overrideDefaultCatalogModel;
140
	
142
	
141
	private ListValueModel<String> catalogChoicesModel;
143
	BufferedWritablePropertyValueModel<String> defaultCatalogModel;
144
	
145
	WritablePropertyValueModel<String> combinedDefaultCatalogModel;
146
	
147
	ListValueModel<String> catalogChoicesModel;
142
148
143
	private BufferedWritablePropertyValueModel<Boolean> overrideDefaultSchemaModel;
149
	BufferedWritablePropertyValueModel<Boolean> overrideDefaultSchemaModel;
144
	
150
	
145
	private BufferedWritablePropertyValueModel<String> defaultSchemaModel;
151
	BufferedWritablePropertyValueModel<String> defaultSchemaModel;
146
	
152
	
147
	private WritablePropertyValueModel<String> combinedDefaultSchemaModel;
153
	WritablePropertyValueModel<String> combinedDefaultSchemaModel;
148
	
154
	
149
	private ListValueModel<String> schemaChoicesModel;
155
	ListValueModel<String> schemaChoicesModel;
150
	
156
	
151
	private BufferedWritablePropertyValueModel<Boolean> discoverAnnotatedClassesModel;
157
	BufferedWritablePropertyValueModel<Boolean> discoverAnnotatedClassesModel;
152
	
158
	
153
	private WritablePropertyValueModel<Boolean> listAnnotatedClassesModel;
159
	WritablePropertyValueModel<Boolean> listAnnotatedClassesModel;
154
160
155
161
156
	// ************ construction/initialization ************
162
	// ************ construction/initialization ************
Lines 175-180 Link Here
175
		this.connectionChoicesModel = this.initializeConnectionChoicesModel();
181
		this.connectionChoicesModel = this.initializeConnectionChoicesModel();
176
		this.connectionProfileModel = this.initializeConnectionProfileModel();
182
		this.connectionProfileModel = this.initializeConnectionProfileModel();
177
		
183
		
184
		this.databaseSupportsCatalogsModel = this.initializeDatabaseSupportsCatalogsModel();
185
		this.databaseExistsModel = this.initializeDatabaseExistsModel();
186
		
178
		this.overrideDefaultCatalogModel = this.initializeOverrideDefaultCatalogModel();
187
		this.overrideDefaultCatalogModel = this.initializeOverrideDefaultCatalogModel();
179
		this.defaultCatalogModel = this.initializeDefaultCatalogModel();
188
		this.defaultCatalogModel = this.initializeDefaultCatalogModel();
180
		this.combinedDefaultCatalogModel = this.initializeCombinedDefaultCatalogModel();
189
		this.combinedDefaultCatalogModel = this.initializeCombinedDefaultCatalogModel();
Lines 256-265 Link Here
256
	}
265
	}
257
	
266
	
258
	protected ListValueModel<String> initializeConnectionChoicesModel() {
267
	protected ListValueModel<String> initializeConnectionChoicesModel() {
259
		return new ExtendedListValueModelWrapper(
268
		return new ExtendedListValueModelWrapper<String>(
260
				(String) null,
269
				new SortedListValueModelAdapter<String>(	
261
				new SortedListValueModelAdapter(	
270
					new CollectionListValueModelAdapter<String>(
262
					new CollectionListValueModelAdapter(
263
						new ConnectionChoicesModel(this.projectHolder))));
271
						new ConnectionChoicesModel(this.projectHolder))));
264
	}
272
	}
265
	
273
	
Lines 271-285 Link Here
271
			}
279
			}
272
		};
280
		};
273
	}
281
	}
282
	
283
	protected PropertyValueModel<Boolean> initializeDatabaseSupportsCatalogsModel() {
284
		return new DatabaseSupportsCatalogsModel(this.connectionProfileModel);
285
	}
286
287
	protected PropertyValueModel<Boolean> initializeDatabaseExistsModel() {
288
		return new DatabaseExistsModel(this.connectionProfileModel);
289
	}
274
290
275
	protected BufferedWritablePropertyValueModel<Boolean> initializeOverrideDefaultCatalogModel() {
291
	protected BufferedWritablePropertyValueModel<Boolean> initializeOverrideDefaultCatalogModel() {
276
		OverrideDefaultCatalogModel model = new OverrideDefaultCatalogModel(this.jpaProjectHolder);
292
		OverrideDefaultCatalogModel model = new OverrideDefaultCatalogModel(this.jpaProjectHolder);
277
		BufferedWritablePropertyValueModel<Boolean> modelBuffer = 
278
			new BufferedWritablePropertyValueModel(model, this.trigger);
279
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.overrideDefaultCatalogListener);
293
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.overrideDefaultCatalogListener);
280
		modelBuffer.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
294
281
		return modelBuffer;
295
		BufferedWritablePropertyValueModel<Boolean> bufferedModel = new BufferedWritablePropertyValueModel<Boolean>(model, this.trigger);
282
		
296
		bufferedModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
297
298
		return bufferedModel;
283
	}
299
	}
284
	
300
	
285
	protected BufferedWritablePropertyValueModel<String> initializeDefaultCatalogModel() {
301
	protected BufferedWritablePropertyValueModel<String> initializeDefaultCatalogModel() {
Lines 299-317 Link Here
299
	}
315
	}
300
	
316
	
301
	protected ListValueModel<String> initializeCatalogChoicesModel() {
317
	protected ListValueModel<String> initializeCatalogChoicesModel() {
302
		Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>();
318
		Collection<CollectionValueModel<String>> cvms = new ArrayList<CollectionValueModel<String>>();
303
		cvms.add(new PropertyCollectionValueModelAdapter(this.defaultCatalogModel));
319
		cvms.add(new PropertyCollectionValueModelAdapter<String>(this.defaultCatalogModel));
304
		cvms.add(new CatalogChoicesModel(this.connectionProfileModel));
320
		cvms.add(new CatalogChoicesModel(this.connectionProfileModel));
305
		return new SortedListValueModelAdapter(
321
		return new SortedListValueModelAdapter<String>(
306
			new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) {
322
			new CompositeCollectionValueModel<CollectionValueModel<String>, String>(cvms) {
307
				@Override
323
				@Override
308
				public Iterator<String> iterator() {
324
				public Iterator<String> iterator() {
309
					Set<String> uniqueValues = new HashSet<String>();
325
					Set<String> uniqueValues = new HashSet<String>();
310
					for (String each : CollectionTools.iterable(super.iterator())) {
326
					CollectionTools.addAll(uniqueValues, super.iterator());
311
						if (each != null) {
312
							uniqueValues.add(each);
313
						}
314
					}
315
					return uniqueValues.iterator();
327
					return uniqueValues.iterator();
316
				}
328
				}
317
			});
329
			});
Lines 338-362 Link Here
338
			new CombinedDefaultSchemaModel(
350
			new CombinedDefaultSchemaModel(
339
				this.defaultSchemaModel,
351
				this.defaultSchemaModel,
340
				this.overrideDefaultSchemaModel,
352
				this.overrideDefaultSchemaModel,
341
				new DefaultDefaultSchemaModel(this.connectionProfileModel));
353
				new DefaultDefaultSchemaModel(this.defaultCatalogModel, this.connectionProfileModel));
342
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
354
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
343
		return model;
355
		return model;
344
	}
356
	}
345
	
357
	
346
	protected ListValueModel<String> initializeSchemaChoicesModel() {
358
	protected ListValueModel<String> initializeSchemaChoicesModel() {
347
		Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>();
359
		Collection<CollectionValueModel<String>> cvms = new ArrayList<CollectionValueModel<String>>();
348
		cvms.add(new PropertyCollectionValueModelAdapter(this.defaultSchemaModel));
360
		cvms.add(new PropertyCollectionValueModelAdapter<String>(this.defaultSchemaModel));
349
		cvms.add(new SchemaChoicesModel(this.connectionProfileModel));
361
		cvms.add(new SchemaChoicesModel(this.defaultCatalogModel, this.connectionProfileModel));
350
		return new SortedListValueModelAdapter(
362
		return new SortedListValueModelAdapter<String>(
351
			new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) {
363
			new CompositeCollectionValueModel<CollectionValueModel<String>, String>(cvms) {
352
				@Override
364
				@Override
353
				public Iterator<String> iterator() {
365
				public Iterator<String> iterator() {
354
					Set<String> uniqueValues = new HashSet<String>();
366
					Set<String> uniqueValues = new HashSet<String>();
355
					for (String each : CollectionTools.iterable(super.iterator())) {
367
					CollectionTools.addAll(uniqueValues, super.iterator());
356
						if (each != null) {
357
							uniqueValues.add(each);
358
						}
359
					}
360
					return uniqueValues.iterator();
368
					return uniqueValues.iterator();
361
				}
369
				}
362
			});
370
			});
Lines 676-682 Link Here
676
		protected V value;
684
		protected V value;
677
		
685
		
678
		
686
		
679
		protected BasePropertyAspectAdapter(PropertyValueModel<S> subjectHolder) {
687
		BasePropertyAspectAdapter(PropertyValueModel<S> subjectHolder) {
680
			super(subjectHolder);
688
			super(subjectHolder);
681
			this.value = null;
689
			this.value = null;
682
		}
690
		}
Lines 691-702 Link Here
691
		
699
		
692
		public final void setValue(V value) {
700
		public final void setValue(V value) {
693
			if (this.subject != null) {
701
			if (this.subject != null) {
694
				setValue_(value);
702
				this.setValue_(value);
695
			}
703
			}
696
		}
704
		}
697
		
705
		
698
		protected void setValue_(V value) {
706
		protected void setValue_(@SuppressWarnings("unused") V v) {
699
			throw new UnsupportedOperationException("setValue");
707
			throw new UnsupportedOperationException();
700
		}
708
		}
701
		
709
		
702
		
710
		
Lines 741-758 Link Here
741
		// ************ internal ***********************************************
749
		// ************ internal ***********************************************
742
		
750
		
743
		protected V buildValue() {
751
		protected V buildValue() {
744
			if (this.subject != null) {
752
			return (this.subject == null) ? null : this.buildValue_();
745
				return buildValue_();
746
			}
747
			return null;
748
		}
753
		}
749
		
754
		
750
		protected abstract V buildValue_();
755
		protected abstract V buildValue_();
751
		
756
		
752
		protected void valueChanged() {
757
		protected void valueChanged() {
753
			V oldValue = this.getValue();
758
			V old = this.getValue();  // subclasses override #getValue()...
754
			this.value = buildValue();
759
			this.value = this.buildValue();
755
			this.fireAspectChange(oldValue, this.getValue());
760
			this.fireAspectChange(old, this.getValue());
756
		}
761
		}
757
	}
762
	}
758
	
763
	
Lines 761-767 Link Here
761
		extends AspectAdapter<S>
766
		extends AspectAdapter<S>
762
		implements CollectionValueModel<E>
767
		implements CollectionValueModel<E>
763
	{
768
	{
764
		protected BaseCollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
769
		BaseCollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
765
			super(subjectHolder);
770
			super(subjectHolder);
766
		}
771
		}
767
		
772
		
Lines 831-837 Link Here
831
		private IPreferenceChangeListener platformChangeListener;
836
		private IPreferenceChangeListener platformChangeListener;
832
		
837
		
833
		
838
		
834
		private JpaProjectHolder(PropertyValueModel<IProject> projectHolder) {
839
		JpaProjectHolder(PropertyValueModel<IProject> projectHolder) {
835
			super(projectHolder);
840
			super(projectHolder);
836
			this.platformChangeListener = buildPlatformChangeListener();
841
			this.platformChangeListener = buildPlatformChangeListener();
837
		}
842
		}
Lines 854-871 Link Here
854
		
859
		
855
		@Override
860
		@Override
856
		protected void engageSubject_() {
861
		protected void engageSubject_() {
857
			IEclipsePreferences preferences = JptCorePlugin.getProjectPreferences(this.subject);
858
			preferences.addPreferenceChangeListener(this.platformChangeListener);
859
			super.engageSubject_();
862
			super.engageSubject_();
863
			this.getPreferences().addPreferenceChangeListener(this.platformChangeListener);
860
		}
864
		}
861
		
865
		
862
		@Override
866
		@Override
863
		protected void disengageSubject_() {
867
		protected void disengageSubject_() {
864
			IEclipsePreferences preferences = JptCorePlugin.getProjectPreferences(this.subject);
868
			this.getPreferences().removePreferenceChangeListener(this.platformChangeListener);
865
			preferences.removePreferenceChangeListener(this.platformChangeListener);
866
			super.disengageSubject_();
869
			super.disengageSubject_();
867
		}
870
		}
868
		
871
872
		protected IEclipsePreferences getPreferences() {
873
			return JptCorePlugin.getProjectPreferences(this.subject);
874
		}
869
		
875
		
870
		// ************ internal ***********************************************
876
		// ************ internal ***********************************************
871
		
877
		
Lines 879-885 Link Here
879
	private static class PlatformIdModel
885
	private static class PlatformIdModel
880
		extends BasePropertyAspectAdapter<JpaProject, String>
886
		extends BasePropertyAspectAdapter<JpaProject, String>
881
	{
887
	{
882
		private PlatformIdModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
888
		PlatformIdModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
883
			super(jpaProjectHolder);
889
			super(jpaProjectHolder);
884
		}
890
		}
885
		
891
		
Lines 903-909 Link Here
903
	
909
	
904
	private final class PlatformGroup
910
	private final class PlatformGroup
905
	{
911
	{
906
		private PlatformGroup(Composite composite) {
912
		PlatformGroup(Composite composite) {
907
			Group group = new Group(composite, SWT.NONE);
913
			Group group = new Group(composite, SWT.NONE);
908
			group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel);
914
			group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel);
909
			group.setLayout(new GridLayout());
915
			group.setLayout(new GridLayout());
Lines 947-953 Link Here
947
		private PropertyChangeListener connectionChangeListener;
953
		private PropertyChangeListener connectionChangeListener;
948
		
954
		
949
		
955
		
950
		private ConnectionModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
956
		ConnectionModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
951
			super(jpaProjectHolder);
957
			super(jpaProjectHolder);
952
			this.connectionChangeListener = buildConnectionChangeListener();
958
			this.connectionChangeListener = buildConnectionChangeListener();
953
		}
959
		}
Lines 976-990 Link Here
976
		
982
		
977
		@Override
983
		@Override
978
		protected void engageSubject_() {
984
		protected void engageSubject_() {
979
			JpaDataSource dataSource = this.subject.getDataSource();
980
			dataSource.addPropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener);
981
			super.engageSubject_();
985
			super.engageSubject_();
986
			this.subject.getDataSource().addPropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener);
982
		}
987
		}
983
		
988
		
984
		@Override
989
		@Override
985
		protected void disengageSubject_() {
990
		protected void disengageSubject_() {
986
			JpaDataSource dataSource = this.subject.getDataSource();
991
			this.subject.getDataSource().removePropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener);
987
			dataSource.removePropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener);
988
			super.disengageSubject_();
992
			super.disengageSubject_();
989
		}
993
		}
990
		
994
		
Lines 1004-1010 Link Here
1004
		private ConnectionProfileListener connectionProfileListener;
1008
		private ConnectionProfileListener connectionProfileListener;
1005
		
1009
		
1006
		
1010
		
1007
		private ConnectionChoicesModel(PropertyValueModel<IProject> subjectHolder) {
1011
		ConnectionChoicesModel(PropertyValueModel<IProject> subjectHolder) {
1008
			super(subjectHolder);
1012
			super(subjectHolder);
1009
			this.connectionProfileListener = buildConnectionProfileListener();
1013
			this.connectionProfileListener = buildConnectionProfileListener();
1010
		}
1014
		}
Lines 1037-1050 Link Here
1037
		
1041
		
1038
		@Override
1042
		@Override
1039
		protected void engageSubject_() {
1043
		protected void engageSubject_() {
1040
			JptDbPlugin.instance().getConnectionProfileFactory().
1044
			this.getConnectionProfileFactory().addConnectionProfileListener(this.connectionProfileListener);
1041
				addConnectionProfileListener(this.connectionProfileListener);
1042
		}
1045
		}
1043
		
1046
		
1044
		@Override
1047
		@Override
1045
		protected void disengageSubject_() {
1048
		protected void disengageSubject_() {
1046
			JptDbPlugin.instance().getConnectionProfileFactory().
1049
			this.getConnectionProfileFactory().removeConnectionProfileListener(this.connectionProfileListener);
1047
				removeConnectionProfileListener(this.connectionProfileListener);
1048
		}
1050
		}
1049
		
1051
		
1050
		
1052
		
Lines 1052-1071 Link Here
1052
		
1054
		
1053
		@Override
1055
		@Override
1054
		protected Iterator<String> iterator_() {
1056
		protected Iterator<String> iterator_() {
1055
			return JptDbPlugin.instance().getConnectionProfileFactory().connectionProfileNames();
1057
			return this.getConnectionProfileFactory().connectionProfileNames();
1058
		}
1059
1060
		private ConnectionProfileFactory getConnectionProfileFactory() {
1061
			return JptDbPlugin.instance().getConnectionProfileFactory();
1056
		}
1062
		}
1057
	}
1063
	}
1058
	
1064
	
1059
1065
1060
	// ************ Catalog ************
1066
	private abstract static class OverrideDefaultModel
1061
	private static class OverrideDefaultCatalogModel
1067
		extends BasePropertyAspectAdapter<JpaProject, Boolean>
1062
	extends BasePropertyAspectAdapter<JpaProject, Boolean>
1063
	{
1068
	{
1064
		// the superclass "value" is the *cached* value
1069
		// the superclass "value" is the *cached* value
1065
		private Boolean actualValue;
1070
		private Boolean actualValue;
1066
		
1071
1067
		
1072
1068
		private OverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1073
		OverrideDefaultModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1069
			super(jpaProjectHolder);
1074
			super(jpaProjectHolder);
1070
		}
1075
		}
1071
		
1076
		
Lines 1074-1087 Link Here
1074
		
1079
		
1075
		@Override
1080
		@Override
1076
		public Boolean getValue() {
1081
		public Boolean getValue() {
1077
			Boolean value = super.getValue();
1082
			Boolean v = super.getValue();
1078
			return (value == null) ? Boolean.FALSE : value;
1083
			return (v == null) ? Boolean.FALSE : v;
1079
		}
1084
		}
1080
		
1085
		
1081
		@Override
1086
		@Override
1082
		public void setValue_(Boolean newValue) {
1087
		public void setValue_(Boolean newValue) {
1083
			this.actualValue = newValue;
1088
			this.actualValue = newValue;
1084
			valueChanged();
1089
			this.valueChanged();
1085
		}
1090
		}
1086
		
1091
		
1087
		
1092
		
Lines 1089-1102 Link Here
1089
		
1094
		
1090
		@Override
1095
		@Override
1091
		protected void engageSubject_() {
1096
		protected void engageSubject_() {
1097
			// we need to build 'actualValue' *before* calling 'super'
1098
			// because 'super' calls back here to #buildValue_()
1092
			this.actualValue = this.buildActualValue_();
1099
			this.actualValue = this.buildActualValue_();
1093
			super.engageSubject_();
1100
			super.engageSubject_();
1094
		}
1101
		}
1095
		
1102
		
1096
		@Override
1103
		@Override
1097
		protected void disengageSubject_() {
1104
		protected void disengageSubject_() {
1098
			this.actualValue = null;
1099
			super.disengageSubject_();
1105
			super.disengageSubject_();
1106
			this.actualValue = null;
1100
		}
1107
		}
1101
		
1108
		
1102
		
1109
		
Lines 1108-1114 Link Here
1108
		}
1115
		}
1109
		
1116
		
1110
		protected Boolean buildActualValue_() {
1117
		protected Boolean buildActualValue_() {
1111
			return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultCatalog());
1118
			return Boolean.valueOf(this.subjectHasUserOverrideDefault());
1119
		}
1120
1121
		protected boolean subjectHasUserOverrideDefault() {
1122
			return ! StringTools.stringIsEmpty(this.getSubjectUserOverrideDefault());
1123
		}
1124
		
1125
		protected abstract String getSubjectUserOverrideDefault();
1126
	}
1127
1128
	
1129
	// ************ Catalog ************
1130
	private static class OverrideDefaultCatalogModel
1131
		extends OverrideDefaultModel
1132
	{
1133
		OverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1134
			super(jpaProjectHolder);
1135
		}
1136
1137
		@Override
1138
		protected String getSubjectUserOverrideDefault() {
1139
			return this.subject.getUserOverrideDefaultCatalog();
1112
		}
1140
		}
1113
	}
1141
	}
1114
1142
Lines 1116-1122 Link Here
1116
	private static class DefaultCatalogModel
1144
	private static class DefaultCatalogModel
1117
		extends PropertyAspectAdapter<JpaProject, String>
1145
		extends PropertyAspectAdapter<JpaProject, String>
1118
	{
1146
	{
1119
		private DefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1147
		DefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1120
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY);
1148
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY);
1121
		}
1149
		}
1122
		
1150
		
Lines 1136-1192 Link Here
1136
			return this.subject.getUserOverrideDefaultCatalog();
1164
			return this.subject.getUserOverrideDefaultCatalog();
1137
		}
1165
		}
1138
	}
1166
	}
1139
	
1167
1140
	private static class DefaultDefaultCatalogModel
1168
	private abstract static class ConnectionProfilePropertyAspectAdapter<V>
1141
		extends BasePropertyAspectAdapter<ConnectionProfile, String>
1169
		extends BasePropertyAspectAdapter<ConnectionProfile, V>
1142
	{
1170
	{
1143
		private ConnectionListener connectionListener;
1171
		private ConnectionListener connectionListener;
1144
		
1172
1145
		
1173
		ConnectionProfilePropertyAspectAdapter(PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1146
		private DefaultDefaultCatalogModel(
1147
				PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1148
			super(connectionProfileModel);
1174
			super(connectionProfileModel);
1149
			this.connectionListener = buildConnectionListener();
1175
			this.connectionListener = this.buildConnectionListener();
1150
		}
1176
		}
1151
		
1177
1152
		
1178
		// the connection opening is probably the only thing that will happen...
1153
		// ************ initialization *****************************************
1154
		
1155
		private ConnectionListener buildConnectionListener() {
1179
		private ConnectionListener buildConnectionListener() {
1156
			return new ConnectionAdapter() {
1180
			return new ConnectionAdapter() {
1157
				@Override
1181
				@Override
1158
				public void opened(ConnectionProfile profile) {
1182
				public void opened(ConnectionProfile profile) {
1159
					if (profile.equals(DefaultDefaultCatalogModel.this.subject)) {
1183
					ConnectionProfilePropertyAspectAdapter.this.profileOpened(profile);
1160
						valueChanged();
1161
					}
1162
				}
1163
				@Override
1164
				public void catalogChanged(ConnectionProfile profile, Catalog catalog) {
1165
					if (profile.equals(DefaultDefaultCatalogModel.this.subject)) {
1166
						valueChanged();
1167
					}
1168
				}
1184
				}
1169
			};
1185
			};
1170
		}
1186
		}
1171
		
1187
1172
		
1188
		void profileOpened(ConnectionProfile profile) {
1173
		// ************ AspectAdapter impl *************************************
1189
			if (profile.equals(this.subject)) {
1174
		
1190
				this.valueChanged();
1191
			}
1192
		}
1193
1175
		@Override
1194
		@Override
1176
		protected void engageSubject_() {
1195
		protected void engageSubject_() {
1177
			this.subject.addConnectionListener(this.connectionListener);
1178
			super.engageSubject_();
1196
			super.engageSubject_();
1197
			this.subject.addConnectionListener(this.connectionListener);
1179
		}
1198
		}
1180
		
1199
1181
		@Override
1200
		@Override
1182
		protected void disengageSubject_() {
1201
		protected void disengageSubject_() {
1183
			this.subject.removeConnectionListener(this.connectionListener);
1202
			this.subject.removeConnectionListener(this.connectionListener);
1184
			super.disengageSubject_();
1203
			super.disengageSubject_();
1185
		}
1204
		}
1186
		
1205
1187
		
1206
	}
1188
		// ************ internal ***********************************************
1207
1189
		
1208
	private static class DatabaseSupportsCatalogsModel
1209
		extends ConnectionProfilePropertyAspectAdapter<Boolean>
1210
	{
1211
		DatabaseSupportsCatalogsModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1212
			super(connectionProfileModel);
1213
		}
1214
1215
		@Override
1216
		protected Boolean buildValue_() {
1217
			return Boolean.valueOf(this.databaseSupportsCatalogs());
1218
		}
1219
1220
		private boolean databaseSupportsCatalogs() {
1221
			Database db = this.subject.getDatabase();
1222
			return (db != null) && db.supportsCatalogs();
1223
		}
1224
	}
1225
1226
	private static class DatabaseExistsModel
1227
		extends ConnectionProfilePropertyAspectAdapter<Boolean>
1228
	{
1229
		DatabaseExistsModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1230
			super(connectionProfileModel);
1231
		}
1232
1233
		@Override
1234
		protected Boolean buildValue_() {
1235
			return Boolean.valueOf(this.databaseExists());
1236
		}
1237
1238
		private boolean databaseExists() {
1239
			return (this.subject.getDatabase() != null);
1240
		}
1241
	}
1242
1243
	private static class DefaultDefaultCatalogModel
1244
		extends ConnectionProfilePropertyAspectAdapter<String>
1245
	{
1246
		DefaultDefaultCatalogModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1247
			super(connectionProfileModel);
1248
		}
1249
1190
		@Override
1250
		@Override
1191
		protected String buildValue_() {
1251
		protected String buildValue_() {
1192
			Database db = this.subject.getDatabase();
1252
			Database db = this.subject.getDatabase();
Lines 1209-1221 Link Here
1209
		private PropertyValueModel<String> defaultDefaultCatalogModel;
1269
		private PropertyValueModel<String> defaultDefaultCatalogModel;
1210
		
1270
		
1211
		
1271
		
1212
		private CombinedDefaultCatalogModel(
1272
		CombinedDefaultCatalogModel(
1213
				WritablePropertyValueModel<String> defaultCatalogModel,
1273
				WritablePropertyValueModel<String> defaultCatalogModel,
1214
				PropertyValueModel<Boolean> overrideDefaultCatalogModel,
1274
				PropertyValueModel<Boolean> overrideDefaultCatalogModel,
1215
				PropertyValueModel<String> defaultDefaultCatalogModel) {
1275
				PropertyValueModel<String> defaultDefaultCatalogModel) {
1216
			super(
1276
			super(
1217
				new CompositeListValueModel(
1277
				new CompositeListValueModel<ListValueModel<?>,Object>(
1218
					CollectionTools.list(
1278
					CollectionTools.<ListValueModel<?>>list(
1219
						new PropertyListValueModelAdapter<String>(defaultCatalogModel),
1279
						new PropertyListValueModelAdapter<String>(defaultCatalogModel),
1220
						new PropertyListValueModelAdapter<Boolean>(overrideDefaultCatalogModel),
1280
						new PropertyListValueModelAdapter<Boolean>(overrideDefaultCatalogModel),
1221
						new PropertyListValueModelAdapter<String>(defaultDefaultCatalogModel)
1281
						new PropertyListValueModelAdapter<String>(defaultDefaultCatalogModel)
Lines 1233-1241 Link Here
1233
			if (this.overrideDefaultCatalogModel.getValue()) {
1293
			if (this.overrideDefaultCatalogModel.getValue()) {
1234
				return this.defaultCatalogModel.getValue();
1294
				return this.defaultCatalogModel.getValue();
1235
			}
1295
			}
1236
			else {
1296
			return this.defaultDefaultCatalogModel.getValue();
1237
				return this.defaultDefaultCatalogModel.getValue();
1238
			}
1239
		}
1297
		}
1240
		
1298
		
1241
		
1299
		
Lines 1250-1363 Link Here
1250
	}
1308
	}
1251
1309
1252
	
1310
	
1253
	private static class CatalogChoicesModel
1311
	private static class ConnectionProfileCollectionAspectAdapter<E>
1254
		extends BaseCollectionAspectAdapter<ConnectionProfile, String>
1312
		extends BaseCollectionAspectAdapter<ConnectionProfile, E>
1255
	{
1313
	{
1256
		private ConnectionListener connectionListener;
1314
		private ConnectionListener connectionListener;
1257
		
1315
1258
		
1316
		ConnectionProfileCollectionAspectAdapter(PropertyValueModel<ConnectionProfile> subjectHolder) {
1259
		private CatalogChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) {
1260
			super(subjectHolder);
1317
			super(subjectHolder);
1261
			this.connectionListener = buildConnectionListener();
1318
			this.connectionListener = this.buildConnectionListener();
1262
		}
1319
		}
1263
		
1320
1264
		
1321
		// the connection opening is probably the only thing that will happen...
1265
		// ************ initialization *****************************************
1266
		
1267
		private ConnectionListener buildConnectionListener() {
1322
		private ConnectionListener buildConnectionListener() {
1268
			return new ConnectionAdapter() {
1323
			return new ConnectionAdapter() {
1269
				@Override
1324
				@Override
1270
				public void opened(ConnectionProfile profile) {
1325
				public void opened(ConnectionProfile profile) {
1271
					if (profile.equals(CatalogChoicesModel.this.subject)) {
1326
					ConnectionProfileCollectionAspectAdapter.this.profileOpened(profile);
1272
						collectionChanged();
1273
					}
1274
				}
1275
				@Override
1276
				public void catalogChanged(ConnectionProfile profile, Catalog catalog) {
1277
					if (profile.equals(CatalogChoicesModel.this.subject)) {
1278
						collectionChanged();
1279
					}
1280
				}
1327
				}
1281
			};
1328
			};
1282
		}
1329
		}
1283
		
1330
1284
		
1331
		void profileOpened(ConnectionProfile profile) {
1285
		// ************ AspectAdapter impl *************************************
1332
			if (profile.equals(this.subject)) {
1286
		
1333
				this.collectionChanged();
1334
			}
1335
		}
1336
1287
		@Override
1337
		@Override
1288
		protected void engageSubject_() {
1338
		protected void engageSubject_() {
1289
			this.subject.addConnectionListener(this.connectionListener);
1339
			this.subject.addConnectionListener(this.connectionListener);
1290
		}
1340
		}
1291
		
1341
1292
		@Override
1342
		@Override
1293
		protected void disengageSubject_() {
1343
		protected void disengageSubject_() {
1294
			this.subject.removeConnectionListener(this.connectionListener);
1344
			this.subject.removeConnectionListener(this.connectionListener);
1295
		}
1345
		}
1296
		
1346
1297
		
1347
	}
1298
		// ************ internal ***********************************************
1348
1299
		
1349
	private static class CatalogChoicesModel
1350
		extends ConnectionProfileCollectionAspectAdapter<String>
1351
	{
1352
		CatalogChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) {
1353
			super(subjectHolder);
1354
		}
1355
1300
		@Override
1356
		@Override
1301
		protected Iterator<String> iterator_() {
1357
		protected Iterator<String> iterator_() {
1302
			return (this.subject.getDatabase() == null) ? 
1358
			Database db = this.subject.getDatabase();
1359
			return ((db == null) || ( ! db.supportsCatalogs())) ? 
1303
				EmptyIterator.<String>instance() : 
1360
				EmptyIterator.<String>instance() : 
1304
				this.subject.getDatabase().sortedCatalogIdentifiers();
1361
				db.sortedCatalogIdentifiers();
1305
		}
1362
		}
1306
	}
1363
	}
1307
1364
1308
	
1365
	
1309
	// ************ Schema ************
1366
	// ************ Schema ************
1310
	private static class OverrideDefaultSchemaModel
1367
	private static class OverrideDefaultSchemaModel
1311
		extends BasePropertyAspectAdapter<JpaProject, Boolean>
1368
		extends OverrideDefaultModel
1312
	{
1369
	{
1313
		// the superclass "value" is the *cached* value
1370
		OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1314
		private Boolean actualValue;
1315
		
1316
		
1317
		private OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1318
			super(jpaProjectHolder);
1371
			super(jpaProjectHolder);
1319
		}
1372
		}
1320
		
1373
1321
		
1322
		// ************ WritablePropertyValueModel impl ************************
1323
		
1324
		@Override
1325
		public Boolean getValue() {
1326
			Boolean value = super.getValue();
1327
			return (value == null) ? Boolean.FALSE : value;
1328
		}
1329
		
1330
		@Override
1331
		public void setValue_(Boolean newValue) {
1332
			this.actualValue = newValue;
1333
			valueChanged();
1334
		}
1335
		
1336
		
1337
		// ************ AspectAdapter impl *************************************
1338
		
1339
		@Override
1340
		protected void engageSubject_() {
1341
			this.actualValue = this.buildActualValue_();
1342
			super.engageSubject_();
1343
		}
1344
		
1345
		@Override
1346
		protected void disengageSubject_() {
1347
			this.actualValue = null;
1348
			super.disengageSubject_();
1349
		}
1350
		
1351
		
1352
		// ************ internal ***********************************************
1353
		
1354
		@Override
1374
		@Override
1355
		protected Boolean buildValue_() {
1375
		public String getSubjectUserOverrideDefault() {
1356
			return this.actualValue;
1376
			return this.subject.getUserOverrideDefaultSchema();
1357
		}
1358
		
1359
		protected Boolean buildActualValue_() {
1360
			return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultSchema());
1361
		}
1377
		}
1362
	}
1378
	}
1363
	
1379
	
Lines 1365-1371 Link Here
1365
	private static class DefaultSchemaModel
1381
	private static class DefaultSchemaModel
1366
		extends PropertyAspectAdapter<JpaProject, String>
1382
		extends PropertyAspectAdapter<JpaProject, String>
1367
	{
1383
	{
1368
		private DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1384
		DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1369
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY);
1385
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY);
1370
		}
1386
		}
1371
		
1387
		
Lines 1388-1451 Link Here
1388
	
1404
	
1389
	
1405
	
1390
	private static class DefaultDefaultSchemaModel
1406
	private static class DefaultDefaultSchemaModel
1391
		extends BasePropertyAspectAdapter<ConnectionProfile, String>
1407
		extends ConnectionProfilePropertyAspectAdapter<String>
1392
	{
1408
	{
1393
		private ConnectionListener connectionListener;
1409
		private final PropertyValueModel<String> defaultCatalogModel;
1394
		
1410
		private final PropertyChangeListener catalogListener;
1395
		
1411
1396
		private DefaultDefaultSchemaModel(
1412
		DefaultDefaultSchemaModel(PropertyValueModel<String> defaultCatalogModel,
1397
				PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1413
				PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1398
			super(connectionProfileModel);
1414
			super(connectionProfileModel);
1399
			this.connectionListener = buildConnectionListener();
1415
			this.defaultCatalogModel = defaultCatalogModel;
1416
			this.catalogListener = this.buildCatalogListener();
1400
		}
1417
		}
1401
		
1418
1402
		
1419
		private PropertyChangeListener buildCatalogListener() {
1403
		// ************ initialization *****************************************
1420
			return new PropertyChangeListener() {
1404
		
1421
				public void propertyChanged(PropertyChangeEvent event) {
1405
		private ConnectionListener buildConnectionListener() {
1422
					DefaultDefaultSchemaModel.this.valueChanged();
1406
			return new ConnectionAdapter() {
1407
				@Override
1408
				public void opened(ConnectionProfile profile) {
1409
					if (profile.equals(DefaultDefaultSchemaModel.this.subject)) {
1410
						valueChanged();
1411
					}
1412
				}
1413
				@Override
1414
				public void schemaChanged(ConnectionProfile profile, Schema schema) {
1415
					if (profile.equals(DefaultDefaultSchemaModel.this.subject)) {
1416
						valueChanged();
1417
					}
1418
				}
1423
				}
1419
			};
1424
			};
1420
		}
1425
		}
1421
		
1426
1422
		
1423
		// ************ AspectAdapter impl *************************************
1424
		
1425
		@Override
1427
		@Override
1426
		protected void engageSubject_() {
1428
		protected void engageSubject_() {
1427
			this.subject.addConnectionListener(this.connectionListener);
1429
			// call 'super' last?
1430
			this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1428
			super.engageSubject_();
1431
			super.engageSubject_();
1429
		}
1432
		}
1430
		
1433
		
1431
		@Override
1434
		@Override
1432
		protected void disengageSubject_() {
1435
		protected void disengageSubject_() {
1433
			this.subject.removeConnectionListener(this.connectionListener);
1434
			super.disengageSubject_();
1436
			super.disengageSubject_();
1437
			this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1435
		}
1438
		}
1436
		
1439
1437
		
1438
		// ************ internal ***********************************************
1439
		
1440
		@Override
1440
		@Override
1441
		protected String buildValue_() {
1441
		protected String buildValue_() {
1442
			Database db = this.subject.getDatabase();
1442
			Schema schema = this.getDefaultSchema();
1443
			if (db == null) {
1444
				return null;
1445
			}
1446
			Schema schema = db.getDefaultSchema();
1447
			return (schema == null) ? null : schema.getIdentifier();
1443
			return (schema == null) ? null : schema.getIdentifier();
1448
		}
1444
		}
1445
1446
		private Schema getDefaultSchema() {
1447
			SchemaContainer sc = this.getSchemaContainer();
1448
			return (sc == null) ? null : sc.getDefaultSchema();
1449
		}
1450
1451
		private SchemaContainer getSchemaContainer() {
1452
			return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase();
1453
		}
1454
1455
		private boolean databaseSupportsCatalogs() {
1456
			Database db = this.getDatabase();
1457
			return (db != null) && db.supportsCatalogs();
1458
		}
1459
1460
		private Catalog getCatalog() {
1461
			String name = this.defaultCatalogModel.getValue();
1462
			return (name == null) ? null : this.getCatalog(name);
1463
		}
1464
1465
		/**
1466
		 * pre-condition: 'name' is not null
1467
		 */
1468
		private Catalog getCatalog(String name) {
1469
			Database db = this.getDatabase();
1470
			return (db == null) ? null : db.getCatalogForIdentifier(name);
1471
		}
1472
1473
		private Database getDatabase() {
1474
			return this.subject.getDatabase();
1475
		}
1476
1449
	}
1477
	}
1450
	
1478
	
1451
	
1479
	
Lines 1460-1466 Link Here
1460
		private PropertyValueModel<String> defaultDefaultSchemaModel;
1488
		private PropertyValueModel<String> defaultDefaultSchemaModel;
1461
		
1489
		
1462
		
1490
		
1463
		private CombinedDefaultSchemaModel(
1491
		CombinedDefaultSchemaModel(
1464
				WritablePropertyValueModel<String> defaultSchemaModel,
1492
				WritablePropertyValueModel<String> defaultSchemaModel,
1465
				PropertyValueModel<Boolean> overrideDefaultSchemaModel,
1493
				PropertyValueModel<Boolean> overrideDefaultSchemaModel,
1466
				PropertyValueModel<String> defaultDefaultSchemaModel) {
1494
				PropertyValueModel<String> defaultDefaultSchemaModel) {
Lines 1484-1492 Link Here
1484
			if (this.overrideDefaultSchemaModel.getValue()) {
1512
			if (this.overrideDefaultSchemaModel.getValue()) {
1485
				return this.defaultSchemaModel.getValue();
1513
				return this.defaultSchemaModel.getValue();
1486
			}
1514
			}
1487
			else {
1515
			return this.defaultDefaultSchemaModel.getValue();
1488
				return this.defaultDefaultSchemaModel.getValue();
1489
			}
1490
		}
1516
		}
1491
		
1517
		
1492
		
1518
		
Lines 1502-1559 Link Here
1502
1528
1503
1529
1504
	private static class SchemaChoicesModel
1530
	private static class SchemaChoicesModel
1505
		extends BaseCollectionAspectAdapter<ConnectionProfile, String>
1531
		extends ConnectionProfileCollectionAspectAdapter<String>
1506
	{
1532
	{
1507
		private ConnectionListener connectionListener;
1533
		private final PropertyValueModel<String> defaultCatalogModel;
1508
		
1534
		private final PropertyChangeListener catalogListener;
1509
		
1535
1510
		private SchemaChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) {
1536
		SchemaChoicesModel(PropertyValueModel<String> defaultCatalogModel,
1537
				PropertyValueModel<ConnectionProfile> subjectHolder) {
1511
			super(subjectHolder);
1538
			super(subjectHolder);
1512
			this.connectionListener = buildConnectionListener();
1539
			this.defaultCatalogModel = defaultCatalogModel;
1540
			this.catalogListener = this.buildCatalogListener();
1513
		}
1541
		}
1514
		
1542
1515
		
1543
		private PropertyChangeListener buildCatalogListener() {
1516
		// ************ initialization *****************************************
1544
			return new PropertyChangeListener() {
1517
		
1545
				public void propertyChanged(PropertyChangeEvent event) {
1518
		private ConnectionListener buildConnectionListener() {
1546
					collectionChanged();
1519
			return new ConnectionAdapter() {
1520
				@Override
1521
				public void opened(ConnectionProfile profile) {
1522
					if (profile.equals(SchemaChoicesModel.this.subject)) {
1523
						collectionChanged();
1524
					}
1525
				}
1526
				@Override
1527
				public void schemaChanged(ConnectionProfile profile, Schema schema) {
1528
					if (profile.equals(SchemaChoicesModel.this.subject)) {
1529
						collectionChanged();
1530
					}
1531
				}
1547
				}
1532
			};
1548
			};
1533
		}
1549
		}
1534
		
1550
1535
		
1536
		// ************ AspectAdapter impl *************************************
1537
		
1538
		@Override
1551
		@Override
1539
		protected void engageSubject_() {
1552
		protected void engageSubject_() {
1540
			this.subject.addConnectionListener(this.connectionListener);
1553
			// call 'super' last?
1554
			this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1555
			super.engageSubject_();
1541
		}
1556
		}
1542
		
1557
1543
		@Override
1558
		@Override
1544
		protected void disengageSubject_() {
1559
		protected void disengageSubject_() {
1545
			this.subject.removeConnectionListener(this.connectionListener);
1560
			super.disengageSubject_();
1561
			this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1546
		}
1562
		}
1547
		
1563
1548
		
1549
		// ************ internal ***********************************************
1550
		
1551
		@Override
1564
		@Override
1552
		protected Iterator<String> iterator_() {
1565
		protected Iterator<String> iterator_() {
1553
			return (this.subject.getDatabase() == null) ? 
1566
			SchemaContainer sc = this.getSchemaContainer();
1554
				EmptyIterator.<String>instance() : 
1567
			return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers();
1555
				this.subject.getDatabase().sortedSchemaIdentifiers();
1568
		}
1569
1570
		private SchemaContainer getSchemaContainer() {
1571
			return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase();
1572
		}
1573
1574
		private boolean databaseSupportsCatalogs() {
1575
			Database db = this.getDatabase();
1576
			return (db != null) && db.supportsCatalogs();
1556
		}
1577
		}
1578
1579
		private Catalog getCatalog() {
1580
			String name = this.defaultCatalogModel.getValue();
1581
			return (name == null) ? null : this.getCatalog(name);
1582
		}
1583
1584
		/**
1585
		 * pre-condition: 'name' is not null
1586
		 */
1587
		private Catalog getCatalog(String name) {
1588
			Database db = this.getDatabase();
1589
			return (db == null) ? null : db.getCatalogForIdentifier(name);
1590
		}
1591
1592
		private Database getDatabase() {
1593
			return this.subject.getDatabase();
1594
		}
1595
1557
	}
1596
	}
1558
	
1597
	
1559
	
1598
	
Lines 1570-1575 Link Here
1570
1609
1571
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION);
1610
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION);
1572
			
1611
			
1612
			// connection
1573
			Combo connectionCombo = createCombo(group, 3, true);
1613
			Combo connectionCombo = createCombo(group, 3, true);
1574
			
1614
			
1575
			ComboModelAdapter.adapt(
1615
			ComboModelAdapter.adapt(
Lines 1621-1627 Link Here
1621
					PropertyValueModel.VALUE,
1661
					PropertyValueModel.VALUE,
1622
					linkUpdateListener);
1662
					linkUpdateListener);
1623
1663
1624
			// overrideDefaultCatalog
1664
			// override default catalog
1625
			Button overrideDefaultCatalogButton = createButton(
1665
			Button overrideDefaultCatalogButton = createButton(
1626
					group, 3, 
1666
					group, 3, 
1627
					JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, 
1667
					JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, 
Lines 1648-1654 Link Here
1648
				JpaProjectPropertiesPage.this.overrideDefaultCatalogModel,
1688
				JpaProjectPropertiesPage.this.overrideDefaultCatalogModel,
1649
				defaultCatalogLabel, defaultCatalogCombo);
1689
				defaultCatalogLabel, defaultCatalogCombo);
1650
			
1690
			
1651
			// overrideDefaultSchema
1691
			// override default schema
1652
			Button overrideDefaultSchemaButton = createButton(
1692
			Button overrideDefaultSchemaButton = createButton(
1653
					group, 3, 
1693
					group, 3, 
1654
					JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, 
1694
					JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, 
Lines 1703-1709 Link Here
1703
	private class DiscoverAnnotatedClassesModel
1743
	private class DiscoverAnnotatedClassesModel
1704
		extends PropertyAspectAdapter<JpaProject, Boolean>
1744
		extends PropertyAspectAdapter<JpaProject, Boolean>
1705
	{
1745
	{
1706
		private DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1746
		DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1707
			super(jpaProjectModel, JpaProject.DISCOVERS_ANNOTATED_CLASSES_PROPERTY);
1747
			super(jpaProjectModel, JpaProject.DISCOVERS_ANNOTATED_CLASSES_PROPERTY);
1708
		}
1748
		}
1709
		
1749
		
(-)src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java (-29 / +40 lines)
Lines 35-40 Link Here
35
import org.eclipse.swt.widgets.Link;
35
import org.eclipse.swt.widgets.Link;
36
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.help.IWorkbenchHelpSystem;
37
import org.eclipse.ui.help.IWorkbenchHelpSystem;
38
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
39
import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelSynchHelper;
38
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
40
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
39
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
41
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
40
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
42
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
Lines 53-58 Link Here
53
	}
55
	}
54
56
55
	@Override
57
	@Override
58
	protected IDataModel getDataModel() {
59
		return super.getDataModel();
60
	}
61
62
	protected DataModelSynchHelper getSynchHelper() {
63
		return this.synchHelper;
64
	}
65
66
	@Override
56
	protected Composite createTopLevelComposite(Composite parent) {
67
	protected Composite createTopLevelComposite(Composite parent) {
57
		Composite composite = new Composite(parent, SWT.NULL);
68
		Composite composite = new Composite(parent, SWT.NULL);
58
		GridLayout layout = new GridLayout();
69
		GridLayout layout = new GridLayout();
Lines 80-93 Link Here
80
		wc.addListener(
91
		wc.addListener(
81
			new IFacetedProjectListener() {
92
			new IFacetedProjectListener() {
82
				public void handleEvent( final IFacetedProjectEvent event ) {
93
				public void handleEvent( final IFacetedProjectEvent event ) {
83
					model.setProperty(RUNTIME, wc.getPrimaryRuntime());
94
					getDataModel().setProperty(RUNTIME, wc.getPrimaryRuntime());
84
				}
95
				}
85
			},
96
			},
86
			IFacetedProjectEvent.Type.PRIMARY_RUNTIME_CHANGED
97
			IFacetedProjectEvent.Type.PRIMARY_RUNTIME_CHANGED
87
		);
98
		);
88
	}
99
	}
89
100
90
	private Button createButton(Composite container, int span, String text, int style) {
101
	Button createButton(Composite container, int span, String text, int style) {
91
		Button button = new Button(container, SWT.NONE | style);
102
		Button button = new Button(container, SWT.NONE | style);
92
		button.setText(text);
103
		button.setText(text);
93
		GridData gd = new GridData();
104
		GridData gd = new GridData();
Lines 96-102 Link Here
96
		return button;
107
		return button;
97
	}
108
	}
98
109
99
	private Combo createCombo(Composite container, int span, boolean fillHorizontal) {
110
	Combo createCombo(Composite container, int span, boolean fillHorizontal) {
100
		Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
111
		Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
101
		GridData gd;
112
		GridData gd;
102
		if (fillHorizontal) {
113
		if (fillHorizontal) {
Lines 128-145 Link Here
128
139
129
	@Override
140
	@Override
130
	public boolean isPageComplete() {
141
	public boolean isPageComplete() {
131
		if (! super.isPageComplete()) {
142
		if ( ! super.isPageComplete()) {
132
			return false;
143
			return false;
133
		}
144
		}
134
		else {
145
135
			IStatus status =model.validate(); 
146
		IStatus status = this.model.validate(); 
136
			if( status.getSeverity() == IStatus.ERROR){
147
		if (status.getSeverity() == IStatus.ERROR) {
137
				setErrorMessage( status.getMessage() );
148
			this.setErrorMessage(status.getMessage());
138
				return false;
149
			return false;
139
			};
140
			setErrorMessage(null);
141
			return true;
142
		}
150
		}
151
152
		this.setErrorMessage(null);
153
		return true;
143
	}
154
	}
144
155
145
	@Override
156
	@Override
Lines 164-170 Link Here
164
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_JPA_PLATFORM);
175
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_JPA_PLATFORM);
165
176
166
			platformCombo = createCombo(group, 1, true);
177
			platformCombo = createCombo(group, 1, true);
167
			synchHelper.synchCombo(platformCombo, PLATFORM_ID, null);
178
			getSynchHelper().synchCombo(platformCombo, PLATFORM_ID, null);
168
		}
179
		}
169
	}
180
	}
170
	
181
	
Lines 221-227 Link Here
221
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE);
232
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE);
222
			
233
			
223
			connectionCombo = createCombo(group, 3, true);
234
			connectionCombo = createCombo(group, 3, true);
224
			synchHelper.synchCombo(connectionCombo, CONNECTION, null);
235
			getSynchHelper().synchCombo(connectionCombo, CONNECTION, null);
225
			connectionCombo.addSelectionListener(
236
			connectionCombo.addSelectionListener(
226
				new SelectionAdapter() {
237
				new SelectionAdapter() {
227
					@Override
238
					@Override
Lines 260-266 Link Here
260
			
271
			
261
			addDriverLibraryButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_addDriverLibraryLabel, SWT.CHECK);
272
			addDriverLibraryButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_addDriverLibraryLabel, SWT.CHECK);
262
			addDriverLibraryButton.setSelection(false);
273
			addDriverLibraryButton.setSelection(false);
263
			synchHelper.synchCheckbox(addDriverLibraryButton, USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, null);
274
			getSynchHelper().synchCheckbox(addDriverLibraryButton, USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, null);
264
275
265
			driverLibraryLabel = new Label(group, SWT.LEFT);
276
			driverLibraryLabel = new Label(group, SWT.LEFT);
266
			driverLibraryLabel.setText(JptUiMessages.JpaFacetWizardPage_driverLibraryLabel);
277
			driverLibraryLabel.setText(JptUiMessages.JpaFacetWizardPage_driverLibraryLabel);
Lines 269-281 Link Here
269
			driverLibraryLabel.setLayoutData(gd);
280
			driverLibraryLabel.setLayoutData(gd);
270
			
281
			
271
			driverLibraryCombo = createCombo(group, 1, true);
282
			driverLibraryCombo = createCombo(group, 1, true);
272
			synchHelper.synchCombo(
283
			getSynchHelper().synchCombo(
273
				driverLibraryCombo, DB_DRIVER_NAME, 
284
				driverLibraryCombo, DB_DRIVER_NAME, 
274
				new Control[] {driverLibraryLabel});
285
				new Control[] {driverLibraryLabel});
275
			
286
			
276
			overrideDefaultCatalogButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, SWT.CHECK);
287
			overrideDefaultCatalogButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel, SWT.CHECK);
277
			overrideDefaultCatalogButton.setSelection(false);
288
			overrideDefaultCatalogButton.setSelection(false);
278
			synchHelper.synchCheckbox(overrideDefaultCatalogButton, USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, null);
289
			getSynchHelper().synchCheckbox(overrideDefaultCatalogButton, USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, null);
279
			
290
			
280
			defaultCatalogLabel = new Label(group, SWT.LEFT);
291
			defaultCatalogLabel = new Label(group, SWT.LEFT);
281
			defaultCatalogLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultCatalogLabel);
292
			defaultCatalogLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultCatalogLabel);
Lines 284-296 Link Here
284
			defaultCatalogLabel.setLayoutData(gd);
295
			defaultCatalogLabel.setLayoutData(gd);
285
			
296
			
286
			defaultCatalogCombo = createCombo(group, 1, true);
297
			defaultCatalogCombo = createCombo(group, 1, true);
287
			synchHelper.synchCombo(
298
			getSynchHelper().synchCombo(
288
				defaultCatalogCombo, USER_OVERRIDE_DEFAULT_CATALOG, 
299
				defaultCatalogCombo, USER_OVERRIDE_DEFAULT_CATALOG, 
289
				new Control[] {defaultCatalogLabel});
300
				new Control[] {defaultCatalogLabel});
290
301
291
			overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK);
302
			overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK);
292
			overrideDefaultSchemaButton.setSelection(false);
303
			overrideDefaultSchemaButton.setSelection(false);
293
			synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null);
304
			getSynchHelper().synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null);
294
			
305
			
295
			defaultSchemaLabel = new Label(group, SWT.LEFT);
306
			defaultSchemaLabel = new Label(group, SWT.LEFT);
296
			defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel);
307
			defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel);
Lines 299-326 Link Here
299
			defaultSchemaLabel.setLayoutData(gd);
310
			defaultSchemaLabel.setLayoutData(gd);
300
			
311
			
301
			defaultSchemaCombo = createCombo(group, 1, true);
312
			defaultSchemaCombo = createCombo(group, 1, true);
302
			synchHelper.synchCombo(
313
			getSynchHelper().synchCombo(
303
				defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA, 
314
				defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA, 
304
				new Control[] {defaultSchemaLabel});
315
				new Control[] {defaultSchemaLabel});
305
		}
316
		}
306
		
317
		
307
		private void openNewConnectionWizard() {
318
		void openNewConnectionWizard() {
308
			String connectionName = DTPUiTools.createNewConnectionProfile();
319
			String connectionName = DTPUiTools.createNewConnectionProfile();
309
			if (connectionName != null) {
320
			if (connectionName != null) {
310
				model.setProperty(CONNECTION, connectionName);
321
				getDataModel().setProperty(CONNECTION, connectionName);
311
			}
322
			}
312
		}
323
		}
313
		
324
		
314
		private void openConnectionProfile() {
325
		void openConnectionProfile() {
315
			ConnectionProfile cp = getConnectionProfile();
326
			ConnectionProfile cp = getConnectionProfile();
316
			if (cp != null) {
327
			if (cp != null) {
317
				cp.connect();
328
				cp.connect();
318
				model.setBooleanProperty(CONNECTION_ACTIVE, cp.isActive());
329
				getDataModel().setBooleanProperty(CONNECTION_ACTIVE, cp.isActive());
319
				updateConnectLink();
330
				updateConnectLink();
320
			}
331
			}
321
		}
332
		}
322
		
333
		
323
		private void updateConnectLink() {
334
		void updateConnectLink() {
324
			ConnectionProfile cp = this.getConnectionProfile();
335
			ConnectionProfile cp = this.getConnectionProfile();
325
			connectLink.setEnabled((cp != null) && cp.isDisconnected());
336
			connectLink.setEnabled((cp != null) && cp.isDisconnected());
326
			addDriverLibraryButton.setEnabled(cp != null);
337
			addDriverLibraryButton.setEnabled(cp != null);
Lines 328-334 Link Here
328
		
339
		
329
		private ConnectionProfile getConnectionProfile() {
340
		private ConnectionProfile getConnectionProfile() {
330
			// we just use the connection profile to log in, so go the the db plug-in
341
			// we just use the connection profile to log in, so go the the db plug-in
331
			return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(model.getStringProperty(CONNECTION));
342
			return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(getDataModel().getStringProperty(CONNECTION));
332
		}
343
		}
333
	}
344
	}
334
	
345
	
Lines 348-357 Link Here
348
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH);
359
			PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH);
349
			
360
			
350
			discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO);
361
			discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO);
351
			synchHelper.synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null);
362
			getSynchHelper().synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null);
352
			
363
			
353
			listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO);
364
			listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO);
354
			synchHelper.synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null);
365
			getSynchHelper().synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null);
355
		}
366
		}
356
	}
367
	}
357
368
Lines 369-375 Link Here
369
380
370
			createOrmXmlButton = new Button(group, SWT.CHECK);
381
			createOrmXmlButton = new Button(group, SWT.CHECK);
371
			createOrmXmlButton.setText(JptUiMessages.JpaFacetWizardPage_createOrmXmlButton);
382
			createOrmXmlButton.setText(JptUiMessages.JpaFacetWizardPage_createOrmXmlButton);
372
			synchHelper.synchCheckbox(createOrmXmlButton, CREATE_ORM_XML, null);
383
			getSynchHelper().synchCheckbox(createOrmXmlButton, CREATE_ORM_XML, null);
373
		}
384
		}
374
	}
385
	}
375
	
386
	
(-)src/org/eclipse/jpt/core/internal/facet/JpaFacetDataModelProvider.java (-311 / +428 lines)
Lines 9-15 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.jpt.core.internal.facet;
10
package org.eclipse.jpt.core.internal.facet;
11
11
12
import java.util.Collections;
13
import java.util.Comparator;
12
import java.util.Comparator;
14
import java.util.HashMap;
13
import java.util.HashMap;
15
import java.util.Iterator;
14
import java.util.Iterator;
Lines 29-39 Link Here
29
import org.eclipse.jpt.db.DatabaseFinder;
28
import org.eclipse.jpt.db.DatabaseFinder;
30
import org.eclipse.jpt.db.JptDbPlugin;
29
import org.eclipse.jpt.db.JptDbPlugin;
31
import org.eclipse.jpt.db.Schema;
30
import org.eclipse.jpt.db.Schema;
31
import org.eclipse.jpt.db.SchemaContainer;
32
import org.eclipse.jpt.utility.internal.CollectionTools;
32
import org.eclipse.jpt.utility.internal.CollectionTools;
33
import org.eclipse.jpt.utility.internal.StringTools;
34
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
35
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
33
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
36
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
37
import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener;
34
import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener;
38
import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate;
35
import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate;
39
import org.eclipse.osgi.util.NLS;
36
import org.eclipse.osgi.util.NLS;
Lines 41-61 Link Here
41
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
38
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
42
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor;
39
import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor;
43
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
40
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
44
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages;
45
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
46
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
41
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
47
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
42
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
48
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
43
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
49
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
44
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
50
45
51
public class JpaFacetDataModelProvider extends FacetInstallDataModelProvider
46
public class JpaFacetDataModelProvider
47
	extends FacetInstallDataModelProvider
52
	implements JpaFacetDataModelProperties
48
	implements JpaFacetDataModelProperties
53
{
49
{
54
	private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE;
50
	private LibraryInstallDelegate defaultLibraryProvider;
55
51
56
	private static final String RUNTIME_NONE = 
52
	/** cache the connection profile - change it whenever the user selects a different name */
57
			WTPCommonPlugin.getResourceString(WTPCommonMessages.RUNTIME_NONE, null);
53
	private ConnectionProfile connectionProfile;
54
	
58
	
55
	
56
	private static final String EJB_FACET_ID = IModuleConstants.JST_EJB_MODULE;
57
59
	private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = 
58
	private static final IStatus PLATFORM_NOT_SPECIFIED_STATUS = 
60
			buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED);
59
			buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_NOT_SPECIFIED);
61
	
60
	
Lines 63-91 Link Here
63
			buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED);
62
			buildInfoStatus(JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED);
64
	
63
	
65
	private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = 
64
	private static final IStatus USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS = 
66
		buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED);
65
			buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED);
67
	
66
	
68
	private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = 
67
	private static final IStatus USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS = 
69
			buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED);
68
			buildErrorStatus(JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED);
70
	
69
	
71
	private static final IStatus RUNTIME_NOT_SPECIFIED_STATUS = 
70
72
			buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_NOT_SPECIFIED);
73
	
74
	private static final IStatus RUNTIME_DOES_NOT_SUPPORT_EJB_30_STATUS = 
75
			buildWarningStatus(JptCoreMessages.VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30);
76
	
77
	
78
	private LibraryInstallDelegate defaultLibraryProvider;
79
	
80
	
81
	/**
71
	/**
82
	 * required default constructor
72
	 * required default constructor
83
	 */
73
	 */
84
	public JpaFacetDataModelProvider() {
74
	public JpaFacetDataModelProvider() {
85
		super();
75
		super();
86
	}
76
	}
87
	
77
88
	
89
	@Override
78
	@Override
90
	public Set<String> getPropertyNames() {
79
	public Set<String> getPropertyNames() {
91
		@SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames();
80
		@SuppressWarnings("unchecked") Set<String> propertyNames = super.getPropertyNames();
Lines 105-128 Link Here
105
		propertyNames.add(CREATE_ORM_XML);
94
		propertyNames.add(CREATE_ORM_XML);
106
		return propertyNames;
95
		return propertyNames;
107
	}
96
	}
97
98
99
	// ********** properties **********
100
101
	private String getPlatformId() {
102
		return (String) this.getProperty(PLATFORM_ID);
103
	}
104
	
105
	private String getConnectionName() {
106
		return (String) this.getProperty(CONNECTION);
107
	}
108
109
	private boolean userWantsToAddDbDriverJarsToClasspath() {
110
		return this.getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH);
111
	}
112
	
113
	private String getDriverName() {
114
		return (String) this.getProperty(DB_DRIVER_NAME);
115
	}
116
117
	private boolean userWantsToOverrideDefaultCatalog() {
118
		return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG);
119
	}
108
	
120
	
121
	private String getUserOverrideDefaultCatalog() {
122
		return (String) this.getProperty(USER_OVERRIDE_DEFAULT_CATALOG);
123
	}
124
125
	private boolean userWantsToOverrideDefaultSchema() {
126
		return this.getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA);
127
	}
128
	
129
	private String getUserOverrideDefaultSchema() {
130
		return (String) this.getProperty(USER_OVERRIDE_DEFAULT_SCHEMA);
131
	}
132
133
	private boolean discoverAnnotatedClasses() {
134
		return this.getBooleanProperty(DISCOVER_ANNOTATED_CLASSES);
135
	}
136
137
	private IFacetedProjectWorkingCopy getFacetedProjectWorkingCopy() {
138
		return (IFacetedProjectWorkingCopy) this.getProperty(FACETED_PROJECT_WORKING_COPY);
139
	}
140
141
	private IProjectFacetVersion getProjectFacetVersion() {
142
		return (IProjectFacetVersion) this.getProperty(FACET_VERSION);
143
	}
144
145
	private IRuntime getRuntime() {
146
		return (IRuntime) this.getProperty(RUNTIME);
147
	}
148
149
	private LibraryInstallDelegate getLibraryInstallDelegate() {
150
		return (LibraryInstallDelegate) this.getProperty(LIBRARY_PROVIDER_DELEGATE);
151
	}
152
153
154
	// ********** enabled **********
155
109
	@Override
156
	@Override
110
	public boolean isPropertyEnabled(String propertyName) {
157
	public boolean isPropertyEnabled(String propertyName) {
111
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
112
			return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG);
113
		}
114
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
115
			return getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA);
116
		}
117
		if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) {
158
		if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) {
118
			return getConnectionProfile() != null;
159
			return (this.getConnectionProfile() != null);
119
		}
160
		}
120
		if (propertyName.equals(DB_DRIVER_NAME)) {
161
		if (propertyName.equals(DB_DRIVER_NAME)) {
121
			return getBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH);
162
			return this.userWantsToAddDbDriverJarsToClasspath();
122
		}
163
		}
164
165
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) {
166
			return this.connectionIsActive() && this.databaseSupportsCatalogs();
167
		}
168
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
169
			return this.userWantsToOverrideDefaultCatalog();
170
		}
171
172
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
173
			return this.connectionIsActive();
174
		}
175
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
176
			return this.userWantsToOverrideDefaultSchema();
177
		}
178
123
		return super.isPropertyEnabled(propertyName);
179
		return super.isPropertyEnabled(propertyName);
124
	}
180
	}
125
	
181
182
183
	// ********** defaults **********
184
126
	@Override
185
	@Override
127
	public Object getDefaultProperty(String propertyName) {
186
	public Object getDefaultProperty(String propertyName) {
128
		if (propertyName.equals(RUNTIME)) {
187
		if (propertyName.equals(RUNTIME)) {
Lines 135-171 Link Here
135
			return JptCorePlugin.getDefaultJpaPlatformId();
194
			return JptCorePlugin.getDefaultJpaPlatformId();
136
		}
195
		}
137
		if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) {
196
		if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) {
138
			return getDefaultLibraryProvider();
197
			return this.getDefaultLibraryProvider();
139
		}
198
		}
140
		if (propertyName.equals(CONNECTION)) {
199
		if (propertyName.equals(CONNECTION)) {
141
			return null;
200
			return null;
142
		}
201
		}
143
		if (propertyName.equals(CONNECTION_ACTIVE)) {
202
		if (propertyName.equals(CONNECTION_ACTIVE)) {
144
			return Boolean.valueOf(connectionIsActive());
203
			return Boolean.valueOf(this.connectionIsActive());
145
		}
204
		}
146
		if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) {
205
		if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) {
147
			return Boolean.FALSE;
206
			return Boolean.FALSE;
148
		}
207
		}
149
		if (propertyName.equals(DB_DRIVER_NAME)) {
208
		if (propertyName.equals(DB_DRIVER_NAME)) {
150
			return getDefaultDriverName();
209
			return this.getDefaultDriverName();
151
		}
210
		}
152
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) {
211
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) {
153
			return Boolean.FALSE;
212
			return Boolean.FALSE;
154
		}
213
		}
155
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
214
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
156
			return getDefaultCatalogName();
215
			return this.getDefaultCatalogName();
157
		}
216
		}
158
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
217
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
159
			return Boolean.FALSE;
218
			return Boolean.FALSE;
160
		}
219
		}
161
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
220
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
162
			return getDefaultSchemaName();
221
			return this.getDefaultSchemaName();
163
		}
222
		}
164
		if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) {
223
		if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) {
165
			return Boolean.valueOf(this.runtimeSupportsEjb30(this.runtime()));
224
			return Boolean.valueOf(this.runtimeSupportsEjb30());
166
		}
225
		}
167
		if (propertyName.equals(LIST_ANNOTATED_CLASSES)) {
226
		if (propertyName.equals(LIST_ANNOTATED_CLASSES)) {
168
			return Boolean.valueOf( ! getBooleanProperty(DISCOVER_ANNOTATED_CLASSES));
227
			return Boolean.valueOf( ! this.discoverAnnotatedClasses());
169
		}
228
		}
170
		if (propertyName.equals(CREATE_ORM_XML)) {
229
		if (propertyName.equals(CREATE_ORM_XML)) {
171
			return Boolean.TRUE;
230
			return Boolean.TRUE;
Lines 173-235 Link Here
173
		
232
		
174
		return super.getDefaultProperty(propertyName);
233
		return super.getDefaultProperty(propertyName);
175
	}
234
	}
176
	
235
177
	private String getDefaultDriverName() {
236
	private LibraryInstallDelegate getDefaultLibraryProvider() {
178
		ConnectionProfile cp = this.getConnectionProfile();
237
		// delegate itself changes, not the instance of delegate
179
		if (cp == null) {
238
		if (this.defaultLibraryProvider == null) {
180
			return null;
239
			this.defaultLibraryProvider = this.buildDefaultLibraryProvider();
181
		}
240
		}
182
		return cp.getDriverName();
241
		return defaultLibraryProvider;
183
	}
242
	}
184
243
	
185
	private String getDefaultCatalogName() {
244
	private LibraryInstallDelegate buildDefaultLibraryProvider() {
186
		ConnectionProfile cp = this.getConnectionProfile();
245
		IFacetedProjectWorkingCopy fpjwc = this.getFacetedProjectWorkingCopy();
187
		if (cp == null) {
246
		if (fpjwc == null) {
188
			return null;
247
			return null;
189
		}
248
		}
190
		Database db = cp.getDatabase();
249
		IProjectFacetVersion pfv = this.getProjectFacetVersion();
191
		if (db == null) {
250
		if (pfv == null) {
192
			return null;
251
			return null;
193
		}
252
		}
194
		Catalog catalog = db.getDefaultCatalog();
253
		LibraryInstallDelegate lp = new LibraryInstallDelegate(fpjwc, pfv, this.buildEnablementVariables());
254
		lp.addListener(this.buildLibraryProviderListener());
255
		return lp;
256
	}
257
258
	private Map<String, Object> buildEnablementVariables() {
259
		Map<String, Object> enablementVariables = new HashMap<String, Object>();
260
		enablementVariables.put(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, this.getPlatformId());
261
		return enablementVariables;
262
	}
263
264
	private IPropertyChangeListener buildLibraryProviderListener() {
265
		return new IPropertyChangeListener() {
266
				public void propertyChanged(String property, Object oldValue, Object newValue ) {
267
					JpaFacetDataModelProvider.this.getDataModel().notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG);
268
				}
269
			};
270
	}
271
272
	private String getDefaultDriverName() {
273
		ConnectionProfile cp = this.getConnectionProfile();
274
		return (cp == null) ? null : cp.getDriverName();
275
	}
276
277
	private String getDefaultCatalogName() {
278
		Catalog catalog = this.getDefaultCatalog();
195
		return (catalog == null) ? null : catalog.getIdentifier();
279
		return (catalog == null) ? null : catalog.getIdentifier();
196
	}
280
	}
197
281
282
	private Catalog getDefaultCatalog() {
283
		Database db = this.getDatabase();
284
		return (db == null) ? null : db.getDefaultCatalog();
285
	}
286
198
	private String getDefaultSchemaName() {
287
	private String getDefaultSchemaName() {
199
		ConnectionProfile cp = this.getConnectionProfile();
288
		Schema schema = this.getDefaultSchema();
200
		if (cp == null) {
201
			return null;
202
		}
203
		Database db = cp.getDatabase();
204
		if (db == null) {
205
			return null;
206
		}
207
		Schema schema = db.getDefaultSchema();
208
		return (schema == null) ? null : schema.getIdentifier();
289
		return (schema == null) ? null : schema.getIdentifier();
209
	}
290
	}
210
	
291
	
211
	private LibraryInstallDelegate getDefaultLibraryProvider() {
292
	private Schema getDefaultSchema() {
212
		// delegate itself changes, not the instance of delegate
293
		SchemaContainer sc = this.getSchemaContainer();
213
		if (defaultLibraryProvider == null) {
294
		return (sc == null) ? null : sc.getDefaultSchema();
214
			IFacetedProjectWorkingCopy fpjwc = (IFacetedProjectWorkingCopy) getProperty(FACETED_PROJECT_WORKING_COPY);
215
			IProjectFacetVersion fv = (IProjectFacetVersion) getProperty(FACET_VERSION);
216
			if (fpjwc != null && fv != null ) {
217
				Map<String, Object> enablementVariables = new HashMap<String, Object>();
218
				enablementVariables.put(
219
					JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, 
220
					getPlatformId());	
221
				defaultLibraryProvider = new LibraryInstallDelegate(fpjwc, fv, enablementVariables);
222
				defaultLibraryProvider.addListener( 
223
					new IPropertyChangeListener() {
224
						public void propertyChanged(final String property, final Object oldValue, final Object newValue ) {
225
							JpaFacetDataModelProvider.this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.VALUE_CHG);
226
						}
227
					});
228
			}
229
		}
230
		return defaultLibraryProvider;
231
	}
295
	}
232
	
296
297
	private boolean runtimeSupportsEjb30() {
298
		IRuntime runtime = this.getRuntime();
299
		return (runtime != null) && runtime.supports(this.getEJB30());
300
	}
301
302
	private IProjectFacetVersion getEJB30() {
303
		return ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$
304
	}
305
306
307
	// ********** synchronize data model **********
308
233
	@Override
309
	@Override
234
	public boolean propertySet(String propertyName, Object propertyValue) {
310
	public boolean propertySet(String propertyName, Object propertyValue) {
235
		boolean ok = super.propertySet(propertyName, propertyValue);
311
		boolean ok = super.propertySet(propertyName, propertyValue);
Lines 237-247 Link Here
237
		if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) {
313
		if (propertyName.equals(FACETED_PROJECT_WORKING_COPY)) {
238
			//no-op
314
			//no-op
239
		}
315
		}
240
		if( propertyName.equals(FACET_VERSION)){
316
		else if (propertyName.equals(FACET_VERSION)) {
241
			this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG);
317
			this.model.notifyPropertyChange(LIBRARY_PROVIDER_DELEGATE, IDataModel.DEFAULT_CHG);
242
		}
318
		}
243
		if (propertyName.equals(RUNTIME)) {
319
		else if (propertyName.equals(RUNTIME)) {
244
			LibraryInstallDelegate lid = getLibraryInstallDelegate();
320
			LibraryInstallDelegate lid = this.getLibraryInstallDelegate();
245
			if (lid != null) {
321
			if (lid != null) {
246
				// may be null while model is being built up
322
				// may be null while model is being built up
247
				// ... or in tests
323
				// ... or in tests
Lines 250-570 Link Here
250
			this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
326
			this.model.notifyPropertyChange(DISCOVER_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
251
			this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
327
			this.model.notifyPropertyChange(LIST_ANNOTATED_CLASSES, IDataModel.DEFAULT_CHG);
252
		}
328
		}
253
		if (propertyName.equals(PLATFORM_ID)) {
329
		else if (propertyName.equals(PLATFORM_ID)) {
254
			LibraryInstallDelegate lid = getLibraryInstallDelegate();
330
			LibraryInstallDelegate lid = this.getLibraryInstallDelegate();
255
			if (lid != null) {
331
			if (lid != null) {
256
				// may be null while model is being built up
332
				// may be null while model is being built up
257
				// ... or in tests
333
				// ... or in tests
258
				lid.setEnablementContextVariable(
334
				lid.setEnablementContextVariable(JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM, propertyValue);
259
					JpaLibraryProviderConstants.EXPR_VAR_JPA_PLATFORM,
260
					(String) propertyValue);
261
			}
335
			}
262
		}
336
		}
263
		if (propertyName.equals(CONNECTION)) {
337
		else if (propertyName.equals(CONNECTION)) {
264
			this.model.notifyPropertyChange(CONNECTION, IDataModel.VALID_VALUES_CHG);
338
			this.setBooleanProperty(CONNECTION_ACTIVE, this.connectionIsActive());
265
			this.model.setBooleanProperty(CONNECTION_ACTIVE, connectionIsActive());
339
340
			// db driver
341
			if (propertyValue == null) {  // connection set to '<None>'
342
				this.setBooleanProperty(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, false);
343
			}
344
			this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG);
266
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG);
345
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.DEFAULT_CHG);
267
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG);
346
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.VALID_VALUES_CHG);
347
348
			// catalog
349
			if ((propertyValue == null) || ! this.databaseSupportsCatalogs()) {  // connection set to '<None>' or "non-catalog" database
350
				this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false);
351
			}
352
			this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG);
268
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG);
353
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG);
269
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG);
354
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG);
355
356
			// schema
357
			if (propertyValue == null) {  // connection set to '<None>'
358
				this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false);
359
			}
360
			this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG);
270
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG);
361
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG);
271
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG);
362
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG);
272
		}
363
		}
273
		if (propertyName.equals(CONNECTION_ACTIVE)) {
364
		else if (propertyName.equals(CONNECTION_ACTIVE)) {
365
			// catalog
366
			if (this.propertyValueIsFalse(propertyValue)) {  // connection is inactive
367
				this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, false);
368
			}
369
			this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG);
274
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG);
370
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.DEFAULT_CHG);
275
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG);
371
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.VALID_VALUES_CHG);
372
373
			// schema
374
			if (this.propertyValueIsFalse(propertyValue)) {  // connection is inactive
375
				this.setBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, false);
376
			}
377
			this.model.notifyPropertyChange(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG);
276
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG);
378
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.DEFAULT_CHG);
277
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG);
379
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.VALID_VALUES_CHG);
278
			this.model.notifyPropertyChange(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH, IDataModel.ENABLE_CHG);
279
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG);
280
		}
380
		}
281
		if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) {
381
		else if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)) {
282
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG);
382
			this.model.notifyPropertyChange(DB_DRIVER_NAME, IDataModel.ENABLE_CHG);
283
			if (! ((Boolean) propertyValue).booleanValue()) {
383
			if (this.propertyValueIsFalse(propertyValue)) {
284
				this.model.setProperty(DB_DRIVER_NAME, null);
384
				this.setProperty(DB_DRIVER_NAME, null);
285
			}
385
			}
286
		}
386
		}
287
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) {
387
		else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) {
288
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG);
388
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_CATALOG, IDataModel.ENABLE_CHG);
289
			if (! ((Boolean) propertyValue).booleanValue()) {
389
			if (this.propertyValueIsFalse(propertyValue)) {
290
				this.model.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null);
390
				this.setProperty(USER_OVERRIDE_DEFAULT_CATALOG, null);
291
			}
391
			}
292
		}
392
		}
293
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
393
		else if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
294
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG);
394
			this.model.notifyPropertyChange(USER_OVERRIDE_DEFAULT_SCHEMA, IDataModel.ENABLE_CHG);
295
			if (! ((Boolean) propertyValue).booleanValue()) {
395
			if (this.propertyValueIsFalse(propertyValue)) {
296
				this.model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null);
396
				this.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, null);
297
			}
397
			}
298
		}
398
		}
299
//		if (propertyName.equals(USE_SERVER_JPA_IMPLEMENTATION)) {
399
		else if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) {
300
//			this.model.setBooleanProperty(USE_USER_JPA_LIBRARY, ! ((Boolean) propertyValue).booleanValue());
400
			this.setBooleanProperty(LIST_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue));
301
//		}
302
//		if (propertyName.equals(USE_USER_JPA_LIBRARY)) {
303
//			this.model.setBooleanProperty(USE_SERVER_JPA_IMPLEMENTATION, ! ((Boolean) propertyValue).booleanValue());
304
//			this.model.notifyPropertyChange(JPA_LIBRARY, IDataModel.ENABLE_CHG);
305
//		}
306
		if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) {
307
			this.model.setBooleanProperty(LIST_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue());
308
		}
401
		}
309
		if (propertyName.equals(LIST_ANNOTATED_CLASSES)) {
402
		else if (propertyName.equals(LIST_ANNOTATED_CLASSES)) {
310
			this.model.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, ! ((Boolean) propertyValue).booleanValue());
403
			this.setBooleanProperty(DISCOVER_ANNOTATED_CLASSES, this.propertyValueIsFalse(propertyValue));
311
		}
404
		}
312
		return ok;
405
		return ok;
313
	}
406
	}
314
407
315
	private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0];
408
	private boolean propertyValueIsFalse(Object propertyValue) {
409
		return ! this.propertyValueIsTrue(propertyValue);
410
	}
411
412
	private boolean propertyValueIsTrue(Object propertyValue) {
413
		return ((Boolean) propertyValue).booleanValue();
414
	}
415
416
417
	// ********** property descriptors **********
316
418
317
	@Override
419
	@Override
318
	public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
420
	public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
319
		if (propertyName.equals(PLATFORM_ID)) {
421
		if (propertyName.equals(PLATFORM_ID)) {
320
			return CollectionTools.sort(
422
			return this.buildValidPlatformDescriptors();
321
				CollectionTools.array(
322
					new TransformationIterator<String, DataModelPropertyDescriptor>(
323
						JpaPlatformRegistry.instance().jpaPlatformIds()) {
324
							@Override
325
							protected DataModelPropertyDescriptor transform(String platformId) {
326
								return platformIdPropertyDescriptor(platformId);
327
							}
328
						},
329
						EMPTY_DMPD_ARRAY),
330
				new Comparator<DataModelPropertyDescriptor>() {
331
					public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) {
332
						return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription()));
333
					};
334
				});
335
		}
423
		}
424
336
		if (propertyName.equals(CONNECTION)) {
425
		if (propertyName.equals(CONNECTION)) {
337
			return CollectionTools.array(
426
			return this.buildValidConnectionDescriptors();
338
				new TransformationIterator<String, DataModelPropertyDescriptor>(
339
						new CompositeIterator<String>(null, connectionNames())) {
340
					@Override
341
					protected DataModelPropertyDescriptor transform(String next) {
342
						return connectionPropertyDescriptor(next);
343
					}
344
				},
345
				EMPTY_DMPD_ARRAY);
346
		}
427
		}
428
347
		if (propertyName.equals(DB_DRIVER_NAME)) {
429
		if (propertyName.equals(DB_DRIVER_NAME)) {
348
			return CollectionTools.array(
430
			return this.buildValidDriverDescriptors();
349
				new TransformationIterator<String, DataModelPropertyDescriptor>(driverNames()) {
350
					@Override
351
					protected DataModelPropertyDescriptor transform(String next) {
352
						return new DataModelPropertyDescriptor(next);
353
					}
354
				},
355
				EMPTY_DMPD_ARRAY);
356
		}
431
		}
432
357
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
433
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
358
			return CollectionTools.array(
434
			return this.buildValidCatalogDescriptors();
359
				new TransformationIterator<String, DataModelPropertyDescriptor>(catalogNames()) {
360
					@Override
361
					protected DataModelPropertyDescriptor transform(String next) {
362
						return new DataModelPropertyDescriptor(next);
363
					}
364
				},
365
				EMPTY_DMPD_ARRAY);
366
		}
435
		}
436
367
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
437
		if (propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
368
			return CollectionTools.array(
438
			return this.buildValidSchemaDescriptors();
369
				new TransformationIterator<String, DataModelPropertyDescriptor>(schemaNames()) {
370
					@Override
371
					protected DataModelPropertyDescriptor transform(String next) {
372
						return new DataModelPropertyDescriptor(next);
373
					}
374
				},
375
				EMPTY_DMPD_ARRAY);
376
		}
439
		}
377
440
378
		return super.getValidPropertyDescriptors(propertyName);
441
		return super.getValidPropertyDescriptors(propertyName);
379
	}
442
	}
380
	
443
444
	private DataModelPropertyDescriptor[] buildValidPlatformDescriptors() {
445
		List<String> platformIDs = CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds());
446
		DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[platformIDs.size()];
447
		for (int i = 0; i < descriptors.length; i++) {
448
			descriptors[i] = this.buildPlatformIdDescriptor(platformIDs.get(i));
449
		}
450
		return CollectionTools.sort(descriptors, this.buildDescriptorComparator());
451
	}
452
453
	/**
454
	 * sort the descriptors by 'description' (as opposed to 'value')
455
	 */
456
	private Comparator<DataModelPropertyDescriptor> buildDescriptorComparator() {
457
		return new Comparator<DataModelPropertyDescriptor>() {
458
				public int compare(DataModelPropertyDescriptor o1, DataModelPropertyDescriptor o2) {
459
					return (o1.getPropertyDescription().compareTo(o2.getPropertyDescription()));
460
				}
461
			};
462
	}
463
464
	private DataModelPropertyDescriptor[] buildValidConnectionDescriptors() {
465
		List<String> connectionNames = this.buildValidConnectionNames();
466
		DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[connectionNames.size()];
467
		for (int i = 0; i < descriptors.length; i++) {
468
			descriptors[i] = this.buildConnectionDescriptor(connectionNames.get(i));
469
		}
470
		return descriptors;
471
	}
472
473
	/**
474
	 * put a null entry at the top of the list (for <none>)
475
	 */
476
	private List<String> buildValidConnectionNames() {
477
		List<String> connectionNames = CollectionTools.sort(CollectionTools.list(this.connectionProfileNames()));
478
		connectionNames.add(0, null);
479
		return connectionNames;
480
	}
481
482
	private DataModelPropertyDescriptor[] buildValidDriverDescriptors() {
483
		return new DataModelPropertyDescriptor[] { new DataModelPropertyDescriptor(this.getDriverName()) };
484
	}
485
486
	private DataModelPropertyDescriptor[] buildValidCatalogDescriptors() {
487
		Database db = this.getDatabase();
488
		return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidCatalogNames(db));
489
	}
490
491
	/**
492
	 * pre-condition: 'db' is not null
493
	 */
494
	private List<String> buildValidCatalogNames(Database db) {
495
		return this.buildValidStrings(db.sortedCatalogIdentifiers(), this.getDefaultCatalogName());
496
	}
497
498
	private DataModelPropertyDescriptor[] buildValidSchemaDescriptors() {
499
		Database db = this.getDatabase();
500
		return (db == null) ? EMPTY_DMPD_ARRAY : this.buildDescriptors(this.buildValidSchemaNames());
501
	}
502
503
	private List<String> buildValidSchemaNames() {
504
		return this.buildValidStrings(this.schemaNames(), this.getDefaultSchemaName());
505
	}
506
507
	private Iterator<String> schemaNames() {
508
		SchemaContainer sc = this.getSchemaContainer();
509
		return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers();
510
	}
511
512
	/**
513
	 * put an entry for the default at the top of the list
514
	 */
515
	private List<String> buildValidStrings(Iterator<String> stream, String defaultString) {
516
		List<String> strings = CollectionTools.list(stream);
517
		if ((defaultString != null) && ! strings.contains(defaultString)) {
518
			strings.add(0, defaultString);
519
		}
520
		return strings;
521
	}
522
523
	private DataModelPropertyDescriptor[] buildDescriptors(List<String> strings) {
524
		DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[strings.size()];
525
		for (int i = 0; i < descriptors.length; i++) {
526
			descriptors[i] = new DataModelPropertyDescriptor(strings.get(i));
527
		}
528
		return descriptors;
529
	}
530
531
	private static final DataModelPropertyDescriptor[] EMPTY_DMPD_ARRAY = new DataModelPropertyDescriptor[0];
532
533
	/**
534
	 * platform and connection have 'description's (in addition to 'value's)
535
	 */
381
	@Override
536
	@Override
382
	public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) {
537
	public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) {
383
		if (propertyName.equals(PLATFORM_ID)) {
538
		if (propertyName.equals(PLATFORM_ID)) {
384
			return platformIdPropertyDescriptor(getStringProperty(PLATFORM_ID));
539
			return this.buildPlatformIdDescriptor(this.getPlatformId());
385
		}
540
		}
386
		if (propertyName.equals(CONNECTION)) {
541
		if (propertyName.equals(CONNECTION)) {
387
			return connectionPropertyDescriptor(getStringProperty(CONNECTION));
542
			return this.buildConnectionDescriptor(this.getConnectionName());
388
		}
543
		}
389
		return super.getPropertyDescriptor(propertyName);
544
		return super.getPropertyDescriptor(propertyName);
390
	}
545
	}
391
	
546
392
	DataModelPropertyDescriptor platformIdPropertyDescriptor(String platformId) {
547
	DataModelPropertyDescriptor buildPlatformIdDescriptor(String platformId) {
393
		return new DataModelPropertyDescriptor(
548
		return new DataModelPropertyDescriptor(platformId, this.getPlatformLabel(platformId));
394
			platformId, JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId));
395
	}
549
	}
396
	
550
397
	DataModelPropertyDescriptor connectionPropertyDescriptor(String connection) {
551
	private String getPlatformLabel(String platformId) {
398
		return StringTools.stringIsEmpty(connection) ?
552
		return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId);
399
					new DataModelPropertyDescriptor(null, JptCoreMessages.NONE)
400
				:
401
					new DataModelPropertyDescriptor(connection);
402
	}
553
	}
403
554
404
	@Override
555
	private DataModelPropertyDescriptor buildConnectionDescriptor(String connectionName) {
405
	public IStatus validate(String name) {
556
		String description = (connectionName == null) ? JptCoreMessages.NONE : null;
406
		if (name.equals(PLATFORM_ID)) {
557
		return new DataModelPropertyDescriptor(connectionName, description);
407
			return this.validatePlatformId(this.getStringProperty(name));
408
		}
409
		if (name.equals(LIBRARY_PROVIDER_DELEGATE)) {
410
			LibraryInstallDelegate delegate = (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE);
411
		    return delegate.validate();
412
		}
413
		if (name.equals(CONNECTION)) {
414
			return this.validateConnectionName(this.getStringProperty(name));
415
		}
416
		if (name.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)
417
				|| name.equals(DB_DRIVER_NAME)) {
418
			return this.validateDbDriverName();
419
		}
420
		if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)
421
			|| name.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
422
			return this.validateUserOverrideDefaultCatalog();
423
		}
424
		if (name.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)
425
				|| name.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
426
			return this.validateUserOverrideDefaultSchema();
427
		}
428
		if (name.equals(DISCOVER_ANNOTATED_CLASSES)) {
429
			return this.validatePersistentClassManagement(this.getBooleanProperty(name));
430
		}
431
		
432
		return super.validate(name);
433
	}
558
	}
434
559
435
	private IRuntime runtime() {
560
436
		return (IRuntime) this.getProperty(RUNTIME);
561
	// ********** database **********
562
563
	private SchemaContainer getSchemaContainer() {
564
		return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase();
437
	}
565
	}
438
566
439
	private boolean runtimeSupportsEjb30(IRuntime runtime) {
567
	private Catalog getCatalog() {
440
		IProjectFacetVersion ejb30 = ProjectFacetsManager.getProjectFacet(EJB_FACET_ID).getVersion("3.0"); //$NON-NLS-1$
568
		String name = this.getUserOverrideDefaultCatalog();
441
		return (runtime == null) ? false : runtime.supports(ejb30);
569
		return (name == null) ? null : this.getCatalog(name);
442
	}
570
	}
443
	
571
444
	private String getPlatformId() {
572
	/**
445
		return this.getStringProperty(PLATFORM_ID);
573
	 * pre-condition: 'name' is not null
574
	 */
575
	private Catalog getCatalog(String name) {
576
		Database db = this.getDatabase();
577
		return (db == null) ? null : db.getCatalogForIdentifier(name);
578
	}
579
580
	private boolean databaseSupportsCatalogs() {
581
		Database db = this.getDatabase();
582
		return (db != null) && db.supportsCatalogs();
446
	}
583
	}
447
	
584
	
448
	private LibraryInstallDelegate getLibraryInstallDelegate() {
585
	private Database getDatabase() {
449
		return (LibraryInstallDelegate) getProperty(LIBRARY_PROVIDER_DELEGATE);
586
		ConnectionProfile cp = this.getConnectionProfile();
587
		return (cp == null) ? null : cp.getDatabase();
450
	}
588
	}
451
589
452
	private String getConnectionName() {
590
	private boolean connectionIsActive() {
453
		return this.getStringProperty(CONNECTION);
591
		ConnectionProfile cp = this.getConnectionProfile();
592
		return (cp != null) && cp.isActive();
454
	}
593
	}
455
	
594
456
	private ConnectionProfile getConnectionProfile() {
595
	private ConnectionProfile getConnectionProfile() {
457
		return this.buildConnectionProfile(this.getConnectionName());
596
		String name = this.getConnectionName();
597
		return (name == null) ? null : this.getConnectionProfile(name);
458
	}
598
	}
459
599
460
	private ConnectionProfileFactory getConnectionProfileFactory() {
600
	/**
461
		// we don't have a JPA project yet, so go to the db plug-in directly to get the factory
601
	 * pre-condition: 'name' is not null
462
		return JptDbPlugin.instance().getConnectionProfileFactory();
602
	 */
603
	private ConnectionProfile getConnectionProfile(String name) {
604
		if (this.cachedConnectionProfileIsStale(name)) {
605
			this.connectionProfile = this.buildConnectionProfile(name);
606
		}
607
		return this.connectionProfile;
463
	}
608
	}
464
609
465
	private ConnectionProfile buildConnectionProfile(String name) {
610
	private boolean cachedConnectionProfileIsStale(String name) {
466
		return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance());
611
		return (this.connectionProfile == null) || ! this.connectionProfile.getName().equals(name);
467
	}
612
	}
468
613
469
	private boolean connectionIsActive() {
614
	private ConnectionProfile buildConnectionProfile(String name) {
470
		return this.connectionIsActive(this.getConnectionName());
615
		return this.getConnectionProfileFactory().buildConnectionProfile(name, DatabaseFinder.Default.instance());
471
	}
616
	}
472
617
473
	private boolean connectionIsActive(String connectionName) {
618
	private Iterator<String> connectionProfileNames() {
474
		ConnectionProfile cp = this.buildConnectionProfile(connectionName);
619
		return this.getConnectionProfileFactory().connectionProfileNames();
475
		return (cp != null) && cp.isActive();
476
	}
620
	}
477
	
621
	
478
	private Iterator<String> connectionNames() {
622
	private ConnectionProfileFactory getConnectionProfileFactory() {
479
		String setValue = getStringProperty(CONNECTION);
623
		// we don't have a JPA project yet, so go to the db plug-in directly to get the factory
480
		
624
		return JptDbPlugin.instance().getConnectionProfileFactory();
481
		List<String> connectionNames = CollectionTools.sort(CollectionTools.list(
482
			this.getConnectionProfileFactory().connectionProfileNames()));
483
		
484
		if (! StringTools.stringIsEmpty(setValue) && ! connectionNames.contains(setValue)) {
485
			return new CompositeIterator<String>(setValue, connectionNames.iterator());
486
		}
487
		return connectionNames.iterator();
488
	}
625
	}
489
	
626
490
	private List<String> buildSortedCatalogNames() {
627
491
		ConnectionProfile cp = this.getConnectionProfile();
628
	// ********** validation **********
492
		if (cp == null) {
629
493
			return Collections.emptyList();
630
	@Override
631
	public IStatus validate(String propertyName) {
632
		if (propertyName.equals(PLATFORM_ID)) {
633
			return this.validatePlatformId();
494
		}
634
		}
495
		Database db = cp.getDatabase();
635
		if (propertyName.equals(LIBRARY_PROVIDER_DELEGATE)) {
496
		if (db == null) {
636
		    return this.getLibraryInstallDelegate().validate();
497
			return Collections.emptyList();
498
		}
637
		}
499
		return CollectionTools.list(db.sortedCatalogIdentifiers());
638
		if (propertyName.equals(CONNECTION)) {
500
	}
639
			return this.validateConnection();
501
	
502
	private Iterator<String> catalogNames() {
503
		String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG);
504
		List<String> catalogNames = this.buildSortedCatalogNames();
505
		
506
		if (StringTools.stringIsEmpty(setValue) || catalogNames.contains(setValue)) {
507
			return catalogNames.iterator();
508
		}
640
		}
509
		return new CompositeIterator<String>(setValue, catalogNames.iterator());
641
		if (propertyName.equals(USER_WANTS_TO_ADD_DB_DRIVER_JARS_TO_CLASSPATH)
510
	}
642
				|| propertyName.equals(DB_DRIVER_NAME)) {
511
	
643
			return this.validateDbDriverName();
512
	private List<String> buildSortedSchemaNames() {
513
		ConnectionProfile cp = this.getConnectionProfile();
514
		if (cp == null) {
515
			return Collections.emptyList();
516
		}
644
		}
517
		Database db = cp.getDatabase();
645
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)
518
		if (db == null) {
646
				|| propertyName.equals(USER_OVERRIDE_DEFAULT_CATALOG)) {
519
			return Collections.emptyList();
647
			return this.validateUserOverrideDefaultCatalog();
520
		}
648
		}
521
		return CollectionTools.list(db.sortedSchemaIdentifiers());  // use identifiers? names seem OK since combo-box is read-only?
649
		if (propertyName.equals(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)
522
	}
650
				|| propertyName.equals(USER_OVERRIDE_DEFAULT_SCHEMA)) {
523
651
			return this.validateUserOverrideDefaultSchema();
524
	private Iterator<String> schemaNames() {
652
		}
525
		String setValue = getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA);
653
		if (propertyName.equals(DISCOVER_ANNOTATED_CLASSES)) {
526
		List<String> schemaNames = this.buildSortedSchemaNames();
654
			return this.validatePersistentClassManagement();
527
		
528
		if (StringTools.stringIsEmpty(setValue) || schemaNames.contains(setValue)) {
529
			return schemaNames.iterator();
530
		}
655
		}
531
		return new CompositeIterator<String>(setValue, schemaNames.iterator());
532
	}
533
	
534
	private Iterator<String> driverNames() {
535
		String setValue = getStringProperty(DB_DRIVER_NAME);
536
		
656
		
537
		return new CompositeIterator<String>(setValue, EmptyIterator.<String> instance());
657
		return super.validate(propertyName);
538
	}
658
	}
539
659
540
660
	private IStatus validatePlatformId() {
541
	// ********** validation **********
661
		return (this.getPlatformId() == null) ? PLATFORM_NOT_SPECIFIED_STATUS : OK_STATUS;
542
543
	private IStatus validatePlatformId(String platformId) {
544
		return StringTools.stringIsEmpty(platformId) ?
545
				PLATFORM_NOT_SPECIFIED_STATUS
546
			:
547
				OK_STATUS;
548
	}
662
	}
549
663
550
	private IStatus validateConnectionName(String connectionName) {
664
	private IStatus validateConnection() {
551
		if (StringTools.stringIsEmpty(connectionName)) {
665
		String connectionName = this.getConnectionName();
552
			return OK_STATUS;
666
		return (connectionName == null) ? OK_STATUS : this.validateNonNullConnection(connectionName);
553
		}
667
	}
554
		ConnectionProfile connectionProfile = getConnectionProfile();
555
		if (connectionProfile == null) {
556
			return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName));
557
	
668
	
669
	private IStatus validateNonNullConnection(String connectionName) {
670
		ConnectionProfile cp = this.getConnectionProfile(connectionName);
671
		if (cp == null) {
672
			return buildErrorStatus(NLS.bind(JptCoreMessages.VALIDATE_CONNECTION_INVALID, connectionName));
558
		}
673
		}
559
		if (! connectionProfile.isActive()) {
674
		if ( ! cp.isActive()) {
560
			return CONNECTION_NOT_CONNECTED_STATUS;
675
			return CONNECTION_NOT_CONNECTED_STATUS;
561
		}
676
		}
562
		return OK_STATUS;
677
		return OK_STATUS;
563
	}
678
	}
564
	
679
	
680
	private IStatus validateDbDriverName() {
681
		return OK_STATUS;
682
	}
683
565
	private IStatus validateUserOverrideDefaultCatalog() {
684
	private IStatus validateUserOverrideDefaultCatalog() {
566
		if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_CATALOG)) {
685
		if (this.userWantsToOverrideDefaultCatalog()) {
567
			if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_CATALOG))) {
686
			if (this.getUserOverrideDefaultCatalog() == null) {
568
				return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS;
687
				return USER_OVERRIDE_DEFAULT_CATALOG_NOT_SPECIFIED_STATUS;
569
			}
688
			}
570
		}
689
		}
Lines 572-594 Link Here
572
	}
691
	}
573
	
692
	
574
	private IStatus validateUserOverrideDefaultSchema() {
693
	private IStatus validateUserOverrideDefaultSchema() {
575
		if (getBooleanProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) {
694
		if (this.userWantsToOverrideDefaultSchema()) {
576
			if (StringTools.stringIsEmpty(getStringProperty(USER_OVERRIDE_DEFAULT_SCHEMA))) {
695
			if (this.getUserOverrideDefaultSchema() == null) {
577
				return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS;
696
				return USER_OVERRIDE_DEFAULT_SCHEMA_NOT_SPECIFIED_STATUS;
578
			}
697
			}
579
		}
698
		}
580
		return OK_STATUS;
699
		return OK_STATUS;
581
	}
700
	}
582
701
583
	private IStatus validatePersistentClassManagement(boolean discoverAnnotatedClasses) {
702
	private IStatus validatePersistentClassManagement() {
703
		@SuppressWarnings("unused") boolean discoverAnnotatedClasses = this.discoverAnnotatedClasses();
584
		// TODO warning if "discovery" is used, but no runtime specified ??
704
		// TODO warning if "discovery" is used, but no runtime specified ??
585
		return OK_STATUS;
705
		return OK_STATUS;
586
	}
706
	}
587
707
588
	private IStatus validateDbDriverName() {
589
		return OK_STATUS;
590
	}
591
592
708
593
	// ********** static methods **********
709
	// ********** static methods **********
594
710
Lines 596-604 Link Here
596
		return buildStatus(IStatus.INFO, message);
712
		return buildStatus(IStatus.INFO, message);
597
	}
713
	}
598
714
599
	private static IStatus buildWarningStatus(String message) {
715
//	private static IStatus buildWarningStatus(String message) {
600
		return buildStatus(IStatus.WARNING, message);
716
//		return buildStatus(IStatus.WARNING, message);
601
	}
717
//	}
602
718
603
	private static IStatus buildErrorStatus(String message) {
719
	private static IStatus buildErrorStatus(String message) {
604
		return buildStatus(IStatus.ERROR, message);
720
		return buildStatus(IStatus.ERROR, message);
Lines 607-610 Link Here
607
	private static IStatus buildStatus(int severity, String message) {
723
	private static IStatus buildStatus(int severity, String message) {
608
		return new Status(severity, JptCorePlugin.PLUGIN_ID, message);
724
		return new Status(severity, JptCorePlugin.PLUGIN_ID, message);
609
	}
725
	}
726
610
}
727
}
(-)src/org/eclipse/jpt/core/internal/GenericJpaModel.java (+1 lines)
Lines 131-136 Link Here
131
		config.setProject(project);
131
		config.setProject(project);
132
		config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project));
132
		config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project));
133
		config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project));
133
		config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project));
134
		config.setUserOverrideDefaultCatalogName(JptCorePlugin.getUserOverrideDefaultCatalogName(project));
134
		config.setUserOverrideDefaultSchemaName(JptCorePlugin.getUserOverrideDefaultSchemaName(project));
135
		config.setUserOverrideDefaultSchemaName(JptCorePlugin.getUserOverrideDefaultSchemaName(project));
135
		config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project));
136
		config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project));
136
		return config;
137
		return config;

Return to bug 267343