View | Details | Raw Unified | Return to bug 236743
Collapse All | Expand All

(-)src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java (-22 / +93 lines)
Lines 12-18 Link Here
12
import java.util.Iterator;
12
import java.util.Iterator;
13
import org.eclipse.jface.dialogs.Dialog;
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jpt.core.JpaProject;
14
import org.eclipse.jpt.core.JpaProject;
15
import org.eclipse.jpt.core.context.Entity;
16
import org.eclipse.jpt.core.context.SecondaryTable;
15
import org.eclipse.jpt.core.context.SecondaryTable;
17
import org.eclipse.jpt.db.ConnectionProfile;
16
import org.eclipse.jpt.db.ConnectionProfile;
18
import org.eclipse.jpt.db.Database;
17
import org.eclipse.jpt.db.Database;
Lines 21-26 Link Here
21
import org.eclipse.jpt.utility.internal.CollectionTools;
20
import org.eclipse.jpt.utility.internal.CollectionTools;
22
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.events.SelectionListener;
24
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.layout.GridLayout;
Lines 32-42 Link Here
32
33
33
public class SecondaryTableDialog extends Dialog {
34
public class SecondaryTableDialog extends Dialog {
34
35
35
	//if creating a new JoinColumn, this will be null,
36
	//if creating a new SecondaryTable, this will be null,
36
	//specify the JoinColumnOwner instead in the appropriate construtor
37
	//specify the defaultSchema and defaultCatalog instead in the appropriate construtor
37
	private SecondaryTable secondaryTable;
38
	private SecondaryTable secondaryTable;
38
	private Entity entity;
39
	private JpaProject jpaProject;
39
40
	private String defaultSchema;
41
	private String defaultCatalog;
42
	
40
	protected Combo nameCombo;
43
	protected Combo nameCombo;
41
	protected Combo catalogCombo;
44
	protected Combo catalogCombo;
42
	protected Combo schemaCombo;
45
	protected Combo schemaCombo;
Lines 48-62 Link Here
48
	private boolean defaultSchemaSelected;
51
	private boolean defaultSchemaSelected;
49
	private boolean defaultCatalogSelected;
52
	private boolean defaultCatalogSelected;
50
53
51
	public SecondaryTableDialog(Shell parent, Entity entity) {
54
	public SecondaryTableDialog(Shell parent, JpaProject jpaProject, String defaultSchema, String defaultCatalog) {
52
		super(parent);
55
		super(parent);
53
		this.entity = entity;
56
		this.jpaProject = jpaProject;
57
		this.defaultSchema = defaultSchema;
58
		this.defaultCatalog = defaultCatalog;
54
	}
59
	}
55
60
56
	public SecondaryTableDialog(Shell parent, SecondaryTable secondaryTable, Entity entity) {
61
	public SecondaryTableDialog(Shell parent, SecondaryTable secondaryTable, JpaProject jpaProject) {
57
		super(parent);
62
		super(parent);
58
		this.secondaryTable = secondaryTable;
63
		this.secondaryTable = secondaryTable;
59
		this.entity = entity;
64
		this.jpaProject = jpaProject;
60
	}
65
	}
61
66
62
	@Override
67
	@Override
Lines 73-84 Link Here
73
	}
78
	}
74
79
75
	protected String getTitle() {
80
	protected String getTitle() {
76
		if (secondaryTable != null) {
81
		if (this.secondaryTable != null) {
77
			return JptUiMappingsMessages.SecondaryTableDialog_editSecondaryTable;
82
			return JptUiMappingsMessages.SecondaryTableDialog_editSecondaryTable;
78
		}
83
		}
79
		else {
84
		return JptUiMappingsMessages.SecondaryTableDialog_addSecondaryTable;
80
			return JptUiMappingsMessages.SecondaryTableDialog_addSecondaryTable;
81
		}
82
	}
85
	}
83
86
84
	@Override
87
	@Override
Lines 123-128 Link Here
123
		this.schemaCombo.setLayoutData(gridData);
126
		this.schemaCombo.setLayoutData(gridData);
124
		populateSchemaCombo();
127
		populateSchemaCombo();
125
128
129
		
130
		this.schemaCombo.addSelectionListener(new SelectionListener() {
131
			
132
			public void widgetSelected(SelectionEvent e) {
133
				repopulateNameCombo();
134
			}
135
		
136
			public void widgetDefaultSelected(SelectionEvent e) {
137
				repopulateNameCombo();
138
			}
139
		});
140
126
		return composite;
141
		return composite;
127
	}
142
	}
128
143
Lines 131-147 Link Here
131
	}
146
	}
132
147
133
	private ConnectionProfile getConnectionProfile() {
148
	private ConnectionProfile getConnectionProfile() {
134
		JpaProject project = (this.secondaryTable == null) ? this.entity.getJpaProject() : this.secondaryTable.getJpaProject();
149
		return this.jpaProject.getConnectionProfile();
135
		return project.getConnectionProfile();
150
	}
151
152
	protected Schema getDefaultTableSchema() {
153
		if (this.secondaryTable != null) {
154
			return getTableSchema(this.secondaryTable.getDefaultSchema());
155
		}
156
		return getTableSchema(this.defaultSchema);
136
	}
157
	}
137
158
159
	
138
	protected Schema getTableSchema() {
160
	protected Schema getTableSchema() {
161
		if (this.secondaryTable != null) {
162
			return getTableSchema(this.secondaryTable.getSchema());
163
		}
164
		return getTableSchema(this.defaultSchema);
165
	}
166
	
167
	protected Schema getTableSchema(String schemaName) {
139
		Database database = this.getDatabase();
168
		Database database = this.getDatabase();
140
		if (database != null) {
169
		if (database != null) {
141
			if (this.secondaryTable != null) {
170
			return database.schemaNamed(schemaName);
142
				return database.schemaNamed(this.secondaryTable.getSchema());
143
			}
144
			return database.schemaNamed(this.entity.getTable().getSchema());
145
		}
171
		}
146
		return null;
172
		return null;
147
	}
173
	}
Lines 162-172 Link Here
162
		}
188
		}
163
	}
189
	}
164
190
191
	protected void repopulateNameCombo() {
192
		String nameText = this.nameCombo.getText();
193
		this.nameCombo.removeAll();
194
		
195
		Schema schema = null;
196
		if (this.schemaCombo.getSelectionIndex() == 0) {
197
			schema = this.getDefaultTableSchema();
198
		}
199
		else if (this.schemaCombo.getText() != null) {
200
			schema = this.getTableSchema(this.schemaCombo.getText());
201
		}
202
		else {
203
			schema = this.getTableSchema();
204
		}
205
		
206
		if (schema != null) {
207
			Iterator<String> tables = schema.tableNames();
208
			for (Iterator<String> stream = CollectionTools.sort( tables); stream.hasNext(); ) {
209
				this.nameCombo.add(stream.next());
210
			}
211
		}
212
		
213
		this.nameCombo.setText(nameText);
214
	}
215
	
165
	protected void populateSchemaCombo() {
216
	protected void populateSchemaCombo() {
217
		String defaultSchema;
166
		if (getSecondaryTable() != null) {
218
		if (getSecondaryTable() != null) {
167
			this.schemaCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultSchema, getSecondaryTable().getDefaultSchema()));
219
			defaultSchema = getSecondaryTable().getDefaultSchema();
220
		}
221
		else {
222
			defaultSchema = this.defaultSchema;
223
		}
224
		if (defaultSchema != null) {
225
			this.schemaCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultSchema, defaultSchema));
168
		}
226
		}
169
170
		Database database = this.getDatabase();
227
		Database database = this.getDatabase();
171
228
172
		if (database != null) {
229
		if (database != null) {
Lines 184-195 Link Here
184
				this.schemaCombo.select(0);
241
				this.schemaCombo.select(0);
185
			}
242
			}
186
		}
243
		}
244
		else {
245
			this.schemaCombo.select(0);
246
		}
187
	}
247
	}
188
248
189
	protected void populateCatalogCombo() {
249
	protected void populateCatalogCombo() {
250
		String defaultCatalog;
190
		if (getSecondaryTable() != null) {
251
		if (getSecondaryTable() != null) {
191
			this.catalogCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultCatalog, getSecondaryTable().getDefaultCatalog()));
252
			defaultCatalog = getSecondaryTable().getDefaultCatalog();
253
		}
254
		else {
255
			defaultCatalog = this.defaultCatalog;
192
		}
256
		}
257
		if (defaultCatalog != null) {
258
			this.catalogCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultCatalog, defaultCatalog));
259
		}
260
193
		Database database = this.getDatabase();
261
		Database database = this.getDatabase();
194
262
195
		if (database != null) {
263
		if (database != null) {
Lines 207-212 Link Here
207
				this.catalogCombo.select(0);
275
				this.catalogCombo.select(0);
208
			}
276
			}
209
		}
277
		}
278
		else {
279
			this.catalogCombo.select(0);			
280
		}
210
	}
281
	}
211
282
212
	protected Combo getNameCombo() {
283
	protected Combo getNameCombo() {
(-)src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java (+15 lines)
Lines 227-232 Link Here
227
				super.addPropertyNames(propertyNames);
227
				super.addPropertyNames(propertyNames);
228
				propertyNames.add(Table.DEFAULT_NAME_PROPERTY);
228
				propertyNames.add(Table.DEFAULT_NAME_PROPERTY);
229
				propertyNames.add(Table.SPECIFIED_NAME_PROPERTY);
229
				propertyNames.add(Table.SPECIFIED_NAME_PROPERTY);
230
				propertyNames.add(Table.DEFAULT_SCHEMA_PROPERTY);
231
				propertyNames.add(Table.SPECIFIED_SCHEMA_PROPERTY);
232
				propertyNames.add(Table.DEFAULT_CATALOG_PROPERTY);
233
				propertyNames.add(Table.SPECIFIED_CATALOG_PROPERTY);
234
			}
235
236
			@Override
237
			protected void propertyChanged(String propertyName) {
238
				super.propertyChanged(propertyName);
239
				if (propertyName == Table.DEFAULT_SCHEMA_PROPERTY 
240
					|| propertyName == Table.SPECIFIED_SCHEMA_PROPERTY
241
					|| propertyName == Table.DEFAULT_CATALOG_PROPERTY
242
					|| propertyName == Table.SPECIFIED_CATALOG_PROPERTY ) {
243
					repopulate();
244
				}
230
			}
245
			}
231
246
232
			@Override
247
			@Override
(-)src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java (+15 lines)
Lines 299-304 Link Here
299
				super.addPropertyNames(propertyNames);
299
				super.addPropertyNames(propertyNames);
300
				propertyNames.add(TableGenerator.DEFAULT_TABLE_PROPERTY);
300
				propertyNames.add(TableGenerator.DEFAULT_TABLE_PROPERTY);
301
				propertyNames.add(TableGenerator.SPECIFIED_TABLE_PROPERTY);
301
				propertyNames.add(TableGenerator.SPECIFIED_TABLE_PROPERTY);
302
				propertyNames.add(TableGenerator.DEFAULT_SCHEMA_PROPERTY);
303
				propertyNames.add(TableGenerator.SPECIFIED_SCHEMA_PROPERTY);
304
				propertyNames.add(TableGenerator.DEFAULT_CATALOG_PROPERTY);
305
				propertyNames.add(TableGenerator.SPECIFIED_CATALOG_PROPERTY);
306
			}
307
308
			@Override
309
			protected void propertyChanged(String propertyName) {
310
				super.propertyChanged(propertyName);
311
				if (propertyName == TableGenerator.DEFAULT_SCHEMA_PROPERTY 
312
					|| propertyName == TableGenerator.SPECIFIED_SCHEMA_PROPERTY
313
					|| propertyName == TableGenerator.DEFAULT_CATALOG_PROPERTY
314
					|| propertyName == TableGenerator.SPECIFIED_CATALOG_PROPERTY ) {
315
					repopulate();
316
				}
302
			}
317
			}
303
318
304
			@Override
319
			@Override
(-)src/org/eclipse/jpt/ui/internal/mappings/details/AbstractSecondaryTablesComposite.java (-4 / +12 lines)
Lines 85-92 Link Here
85
			String schema = dialog.getSelectedSchema();
85
			String schema = dialog.getSelectedSchema();
86
			SecondaryTable secondaryTable = this.subject().addSpecifiedSecondaryTable(index);
86
			SecondaryTable secondaryTable = this.subject().addSpecifiedSecondaryTable(index);
87
			secondaryTable.setSpecifiedName(name);
87
			secondaryTable.setSpecifiedName(name);
88
			secondaryTable.setSpecifiedCatalog(catalog);
88
			if (!dialog.isDefaultCatalogSelected()) {
89
			secondaryTable.setSpecifiedSchema(schema);
89
				secondaryTable.setSpecifiedCatalog(catalog);
90
			}
91
			if (!dialog.isDefaultSchemaSelected()) {
92
				secondaryTable.setSpecifiedSchema(schema);
93
			}
90
94
91
			listSelectionModel.setSelectedValue(secondaryTable);
95
			listSelectionModel.setSelectedValue(secondaryTable);
92
		}
96
		}
Lines 110-120 Link Here
110
		};
114
		};
111
	}
115
	}
112
116
117
	protected SecondaryTableDialog buildSecondaryTableDialogForAdd() {
118
		return new SecondaryTableDialog(getControl().getShell(), subject().getJpaProject(), subject().getTable().getDefaultSchema(), subject().getTable().getDefaultCatalog());
119
	}
120
	
113
	protected AddRemoveListPane.Adapter buildSecondaryTablesAdapter() {
121
	protected AddRemoveListPane.Adapter buildSecondaryTablesAdapter() {
114
		return new AddRemoveListPane.AbstractAdapter() {
122
		return new AddRemoveListPane.AbstractAdapter() {
115
123
116
			public void addNewItem(ObjectListSelectionModel listSelectionModel) {
124
			public void addNewItem(ObjectListSelectionModel listSelectionModel) {
117
				SecondaryTableDialog dialog = new SecondaryTableDialog(getControl().getShell(), subject());
125
				SecondaryTableDialog dialog = buildSecondaryTableDialogForAdd();
118
				addSecondaryTableFromDialog(dialog, listSelectionModel);
126
				addSecondaryTableFromDialog(dialog, listSelectionModel);
119
			}
127
			}
120
128
Lines 131-137 Link Here
131
			@Override
139
			@Override
132
			public void optionOnSelection(ObjectListSelectionModel listSelectionModel) {
140
			public void optionOnSelection(ObjectListSelectionModel listSelectionModel) {
133
				SecondaryTable secondaryTable = (SecondaryTable) listSelectionModel.selectedValue();
141
				SecondaryTable secondaryTable = (SecondaryTable) listSelectionModel.selectedValue();
134
				SecondaryTableDialog dialog = new SecondaryTableDialog(getControl().getShell(), secondaryTable, subject());
142
				SecondaryTableDialog dialog = new SecondaryTableDialog(getControl().getShell(), secondaryTable, subject().getJpaProject());
135
				editSecondaryTableFromDialog(dialog, secondaryTable);
143
				editSecondaryTableFromDialog(dialog, secondaryTable);
136
			}
144
			}
137
145
(-)src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java (+15 lines)
Lines 146-154 Link Here
146
				super.addPropertyNames(propertyNames);
146
				super.addPropertyNames(propertyNames);
147
				propertyNames.add(Table.DEFAULT_NAME_PROPERTY);
147
				propertyNames.add(Table.DEFAULT_NAME_PROPERTY);
148
				propertyNames.add(Table.SPECIFIED_NAME_PROPERTY);
148
				propertyNames.add(Table.SPECIFIED_NAME_PROPERTY);
149
				propertyNames.add(Table.DEFAULT_SCHEMA_PROPERTY);
150
				propertyNames.add(Table.SPECIFIED_SCHEMA_PROPERTY);
151
				propertyNames.add(Table.DEFAULT_CATALOG_PROPERTY);
152
				propertyNames.add(Table.SPECIFIED_CATALOG_PROPERTY);
149
			}
153
			}
150
154
151
			@Override
155
			@Override
156
			protected void propertyChanged(String propertyName) {
157
				super.propertyChanged(propertyName);
158
				if (propertyName == Table.DEFAULT_SCHEMA_PROPERTY 
159
					|| propertyName == Table.SPECIFIED_SCHEMA_PROPERTY
160
					|| propertyName == Table.DEFAULT_CATALOG_PROPERTY
161
					|| propertyName == Table.SPECIFIED_CATALOG_PROPERTY ) {
162
					repopulate();
163
				}
164
			}
165
			
166
			@Override
152
			protected String defaultValue() {
167
			protected String defaultValue() {
153
				return subject().getDefaultName();
168
				return subject().getDefaultName();
154
			}
169
			}
(-)src/org/eclipse/jpt/ui/internal/orm/details/OrmSecondaryTablesComposite.java (+7 lines)
Lines 21-26 Link Here
21
import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages;
21
import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages;
22
import org.eclipse.jpt.ui.internal.mappings.details.AbstractSecondaryTablesComposite;
22
import org.eclipse.jpt.ui.internal.mappings.details.AbstractSecondaryTablesComposite;
23
import org.eclipse.jpt.ui.internal.mappings.details.PrimaryKeyJoinColumnsInSecondaryTableComposite;
23
import org.eclipse.jpt.ui.internal.mappings.details.PrimaryKeyJoinColumnsInSecondaryTableComposite;
24
import org.eclipse.jpt.ui.internal.mappings.details.SecondaryTableDialog;
24
import org.eclipse.jpt.ui.internal.util.PaneEnabler;
25
import org.eclipse.jpt.ui.internal.util.PaneEnabler;
25
import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane;
26
import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane;
26
import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane;
27
import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane;
Lines 175-180 Link Here
175
		new PaneEnabler(defineInXmlHolder, listPane);
176
		new PaneEnabler(defineInXmlHolder, listPane);
176
	}
177
	}
177
178
179
	@Override
180
	protected SecondaryTableDialog buildSecondaryTableDialogForAdd() {
181
		//defaultSchema and defaultCatalog should not be taken from the Table in this case.  The table default schema could be what is the specified schema on the java table.
182
		return new SecondaryTableDialog(getControl().getShell(), subject().getJpaProject(), subject().getEntityMappings().getDefaultSchema(), subject().getEntityMappings().getDefaultCatalog());
183
	}
184
178
	private class DefineInXmlHolder extends ListPropertyValueModelAdapter<Boolean>
185
	private class DefineInXmlHolder extends ListPropertyValueModelAdapter<Boolean>
179
		implements WritablePropertyValueModel<Boolean> {
186
		implements WritablePropertyValueModel<Boolean> {
180
187
(-)src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java (+15 lines)
Lines 156-161 Link Here
156
				super.addPropertyNames(propertyNames);
156
				super.addPropertyNames(propertyNames);
157
				propertyNames.add(TableGenerator.DEFAULT_TABLE_PROPERTY);
157
				propertyNames.add(TableGenerator.DEFAULT_TABLE_PROPERTY);
158
				propertyNames.add(TableGenerator.SPECIFIED_TABLE_PROPERTY);
158
				propertyNames.add(TableGenerator.SPECIFIED_TABLE_PROPERTY);
159
				propertyNames.add(TableGenerator.DEFAULT_SCHEMA_PROPERTY);
160
				propertyNames.add(TableGenerator.SPECIFIED_SCHEMA_PROPERTY);
161
				propertyNames.add(TableGenerator.DEFAULT_CATALOG_PROPERTY);
162
				propertyNames.add(TableGenerator.SPECIFIED_CATALOG_PROPERTY);
163
			}
164
165
			@Override
166
			protected void propertyChanged(String propertyName) {
167
				super.propertyChanged(propertyName);
168
				if (propertyName == TableGenerator.DEFAULT_SCHEMA_PROPERTY 
169
					|| propertyName == TableGenerator.SPECIFIED_SCHEMA_PROPERTY
170
					|| propertyName == TableGenerator.DEFAULT_CATALOG_PROPERTY
171
					|| propertyName == TableGenerator.SPECIFIED_CATALOG_PROPERTY ) {
172
					repopulate();
173
				}
159
			}
174
			}
160
175
161
			@Override
176
			@Override

Return to bug 236743