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