Revision 38370
trunk/applications/appgvSIG/src/com/prodevelop/cit/gvsig/vectorialdb/wizard/NewVectorDBConnectionPanel.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
import java.awt.Component; |
5 |
import java.awt.GridBagConstraints; |
|
6 |
import java.awt.Insets; |
|
5 | 7 |
import java.awt.event.ActionEvent; |
6 | 8 |
import java.awt.event.ActionListener; |
7 | 9 |
import java.awt.event.ItemEvent; |
... | ... | |
10 | 12 |
import java.awt.event.KeyListener; |
11 | 13 |
import java.beans.PropertyChangeEvent; |
12 | 14 |
import java.beans.PropertyChangeListener; |
15 |
import java.sql.ResultSet; |
|
16 |
import java.sql.SQLException; |
|
17 |
import java.util.Vector; |
|
13 | 18 |
|
14 | 19 |
import javax.swing.ImageIcon; |
15 | 20 |
import javax.swing.JButton; |
... | ... | |
24 | 29 |
|
25 | 30 |
import com.iver.andami.PluginServices; |
26 | 31 |
import com.iver.cit.gvsig.SingleVectorialDBConnectionExtension; |
32 |
import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC; |
|
27 | 33 |
import com.iver.cit.gvsig.fmap.drivers.DBException; |
28 | 34 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
29 | 35 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams; |
... | ... | |
68 | 74 |
private JComboBox datasourceComboBox; |
69 | 75 |
private ConnectionWithParams theConnWithParams = null; |
70 | 76 |
private JButton dbButton; |
77 |
private JLabel schemaLB; |
|
78 |
private JComboBox schemaCB; |
|
71 | 79 |
|
72 | 80 |
/** |
73 | 81 |
* This method initializes this |
... | ... | |
79 | 87 |
loadVectorialDBDatasourcesCombo(); |
80 | 88 |
|
81 | 89 |
chooseConnLabel = new JLabel(); |
82 |
chooseConnLabel.setText(PluginServices.getText(this, "choose_connection"));
|
|
83 |
chooseConnLabel.setBounds(new java.awt.Rectangle(14,9+50,300,22));
|
|
84 |
|
|
90 |
chooseConnLabel.setText(PluginServices.getText(this,
|
|
91 |
"choose_connection") + ":");
|
|
92 |
chooseConnLabel.setBounds(new java.awt.Rectangle(15, 10, 300, 20)); |
|
85 | 93 |
dbButton = getJdbcButton(); |
86 | 94 |
|
87 | 95 |
this.setLayout(null); |
... | ... | |
94 | 102 |
this.add(datasourceComboBox, null); |
95 | 103 |
this.add(dbButton, null); |
96 | 104 |
|
105 |
this.add(getSchemaLB(), null); |
|
106 |
this.add(getSchemaCB(), null); |
|
107 |
|
|
97 | 108 |
this.updateFinishButton(); |
98 | 109 |
getTableNameField().setText(getNewTableName()); |
99 | 110 |
} |
100 | 111 |
|
112 |
private JLabel getSchemaLB() { |
|
113 |
if (schemaLB == null) { |
|
114 |
schemaLB = new JLabel(PluginServices.getText(this, "schema") + ":"); |
|
115 |
schemaLB.setBounds(new java.awt.Rectangle(15, 70, 300, 20)); |
|
116 |
} |
|
117 |
return schemaLB; |
|
118 |
} |
|
119 |
|
|
120 |
private JComboBox getSchemaCB() { |
|
121 |
if (schemaCB == null) { |
|
122 |
schemaCB = new JComboBox(); |
|
123 |
schemaCB.setBounds(new java.awt.Rectangle(15, 95, 300, 20)); |
|
124 |
loadAvaliableSchemas(); |
|
125 |
} |
|
126 |
return schemaCB; |
|
127 |
} |
|
128 |
|
|
129 |
private void loadAvaliableSchemas() { |
|
130 |
|
|
131 |
if ((theConnWithParams == null) || (!theConnWithParams.isConnected())) { |
|
132 |
return; |
|
133 |
} |
|
134 |
|
|
135 |
try { |
|
136 |
schemaCB.removeAllItems(); |
|
137 |
ResultSet rs = ((ConnectionJDBC) theConnWithParams.getConnection()) |
|
138 |
.getConnection().getMetaData().getSchemas(); |
|
139 |
while (rs.next()) { |
|
140 |
schemaCB.addItem(rs.getString("TABLE_SCHEM")); |
|
141 |
} |
|
142 |
} catch (SQLException e) { |
|
143 |
e.printStackTrace(); |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
101 | 147 |
private String getNewTableName() { |
102 | 148 |
String resp = "GVSIG_" + NEW_TABLE_NAME_INDEX; |
103 | 149 |
NEW_TABLE_NAME_INDEX++; |
... | ... | |
108 | 154 |
|
109 | 155 |
if (tableNameField == null) { |
110 | 156 |
tableNameField = new JTextField(); |
111 |
tableNameField.setBounds(new java.awt.Rectangle(14,32,300,22));
|
|
157 |
tableNameField.setBounds(new java.awt.Rectangle(15, 155, 300, 20));
|
|
112 | 158 |
tableNameField.addKeyListener(this); |
113 | 159 |
} |
114 | 160 |
return tableNameField; |
... | ... | |
120 | 166 |
if (tableNameLabel == null) { |
121 | 167 |
tableNameLabel = new JLabel(); |
122 | 168 |
tableNameLabel.setText(PluginServices.getText(this, "Tabla") + ":"); |
123 |
tableNameLabel.setBounds(new java.awt.Rectangle(14,9,300,22)); |
|
169 |
tableNameLabel |
|
170 |
.setBounds(new java.awt.Rectangle(15, 130, 300, 20)); |
|
124 | 171 |
} |
125 | 172 |
return tableNameLabel; |
126 | 173 |
} |
... | ... | |
136 | 183 |
private JComboBox getDatasourceComboBox() { |
137 | 184 |
if (datasourceComboBox == null) { |
138 | 185 |
datasourceComboBox = new JComboBox(); |
139 |
datasourceComboBox.setBounds(new java.awt.Rectangle(14,32+50,300,22)); |
|
186 |
datasourceComboBox |
|
187 |
.setBounds(new java.awt.Rectangle(15, 35, 300, 20)); |
|
140 | 188 |
datasourceComboBox.addItemListener(this); |
141 | 189 |
} |
142 | 190 |
|
... | ... | |
203 | 251 |
} |
204 | 252 |
|
205 | 253 |
theConnWithParams = cwp; |
254 |
loadAvaliableSchemas(); |
|
206 | 255 |
this.updateFinishButton(); |
207 | 256 |
datasourceComboBox.repaint(); |
208 | 257 |
} |
... | ... | |
306 | 355 |
dbButton.addActionListener(this); |
307 | 356 |
dbButton.setToolTipText(PluginServices.getText(this, |
308 | 357 |
"add_connection")); |
309 |
dbButton.setBounds(new java.awt.Rectangle(320, 32+50, 26, 21)); |
|
310 |
|
|
358 |
dbButton.setBounds(new java.awt.Rectangle(320, 32, 26, 21)); |
|
311 | 359 |
String _file = createResourceUrl("images/jdbc.png").getFile(); |
312 | 360 |
dbButton.setIcon(new ImageIcon(_file)); |
313 | 361 |
} |
... | ... | |
347 | 395 |
} |
348 | 396 |
|
349 | 397 |
private void updateFinishButton() { |
398 |
if ((theConnWithParams != null) && (theConnWithParams.isConnected()) |
|
399 |
&& (schemaCB.getSelectedItem() != null) |
|
400 |
&& (schemaCB.getSelectedItem().toString().length() > 0)) { |
|
350 | 401 |
String aux_table_name = getTableName(); |
351 | 402 |
boolean active = (theConnWithParams != null) && validTableName(aux_table_name); |
352 | 403 |
getWizardComponents().getFinishButton().setEnabled(active); |
353 | 404 |
} |
405 |
} |
|
354 | 406 |
|
355 | 407 |
private boolean validTableName(String str) { |
356 | 408 |
|
Also available in: Unified diff