Revision 45634 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geodb.app/org.gvsig.geodb.app.mainplugin/src/main/java/org/gvsig/geodb/AbstractWizardDB.java
AbstractWizardDB.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.awt.BorderLayout; |
4 | 4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
|
6 |
import java.awt.event.ItemEvent; |
|
7 | 5 |
import java.util.ArrayList; |
8 | 6 |
import java.util.Collection; |
9 | 7 |
import java.util.HashMap; |
10 | 8 |
import java.util.List; |
11 | 9 |
import java.util.Map; |
12 |
import javax.swing.ComboBoxModel; |
|
13 |
import javax.swing.DefaultComboBoxModel; |
|
14 | 10 |
import javax.swing.DefaultListModel; |
15 |
import javax.swing.DefaultListSelectionModel; |
|
16 |
import javax.swing.ListModel; |
|
17 | 11 |
import javax.swing.ListSelectionModel; |
18 | 12 |
import javax.swing.event.ChangeEvent; |
19 | 13 |
import javax.swing.event.ListSelectionEvent; |
20 |
import org.apache.commons.lang3.StringUtils; |
|
21 |
import org.cresques.cts.IProjection; |
|
22 | 14 |
import org.gvsig.app.gui.WizardPanel; |
23 |
import org.gvsig.expressionevaluator.Expression; |
|
24 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
25 | 15 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
26 | 16 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
27 |
import org.gvsig.expressionevaluator.swing.ExpressionPickerController; |
|
28 | 17 |
import org.gvsig.fmap.dal.DALLocator; |
29 | 18 |
import org.gvsig.fmap.dal.DataManager; |
30 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
31 | 19 |
import static org.gvsig.fmap.dal.DataServerExplorer.MODE_ALL; |
32 | 20 |
import org.gvsig.fmap.dal.DataStoreParameters; |
33 |
import org.gvsig.fmap.dal.DataTypes; |
|
34 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
38 | 21 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
39 | 22 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
40 | 23 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
... | ... | |
42 | 25 |
import static org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer.SHOW_VIEWS; |
43 | 26 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
44 | 27 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
45 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel; |
|
46 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager; |
|
47 | 28 |
import org.gvsig.tools.ToolsLocator; |
48 | 29 |
import org.gvsig.tools.dispose.DisposeUtils; |
49 | 30 |
import org.gvsig.tools.i18n.I18nManager; |
... | ... | |
52 | 33 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
53 | 34 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
54 | 35 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
55 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
56 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
57 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
58 |
import org.gvsig.tools.util.LabeledValue; |
|
59 |
import org.gvsig.tools.util.LabeledValueImpl; |
|
60 | 36 |
import org.slf4j.Logger; |
61 | 37 |
import org.slf4j.LoggerFactory; |
62 | 38 |
|
... | ... | |
70 | 46 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractWizardDB.class); |
71 | 47 |
|
72 | 48 |
|
73 |
private AbstractWizardDBView view;
|
|
49 |
protected AbstractWizardDBView view;
|
|
74 | 50 |
private PickerController<JDBCServerExplorerParameters> pickerConnection; |
75 |
private PickerController<IProjection> pickerProjection; |
|
76 |
private ExpressionPickerController pickerFilter; |
|
77 |
private JListWithCheckbox lwcTables; |
|
78 |
private JListWithCheckbox lwcColumns; |
|
79 |
private Map<String, TableInfo> tablesInfo = null; |
|
80 |
private FilteredListController tablesFilterController; |
|
51 |
protected JListWithCheckbox lwcTables; |
|
52 |
protected Map<String, TableInfo> tablesInfo = null; |
|
53 |
protected FilteredListController tablesFilterController; |
|
54 |
protected TableInfoController tableInfoController; |
|
81 | 55 |
|
56 |
|
|
82 | 57 |
public AbstractWizardDB() { |
83 | 58 |
initComponents(); |
84 | 59 |
} |
... | ... | |
90 | 65 |
|
91 | 66 |
this.view = new AbstractWizardDBView(); |
92 | 67 |
|
93 |
toolsSwingManager.translate(this.view.btnDeselectAllColumns); |
|
94 |
toolsSwingManager.translate(this.view.btnSelectAllColumns); |
|
95 | 68 |
toolsSwingManager.translate(this.view.lblColumns); |
96 | 69 |
toolsSwingManager.translate(this.view.lblConnection); |
97 | 70 |
toolsSwingManager.translate(this.view.lblFilter); |
... | ... | |
100 | 73 |
toolsSwingManager.translate(this.view.lblName); |
101 | 74 |
toolsSwingManager.translate(this.view.lblProjection); |
102 | 75 |
toolsSwingManager.translate(this.view.lblTable); |
103 |
toolsSwingManager.translate(this.view.btnAdvancedProperties); |
|
104 | 76 |
|
105 | 77 |
toolsSwingManager.addClearButton(this.view.txtName); |
106 | 78 |
toolsSwingManager.setDefaultPopupMenu(this.view.txtName); |
... | ... | |
108 | 80 |
this.lwcTables = toolsSwingManager.createJListWithCheckbox( |
109 | 81 |
this.view.lstTables |
110 | 82 |
); |
111 |
this.lwcColumns = toolsSwingManager.createJListWithCheckbox( |
|
112 |
this.view.lstColumns |
|
113 |
); |
|
114 | 83 |
|
115 |
this.pickerConnection = dataSwingManager.createJDBCConnectionPickerController( |
|
116 |
this.view.cboConnection, |
|
117 |
this.view.btnConnection |
|
118 |
); |
|
119 |
this.pickerConnection.addChangeListener((ChangeEvent e) -> { |
|
120 |
doUpdateTables(); |
|
121 |
setEditableTables(true); |
|
122 |
}); |
|
123 |
this.pickerProjection = dataSwingManager.createProjectionPickerController( |
|
124 |
this.view.txtProjection, |
|
125 |
this.view.btnProjection |
|
126 |
); |
|
127 |
this.pickerFilter = expressionSwingManager.createExpressionPickerController( |
|
128 |
this.view.txtFilter, |
|
129 |
this.view.btnFilter, |
|
130 |
this.view.btnFilterBookmarks, |
|
131 |
this.view.btnFilterHistory |
|
132 |
); |
|
133 | 84 |
this.lwcTables.addListSelectionListener((ListSelectionEvent e) -> { |
134 | 85 |
doChangeTableSelected(); |
135 | 86 |
}); |
87 |
|
|
88 |
this.initializePickerConnection(); |
|
89 |
|
|
136 | 90 |
this.lwcTables.addChecksListener((ListSelectionEvent e) -> { |
137 |
doChangeTableSelected();
|
|
91 |
doChangeTableChecked(e.getFirstIndex(), e.getLastIndex());
|
|
138 | 92 |
}); |
139 |
this.view.cboGeometryField.addItemListener((ItemEvent e) -> { |
|
140 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
141 |
doChangeGeometryField(); |
|
142 |
} |
|
143 |
}); |
|
144 |
this.view.btnDeselectAllColumns.addActionListener((ActionEvent e) -> { |
|
145 |
doDeselectAllColumns(); |
|
146 |
}); |
|
147 |
this.view.btnSelectAllColumns.addActionListener((ActionEvent e) -> { |
|
148 |
doSelectAllColumns(); |
|
149 |
}); |
|
150 |
this.view.btnAdvancedProperties.addActionListener((ActionEvent e) -> { |
|
151 |
doShowAdvancedProperties(); |
|
152 |
}); |
|
93 |
|
|
153 | 94 |
this.tablesFilterController = toolsSwingManager.createFilteredListController( |
154 | 95 |
this.view.lstTables, |
155 | 96 |
this.view.txtTablesFilter, |
156 | 97 |
this.view.btnTablesFilter |
157 | 98 |
); |
99 |
|
|
100 |
this.tableInfoController = new TableInfoController( |
|
101 |
this.view.btnDeselectAllColumns, |
|
102 |
this.view.btnSelectAllColumns, |
|
103 |
this.view.lstColumns, |
|
104 |
this.view.txtName, |
|
105 |
this.view.cboIdField, |
|
106 |
this.view.cboGeometryField, |
|
107 |
this.view.txtProjection, |
|
108 |
this.view.btnProjection, |
|
109 |
this.view.txtFilter, |
|
110 |
this.view.btnFilter, |
|
111 |
this.view.btnFilterBookmarks, |
|
112 |
this.view.btnFilterHistory, |
|
113 |
this.view.btnAdvancedProperties, |
|
114 |
this.view.lblReadOnlyNotification |
|
115 |
); |
|
158 | 116 |
|
159 | 117 |
this.clearTables(); |
160 | 118 |
this.setEditableTables(false); |
... | ... | |
163 | 121 |
this.add(this.view, BorderLayout.CENTER); |
164 | 122 |
this.setPreferredSize(new Dimension(500, 400)); |
165 | 123 |
} |
124 |
|
|
125 |
private void initializePickerConnection() { |
|
126 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
|
127 |
this.pickerConnection = dataSwingManager.createJDBCConnectionPickerController( |
|
128 |
this.view.cboConnection, |
|
129 |
this.view.btnConnection |
|
130 |
); |
|
131 |
this.pickerConnection.addChangeListener((ChangeEvent e) -> { |
|
132 |
doUpdateTables(); |
|
133 |
setEditableTables(true); |
|
134 |
}); |
|
135 |
} |
|
166 | 136 |
|
167 | 137 |
protected abstract boolean requireGeometry(); |
168 | 138 |
|
... | ... | |
174 | 144 |
return this.tablesInfo.values(); |
175 | 145 |
} |
176 | 146 |
|
177 |
private void doDeselectAllColumns() { |
|
178 |
TableInfo info = this.getCurrentTableInfo(); |
|
179 |
if (info == null) { |
|
180 |
return; |
|
181 |
} |
|
182 |
info.getColumnChecksModel().clearSelection(); |
|
183 |
} |
|
184 |
|
|
185 |
private void doSelectAllColumns() { |
|
186 |
TableInfo info = this.getCurrentTableInfo(); |
|
187 |
if (info == null) { |
|
188 |
return; |
|
189 |
} |
|
190 |
info.getColumnChecksModel().setSelectionInterval(0, info.getAttributeDescriptors().size()); |
|
191 |
} |
|
192 |
|
|
193 |
private void doShowAdvancedProperties() { |
|
194 |
final TableInfo info = this.getCurrentTableInfo(); |
|
195 |
if (info == null) { |
|
196 |
return; |
|
197 |
} |
|
198 |
this.fetch(info); |
|
199 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
200 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
201 |
DataStoreParametersPanelManager paramsPanelManager = DALSwingLocator.getDataStoreParametersPanelManager(); |
|
202 |
|
|
203 |
final DataStoreParametersPanel panel = paramsPanelManager.createDataStoreParametersPanel(info.getParameters()); |
|
204 |
final Dialog dialog = winmgr.createDialog( |
|
205 |
panel.asJComponent(), |
|
206 |
i18n.getTranslation("_Connection_parameters"), |
|
207 |
null, |
|
208 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
209 |
); |
|
210 |
dialog.addActionListener((ActionEvent e) -> { |
|
211 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK ) { |
|
212 |
JDBCStoreParameters parameters = info.getParameters(); |
|
213 |
panel.fetchParameters(parameters); |
|
214 |
info.fetch(parameters); |
|
215 |
put(info); |
|
216 |
} |
|
217 |
}); |
|
218 |
dialog.show(WindowManager.MODE.DIALOG); |
|
219 |
} |
|
220 |
|
|
221 | 147 |
private void clearTables() { |
222 | 148 |
this.lwcTables.setModel(new DefaultListModel()); |
223 | 149 |
this.lwcTables.getCheckedModel().clearSelection(); |
... | ... | |
225 | 151 |
} |
226 | 152 |
|
227 | 153 |
private void clearTableConfig() { |
228 |
this.lwcColumns.setModel(new DefaultListModel()); |
|
229 |
this.lwcColumns.getCheckedModel().clearSelection(); |
|
230 |
this.view.txtName.setText(""); |
|
231 |
this.view.cboGeometryField.setModel(new DefaultComboBoxModel()); |
|
232 |
this.view.cboIdField.setModel(new DefaultComboBoxModel()); |
|
233 |
this.pickerProjection.set(null); |
|
234 |
this.pickerFilter.set(null); |
|
154 |
this.tableInfoController.put(null); |
|
235 | 155 |
} |
236 | 156 |
|
237 | 157 |
private void setEditableTables(boolean enable) { |
238 | 158 |
this.view.lstTables.setEnabled(enable); |
239 |
this.setEditableTableConfig(enable); |
|
240 |
this.view.btnDeselectAllColumns.setEnabled(enable); |
|
241 |
this.view.btnSelectAllColumns.setEnabled(enable); |
|
159 |
this.tableInfoController.setEditable(enable); |
|
242 | 160 |
} |
243 | 161 |
|
244 |
private void setEditableTableConfig(boolean enable) { |
|
245 |
this.view.lstColumns.setEnabled(enable); |
|
246 |
this.view.txtName.setEditable(enable); |
|
247 |
this.view.cboGeometryField.setEnabled(enable); |
|
248 |
this.view.cboIdField.setEnabled(enable); |
|
249 |
this.pickerProjection.setEditable(enable); |
|
250 |
this.pickerFilter.setEditable(enable); |
|
251 |
} |
|
252 |
|
|
253 |
private TableInfo getCurrentTableInfo() { |
|
254 |
TableInfo xx = (TableInfo) this.view.lstTables.getSelectedValue(); |
|
255 |
return xx; |
|
256 |
} |
|
257 |
|
|
258 |
private void doChangeGeometryField() { |
|
259 |
TableInfo info = this.getCurrentTableInfo(); |
|
260 |
if (info == null) { |
|
261 |
return; |
|
262 |
} |
|
263 |
String attrName = (String) this.view.cboGeometryField.getSelectedItem(); |
|
264 |
if (StringUtils.isBlank(attrName)) { |
|
265 |
return; |
|
266 |
} |
|
267 |
FeatureAttributeDescriptor attr = info.getAttributeDescriptor(attrName); |
|
268 |
IProjection srs = attr.getSRS(); |
|
269 |
if (srs == null) { |
|
270 |
return; |
|
271 |
} |
|
272 |
this.pickerProjection.set(srs); |
|
273 |
} |
|
274 |
|
|
275 | 162 |
private void doUpdateTables() { |
276 | 163 |
JDBCServerExplorerParameters connection = this.pickerConnection.get(); |
277 | 164 |
if (connection == null) { |
... | ... | |
287 | 174 |
); |
288 | 175 |
List<TableInfo> parameters = new ArrayList<>(); |
289 | 176 |
for (DataStoreParameters params : explorer.list(MODE_ALL, SHOW_TABLES)) { |
290 |
parameters.add(new TableInfo((JDBCStoreParameters) params, requireGeometry(), false)); |
|
177 |
JDBCStoreParameters jdbcParams = (JDBCStoreParameters) params; |
|
178 |
parameters.add(new TableInfo(jdbcParams.getTable(), jdbcParams, requireGeometry(), false)); |
|
291 | 179 |
} |
292 | 180 |
for (DataStoreParameters params : explorer.list(MODE_ALL, SHOW_VIEWS)) { |
293 |
parameters.add(new TableInfo((JDBCStoreParameters) params, requireGeometry(), true)); |
|
181 |
JDBCStoreParameters jdbcParams = (JDBCStoreParameters) params; |
|
182 |
parameters.add(new TableInfo(jdbcParams.getTable(), jdbcParams, requireGeometry(), true)); |
|
294 | 183 |
} |
295 | 184 |
parameters.sort((TableInfo o1, TableInfo o2) -> |
296 | 185 |
o1.getLabel().compareTo(o2.getLabel()) |
... | ... | |
313 | 202 |
TableInfo tableInfo = (TableInfo) this.lwcTables.getSelectedValue(); |
314 | 203 |
if (tableInfo == null) { |
315 | 204 |
this.clearTableConfig(); |
316 |
this.setEditableTableConfig(false);
|
|
205 |
this.tableInfoController.setEditable(false);
|
|
317 | 206 |
return; |
318 | 207 |
} |
319 | 208 |
this.updateTableInfoFromUI(); |
320 |
this.put(tableInfo); |
|
209 |
this.tableInfoController.put(tableInfo); |
|
210 |
} |
|
211 |
|
|
212 |
private void doChangeTableChecked(int firstIndex, int lastIndex) { |
|
213 |
ListSelectionModel checkedModel = this.lwcTables.getCheckedModel(); |
|
214 |
for (int i = firstIndex; i <= lastIndex; i++) { |
|
215 |
TableInfo tableInfo = (TableInfo) this.lwcTables.getModel().getElementAt(i); |
|
216 |
tableInfo.setSelected(checkedModel.isSelectedIndex(i)); |
|
217 |
} |
|
321 | 218 |
this.checkFinishable(); |
322 | 219 |
} |
323 | 220 |
|
324 | 221 |
private void updateTableInfoFromUI() { |
325 |
String previousTableName = this.view.txtName.getText(); |
|
326 |
if (this.tablesInfo!=null && !this.tablesInfo.isEmpty()) { |
|
327 |
TableInfo previousInfo = this.tablesInfo.get(previousTableName); |
|
328 |
if (previousInfo != null) { |
|
329 |
this.fetch(previousInfo); |
|
330 |
} |
|
222 |
String previousId = this.tableInfoController.getId(); |
|
223 |
if (previousId == null) { |
|
224 |
return; |
|
331 | 225 |
} |
332 |
} |
|
333 | 226 |
|
334 |
private void put(TableInfo tableInfo) { |
|
335 |
this.lwcColumns.setModel(tableInfo.getColumnsListModel()); |
|
336 |
this.lwcColumns.setCheckedModel(tableInfo.getColumnChecksModel()); |
|
337 |
|
|
338 |
this.view.cboGeometryField.setModel(tableInfo.getGeomFieldComboModel()); |
|
339 |
this.view.cboGeometryField.setSelectedIndex(tableInfo.getGeomFieldSelected()); |
|
340 |
|
|
341 |
this.view.cboIdField.setModel(tableInfo.getIdFieldComboModel()); |
|
342 |
this.view.cboIdField.setSelectedIndex(tableInfo.getIdFieldSelected()); |
|
343 |
|
|
344 |
this.pickerProjection.set(tableInfo.getProjection()); |
|
345 |
this.pickerFilter.set(tableInfo.getFilter()); |
|
346 |
this.view.txtName.setText(tableInfo.getDocumentName()); |
|
347 |
|
|
348 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
349 |
boolean readOnly = tableInfo.isReadOnly(); |
|
350 |
String readOnlyMessage = readOnly?" <b>"+i18n.getTranslation("_Read_only")+"</b>":""; |
|
351 |
if(tableInfo.isView()){ |
|
352 |
this.view.lblReadOnlyNotification.setText("<html>"+i18n.getTranslation("_View")+readOnlyMessage+"</html>"); |
|
353 |
} else { |
|
354 |
this.view.lblReadOnlyNotification.setText("<html>"+i18n.getTranslation("_Table")+readOnlyMessage+"</html>"); |
|
227 |
if (this.tablesInfo != null && !this.tablesInfo.isEmpty()) { |
|
228 |
TableInfo previousInfo = this.tablesInfo.get(previousId); |
|
229 |
if (previousInfo != null) { |
|
230 |
this.tableInfoController.fetch(previousInfo); |
|
231 |
} |
|
355 | 232 |
} |
356 | 233 |
} |
357 | 234 |
|
358 |
private void fetch(TableInfo tableInfo) { |
|
359 |
tableInfo.setIdFieldSelected(this.view.cboIdField.getSelectedIndex()); |
|
360 |
tableInfo.setGeomFieldSelected(this.view.cboGeometryField.getSelectedIndex()); |
|
361 |
tableInfo.setFilter(this.pickerFilter.get()); |
|
362 |
tableInfo.setProjection(this.pickerProjection.get()); |
|
363 |
tableInfo.setDocumentName(this.view.txtName.getText()); |
|
364 |
int index = this.lwcTables.getSelectedIndex(); |
|
365 |
tableInfo.setSelected(this.lwcTables.getCheckedModel().isSelectedIndex(index)); |
|
366 |
} |
|
367 | 235 |
|
368 | 236 |
@Override |
369 | 237 |
public void initWizard() { |
Also available in: Unified diff