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() { |