gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.app / org.gvsig.vcsgis.app.mainplugin / src / main / java / org / gvsig / vcsgis / app / addlayer / AbstractWizardVCSGis.java @ 8245
History | View | Annotate | Download (32.5 KB)
1 |
package org.gvsig.vcsgis.app.addlayer; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Cursor; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.net.URL; |
8 |
import java.util.ArrayList; |
9 |
import java.util.Collection; |
10 |
import java.util.HashMap; |
11 |
import java.util.List; |
12 |
import java.util.Map; |
13 |
import java.util.function.Function; |
14 |
import java.util.function.Predicate; |
15 |
import javax.swing.ImageIcon; |
16 |
import javax.swing.JButton; |
17 |
import javax.swing.JCheckBox; |
18 |
import javax.swing.JComboBox; |
19 |
import javax.swing.JComponent; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JList; |
22 |
import javax.swing.JOptionPane; |
23 |
import javax.swing.JTextField; |
24 |
import javax.swing.SwingUtilities; |
25 |
import javax.swing.UIManager; |
26 |
import javax.swing.event.ChangeEvent; |
27 |
import org.apache.commons.io.FilenameUtils; |
28 |
import org.apache.commons.lang3.StringUtils; |
29 |
import org.gvsig.app.gui.WizardPanel; |
30 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
31 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
33 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
34 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
35 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 |
import org.gvsig.geodb.TableInfo; |
38 |
import org.gvsig.geodb.TableInfoController; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dispose.DisposeUtils; |
41 |
import org.gvsig.tools.i18n.I18nManager; |
42 |
import org.gvsig.tools.locator.LocatorException; |
43 |
import org.gvsig.tools.swing.api.InitComponentsListener; |
44 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
45 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
46 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
47 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
48 |
import org.gvsig.tools.swing.api.task.TaskStatusController; |
49 |
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager; |
50 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
51 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
52 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
53 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
54 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
55 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
56 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
57 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
58 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
59 |
import org.gvsig.vcsgis.swing.VCSGisEntitySelectorController; |
60 |
import static org.gvsig.vcsgis.swing.VCSGisEntitySelectorController.ACTION_BEGIN_PROCESSING_ID; |
61 |
import static org.gvsig.vcsgis.swing.VCSGisEntitySelectorController.ACTION_CHECK_ID; |
62 |
import static org.gvsig.vcsgis.swing.VCSGisEntitySelectorController.ACTION_END_PROCESSING_ID; |
63 |
import static org.gvsig.vcsgis.swing.VCSGisEntitySelectorController.ACTION_RELOAD_ID; |
64 |
import static org.gvsig.vcsgis.swing.VCSGisEntitySelectorController.ACTION_SELECT_ID; |
65 |
import org.gvsig.vcsgis.swing.VCSGisJCheckoutDataModel; |
66 |
import org.gvsig.vcsgis.swing.VCSGisJInitWorkspace; |
67 |
import org.gvsig.vcsgis.swing.VCSGisSwingLocator; |
68 |
import org.gvsig.vcsgis.swing.VCSGisSwingManager; |
69 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices; |
70 |
import org.slf4j.Logger; |
71 |
import org.slf4j.LoggerFactory; |
72 |
|
73 |
/**
|
74 |
*
|
75 |
* @author jjdelcerro
|
76 |
*/
|
77 |
@SuppressWarnings("UseSpecificCatch") |
78 |
public abstract class AbstractWizardVCSGis extends WizardPanel { |
79 |
|
80 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractWizardVCSGis.class); |
81 |
|
82 |
protected WizardVCSGisViewExtended view;
|
83 |
private PickerController<VCSGisWorkspace> workspacePicker;
|
84 |
protected Map<String, TableInfo> tablesInfo = null; |
85 |
private boolean processing; |
86 |
private TaskStatusController taskStatusController;
|
87 |
private TableInfoController tableInfoController;
|
88 |
private VCSGisEntitySelectorController entitySelector;
|
89 |
|
90 |
private class VCSGisTableInfoController extends TableInfoController { |
91 |
|
92 |
public VCSGisTableInfoController(JButton btnDeselectAllColumns, JButton btnSelectAllColumns, JList lstColumns, JTextField txtName, JComboBox cboIdField, JComboBox cboGeometryField, JTextField txtProjection, JButton btnProjection, JTextField txtFilter, JButton btnFilter, JButton btnFilterBookmarks, JButton btnFilterHistory, JButton btnAdvancedProperties, JLabel lblReadOnlyNotification, JComponent pnlCfgActions, JButton btnChangeViewProjection, JCheckBox visible) { |
93 |
super(btnDeselectAllColumns, btnSelectAllColumns, lstColumns, txtName, cboIdField, cboGeometryField, txtProjection, btnProjection, txtFilter, btnFilter, btnFilterBookmarks, btnFilterHistory, btnAdvancedProperties, lblReadOnlyNotification, pnlCfgActions, btnChangeViewProjection, visible);
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public void put(TableInfo tableInfo) { |
98 |
if( tableInfo!=null ) { |
99 |
Boolean v = tableInfo.getVisible();
|
100 |
if( v == null ) { |
101 |
VCSGisEntity entity = ((VCSGisTableInfo)tableInfo).getEntity(); |
102 |
if( entity!=null ) { |
103 |
String category = getCategory(entity);
|
104 |
boolean defaultVisibility = entity.getCategoryTags(category).getBoolean("visibility",true); |
105 |
tableInfo.setVisible(defaultVisibility); |
106 |
} |
107 |
} |
108 |
} |
109 |
super.put(tableInfo);
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
protected void updateLabel(StringBuilder builder) throws LocatorException { |
114 |
super.updateLabel(builder);
|
115 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
116 |
VCSGisTableInfo info = (VCSGisTableInfo) this.getTableInfo();
|
117 |
if( info.needConnectToModel() ) {
|
118 |
builder.append(" - <b>");
|
119 |
builder.append(i18n.getTranslation("_Connect_to_model_required"));
|
120 |
builder.append(" (");
|
121 |
builder.append(info.getEntity().getDataModels()); |
122 |
builder.append(")</b>");
|
123 |
} |
124 |
} |
125 |
|
126 |
} |
127 |
|
128 |
public AbstractWizardVCSGis() {
|
129 |
createComponents(); |
130 |
} |
131 |
|
132 |
private static void waitCursor(Component component, Runnable action) { |
133 |
Cursor saved_cursor = component.getCursor();
|
134 |
try {
|
135 |
component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
136 |
action.run(); |
137 |
} finally {
|
138 |
component.setCursor(saved_cursor); |
139 |
} |
140 |
} |
141 |
|
142 |
private void createComponents() { |
143 |
|
144 |
ToolsSwingUtils.addInitComponentsListener(this, new InitComponentsListener() { |
145 |
@Override
|
146 |
public void doDisposeComponents() { |
147 |
disposeComponents(); |
148 |
} |
149 |
|
150 |
@Override
|
151 |
public void doInitComponents() { |
152 |
initComponents(); |
153 |
} |
154 |
}); |
155 |
|
156 |
this.view = new WizardVCSGisViewExtended(); |
157 |
|
158 |
this.tableInfoController = new VCSGisTableInfoController( |
159 |
this.view.btnDeselectAllColumns,
|
160 |
this.view.btnSelectAllColumns,
|
161 |
this.view.lstColumns,
|
162 |
this.view.txtName,
|
163 |
this.view.cboIdField,
|
164 |
this.view.cboGeometryField,
|
165 |
this.view.txtProjection,
|
166 |
this.view.btnProjection,
|
167 |
this.view.txtFilter,
|
168 |
this.view.btnFilter,
|
169 |
this.view.btnFilterBookmarks,
|
170 |
this.view.btnFilterHistory,
|
171 |
this.view.btnAdvancedProperties,
|
172 |
this.view.lblReadOnlyNotification,
|
173 |
null,
|
174 |
this.view.btnChangeViewProjection,
|
175 |
this.view.chkVisible
|
176 |
); |
177 |
} |
178 |
|
179 |
private void disposeComponents() { |
180 |
DisposeUtils.disposeQuietly(entitySelector); |
181 |
} |
182 |
|
183 |
private void initComponents() { |
184 |
if(this.entitySelector != null) { |
185 |
return;
|
186 |
} |
187 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
188 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
189 |
ExpressionEvaluatorSwingManager expressionSwingManager = ExpressionEvaluatorSwingLocator.getManager(); |
190 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
191 |
|
192 |
this.view = new WizardVCSGisViewExtended(); |
193 |
|
194 |
this.entitySelector = swingManager.createEntitySelectorController(
|
195 |
this.view.treeTables,
|
196 |
this.view.txtTablesFilter,
|
197 |
this.view.btnTablesFilter);
|
198 |
|
199 |
Predicate<VCSGisEntity> entitySelectorFilter = VCSGisEntitySelectorController.ALL_ENTITIES;
|
200 |
|
201 |
if(this.requireGeometry()){ |
202 |
entitySelectorFilter = (VCSGisEntity t) -> (StringUtils.isNotBlank(t.getGeometryFieldName())); |
203 |
} |
204 |
|
205 |
this.entitySelector.setFilter(entitySelectorFilter);
|
206 |
this.entitySelector.setViewFilter(entitySelectorFilter);
|
207 |
this.entitySelector.setLabelEntityFormatter(this.getLabelEntityFormatter()); |
208 |
|
209 |
this.entitySelector.setChecksEnabled(true); |
210 |
|
211 |
TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager(); |
212 |
|
213 |
this.taskStatusController = taskStatusManager.createTaskStatusController(
|
214 |
this.view.lblStatusTitle,
|
215 |
this.view.lblStatusMessages,
|
216 |
this.view.pbStatus
|
217 |
); |
218 |
this.taskStatusController.setShowCancelButton(false); |
219 |
this.taskStatusController.setShowRemoveTaskButton(false); |
220 |
this.taskStatusController.bind(ToolsLocator.getTaskStatusManager());
|
221 |
|
222 |
toolsSwingManager.translate(this.view.lblColumns);
|
223 |
toolsSwingManager.translate(this.view.lblWorkspace);
|
224 |
toolsSwingManager.translate(this.view.lblFilter);
|
225 |
toolsSwingManager.translate(this.view.lblGeometryField);
|
226 |
toolsSwingManager.translate(this.view.lblIdField);
|
227 |
toolsSwingManager.translate(this.view.lblName);
|
228 |
toolsSwingManager.translate(this.view.lblProjection);
|
229 |
toolsSwingManager.translate(this.view.lblTable);
|
230 |
toolsSwingManager.translate(this.view.cboWorkspaces);
|
231 |
toolsSwingManager.translate(this.view.btnAddWorkspace);
|
232 |
toolsSwingManager.translate(this.view.btnCheckout);
|
233 |
toolsSwingManager.translate(this.view.btnInitWorkspace);
|
234 |
toolsSwingManager.translate(this.view.chkMaintainStructureInToC);
|
235 |
toolsSwingManager.translate(this.view.btnTablesCheckAll);
|
236 |
toolsSwingManager.translate(this.view.btnTablesUncheckAll);
|
237 |
toolsSwingManager.translate(this.view.btnTablesCollapseAll);
|
238 |
toolsSwingManager.translate(this.view.btnTablesExpandAll);
|
239 |
toolsSwingManager.translate(this.view.chkCheckScale);
|
240 |
toolsSwingManager.translate(this.view.chkAddToCWhenLoadingAll);
|
241 |
toolsSwingManager.translate(this.view.tabTableInfo);
|
242 |
toolsSwingManager.translate(this.view.lblVisible);
|
243 |
toolsSwingManager.translate(this.view.btnConnectToModel);
|
244 |
|
245 |
this.view.btnInitWorkspace.setText(toHTML(this.view.btnInitWorkspace.getText())); |
246 |
|
247 |
toolsSwingManager.addClearButton(this.view.txtName);
|
248 |
toolsSwingManager.setDefaultPopupMenu(this.view.txtName);
|
249 |
|
250 |
this.view.btnInitWorkspace.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
251 |
this.view.btnAddWorkspace.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
252 |
|
253 |
this.workspacePicker = swingManager.createWorkspacePickerController(
|
254 |
this.view.cboWorkspaces,
|
255 |
this.view.btnAddWorkspace
|
256 |
); |
257 |
|
258 |
this.workspacePicker.addChangeListener((ChangeEvent e) -> { |
259 |
waitCursor(this, () -> {
|
260 |
doChangeWorkspace(); |
261 |
doUpdateComponents(); |
262 |
}); |
263 |
}); |
264 |
|
265 |
this.entitySelector.addActionListener((ActionEvent e) -> { |
266 |
switch(e.getID()){
|
267 |
case ACTION_RELOAD_ID:
|
268 |
doReloadTablesInfo(); |
269 |
break;
|
270 |
case ACTION_BEGIN_PROCESSING_ID:
|
271 |
case ACTION_END_PROCESSING_ID:
|
272 |
doUpdateComponents(); |
273 |
break;
|
274 |
case ACTION_SELECT_ID:
|
275 |
doChangeTableSelected(); |
276 |
break;
|
277 |
case ACTION_CHECK_ID:
|
278 |
doChangeTableChecked(); |
279 |
doUpdateComponents(); |
280 |
break;
|
281 |
|
282 |
} |
283 |
}); |
284 |
this.view.btnTablesCheckAll.addActionListener((ActionEvent e) -> { |
285 |
// this.entitySelector.checkAll();
|
286 |
waitCursor(this, () -> {
|
287 |
List<String> entityCodes = new ArrayList<>(); |
288 |
Collection<VCSGisEntity> entities = entitySelector.getEntities();
|
289 |
for (VCSGisEntity entity : entities) {
|
290 |
if( entity instanceof VCSGisWorkspaceEntity ){ |
291 |
entityCodes.add(entity.getEntityCode()); |
292 |
} |
293 |
} |
294 |
entitySelector.setCheck(entityCodes, true);
|
295 |
}); |
296 |
}); |
297 |
|
298 |
this.view.btnTablesUncheckAll.addActionListener((ActionEvent e) -> { |
299 |
this.entitySelector.clearChecks();
|
300 |
}); |
301 |
|
302 |
this.view.btnTablesCollapseAll.addActionListener((ActionEvent e) -> { |
303 |
this.entitySelector.collapseAll();
|
304 |
}); |
305 |
|
306 |
this.view.btnTablesExpandAll.addActionListener((ActionEvent e) -> { |
307 |
this.entitySelector.expandAll();
|
308 |
}); |
309 |
|
310 |
this.view.btnInitWorkspace.addActionListener((ActionEvent e) -> { |
311 |
doShowInitWorkspace(); |
312 |
}); |
313 |
|
314 |
this.view.btnCheckout.addActionListener((ActionEvent e) -> { |
315 |
doCheckout(); |
316 |
}); |
317 |
|
318 |
this.view.btnConnectToModel.addActionListener((ActionEvent e) -> { |
319 |
doConnectToModel(); |
320 |
}); |
321 |
|
322 |
this.view.btnChangeViewProjection.setVisible(this.requireGeometry()); |
323 |
|
324 |
this.view.btnInitWorkspace.setBackground(UIManager.getColor("Panel.background")); |
325 |
// this.view.txtRepositoryInfo.setBackground(UIManager.getColor("Panel.background"));
|
326 |
|
327 |
this.clearTables();
|
328 |
|
329 |
this.view.chkMaintainStructureInToC.setVisible(false); |
330 |
this.view.chkMaintainStructureInToC.setSelected(true); |
331 |
|
332 |
this.view.chkCheckScale.setSelected(true); |
333 |
|
334 |
this.view.chkAddToCWhenLoadingAll.setSelected(true); |
335 |
|
336 |
this.setLayout(new BorderLayout()); |
337 |
this.add(this.view, BorderLayout.CENTER); |
338 |
|
339 |
ToolsSwingUtils.ensureRowsCols(this, 22, 90, 25, 100); |
340 |
doUpdateComponents(); |
341 |
} |
342 |
|
343 |
protected abstract boolean requireGeometry(); |
344 |
|
345 |
protected boolean maintainStructureInToC() { |
346 |
return this.view.chkMaintainStructureInToC.isSelected(); |
347 |
} |
348 |
|
349 |
protected void setVisibleMaintainStructureInToC(boolean visible) { |
350 |
this.view.chkMaintainStructureInToC.setVisible(visible);
|
351 |
} |
352 |
|
353 |
protected Collection<TableInfo> getTablesInformation() { |
354 |
this.updateTableInfoFromUI();
|
355 |
if( this.tablesInfo == null ) { |
356 |
this.tablesInfo = new HashMap<>(); |
357 |
} |
358 |
return this.tablesInfo.values(); |
359 |
} |
360 |
|
361 |
private void clearTables() { |
362 |
this.entitySelector.clear();
|
363 |
this.tableInfoController.clear();
|
364 |
} |
365 |
|
366 |
private void doChangeWorkspace() { |
367 |
if (notInSwingThreadInvokeLater(this::doChangeWorkspace)) { |
368 |
return;
|
369 |
} |
370 |
|
371 |
VCSGisWorkspace workspace = workspacePicker.get(); |
372 |
|
373 |
this.entitySelector.setWorkspace(workspace);
|
374 |
// if (workspace == null) {
|
375 |
// this.view.txtRepositoryInfo.setText("");
|
376 |
// return;
|
377 |
// }
|
378 |
//
|
379 |
// this.view.txtRepositoryInfo.setText(workspace.getRepository().getLabel());
|
380 |
} |
381 |
|
382 |
private TableInfo getTableInfo(VCSGisEntity entity){
|
383 |
Collection<TableInfo> tablesInformation = getTablesInformation();
|
384 |
for (TableInfo tableInfo : tablesInformation) {
|
385 |
VCSGisEntity tableInfoEntity = (VCSGisEntity) tableInfo.getProperty("entity");
|
386 |
if(tableInfoEntity!=null && StringUtils.equals(tableInfoEntity.getEntityCode(), entity.getEntityCode())){ |
387 |
return tableInfo;
|
388 |
} |
389 |
} |
390 |
return null; |
391 |
} |
392 |
|
393 |
private void doChangeTableSelected() { |
394 |
if( notInSwingThreadInvokeLater(() -> {doChangeTableSelected();}) ) {
|
395 |
return;
|
396 |
} |
397 |
|
398 |
VCSGisEntity selected = this.entitySelector.getSelectedEntity();
|
399 |
if(selected == null){ |
400 |
this.tableInfoController.put(null); |
401 |
return;
|
402 |
} |
403 |
TableInfo tableInfo = getTableInfo(selected); |
404 |
if (tableInfo != null) { |
405 |
this.updateTableInfoFromUI();
|
406 |
this.tableInfoController.put(tableInfo);
|
407 |
this.tableInfoController.setEnabled(true); |
408 |
} else {
|
409 |
this.tableInfoController.clear();
|
410 |
this.tableInfoController.setEnabled(false); |
411 |
} |
412 |
|
413 |
showMessage("");
|
414 |
doUpdateComponents(); |
415 |
} |
416 |
|
417 |
private void doChangeTableChecked() { |
418 |
List<VCSGisEntity> checkedEntities = this.entitySelector.getCheckedEntities(); |
419 |
List<String> entityCodes = new ArrayList<>(); |
420 |
for (VCSGisEntity checkedEntity : checkedEntities) {
|
421 |
if( checkedEntity!=null && !(checkedEntity instanceof VCSGisWorkspaceEntity)){ |
422 |
entityCodes.add(checkedEntity.getEntityCode()); |
423 |
} |
424 |
} |
425 |
this.entitySelector.setCheck(entityCodes, false); |
426 |
|
427 |
Collection<TableInfo> tablesInformation = getTablesInformation();
|
428 |
for (TableInfo tableInfo : tablesInformation) {
|
429 |
VCSGisEntity tableInfoEntity = (VCSGisEntity) tableInfo.getProperty("entity");
|
430 |
tableInfo.setSelected(checkedEntities.contains(tableInfoEntity)); |
431 |
} |
432 |
this.checkFinishable();
|
433 |
} |
434 |
|
435 |
|
436 |
private void updateTableInfoFromUI() { |
437 |
String previousId = this.tableInfoController.getId(); |
438 |
if (previousId == null) { |
439 |
return;
|
440 |
} |
441 |
|
442 |
if (this.tablesInfo != null && !this.tablesInfo.isEmpty()) { |
443 |
TableInfo previousInfo = this.tablesInfo.get(previousId);
|
444 |
if (previousInfo != null) { |
445 |
this.tableInfoController.fetch(previousInfo);
|
446 |
} |
447 |
} |
448 |
} |
449 |
|
450 |
@Override
|
451 |
public void initWizard() { |
452 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
453 |
setTabName(i18n.getTranslation("_VCSGis"));
|
454 |
} |
455 |
|
456 |
@Override
|
457 |
public boolean areSettingsValid() { |
458 |
if(processing){
|
459 |
return false; |
460 |
} |
461 |
boolean hasInvalidValues = false; |
462 |
boolean hasSelectedTables = false; |
463 |
for (TableInfo tableInfo : this.getTablesInformation() ) { |
464 |
if (tableInfo.isSelected()) {
|
465 |
hasSelectedTables = true;
|
466 |
if (!tableInfo.hasValidValues()) {
|
467 |
hasInvalidValues = true;
|
468 |
} |
469 |
} |
470 |
} |
471 |
return hasSelectedTables && !hasInvalidValues;
|
472 |
} |
473 |
|
474 |
@Override
|
475 |
public DataStoreParameters[] getParameters() { |
476 |
int sz = 0; |
477 |
for (TableInfo tableInfo : this.getTablesInformation() ) { |
478 |
if( tableInfo.isSelected() ) {
|
479 |
sz++; |
480 |
} |
481 |
} |
482 |
if( sz == 0 ) { |
483 |
return null; |
484 |
} |
485 |
DataStoreParameters[] dbParameters = new DataStoreParameters[sz]; |
486 |
int n = 0; |
487 |
for (TableInfo tableInfo : this.getTablesInformation() ) { |
488 |
if( tableInfo.isSelected() ) {
|
489 |
dbParameters[n++] = tableInfo.getParameters(); |
490 |
} |
491 |
} |
492 |
return dbParameters;
|
493 |
} |
494 |
|
495 |
@Override
|
496 |
public void execute() { |
497 |
executeWizard(); |
498 |
} |
499 |
|
500 |
@Override
|
501 |
public void close() { |
502 |
|
503 |
} |
504 |
|
505 |
protected void checkFinishable() { |
506 |
boolean finishable = areSettingsValid();
|
507 |
callStateChanged(finishable); |
508 |
} |
509 |
|
510 |
private void doUpdateComponents() { |
511 |
VCSGisEntity entity = this.entitySelector.getSelectedEntity();
|
512 |
|
513 |
boolean theProcessing = this.processing || this.entitySelector.isProcessing(); |
514 |
|
515 |
VCSGisWorkspace ws = getWorkspace(); |
516 |
if(entity == null){ |
517 |
this.view.btnCheckout.setEnabled(false); |
518 |
this.tableInfoController.setEnabled(false); |
519 |
} else if(entity instanceof VCSGisWorkspaceEntity){ |
520 |
this.view.btnCheckout.setEnabled(false); |
521 |
this.tableInfoController.setEditable(!theProcessing && ws != null); |
522 |
this.tableInfoController.setEnabled(ws != null); |
523 |
} else { //Entidad de repositorio |
524 |
this.view.btnCheckout.setEnabled(!theProcessing && ws != null); |
525 |
this.tableInfoController.setEnabled(false); |
526 |
} |
527 |
|
528 |
this.entitySelector.setEnabled(!theProcessing && ws != null); |
529 |
this.view.btnTablesCheckAll.setEnabled(this.entitySelector.isEnabled()); |
530 |
this.view.btnTablesUncheckAll.setEnabled(this.entitySelector.isEnabled()); |
531 |
this.view.btnTablesCollapseAll.setEnabled(this.entitySelector.isEnabled()); |
532 |
this.view.btnTablesExpandAll.setEnabled(this.entitySelector.isEnabled()); |
533 |
this.workspacePicker.setEnabled(!theProcessing);
|
534 |
this.view.btnInitWorkspace.setEnabled(!theProcessing);
|
535 |
// this.view.txtRepositoryInfo.setEnabled(!theProcessing && ws != null);
|
536 |
this.setVisibleStatus(theProcessing);
|
537 |
this.checkFinishable();
|
538 |
} |
539 |
|
540 |
private void doShowInitWorkspace() { |
541 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
542 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
543 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
544 |
|
545 |
final VCSGisJInitWorkspace panelInitWorkspace = swingManager.createInitWorkspacePanel();
|
546 |
final Dialog dialogInitWorkspace = winManager.createDialog( |
547 |
panelInitWorkspace.asJComponent(), |
548 |
i18nManager.getTranslation("_VCS_Initialize_workingcopy"),
|
549 |
i18nManager.getTranslation("_VCS_Initialize_workingcopy"),
|
550 |
WindowManager_v2.BUTTONS_OK_CANCEL |
551 |
); |
552 |
|
553 |
panelInitWorkspace.setDialog(dialogInitWorkspace); |
554 |
dialogInitWorkspace.setButtonLabel( |
555 |
WindowManager_v2.BUTTON_OK, |
556 |
i18nManager.getTranslation("_VCS_Initialize_workingcopy")
|
557 |
); |
558 |
dialogInitWorkspace.addActionListener((ActionEvent e) -> {
|
559 |
switch (dialogInitWorkspace.getAction()) {
|
560 |
case WindowManager_v2.BUTTON_OK:
|
561 |
int r = panelInitWorkspace.initializeWorkspace();
|
562 |
if (r != 0) { |
563 |
String message = "_Cant_initialize_workingcopy_{0}"; |
564 |
|
565 |
StringBuilder compoundMessage = new StringBuilder(); |
566 |
String[] messageArgs = new String[]{panelInitWorkspace.getWorkspaceName()}; |
567 |
|
568 |
compoundMessage.append(i18nManager.getTranslation( |
569 |
message, |
570 |
messageArgs |
571 |
)); |
572 |
|
573 |
ThreadSafeDialogsManager dialogsManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
574 |
dialogsManager.messageDialog( |
575 |
compoundMessage.toString(), |
576 |
i18nManager.getTranslation("_VCS_Initialize_workingcopy"),
|
577 |
JOptionPane.WARNING_MESSAGE
|
578 |
); |
579 |
} |
580 |
|
581 |
break;
|
582 |
|
583 |
} |
584 |
}); |
585 |
dialogInitWorkspace.show(WindowManager.MODE.DIALOG); |
586 |
} |
587 |
|
588 |
public VCSGisWorkspace getWorkspace() {
|
589 |
return this.workspacePicker.get(); |
590 |
} |
591 |
|
592 |
private void doReloadTablesInfo() { |
593 |
if (notInSwingThreadInvokeLater(() -> { doReloadTablesInfo(); })) {
|
594 |
return;
|
595 |
} |
596 |
|
597 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
598 |
|
599 |
try {
|
600 |
Collection<VCSGisEntity> entities = this.entitySelector.getEntities(); |
601 |
for (VCSGisEntity entity : entities) {
|
602 |
if (entity instanceof VCSGisWorkspaceEntity) { |
603 |
JDBCStoreParameters parameters = getWorkspace().getExplorer().get(entity.getEntityName()); |
604 |
TableInfo tableInfo = new VCSGisTableInfo(entity, parameters, this.requireGeometry(), false); |
605 |
if(StringUtils.isNotBlank(entity.getLabel()) ) {
|
606 |
tableInfo.setDocumentName(entity.getLabel()); |
607 |
} |
608 |
tableInfo.setProperty("entity", entity);
|
609 |
this.tablesInfo.put(tableInfo.getId(), tableInfo);
|
610 |
} |
611 |
} |
612 |
|
613 |
} catch (Exception e) { |
614 |
LOGGER.warn("_Cant_update_layers_list", e);
|
615 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
616 |
dialogs.messageDialog( |
617 |
i18n.getTranslation("_Cant_update_layers_list") + "\n" + e.getMessage(), |
618 |
i18n.getTranslation("_Add_layer"),
|
619 |
JOptionPane.WARNING_MESSAGE
|
620 |
); |
621 |
} |
622 |
} |
623 |
|
624 |
private void doCheckout() { |
625 |
VCSGisWorkspace workspace = getWorkspace(); |
626 |
if (workspace == null) { |
627 |
return;
|
628 |
} |
629 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
630 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
631 |
VCSGisEntity rEntity = this.entitySelector.getSelectedEntity();
|
632 |
if(rEntity== null || rEntity instanceof VCSGisWorkspaceEntity){ |
633 |
return;
|
634 |
} |
635 |
final String entityName = rEntity.getEntityName(); |
636 |
Thread task = new Thread(() -> { |
637 |
try {
|
638 |
processing = true;
|
639 |
doUpdateComponents(); |
640 |
|
641 |
showMessage(i18n.getTranslation("_Checking_out"));
|
642 |
int res = workspace.checkout(
|
643 |
entityName, |
644 |
null,
|
645 |
this.getTaskStatusController().getSimpleTaskStatus()
|
646 |
); |
647 |
if (res != ERR_OK) {
|
648 |
LOGGER.warn("_Cant_checkout_table");
|
649 |
dialogs.messageDialog( |
650 |
i18n.getTranslation("_Cant_checkout_table") + "\n" + workspace.getErrorMessage(res), |
651 |
i18n.getTranslation("_Add_table"),
|
652 |
JOptionPane.WARNING_MESSAGE
|
653 |
); |
654 |
return;
|
655 |
} |
656 |
downloadAndRegisterResources(entityName); |
657 |
showMessage(i18n.getTranslation("_Checkout_finished"));
|
658 |
JDBCStoreParameters parameters = getWorkspace().getExplorer().get(entityName); |
659 |
TableInfo tableInfo = new VCSGisTableInfo(workspace.getWorkspaceEntity(entityName), parameters, this.requireGeometry(), false); |
660 |
this.tablesInfo.put(tableInfo.getId(), tableInfo);
|
661 |
doPostCheckout(entityName); |
662 |
} catch (Exception e) { |
663 |
LOGGER.warn("_Cant_add_table");
|
664 |
dialogs.messageDialog( |
665 |
i18n.getTranslation("_Cant_add_table") + "\n" + e.getMessage(), |
666 |
i18n.getTranslation("_Add_table"),
|
667 |
JOptionPane.WARNING_MESSAGE
|
668 |
); |
669 |
} finally {
|
670 |
processing = false;
|
671 |
doUpdateComponents(); |
672 |
} |
673 |
}, "VCSGisAddTableCheckout");
|
674 |
processing = true;
|
675 |
doUpdateComponents(); |
676 |
task.start(); |
677 |
} |
678 |
|
679 |
private void doPostCheckout(String entityName) { |
680 |
if (notInSwingThreadInvokeLater(() -> { doPostCheckout(entityName); })) {
|
681 |
return;
|
682 |
} |
683 |
VCSGisWorkspace workspace = getWorkspace(); |
684 |
if (workspace == null) { |
685 |
return;
|
686 |
} |
687 |
|
688 |
doChangeWorkspace(); |
689 |
this.entitySelector.setSelectedEntity(workspace.getWorkspaceEntity(entityName));
|
690 |
doChangeTableSelected(); |
691 |
} |
692 |
|
693 |
private void showMessage(String message) { |
694 |
if( notInSwingThreadInvokeLater(() -> {showMessage(message);}) ) {
|
695 |
return;
|
696 |
} |
697 |
this.view.lblStatusMessages.setText(message);
|
698 |
} |
699 |
|
700 |
public boolean isProcessing() { |
701 |
return processing;
|
702 |
} |
703 |
|
704 |
public void setVisibleStatus(boolean visible) { |
705 |
if( notInSwingThreadInvokeLater(() -> {setVisibleStatus(visible);}) ) {
|
706 |
return;
|
707 |
} |
708 |
this.view.lblStatusTitle.setVisible(visible);
|
709 |
this.view.pbStatus.setVisible(visible);
|
710 |
this.view.lblStatusMessages.setVisible(true); |
711 |
} |
712 |
|
713 |
public TaskStatusController getTaskStatusController() {
|
714 |
return this.taskStatusController; |
715 |
} |
716 |
|
717 |
public static boolean notInSwingThreadInvokeLater(Runnable x) { |
718 |
if( SwingUtilities.isEventDispatchThread() ) { |
719 |
return false; |
720 |
} |
721 |
SwingUtilities.invokeLater(x);
|
722 |
return true; |
723 |
} |
724 |
|
725 |
protected static class WizardVCSGisViewExtended extends AbstractWizardVCSGisView { |
726 |
|
727 |
@Override
|
728 |
public ImageIcon loadImage(String imageName) { |
729 |
String name = FilenameUtils.getBaseName(imageName);
|
730 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
731 |
if (theme.exists(name)) {
|
732 |
return theme.get(name);
|
733 |
} |
734 |
URL url = WizardVCSGisViewExtended.class.getResource("images/" + name + ".png"); |
735 |
if (url == null) { |
736 |
return null; |
737 |
} |
738 |
return new ImageIcon(url); |
739 |
} |
740 |
} |
741 |
|
742 |
private String toHTML(String s) { |
743 |
s = StringUtils.replace(s, "\n", "<br>"); |
744 |
s = StringUtils.replace(s, "<html>", ""); |
745 |
s = StringUtils.replace(s, "</html>", ""); |
746 |
s = "<html>"+s+"</html>"; |
747 |
return s;
|
748 |
} |
749 |
|
750 |
protected void downloadAndRegisterResources(String tableName) { |
751 |
VCSGisWorkspace workspace = getWorkspace(); |
752 |
VCSGisWorkspaceEntity entity = workspace.getWorkspaceEntityByName(tableName); |
753 |
if(entity == null){ |
754 |
return;
|
755 |
} |
756 |
VCSGisEntity lEntity = workspace.getEntity(entity.getEntityCode()); |
757 |
String resources = lEntity.getResources();
|
758 |
if (StringUtils.isNotBlank(resources)) {
|
759 |
try {
|
760 |
if (!workspace.existsInWorkspace(workspace.getWorkspaceEntity(resources))) {
|
761 |
workspace.checkout( |
762 |
resources, |
763 |
null
|
764 |
); |
765 |
} |
766 |
} catch (Exception e) { |
767 |
LOGGER.warn("Can't checkout resources table '" + resources + "'", e); |
768 |
} |
769 |
workspace.getExplorer().setCustomResources(entity.getEntityName(), resources,true);
|
770 |
} |
771 |
|
772 |
} |
773 |
|
774 |
@Override
|
775 |
public void setMapContext(MapContext mapContext) { |
776 |
super.setMapContext(mapContext);
|
777 |
this.tableInfoController.setMapContext(mapContext);
|
778 |
} |
779 |
|
780 |
protected Function<VCSGisEntity,String> getLabelEntityFormatter() { |
781 |
return null; |
782 |
|
783 |
} |
784 |
|
785 |
protected boolean getCheckScale() { |
786 |
return this.view.chkCheckScale.isSelected(); |
787 |
} |
788 |
|
789 |
protected boolean getAddToCWhenLoadingAll() { |
790 |
return this.view.chkAddToCWhenLoadingAll.isSelected(); |
791 |
} |
792 |
|
793 |
protected String getCategory(VCSGisEntity entity) { |
794 |
return this.entitySelector.getCategory(entity); |
795 |
} |
796 |
|
797 |
protected void registerDataModelRepository(VCSGisWorkspace workspace, String dataModelName) { |
798 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
799 |
VCSGisSwingServices services = swingManager.getDefaultServices(); |
800 |
|
801 |
workspace.registerDataModelRepository(dataModelName); |
802 |
services.connectedToModel(workspace, dataModelName); |
803 |
} |
804 |
|
805 |
private void doConnectToModel() { |
806 |
VCSGisWorkspace workspace = getWorkspace(); |
807 |
if (workspace == null) { |
808 |
return;
|
809 |
} |
810 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
811 |
// ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
|
812 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
813 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
814 |
|
815 |
String modelName = null; |
816 |
VCSGisEntity entity = this.entitySelector.getSelectedEntity();
|
817 |
if(entity != null ){ |
818 |
modelName = entity.getFirstDataModel(); |
819 |
} |
820 |
VCSGisJCheckoutDataModel panel = swingManager.createCheckoutDataModelPanel(workspace, modelName); |
821 |
Dialog theDialog = winManager.createDialog(
|
822 |
panel.asJComponent(), |
823 |
i18n.getTranslation("_VCS_Connect_to_datamodel"),
|
824 |
null,
|
825 |
WindowManager_v2.BUTTONS_OK_CANCEL |
826 |
); |
827 |
panel.setDialog(theDialog); |
828 |
theDialog.addActionListener((ActionEvent e) -> {
|
829 |
if( theDialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
830 |
panel.connectToModel(); |
831 |
} |
832 |
}); |
833 |
theDialog.show(WindowManager.MODE.DIALOG); |
834 |
} |
835 |
|
836 |
} |