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 (-213 / +212 lines)
Lines 50-55 Link Here
50
import org.eclipse.jpt.db.Database;
50
import org.eclipse.jpt.db.Database;
51
import org.eclipse.jpt.db.JptDbPlugin;
51
import org.eclipse.jpt.db.JptDbPlugin;
52
import org.eclipse.jpt.db.Schema;
52
import org.eclipse.jpt.db.Schema;
53
import org.eclipse.jpt.db.SchemaContainer;
53
import org.eclipse.jpt.db.ui.internal.DTPUiTools;
54
import org.eclipse.jpt.db.ui.internal.DTPUiTools;
54
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
55
import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
55
import org.eclipse.jpt.ui.internal.JptUiMessages;
56
import org.eclipse.jpt.ui.internal.JptUiMessages;
Lines 271-285 Link Here
271
			}
272
			}
272
		};
273
		};
273
	}
274
	}
274
275
	
275
	protected BufferedWritablePropertyValueModel<Boolean> initializeOverrideDefaultCatalogModel() {
276
	protected BufferedWritablePropertyValueModel<Boolean> initializeOverrideDefaultCatalogModel() {
276
		OverrideDefaultCatalogModel model = new OverrideDefaultCatalogModel(this.jpaProjectHolder);
277
		OverrideDefaultCatalogModel model = new OverrideDefaultCatalogModel(this.jpaProjectHolder);
277
		BufferedWritablePropertyValueModel<Boolean> modelBuffer = 
278
			new BufferedWritablePropertyValueModel(model, this.trigger);
279
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.overrideDefaultCatalogListener);
278
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.overrideDefaultCatalogListener);
280
		modelBuffer.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
279
281
		return modelBuffer;
280
		BufferedWritablePropertyValueModel<Boolean> bufferedModel = new BufferedWritablePropertyValueModel<Boolean>(model, this.trigger);
282
		
281
		bufferedModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
282
283
		return bufferedModel;
283
	}
284
	}
284
	
285
	
285
	protected BufferedWritablePropertyValueModel<String> initializeDefaultCatalogModel() {
286
	protected BufferedWritablePropertyValueModel<String> initializeDefaultCatalogModel() {
Lines 338-344 Link Here
338
			new CombinedDefaultSchemaModel(
339
			new CombinedDefaultSchemaModel(
339
				this.defaultSchemaModel,
340
				this.defaultSchemaModel,
340
				this.overrideDefaultSchemaModel,
341
				this.overrideDefaultSchemaModel,
341
				new DefaultDefaultSchemaModel(this.connectionProfileModel));
342
				new DefaultDefaultSchemaModel(this.defaultCatalogModel, this.connectionProfileModel));
342
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
343
		model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener);
343
		return model;
344
		return model;
344
	}
345
	}
Lines 346-352 Link Here
346
	protected ListValueModel<String> initializeSchemaChoicesModel() {
347
	protected ListValueModel<String> initializeSchemaChoicesModel() {
347
		Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>();
348
		Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>();
348
		cvms.add(new PropertyCollectionValueModelAdapter(this.defaultSchemaModel));
349
		cvms.add(new PropertyCollectionValueModelAdapter(this.defaultSchemaModel));
349
		cvms.add(new SchemaChoicesModel(this.connectionProfileModel));
350
		cvms.add(new SchemaChoicesModel(this.defaultCatalogModel, this.connectionProfileModel));
350
		return new SortedListValueModelAdapter(
351
		return new SortedListValueModelAdapter(
351
			new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) {
352
			new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) {
352
				@Override
353
				@Override
Lines 1057-1071 Link Here
1057
	}
1058
	}
1058
	
1059
	
1059
1060
1060
	// ************ Catalog ************
1061
	private abstract static class OverrideDefaultModel
1061
	private static class OverrideDefaultCatalogModel
1062
		extends BasePropertyAspectAdapter<JpaProject, Boolean>
1062
	extends BasePropertyAspectAdapter<JpaProject, Boolean>
1063
	{
1063
	{
1064
		// the superclass "value" is the *cached* value
1064
		// the superclass "value" is the *cached* value
1065
		private Boolean actualValue;
1065
		private Boolean actualValue;
1066
		
1066
1067
		
1067
1068
		private OverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1068
		OverrideDefaultModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1069
			super(jpaProjectHolder);
1069
			super(jpaProjectHolder);
1070
		}
1070
		}
1071
		
1071
		
Lines 1074-1087 Link Here
1074
		
1074
		
1075
		@Override
1075
		@Override
1076
		public Boolean getValue() {
1076
		public Boolean getValue() {
1077
			Boolean value = super.getValue();
1077
			Boolean v = super.getValue();
1078
			return (value == null) ? Boolean.FALSE : value;
1078
			return (v == null) ? Boolean.FALSE : v;
1079
		}
1079
		}
1080
		
1080
		
1081
		@Override
1081
		@Override
1082
		public void setValue_(Boolean newValue) {
1082
		public void setValue_(Boolean newValue) {
1083
			this.actualValue = newValue;
1083
			this.actualValue = newValue;
1084
			valueChanged();
1084
			this.valueChanged();
1085
		}
1085
		}
1086
		
1086
		
1087
		
1087
		
Lines 1089-1102 Link Here
1089
		
1089
		
1090
		@Override
1090
		@Override
1091
		protected void engageSubject_() {
1091
		protected void engageSubject_() {
1092
			// we need to build 'actualValue' *before* calling 'super'
1093
			// because 'super' calls back here to #buildValue_()
1092
			this.actualValue = this.buildActualValue_();
1094
			this.actualValue = this.buildActualValue_();
1093
			super.engageSubject_();
1095
			super.engageSubject_();
1094
		}
1096
		}
1095
		
1097
		
1096
		@Override
1098
		@Override
1097
		protected void disengageSubject_() {
1099
		protected void disengageSubject_() {
1098
			this.actualValue = null;
1099
			super.disengageSubject_();
1100
			super.disengageSubject_();
1101
			this.actualValue = null;
1100
		}
1102
		}
1101
		
1103
		
1102
		
1104
		
Lines 1108-1114 Link Here
1108
		}
1110
		}
1109
		
1111
		
1110
		protected Boolean buildActualValue_() {
1112
		protected Boolean buildActualValue_() {
1111
			return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultCatalog());
1113
			return Boolean.valueOf(this.subjectHasUserOverrideDefault());
1114
		}
1115
1116
		protected boolean subjectHasUserOverrideDefault() {
1117
			return ! StringTools.stringIsEmpty(this.getSubjectUserOverrideDefault());
1118
		}
1119
		
1120
		protected abstract String getSubjectUserOverrideDefault();
1121
	}
1122
1123
	
1124
	// ************ Catalog ************
1125
	private static class OverrideDefaultCatalogModel
1126
		extends OverrideDefaultModel
1127
	{
1128
		OverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1129
			super(jpaProjectHolder);
1130
		}
1131
1132
		@Override
1133
		protected String getSubjectUserOverrideDefault() {
1134
			return this.subject.getUserOverrideDefaultCatalog();
1112
		}
1135
		}
1113
	}
1136
	}
1114
1137
Lines 1116-1122 Link Here
1116
	private static class DefaultCatalogModel
1139
	private static class DefaultCatalogModel
1117
		extends PropertyAspectAdapter<JpaProject, String>
1140
		extends PropertyAspectAdapter<JpaProject, String>
1118
	{
1141
	{
1119
		private DefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1142
		DefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1120
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY);
1143
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY);
1121
		}
1144
		}
1122
		
1145
		
Lines 1136-1192 Link Here
1136
			return this.subject.getUserOverrideDefaultCatalog();
1159
			return this.subject.getUserOverrideDefaultCatalog();
1137
		}
1160
		}
1138
	}
1161
	}
1139
	
1162
1140
	private static class DefaultDefaultCatalogModel
1163
	private abstract static class ConnectionProfilePropertyAspectAdapter<V>
1141
		extends BasePropertyAspectAdapter<ConnectionProfile, String>
1164
		extends BasePropertyAspectAdapter<ConnectionProfile, V>
1142
	{
1165
	{
1143
		private ConnectionListener connectionListener;
1166
		private ConnectionListener connectionListener;
1144
		
1167
1145
		
1168
		ConnectionProfilePropertyAspectAdapter(PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1146
		private DefaultDefaultCatalogModel(
1147
				PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1148
			super(connectionProfileModel);
1169
			super(connectionProfileModel);
1149
			this.connectionListener = buildConnectionListener();
1170
			this.connectionListener = this.buildConnectionListener();
1150
		}
1171
		}
1151
		
1172
1152
		
1173
		// the connection opening is probably the only thing that will happen...
1153
		// ************ initialization *****************************************
1154
		
1155
		private ConnectionListener buildConnectionListener() {
1174
		private ConnectionListener buildConnectionListener() {
1156
			return new ConnectionAdapter() {
1175
			return new ConnectionAdapter() {
1157
				@Override
1176
				@Override
1158
				public void opened(ConnectionProfile profile) {
1177
				public void opened(ConnectionProfile profile) {
1159
					if (profile.equals(DefaultDefaultCatalogModel.this.subject)) {
1178
					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
				}
1179
				}
1169
			};
1180
			};
1170
		}
1181
		}
1171
		
1182
1172
		
1183
		void profileOpened(ConnectionProfile profile) {
1173
		// ************ AspectAdapter impl *************************************
1184
			if (profile.equals(this.subject)) {
1174
		
1185
				this.valueChanged();
1186
			}
1187
		}
1188
1175
		@Override
1189
		@Override
1176
		protected void engageSubject_() {
1190
		protected void engageSubject_() {
1177
			this.subject.addConnectionListener(this.connectionListener);
1178
			super.engageSubject_();
1191
			super.engageSubject_();
1192
			this.subject.addConnectionListener(this.connectionListener);
1179
		}
1193
		}
1180
		
1194
1181
		@Override
1195
		@Override
1182
		protected void disengageSubject_() {
1196
		protected void disengageSubject_() {
1183
			this.subject.removeConnectionListener(this.connectionListener);
1197
			this.subject.removeConnectionListener(this.connectionListener);
1184
			super.disengageSubject_();
1198
			super.disengageSubject_();
1185
		}
1199
		}
1186
		
1200
1187
		
1201
	}
1188
		// ************ internal ***********************************************
1202
1189
		
1203
	private static class DefaultDefaultCatalogModel
1204
		extends ConnectionProfilePropertyAspectAdapter<String>
1205
	{
1206
		DefaultDefaultCatalogModel(PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1207
			super(connectionProfileModel);
1208
		}
1209
1190
		@Override
1210
		@Override
1191
		protected String buildValue_() {
1211
		protected String buildValue_() {
1192
			Database db = this.subject.getDatabase();
1212
			Database db = this.subject.getDatabase();
Lines 1209-1221 Link Here
1209
		private PropertyValueModel<String> defaultDefaultCatalogModel;
1229
		private PropertyValueModel<String> defaultDefaultCatalogModel;
1210
		
1230
		
1211
		
1231
		
1212
		private CombinedDefaultCatalogModel(
1232
		CombinedDefaultCatalogModel(
1213
				WritablePropertyValueModel<String> defaultCatalogModel,
1233
				WritablePropertyValueModel<String> defaultCatalogModel,
1214
				PropertyValueModel<Boolean> overrideDefaultCatalogModel,
1234
				PropertyValueModel<Boolean> overrideDefaultCatalogModel,
1215
				PropertyValueModel<String> defaultDefaultCatalogModel) {
1235
				PropertyValueModel<String> defaultDefaultCatalogModel) {
1216
			super(
1236
			super(
1217
				new CompositeListValueModel(
1237
				new CompositeListValueModel<ListValueModel<?>,Object>(
1218
					CollectionTools.list(
1238
					CollectionTools.<ListValueModel<?>>list(
1219
						new PropertyListValueModelAdapter<String>(defaultCatalogModel),
1239
						new PropertyListValueModelAdapter<String>(defaultCatalogModel),
1220
						new PropertyListValueModelAdapter<Boolean>(overrideDefaultCatalogModel),
1240
						new PropertyListValueModelAdapter<Boolean>(overrideDefaultCatalogModel),
1221
						new PropertyListValueModelAdapter<String>(defaultDefaultCatalogModel)
1241
						new PropertyListValueModelAdapter<String>(defaultDefaultCatalogModel)
Lines 1233-1241 Link Here
1233
			if (this.overrideDefaultCatalogModel.getValue()) {
1253
			if (this.overrideDefaultCatalogModel.getValue()) {
1234
				return this.defaultCatalogModel.getValue();
1254
				return this.defaultCatalogModel.getValue();
1235
			}
1255
			}
1236
			else {
1256
			return this.defaultDefaultCatalogModel.getValue();
1237
				return this.defaultDefaultCatalogModel.getValue();
1238
			}
1239
		}
1257
		}
1240
		
1258
		
1241
		
1259
		
Lines 1250-1363 Link Here
1250
	}
1268
	}
1251
1269
1252
	
1270
	
1253
	private static class CatalogChoicesModel
1271
	private static class ConnectionProfileCollectionAspectAdapter<E>
1254
		extends BaseCollectionAspectAdapter<ConnectionProfile, String>
1272
		extends BaseCollectionAspectAdapter<ConnectionProfile, E>
1255
	{
1273
	{
1256
		private ConnectionListener connectionListener;
1274
		private ConnectionListener connectionListener;
1257
		
1275
1258
		
1276
		ConnectionProfileCollectionAspectAdapter(PropertyValueModel<ConnectionProfile> subjectHolder) {
1259
		private CatalogChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) {
1260
			super(subjectHolder);
1277
			super(subjectHolder);
1261
			this.connectionListener = buildConnectionListener();
1278
			this.connectionListener = this.buildConnectionListener();
1262
		}
1279
		}
1263
		
1280
1264
		
1281
		// the connection opening is probably the only thing that will happen...
1265
		// ************ initialization *****************************************
1266
		
1267
		private ConnectionListener buildConnectionListener() {
1282
		private ConnectionListener buildConnectionListener() {
1268
			return new ConnectionAdapter() {
1283
			return new ConnectionAdapter() {
1269
				@Override
1284
				@Override
1270
				public void opened(ConnectionProfile profile) {
1285
				public void opened(ConnectionProfile profile) {
1271
					if (profile.equals(CatalogChoicesModel.this.subject)) {
1286
					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
				}
1287
				}
1281
			};
1288
			};
1282
		}
1289
		}
1283
		
1290
1284
		
1291
		void profileOpened(ConnectionProfile profile) {
1285
		// ************ AspectAdapter impl *************************************
1292
			if (profile.equals(this.subject)) {
1286
		
1293
				this.collectionChanged();
1294
			}
1295
		}
1296
1287
		@Override
1297
		@Override
1288
		protected void engageSubject_() {
1298
		protected void engageSubject_() {
1289
			this.subject.addConnectionListener(this.connectionListener);
1299
			this.subject.addConnectionListener(this.connectionListener);
1290
		}
1300
		}
1291
		
1301
1292
		@Override
1302
		@Override
1293
		protected void disengageSubject_() {
1303
		protected void disengageSubject_() {
1294
			this.subject.removeConnectionListener(this.connectionListener);
1304
			this.subject.removeConnectionListener(this.connectionListener);
1295
		}
1305
		}
1296
		
1306
1297
		
1307
	}
1298
		// ************ internal ***********************************************
1308
1299
		
1309
	private static class CatalogChoicesModel
1310
		extends ConnectionProfileCollectionAspectAdapter<String>
1311
	{
1312
		CatalogChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) {
1313
			super(subjectHolder);
1314
		}
1315
1300
		@Override
1316
		@Override
1301
		protected Iterator<String> iterator_() {
1317
		protected Iterator<String> iterator_() {
1302
			return (this.subject.getDatabase() == null) ? 
1318
			Database db = this.subject.getDatabase();
1319
			return ((db == null) || ( ! db.supportsCatalogs())) ? 
1303
				EmptyIterator.<String>instance() : 
1320
				EmptyIterator.<String>instance() : 
1304
				this.subject.getDatabase().sortedCatalogIdentifiers();
1321
				db.sortedCatalogIdentifiers();
1305
		}
1322
		}
1306
	}
1323
	}
1307
1324
1308
	
1325
	
1309
	// ************ Schema ************
1326
	// ************ Schema ************
1310
	private static class OverrideDefaultSchemaModel
1327
	private static class OverrideDefaultSchemaModel
1311
		extends BasePropertyAspectAdapter<JpaProject, Boolean>
1328
		extends OverrideDefaultModel
1312
	{
1329
	{
1313
		// the superclass "value" is the *cached* value
1330
		OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1314
		private Boolean actualValue;
1315
		
1316
		
1317
		private OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) {
1318
			super(jpaProjectHolder);
1331
			super(jpaProjectHolder);
1319
		}
1332
		}
1320
		
1333
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
1334
		@Override
1355
		protected Boolean buildValue_() {
1335
		public String getSubjectUserOverrideDefault() {
1356
			return this.actualValue;
1336
			return this.subject.getUserOverrideDefaultSchema();
1357
		}
1358
		
1359
		protected Boolean buildActualValue_() {
1360
			return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultSchema());
1361
		}
1337
		}
1362
	}
1338
	}
1363
	
1339
	
Lines 1365-1371 Link Here
1365
	private static class DefaultSchemaModel
1341
	private static class DefaultSchemaModel
1366
		extends PropertyAspectAdapter<JpaProject, String>
1342
		extends PropertyAspectAdapter<JpaProject, String>
1367
	{
1343
	{
1368
		private DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1344
		DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { 
1369
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY);
1345
			super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY);
1370
		}
1346
		}
1371
		
1347
		
Lines 1388-1451 Link Here
1388
	
1364
	
1389
	
1365
	
1390
	private static class DefaultDefaultSchemaModel
1366
	private static class DefaultDefaultSchemaModel
1391
		extends BasePropertyAspectAdapter<ConnectionProfile, String>
1367
		extends ConnectionProfilePropertyAspectAdapter<String>
1392
	{
1368
	{
1393
		private ConnectionListener connectionListener;
1369
		private final PropertyValueModel<String> defaultCatalogModel;
1394
		
1370
		private final PropertyChangeListener catalogListener;
1395
		
1371
1396
		private DefaultDefaultSchemaModel(
1372
		DefaultDefaultSchemaModel(PropertyValueModel<String> defaultCatalogModel,
1397
				PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1373
				PropertyValueModel<ConnectionProfile> connectionProfileModel) {
1398
			super(connectionProfileModel);
1374
			super(connectionProfileModel);
1399
			this.connectionListener = buildConnectionListener();
1375
			this.defaultCatalogModel = defaultCatalogModel;
1376
			this.catalogListener = this.buildCatalogListener();
1400
		}
1377
		}
1401
		
1378
1402
		
1379
		private PropertyChangeListener buildCatalogListener() {
1403
		// ************ initialization *****************************************
1380
			return new PropertyChangeListener() {
1404
		
1381
				public void propertyChanged(PropertyChangeEvent event) {
1405
		private ConnectionListener buildConnectionListener() {
1382
					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
				}
1383
				}
1419
			};
1384
			};
1420
		}
1385
		}
1421
		
1386
1422
		
1423
		// ************ AspectAdapter impl *************************************
1424
		
1425
		@Override
1387
		@Override
1426
		protected void engageSubject_() {
1388
		protected void engageSubject_() {
1427
			this.subject.addConnectionListener(this.connectionListener);
1389
			// call 'super' last?
1390
			this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1428
			super.engageSubject_();
1391
			super.engageSubject_();
1429
		}
1392
		}
1430
		
1393
		
1431
		@Override
1394
		@Override
1432
		protected void disengageSubject_() {
1395
		protected void disengageSubject_() {
1433
			this.subject.removeConnectionListener(this.connectionListener);
1434
			super.disengageSubject_();
1396
			super.disengageSubject_();
1397
			this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1435
		}
1398
		}
1436
		
1399
1437
		
1438
		// ************ internal ***********************************************
1439
		
1440
		@Override
1400
		@Override
1441
		protected String buildValue_() {
1401
		protected String buildValue_() {
1442
			Database db = this.subject.getDatabase();
1402
			Schema schema = this.getDefaultSchema();
1443
			if (db == null) {
1444
				return null;
1445
			}
1446
			Schema schema = db.getDefaultSchema();
1447
			return (schema == null) ? null : schema.getIdentifier();
1403
			return (schema == null) ? null : schema.getIdentifier();
1448
		}
1404
		}
1405
1406
		private Schema getDefaultSchema() {
1407
			SchemaContainer sc = this.getSchemaContainer();
1408
			return (sc == null) ? null : sc.getDefaultSchema();
1409
		}
1410
1411
		private SchemaContainer getSchemaContainer() {
1412
			return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase();
1413
		}
1414
1415
		private boolean databaseSupportsCatalogs() {
1416
			Database db = this.getDatabase();
1417
			return (db != null) && db.supportsCatalogs();
1418
		}
1419
1420
		private Catalog getCatalog() {
1421
			String name = this.defaultCatalogModel.getValue();
1422
			return (name == null) ? null : this.getCatalog(name);
1423
		}
1424
1425
		/**
1426
		 * pre-condition: 'name' is not null
1427
		 */
1428
		private Catalog getCatalog(String name) {
1429
			Database db = this.getDatabase();
1430
			return (db == null) ? null : db.getCatalogForIdentifier(name);
1431
		}
1432
1433
		private Database getDatabase() {
1434
			return this.subject.getDatabase();
1435
		}
1436
1449
	}
1437
	}
1450
	
1438
	
1451
	
1439
	
Lines 1460-1466 Link Here
1460
		private PropertyValueModel<String> defaultDefaultSchemaModel;
1448
		private PropertyValueModel<String> defaultDefaultSchemaModel;
1461
		
1449
		
1462
		
1450
		
1463
		private CombinedDefaultSchemaModel(
1451
		CombinedDefaultSchemaModel(
1464
				WritablePropertyValueModel<String> defaultSchemaModel,
1452
				WritablePropertyValueModel<String> defaultSchemaModel,
1465
				PropertyValueModel<Boolean> overrideDefaultSchemaModel,
1453
				PropertyValueModel<Boolean> overrideDefaultSchemaModel,
1466
				PropertyValueModel<String> defaultDefaultSchemaModel) {
1454
				PropertyValueModel<String> defaultDefaultSchemaModel) {
Lines 1484-1492 Link Here
1484
			if (this.overrideDefaultSchemaModel.getValue()) {
1472
			if (this.overrideDefaultSchemaModel.getValue()) {
1485
				return this.defaultSchemaModel.getValue();
1473
				return this.defaultSchemaModel.getValue();
1486
			}
1474
			}
1487
			else {
1475
			return this.defaultDefaultSchemaModel.getValue();
1488
				return this.defaultDefaultSchemaModel.getValue();
1489
			}
1490
		}
1476
		}
1491
		
1477
		
1492
		
1478
		
Lines 1502-1559 Link Here
1502
1488
1503
1489
1504
	private static class SchemaChoicesModel
1490
	private static class SchemaChoicesModel
1505
		extends BaseCollectionAspectAdapter<ConnectionProfile, String>
1491
		extends ConnectionProfileCollectionAspectAdapter<String>
1506
	{
1492
	{
1507
		private ConnectionListener connectionListener;
1493
		private final PropertyValueModel<String> defaultCatalogModel;
1508
		
1494
		private final PropertyChangeListener catalogListener;
1509
		
1495
1510
		private SchemaChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) {
1496
		SchemaChoicesModel(PropertyValueModel<String> defaultCatalogModel,
1497
				PropertyValueModel<ConnectionProfile> subjectHolder) {
1511
			super(subjectHolder);
1498
			super(subjectHolder);
1512
			this.connectionListener = buildConnectionListener();
1499
			this.defaultCatalogModel = defaultCatalogModel;
1500
			this.catalogListener = this.buildCatalogListener();
1513
		}
1501
		}
1514
		
1502
1515
		
1503
		private PropertyChangeListener buildCatalogListener() {
1516
		// ************ initialization *****************************************
1504
			return new PropertyChangeListener() {
1517
		
1505
				public void propertyChanged(PropertyChangeEvent event) {
1518
		private ConnectionListener buildConnectionListener() {
1506
					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
				}
1507
				}
1532
			};
1508
			};
1533
		}
1509
		}
1534
		
1510
1535
		
1536
		// ************ AspectAdapter impl *************************************
1537
		
1538
		@Override
1511
		@Override
1539
		protected void engageSubject_() {
1512
		protected void engageSubject_() {
1540
			this.subject.addConnectionListener(this.connectionListener);
1513
			// call 'super' last?
1514
			this.defaultCatalogModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1515
			super.engageSubject_();
1541
		}
1516
		}
1542
		
1517
1543
		@Override
1518
		@Override
1544
		protected void disengageSubject_() {
1519
		protected void disengageSubject_() {
1545
			this.subject.removeConnectionListener(this.connectionListener);
1520
			super.disengageSubject_();
1521
			this.defaultCatalogModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.catalogListener);
1546
		}
1522
		}
1547
		
1523
1548
		
1549
		// ************ internal ***********************************************
1550
		
1551
		@Override
1524
		@Override
1552
		protected Iterator<String> iterator_() {
1525
		protected Iterator<String> iterator_() {
1553
			return (this.subject.getDatabase() == null) ? 
1526
			SchemaContainer sc = this.getSchemaContainer();
1554
				EmptyIterator.<String>instance() : 
1527
			return (sc == null) ? EmptyIterator.<String>instance() : sc.sortedSchemaIdentifiers();
1555
				this.subject.getDatabase().sortedSchemaIdentifiers();
1528
		}
1529
1530
		private SchemaContainer getSchemaContainer() {
1531
			return this.databaseSupportsCatalogs() ? this.getCatalog() : this.getDatabase();
1532
		}
1533
1534
		private boolean databaseSupportsCatalogs() {
1535
			Database db = this.getDatabase();
1536
			return (db != null) && db.supportsCatalogs();
1537
		}
1538
1539
		private Catalog getCatalog() {
1540
			String name = this.defaultCatalogModel.getValue();
1541
			return (name == null) ? null : this.getCatalog(name);
1542
		}
1543
1544
		/**
1545
		 * pre-condition: 'name' is not null
1546
		 */
1547
		private Catalog getCatalog(String name) {
1548
			Database db = this.getDatabase();
1549
			return (db == null) ? null : db.getCatalogForIdentifier(name);
1550
		}
1551
1552
		private Database getDatabase() {
1553
			return this.subject.getDatabase();
1556
		}
1554
		}
1555
1557
	}
1556
	}
1558
	
1557
	
1559
	
1558
	
(-)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