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