gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / initworkspace / OnlineJInitWorkingcopyImpl.java @ 9681
History | View | Annotate | Download (34.1 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (c) 2007-2020 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.online.swing.impl.initworkspace; |
25 |
|
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.awt.event.FocusEvent; |
29 |
import java.awt.event.FocusListener; |
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
import java.net.URL; |
33 |
import java.util.ArrayList; |
34 |
import java.util.Collections; |
35 |
import java.util.List; |
36 |
import javax.swing.DefaultComboBoxModel; |
37 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JComponent; |
39 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.SwingUtilities; |
41 |
import javax.swing.event.ChangeEvent; |
42 |
import javax.swing.event.TableModelEvent; |
43 |
import org.apache.commons.collections4.CollectionUtils; |
44 |
import org.apache.commons.lang3.StringUtils; |
45 |
import org.cresques.cts.IProjection; |
46 |
import org.gvsig.fmap.dal.store.h2.H2SpatialUtils; |
47 |
import org.gvsig.fmap.mapcontrol.MapControl; |
48 |
import org.gvsig.online.lib.api.OnlineLayer; |
49 |
import org.gvsig.online.lib.api.OnlineLocator; |
50 |
import org.gvsig.online.lib.api.OnlineManager; |
51 |
import static org.gvsig.online.lib.api.OnlineManager.AUTH_MODE_ONLINE; |
52 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_NO_ERROR; |
53 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_PROJECT_REQUIRED; |
54 |
import static org.gvsig.online.lib.api.OnlineManager.ERR_WORKINGAREA_REQUIRED; |
55 |
import static org.gvsig.online.lib.api.OnlineManager.FEATURECODE_FIELD_NAME; |
56 |
import org.gvsig.online.lib.api.OnlineProject; |
57 |
import org.gvsig.online.lib.api.OnlineSite; |
58 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
59 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester.OnlineUserIdentificationRequesterFactory; |
60 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
61 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyDescriptor; |
62 |
import org.gvsig.online.lib.api.workingcopy.WorkingArea; |
63 |
import org.gvsig.online.swing.api.MessageStatus; |
64 |
import org.gvsig.online.swing.api.OnlineJInitWorkingcopy; |
65 |
import org.gvsig.online.swing.api.OnlineSwingLocator; |
66 |
import org.gvsig.online.swing.api.OnlineSwingManager; |
67 |
import org.gvsig.online.swing.api.OnlineSwingServices; |
68 |
import org.gvsig.online.swing.impl.AddLayerToProjectController; |
69 |
import org.gvsig.online.swing.impl.OnlineSwingCommons; |
70 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.notInSwingThreadInvokeLater; |
71 |
import org.gvsig.online.swing.impl.workingarea.WorkingAreaPickerControllerImpl; |
72 |
import org.gvsig.tools.ToolsLocator; |
73 |
import org.gvsig.tools.dataTypes.CoercionException; |
74 |
import org.gvsig.tools.dataTypes.DataTypes; |
75 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
76 |
import org.gvsig.tools.dispose.DisposeUtils; |
77 |
import org.gvsig.tools.i18n.I18nManager; |
78 |
import org.gvsig.tools.swing.api.Component; |
79 |
import org.gvsig.tools.swing.api.ListElement; |
80 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
81 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
82 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
83 |
import org.gvsig.tools.swing.api.bookmarkshistory.TextFieldWithHistoryAndBookmarkController; |
84 |
import org.gvsig.tools.swing.api.pickercontroller.FilePickerController; |
85 |
import org.gvsig.tools.swing.api.task.TaskStatusController; |
86 |
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager; |
87 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
88 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
89 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
90 |
import org.gvsig.tools.task.SimpleTaskStatus; |
91 |
import org.gvsig.tools.task.UserCancelTaskException; |
92 |
import org.gvsig.tools.util.LabeledValue; |
93 |
import org.gvsig.tools.util.LabeledValueImpl; |
94 |
import org.slf4j.LoggerFactory; |
95 |
|
96 |
/**
|
97 |
*
|
98 |
* @author gvSIG Team
|
99 |
*/
|
100 |
@SuppressWarnings("UseSpecificCatch") |
101 |
public class OnlineJInitWorkingcopyImpl extends OnlineJInitWorkingcopyView |
102 |
implements Component, OnlineJInitWorkingcopy { |
103 |
|
104 |
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(OnlineJInitWorkingcopyImpl.class); |
105 |
|
106 |
private Dialog dialog; |
107 |
|
108 |
private OnlineSite site;
|
109 |
|
110 |
private FilePickerController workspaceFilePicker;
|
111 |
private TextFieldWithHistoryAndBookmarkController siteURLController;
|
112 |
private WorkingAreaPickerControllerImpl workingAreaPicker;
|
113 |
private TaskStatusController taskStatusController;
|
114 |
private OnlineUserIdentificationRequester.OnlineUserIdentificationRequesterConfig authenticationRequesterConfig;
|
115 |
private MessageStatus message;
|
116 |
private AddLayerToProjectController addLayerToProjectController;
|
117 |
|
118 |
|
119 |
public OnlineJInitWorkingcopyImpl() {
|
120 |
translate(); |
121 |
|
122 |
initComponents(); |
123 |
|
124 |
} |
125 |
|
126 |
private void initComponents() { |
127 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
128 |
TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager(); |
129 |
OnlineSwingServices onlineServices = OnlineSwingLocator.getOnlineSwingManager().getDefaultServices(); |
130 |
OnlineManager onlineManager = OnlineLocator.getOnlineManager(); |
131 |
|
132 |
this.message = OnlineSwingLocator.getOnlineSwingManager().createMessageStatus(lblStatusTitle, pbStatus, lblStatusMessages);
|
133 |
this.taskStatusController = taskStatusManager.createTaskStatusController(
|
134 |
null,
|
135 |
this.lblStatusTitle,
|
136 |
this.lblStatusMessages,
|
137 |
this.pbStatus,
|
138 |
this.btnStatusCancel,
|
139 |
null
|
140 |
); |
141 |
this.taskStatusController.setShowCancelButton(false); |
142 |
this.taskStatusController.setShowRemoveTaskButton(false); |
143 |
// this.taskStatusController.bind(ToolsLocator.getTaskStatusManager());
|
144 |
SwingUtilities.invokeLater(() -> {this.setVisibleStatus(false); }); |
145 |
|
146 |
this.workspaceFilePicker = toolsSwingManager.createFilePickerController(
|
147 |
txtWorkspaceFile, |
148 |
btnWorkspaceFile |
149 |
); |
150 |
this.workspaceFilePicker.addChangeListener((ChangeEvent e) -> { |
151 |
if (StringUtils.isBlank(this.txtWorkspaceName.getText())) { |
152 |
File file = this.workspaceFilePicker.get(); |
153 |
if(file != null){ |
154 |
this.txtWorkspaceName.setText(H2SpatialUtils.removeH2FileNameExtension(file.getName()));
|
155 |
} |
156 |
} |
157 |
doUpdateComponents(); |
158 |
}); |
159 |
|
160 |
this.txtWorkspaceFile.addFocusListener(new FocusListener() { |
161 |
@Override
|
162 |
public void focusGained(FocusEvent e) { |
163 |
//DO NOTHING
|
164 |
} |
165 |
|
166 |
@Override
|
167 |
public void focusLost(FocusEvent e) { |
168 |
doUpdateComponents(); |
169 |
} |
170 |
}); |
171 |
|
172 |
this.txtWorkspaceName.addActionListener((ActionEvent e) -> { |
173 |
doUpdateComponents(); |
174 |
}); |
175 |
|
176 |
this.txtWorkspaceName.addFocusListener(new FocusListener() { |
177 |
@Override
|
178 |
public void focusGained(FocusEvent e) { |
179 |
//DO NOTHING
|
180 |
} |
181 |
|
182 |
@Override
|
183 |
public void focusLost(FocusEvent e) { |
184 |
doUpdateComponents(); |
185 |
} |
186 |
}); |
187 |
|
188 |
this.siteURLController = toolsSwingManager.createTextFieldWithHistoryAndBookmarkController(
|
189 |
OnlineSwingCommons.BOOKMARKSANDHISTORY_SITE_URL, |
190 |
txtSiteURL, |
191 |
btnSiteURLRefresh, |
192 |
btnSiteURLHistory, |
193 |
btnSiteURLBookmarks |
194 |
); |
195 |
this.siteURLController.setEnabled(true); |
196 |
this.siteURLController.addActionListener((ActionEvent e) -> { |
197 |
doChangeAuthentication(); |
198 |
doChangeSiteURL(); |
199 |
}); |
200 |
|
201 |
OnlineUserIdentificationRequesterFactory defaultAuthenticationFactory = null;
|
202 |
DefaultComboBoxModel<LabeledValue<OnlineUserIdentificationRequesterFactory>> userIdentificationRequestersModel = new DefaultComboBoxModel<>(); |
203 |
for (OnlineUserIdentificationRequesterFactory factory : onlineManager.getUserIdentificationRequesters()) {
|
204 |
userIdentificationRequestersModel.addElement( |
205 |
new LabeledValueImpl<>(
|
206 |
factory.getName(), factory |
207 |
) |
208 |
); |
209 |
if( defaultAuthenticationFactory == null || StringUtils.equalsIgnoreCase(factory.getName(), AUTH_MODE_ONLINE)) { |
210 |
defaultAuthenticationFactory = factory; |
211 |
} |
212 |
} |
213 |
this.authenticationRequesterConfig = null; |
214 |
this.cboAuthentication.setModel(userIdentificationRequestersModel);
|
215 |
this.cboAuthentication.setSelectedIndex(-1); |
216 |
|
217 |
this.cboAuthentication.addActionListener((ActionEvent e) -> { |
218 |
doChangeSiteURL(); |
219 |
doChangeAuthentication(); |
220 |
}); |
221 |
// ListElement.setSelected(cboAuthentication, defaultAuthenticationFactory);
|
222 |
|
223 |
this.btnAuthentication.addActionListener((ActionEvent e) -> { |
224 |
doAuthenticationRequesterConfig(); |
225 |
}); |
226 |
this.btnAuthenticationTest.addActionListener((ActionEvent e) -> { |
227 |
doAuthenticationTest(); |
228 |
}); |
229 |
|
230 |
this.cboProjects.addActionListener((ActionEvent e) -> { |
231 |
SwingUtilities.invokeLater(() -> {doChangeProject();});
|
232 |
}); |
233 |
|
234 |
this.workingAreaPicker = new WorkingAreaPickerControllerImpl( |
235 |
() -> {return getSite();},
|
236 |
txtWorkingAreaLabel, |
237 |
txtWorkingArea, |
238 |
btnWorkingAreaFromView, |
239 |
btnWorkingAreaDialog, |
240 |
btnWorkingAreaHistory, |
241 |
btnWorkingAreaBookmarks, |
242 |
() -> { |
243 |
LabeledValue<MapControl> n = onlineServices.getActiveMapControl(); |
244 |
return (n == null) ? null : n.getValue(); |
245 |
}, |
246 |
() -> { |
247 |
List<OnlineLayer> selectedLayers = getLayersModel().getSelectedLayers();
|
248 |
if (selectedLayers.isEmpty()) {
|
249 |
return null; |
250 |
} |
251 |
return selectedLayers;
|
252 |
} |
253 |
); |
254 |
this.workingAreaPicker.addChangeListener((ChangeEvent e) -> { |
255 |
doUpdateComponents(); |
256 |
}); |
257 |
|
258 |
this.addLayerToProjectController = new AddLayerToProjectController( |
259 |
rdbDontAddToProject, |
260 |
rdbAddLayerToView, |
261 |
rdbAddTableToProject, |
262 |
cboView, |
263 |
message |
264 |
); |
265 |
|
266 |
this.addLayerToProjectController.addChangeListener((ChangeEvent e) -> { |
267 |
this.message.clear();
|
268 |
doUpdateComponents(); |
269 |
}); |
270 |
|
271 |
this.btnChangeViewProjection.addActionListener((ActionEvent e) -> { |
272 |
doChangeViewProjection(); |
273 |
}); |
274 |
|
275 |
SwingUtilities.invokeLater(() -> { message.clear(); });
|
276 |
ToolsSwingUtils.ensureRowsCols(this, 20, 100, 34, 162); |
277 |
|
278 |
} |
279 |
|
280 |
@Override
|
281 |
public void setDialog(Dialog dialog) { |
282 |
this.dialog = dialog;
|
283 |
this.doUpdateComponents();
|
284 |
} |
285 |
|
286 |
private void doUpdateComponents() { |
287 |
message.clear(); |
288 |
|
289 |
boolean enableAll = true; |
290 |
|
291 |
boolean isThereURL = false; |
292 |
boolean isThereAuth = false; |
293 |
boolean isThereSite = false; |
294 |
boolean isThereProject = false; |
295 |
boolean isThereDbfile = false; |
296 |
boolean isThereWsName = false; |
297 |
boolean isThereSelectedsLayers = false; |
298 |
boolean isThereWorkingArea = false; |
299 |
|
300 |
// 0. Check is processing
|
301 |
enableAll = !this.isProcessing();
|
302 |
|
303 |
// 1. Check Site URL
|
304 |
if( enableAll ) {
|
305 |
URL url = this.getSiteURL(); |
306 |
isThereURL = (url != null);
|
307 |
if( !isThereURL ) {
|
308 |
if( StringUtils.isBlank(this.txtSiteURL.getText()) ) { |
309 |
message.alert(enableAll, "_The_site_url_is_blank");
|
310 |
} else {
|
311 |
message.alert(enableAll, "_Invalid_site_url");
|
312 |
} |
313 |
} |
314 |
enableAll = enableAll && isThereURL; |
315 |
} |
316 |
|
317 |
// Check auth
|
318 |
if( enableAll ) {
|
319 |
isThereAuth = (this.authenticationRequesterConfig != null); |
320 |
if( !isThereAuth ) {
|
321 |
message.alert(enableAll, "_Select_a_Online_authentication_mode");
|
322 |
} |
323 |
enableAll = enableAll && isThereAuth; |
324 |
} |
325 |
|
326 |
// Check site
|
327 |
if( enableAll ) {
|
328 |
isThereSite = (this.getSite() != null); |
329 |
if( !isThereSite ) {
|
330 |
message.alert(enableAll, "_Select_a_valid_Online_url_and_authentication_mode");
|
331 |
} |
332 |
enableAll = enableAll && isThereSite; |
333 |
} |
334 |
|
335 |
// 2. Check online project
|
336 |
if( enableAll ) {
|
337 |
OnlineProject project = this.getProject();
|
338 |
isThereProject = (project != null);
|
339 |
if( !isThereProject ) {
|
340 |
message.alert(enableAll, "_Select_a_Online_project");
|
341 |
} |
342 |
enableAll = enableAll && isThereProject; |
343 |
} |
344 |
|
345 |
// 3. Check layers selected
|
346 |
if( enableAll || isThereProject ) {
|
347 |
isThereSelectedsLayers = !this.getLayersModel().isSelectionEmpty();
|
348 |
if( !isThereSelectedsLayers ) {
|
349 |
message.alert(enableAll, "_You_must_select_some_layer");
|
350 |
} |
351 |
enableAll = enableAll && isThereURL && isThereSelectedsLayers; |
352 |
} |
353 |
|
354 |
// 4. Check selected working area
|
355 |
if( enableAll || isThereProject ) {
|
356 |
WorkingArea workingArea = this.workingAreaPicker.getWithoutAddHistory();
|
357 |
isThereWorkingArea = (workingArea != null && workingArea.getValue() != null); |
358 |
if( !isThereWorkingArea ) {
|
359 |
message.alert(enableAll, "_You_must_select_a_working_area");
|
360 |
} |
361 |
enableAll = enableAll && isThereURL && isThereWorkingArea; |
362 |
} |
363 |
|
364 |
// 5. Check workspace file
|
365 |
if( enableAll ) {
|
366 |
File f = this.getWorkspaceFile(); |
367 |
isThereDbfile = (f!=null);
|
368 |
if( !isThereDbfile ) {
|
369 |
message.alert(enableAll, "_Selected_working_copy_file_is_not_valid");
|
370 |
} else {
|
371 |
f = H2SpatialUtils.normalizeH2File(f); |
372 |
if( f.exists() ) {
|
373 |
message.alert(enableAll, "_Selected_working_copy_file_already_exists");
|
374 |
isThereDbfile = false;
|
375 |
} |
376 |
} |
377 |
enableAll = enableAll && isThereDbfile; |
378 |
} |
379 |
|
380 |
// 6. Check workspace name
|
381 |
if( enableAll ) {
|
382 |
String wsname = this.getWorkspaceName(); |
383 |
isThereWsName = StringUtils.isNotBlank(wsname); |
384 |
if( !isThereWsName ) {
|
385 |
message.alert(enableAll, "_Need_a_working_copy_name");
|
386 |
} else {
|
387 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
388 |
OnlineWorkingcopyDescriptor ws = manager.getWorkingcopyDescriptor(wsname); |
389 |
if( ws!=null ) { |
390 |
message.alert(enableAll, "_A_working_copy_with_that_name_already_exists");
|
391 |
isThereWsName = false;
|
392 |
} |
393 |
} |
394 |
enableAll = isThereURL && isThereWsName; |
395 |
} |
396 |
|
397 |
this.siteURLController.setEnabled(!this.isProcessing()); |
398 |
this.cboAuthentication.setEnabled(true); |
399 |
this.btnAuthentication.setEnabled(isThereAuth && this.authenticationRequesterConfig.hasIdentificationConfig()); |
400 |
this.btnAuthenticationTest.setEnabled(isThereAuth);
|
401 |
this.cboProjects.setEnabled(isThereSite);
|
402 |
this.workspaceFilePicker.setEnabled(isThereProject);
|
403 |
this.chkCreateConnectionToDatabase.setEnabled(isThereProject && isThereDbfile);
|
404 |
this.txtWorkspaceName.setEnabled(isThereProject && isThereDbfile);
|
405 |
this.tblLayers.setEnabled(isThereURL && isThereProject);
|
406 |
|
407 |
this.workingAreaPicker.setEnabled(isThereProject);
|
408 |
this.workingAreaPicker.setWorkingAreaDialogEnabled(isThereSelectedsLayers);
|
409 |
|
410 |
this.addLayerToProjectController.setEnabled(this.getSelectedLayers()); |
411 |
|
412 |
this.btnChangeViewProjection.setEnabled(this.getLayersProjection(this.getSelectedLayers())!=null); |
413 |
|
414 |
if (this.dialog != null) { |
415 |
this.dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK,enableAll);
|
416 |
} |
417 |
} |
418 |
|
419 |
|
420 |
@Override
|
421 |
public JComponent asJComponent() { |
422 |
return this; |
423 |
} |
424 |
|
425 |
private void translate() { |
426 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
427 |
swingManager.translate(this.chkCreateConnectionToDatabase);
|
428 |
swingManager.translate(this.lblWorkspaceName);
|
429 |
swingManager.translate(this.lblSiteUrl);
|
430 |
swingManager.translate(this.lblProjects);
|
431 |
swingManager.translate(this.lblWorkspaceFile);
|
432 |
swingManager.translate(this.lblLayers);
|
433 |
swingManager.translate(this.lblWorkspaceFile);
|
434 |
swingManager.translate(this.lblWorkingArea);
|
435 |
swingManager.translate(this.btnWorkingAreaFromView);
|
436 |
swingManager.translate(this.btnWorkingAreaDialog);
|
437 |
swingManager.translate(this.rdbDontAddToProject);
|
438 |
swingManager.translate(this.rdbAddLayerToView);
|
439 |
swingManager.translate(this.rdbAddTableToProject);
|
440 |
} |
441 |
|
442 |
private URL getSiteURL() { |
443 |
if(siteURLController.isEnabled()){
|
444 |
String value = this.siteURLController.getText(); |
445 |
|
446 |
URL url;
|
447 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
448 |
try {
|
449 |
url = (URL) manager.coerce(DataTypes.URL, value);
|
450 |
} catch (CoercionException ex) {
|
451 |
String s = (value==null)? "null":StringUtils.abbreviate(value, 100); |
452 |
LOGGER.warn("Can't coerce value ("+s+") to "+DataTypes.URL_NAME+".", ex); |
453 |
return null; |
454 |
} |
455 |
|
456 |
return url;
|
457 |
} |
458 |
return null; |
459 |
} |
460 |
|
461 |
private File getWorkspaceFile() { |
462 |
File file = this.workspaceFilePicker.get(); |
463 |
return file;
|
464 |
} |
465 |
|
466 |
@Override
|
467 |
public int actionPerformed() { |
468 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
469 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
470 |
OnlineProject theProject = this.getProject();
|
471 |
WorkingArea workingArea = this.workingAreaPicker.get();
|
472 |
|
473 |
OnlineSwingManager swingManager = OnlineSwingLocator.getOnlineSwingManager(); |
474 |
OnlineSwingServices services = swingManager.getDefaultServices(); |
475 |
|
476 |
if (theProject == null) { |
477 |
return ERR_PROJECT_REQUIRED;
|
478 |
} |
479 |
if (workingArea == null) { |
480 |
return ERR_WORKINGAREA_REQUIRED;
|
481 |
} |
482 |
int err = ERR_NO_ERROR;
|
483 |
SimpleTaskStatus status = this.getTaskStatus();
|
484 |
try {
|
485 |
File file = this.getWorkspaceFile(); |
486 |
if (file != null) { |
487 |
status.setTitle(i18n.getTranslation("_Initializing_workspace"));
|
488 |
err = manager.initWorkingcopy(file, theProject, getWorkspaceName(), getTaskStatus()); |
489 |
if (err == ERR_NO_ERROR) {
|
490 |
OnlineWorkingcopy ws = manager.openWorkingcopy(file); |
491 |
if (this.chkCreateConnectionToDatabase.isSelected()) { |
492 |
ws.addToConnectionPool(); |
493 |
} |
494 |
ws.download_config(true, status);
|
495 |
ws.download_resources(true, status);
|
496 |
ws.setCurrentWorkingArea(workingArea); |
497 |
LayersTableModel model = (LayersTableModel) this.tblLayers.getModel();
|
498 |
List<OnlineLayer> selectedLayers = model.getSelectedLayers();
|
499 |
if (!CollectionUtils.isEmpty(selectedLayers)) {
|
500 |
status.setRangeOfValues(0, selectedLayers.size());
|
501 |
status.setCurValue(0);
|
502 |
for (OnlineLayer layer : selectedLayers) {
|
503 |
status.incrementCurrentValue(); |
504 |
status.setTitle(i18n.getTranslation("_Adding_layer") + " " + layer.getName()); |
505 |
if (status.isCancellationRequested()) {
|
506 |
status.cancel(); |
507 |
throw new UserCancelTaskException(); |
508 |
} |
509 |
String fieldForLabel = FEATURECODE_FIELD_NAME; // FIXME: Pedir en el GUI |
510 |
// String label = layer.getName(); // FIXME: Pedir en el GUI
|
511 |
int tileSize = layer.calculateTileSize(5000, status); |
512 |
ws.addEntity( |
513 |
layer.getFeatureType(), |
514 |
layer.getName(), |
515 |
null,
|
516 |
fieldForLabel, |
517 |
layer.getTitle(), |
518 |
layer.getPkName(), |
519 |
tileSize |
520 |
); |
521 |
} |
522 |
|
523 |
status.setRangeOfValues(0, selectedLayers.size());
|
524 |
status.setCurValue(0);
|
525 |
for (OnlineLayer layer : selectedLayers) {
|
526 |
status.incrementCurrentValue(); |
527 |
status.setTitle(i18n.getTranslation("_Downloading_layer") + " " + layer.getName()); |
528 |
if (status.isCancellationRequested()) {
|
529 |
status.cancel(); |
530 |
throw new UserCancelTaskException(); |
531 |
} |
532 |
err = ws.download(layer.getName(), workingArea.getValue(), status); |
533 |
if (err != ERR_NO_ERROR) {
|
534 |
// TODO: Que hacer aqui si da error
|
535 |
} |
536 |
} |
537 |
|
538 |
for (OnlineLayer layer : selectedLayers) {
|
539 |
this.addLayerToProjectController.process(ws, layer);
|
540 |
} |
541 |
} |
542 |
} |
543 |
} |
544 |
} catch (UserCancelTaskException ex) {
|
545 |
LOGGER.info("Cancelled by user.");
|
546 |
err = OnlineManager.ERR_CANCELLED_BY_USER; |
547 |
} catch (Exception ex) { |
548 |
LOGGER.info("Can't initialize workspace", ex);
|
549 |
err = OnlineManager.ERR_EXCEPTION; |
550 |
} |
551 |
if (err == ERR_NO_ERROR || err == OnlineManager.ERR_CANCELLED_BY_USER) {
|
552 |
URL siteurl = getSiteURL();
|
553 |
if (siteurl != null) { |
554 |
this.siteURLController.addHistory(siteurl.toString());
|
555 |
} |
556 |
} |
557 |
return err;
|
558 |
} |
559 |
|
560 |
private OnlineSite createSite() {
|
561 |
try {
|
562 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
563 |
URL url = getSiteURL();
|
564 |
if (url != null){ |
565 |
return manager.connectSite(this.authenticationRequesterConfig, url); |
566 |
} |
567 |
} catch (IOException ex) { |
568 |
LOGGER.warn("Can't connect to site '"+this.txtSiteURL.getText()+"'", ex); |
569 |
} |
570 |
return null; |
571 |
} |
572 |
|
573 |
private OnlineSite getSite() {
|
574 |
if (site == null){ |
575 |
this.site = createSite();
|
576 |
} |
577 |
return site;
|
578 |
} |
579 |
|
580 |
private OnlineProject getProject() {
|
581 |
OnlineSite theSite = this.getSite();
|
582 |
if( theSite == null ) { |
583 |
return null; |
584 |
} |
585 |
LabeledValue<Integer> item = (LabeledValue<Integer>) this.cboProjects.getSelectedItem(); |
586 |
if( item == null ) { |
587 |
return null; |
588 |
} |
589 |
return theSite.getProject(item.getValue());
|
590 |
} |
591 |
|
592 |
@Override
|
593 |
public String getWorkspaceName() { |
594 |
return txtWorkspaceName.getText();
|
595 |
} |
596 |
|
597 |
public static void selfRegister() { |
598 |
|
599 |
} |
600 |
|
601 |
@Override
|
602 |
public boolean isProcessing() { |
603 |
return false; |
604 |
} |
605 |
|
606 |
// private void message2(boolean doMessage, String s) {
|
607 |
// if( doMessage ) {
|
608 |
// message(s);
|
609 |
// }
|
610 |
// }
|
611 |
//
|
612 |
// private void message(String message) {
|
613 |
// if( notInSwingThreadInvokeLater(() -> {message(message);}) ) {
|
614 |
// return;
|
615 |
// }
|
616 |
// String s = message;
|
617 |
// if( StringUtils.startsWith(s, "_") ) {
|
618 |
// I18nManager i18n = ToolsLocator.getI18nManager();
|
619 |
// s = i18n.getTranslation(s);
|
620 |
// }
|
621 |
// this.lblStatusMessages.setText(s);
|
622 |
//// this.lblStatusMessages.setToolTipText(toolTipText);
|
623 |
//
|
624 |
// }
|
625 |
|
626 |
@Override
|
627 |
public ImageIcon loadImage(String imageName) { |
628 |
return OnlineSwingCommons.loadImage(imageName);
|
629 |
} |
630 |
|
631 |
private void doChangeSiteURL() { |
632 |
URL url = null; |
633 |
try {
|
634 |
OnlineManager onlineManager = OnlineLocator.getOnlineManager(); |
635 |
url = this.getSiteURL();
|
636 |
if( this.authenticationRequesterConfig==null ) { |
637 |
this.authenticationRequesterConfig = onlineManager.getUserIdentificationRequester(url);
|
638 |
if( this.authenticationRequesterConfig!=null ) { |
639 |
ListElement.setSelected(cboAuthentication, this.authenticationRequesterConfig.getFactory());
|
640 |
// La linea anterior provoca que se relance el evento y
|
641 |
// vuelba a entrar en este metodo.
|
642 |
return;
|
643 |
} |
644 |
} |
645 |
if( url == null || this.authenticationRequesterConfig==null ) { |
646 |
DisposeUtils.dispose(this.site);
|
647 |
this.site = null; |
648 |
return;
|
649 |
} |
650 |
this.site = onlineManager.connectSite(this.authenticationRequesterConfig,url); |
651 |
this.siteURLController.addHistory(url.toString());
|
652 |
doFillProjects(); |
653 |
doUpdateComponents(); |
654 |
} catch (Exception ex) { |
655 |
LOGGER.warn("Can't chage site url ("+url+").",ex); |
656 |
} |
657 |
} |
658 |
|
659 |
private void doFillProjects() { |
660 |
OnlineSite theSite = this.getSite();
|
661 |
if( theSite == null ) { |
662 |
return;
|
663 |
} |
664 |
List<LabeledValue<Integer>> projects = new ArrayList<>(); |
665 |
for (OnlineProject project : theSite.projects()) {
|
666 |
projects.add(new LabeledValueImpl<>(project.getTitle(),project.getId()));
|
667 |
} |
668 |
projects.sort((LabeledValue<Integer> o1, LabeledValue<Integer> o2) -> o1.getLabel().compareTo(o2.getLabel())); |
669 |
DefaultComboBoxModel<LabeledValue<Integer>> model = new DefaultComboBoxModel<>(); |
670 |
for (LabeledValue<Integer> project : projects) { |
671 |
model.addElement(project); |
672 |
} |
673 |
this.cboProjects.setModel(model);
|
674 |
this.cboProjects.setSelectedIndex(-1); |
675 |
this.workspaceFilePicker.set(null); |
676 |
this.txtWorkspaceName.setText(""); |
677 |
this.clearLayers();
|
678 |
} |
679 |
|
680 |
private void doChangeProject() { |
681 |
OnlineSite theSite = this.getSite();
|
682 |
LabeledValue<Integer> selected = (LabeledValue<Integer>) this.cboProjects.getSelectedItem(); |
683 |
if( selected == null || theSite == null ) { |
684 |
this.workspaceFilePicker.set(null); |
685 |
this.txtWorkspaceName.setText(""); |
686 |
this.clearLayers();
|
687 |
return;
|
688 |
} |
689 |
int projectId = selected.getValue();
|
690 |
OnlineProject project = theSite.getProject(projectId); |
691 |
|
692 |
List<OnlineLayer> layers = new ArrayList<>(); |
693 |
for (OnlineLayer layer : project.layers()) {
|
694 |
if( layer.isHidden() ) {
|
695 |
continue;
|
696 |
} |
697 |
layers.add(layer); |
698 |
} |
699 |
layers.sort((OnlineLayer o1, OnlineLayer o2) -> o1.getLabel().compareTo(o2.getLabel())); |
700 |
LayersTableModel model = new LayersTableModel(layers);
|
701 |
model.addTableModelListener((TableModelEvent e) -> {
|
702 |
doUpdateComponents(); |
703 |
}); |
704 |
this.tblLayers.setModel(model);
|
705 |
doUpdateComponents(); |
706 |
} |
707 |
|
708 |
private void clearLayers() { |
709 |
LayersTableModel model = new LayersTableModel();
|
710 |
this.tblLayers.setModel(model);
|
711 |
} |
712 |
|
713 |
private LayersTableModel getLayersModel() {
|
714 |
return (LayersTableModel) this.tblLayers.getModel(); |
715 |
} |
716 |
|
717 |
private SimpleTaskStatus getTaskStatus() {
|
718 |
SimpleTaskStatus taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("_Create_workingcopy");
|
719 |
taskStatus.setAutoremove(true);
|
720 |
taskStatus.add(); |
721 |
taskStatus.setIndeterminate(); |
722 |
this.taskStatusController.bind(taskStatus);
|
723 |
return taskStatus;
|
724 |
} |
725 |
|
726 |
public void setVisibleStatus(boolean visible) { |
727 |
if( notInSwingThreadInvokeLater(() -> {setVisibleStatus(visible);}) ) {
|
728 |
return;
|
729 |
} |
730 |
this.lblStatusTitle.setVisible(visible);
|
731 |
this.pbStatus.setVisible(visible);
|
732 |
this.lblStatusMessages.setVisible(true); |
733 |
} |
734 |
|
735 |
|
736 |
private void doChangeAuthentication() { |
737 |
LabeledValue<OnlineUserIdentificationRequesterFactory> item = (LabeledValue<OnlineUserIdentificationRequesterFactory>) this.cboAuthentication.getSelectedItem();
|
738 |
if (item == null) { |
739 |
return;
|
740 |
} |
741 |
OnlineUserIdentificationRequesterFactory factory = item.getValue(); |
742 |
if (this.authenticationRequesterConfig!=null && StringUtils.equalsIgnoreCase(factory.getName(), this.authenticationRequesterConfig.getName())) { |
743 |
return;
|
744 |
} |
745 |
URL url = null; |
746 |
try {
|
747 |
url = this.getSiteURL();
|
748 |
if( url == null ) { |
749 |
return;
|
750 |
} |
751 |
this.authenticationRequesterConfig = factory.create(url.toString());
|
752 |
OnlineManager onlineManager = OnlineLocator.getOnlineManager(); |
753 |
if (this.authenticationRequesterConfig == null) { |
754 |
DisposeUtils.dispose(this.site);
|
755 |
this.site = null; |
756 |
return;
|
757 |
} |
758 |
this.site = onlineManager.connectSite(this.authenticationRequesterConfig, url); |
759 |
doFillProjects(); |
760 |
doUpdateComponents(); |
761 |
} catch (Exception ex) { |
762 |
LOGGER.warn("Can't chage autentication mode.", ex);
|
763 |
} |
764 |
} |
765 |
|
766 |
private void doAuthenticationRequesterConfig() { |
767 |
if( this.getSiteURL()==null || this.authenticationRequesterConfig==null ) { |
768 |
return;
|
769 |
} |
770 |
if( !this.authenticationRequesterConfig.hasIdentificationConfig() ) { |
771 |
return;
|
772 |
} |
773 |
if( this.authenticationRequesterConfig.requestIdentificationConfig() ) { |
774 |
// reconstruimos el site con la nueva configuaracion.
|
775 |
this.site = this.createSite(); |
776 |
} |
777 |
} |
778 |
|
779 |
private void doAuthenticationTest() { |
780 |
if( this.getSiteURL()==null || this.authenticationRequesterConfig==null ) { |
781 |
LOGGER.warn("Can't run authentication test. Configure authentication.");
|
782 |
return;
|
783 |
} |
784 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
785 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
786 |
OnlineUserIdentificationRequester requester = this.authenticationRequesterConfig.createUserIdentificationRequester();
|
787 |
if( requester==null ) { |
788 |
// LOGGER.warn("Can't run authentication test. Configure authentication.");
|
789 |
dialogs.messageDialog( |
790 |
i18n.getTranslation("_Cant_run_authentication_test")
|
791 |
+ "\n"
|
792 |
+ i18n.getTranslation("_Review_the_authentication_settings"),
|
793 |
i18n.getTranslation(i18n.getTranslation("_Authentication_testing")),
|
794 |
JOptionPane.WARNING_MESSAGE
|
795 |
); |
796 |
return;
|
797 |
} |
798 |
requester.removeCredetials(); |
799 |
if( !requester.requestIdentification() ) {
|
800 |
// LOGGER.warn("Test authentication failed");
|
801 |
dialogs.messageDialog( |
802 |
i18n.getTranslation("_Test_authentication_failed"),
|
803 |
i18n.getTranslation(i18n.getTranslation("_Authentication_testing")),
|
804 |
JOptionPane.WARNING_MESSAGE
|
805 |
); |
806 |
return;
|
807 |
} |
808 |
// LOGGER.warn("Test authentication ok");
|
809 |
dialogs.messageDialog( |
810 |
i18n.getTranslation("_Passed_the_authentication_test"),
|
811 |
i18n.getTranslation(i18n.getTranslation("_Authentication_testing")),
|
812 |
JOptionPane.WARNING_MESSAGE
|
813 |
); |
814 |
} |
815 |
|
816 |
private List<OnlineLayer> getSelectedLayers() { |
817 |
try {
|
818 |
LayersTableModel model = (LayersTableModel) this.tblLayers.getModel();
|
819 |
if( model == null ) { |
820 |
return Collections.EMPTY_LIST; |
821 |
} |
822 |
List<OnlineLayer> selectedLayers = model.getSelectedLayers();
|
823 |
if( selectedLayers == null ) { |
824 |
return Collections.EMPTY_LIST; |
825 |
} |
826 |
return selectedLayers;
|
827 |
} catch(Exception ex) { |
828 |
return Collections.EMPTY_LIST; |
829 |
} |
830 |
} |
831 |
|
832 |
private IProjection getLayersProjection(List<OnlineLayer> layers) { |
833 |
if( layers == null ) { |
834 |
return null; |
835 |
} |
836 |
IProjection proj = null;
|
837 |
for (OnlineLayer layer : layers) {
|
838 |
IProjection curproj = layer.getProjection(); |
839 |
if( proj == null ) { |
840 |
proj = curproj; |
841 |
} else if( !proj.equals(curproj) ) { |
842 |
return null; |
843 |
} |
844 |
} |
845 |
return proj;
|
846 |
} |
847 |
|
848 |
private void doChangeViewProjection() { |
849 |
IProjection proj = this.getLayersProjection(this.getSelectedLayers()); |
850 |
if( proj == null ) { |
851 |
return;
|
852 |
} |
853 |
OnlineSwingServices onlineServices = OnlineSwingLocator.getOnlineSwingManager().getDefaultServices(); |
854 |
LabeledValue<MapControl> labeledMapControl = onlineServices.getActiveMapControl(); |
855 |
if( labeledMapControl == null ) { |
856 |
return;
|
857 |
} |
858 |
MapControl mapControl = labeledMapControl.getValue(); |
859 |
if( mapControl == null ) { |
860 |
return;
|
861 |
} |
862 |
mapControl.setProjection(proj); |
863 |
this.doUpdateComponents();
|
864 |
} |
865 |
} |