root / tags / v2_0_0_Build_2050 / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerWizardPanel.java @ 38653
History | View | Annotate | Download (22.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I. S.A. {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
28 |
|
29 |
import java.awt.Component; |
30 |
import java.awt.GridBagConstraints; |
31 |
import java.awt.GridBagLayout; |
32 |
import java.awt.Insets; |
33 |
import java.awt.event.ActionEvent; |
34 |
import java.awt.event.ActionListener; |
35 |
import java.io.File; |
36 |
import java.util.ArrayList; |
37 |
import java.util.Iterator; |
38 |
import java.util.List; |
39 |
import java.util.prefs.Preferences; |
40 |
|
41 |
import javax.swing.AbstractListModel; |
42 |
import javax.swing.JButton; |
43 |
import javax.swing.JList; |
44 |
import javax.swing.JPanel; |
45 |
import javax.swing.JScrollPane; |
46 |
import javax.swing.ScrollPaneConstants; |
47 |
import javax.swing.event.ListSelectionEvent; |
48 |
import javax.swing.event.ListSelectionListener; |
49 |
import javax.swing.filechooser.FileFilter; |
50 |
|
51 |
import org.slf4j.Logger; |
52 |
import org.slf4j.LoggerFactory; |
53 |
|
54 |
import org.gvsig.andami.PluginServices; |
55 |
import org.gvsig.andami.messages.Messages; |
56 |
import org.gvsig.andami.messages.NotificationManager; |
57 |
import org.gvsig.app.ApplicationLocator; |
58 |
import org.gvsig.app.ApplicationManager; |
59 |
import org.gvsig.app.gui.WizardPanel; |
60 |
import org.gvsig.app.prepareAction.PrepareContext; |
61 |
import org.gvsig.fmap.dal.DALLocator; |
62 |
import org.gvsig.fmap.dal.DataManager; |
63 |
import org.gvsig.fmap.dal.DataStoreParameters; |
64 |
import org.gvsig.fmap.dal.exception.DataException; |
65 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
66 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter; |
67 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
68 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
69 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
70 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
71 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectViewer; |
72 |
import org.gvsig.gui.beans.swing.JFileChooser; |
73 |
import org.gvsig.tools.dynobject.DynObject; |
74 |
import org.gvsig.tools.service.ServiceException; |
75 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
76 |
|
77 |
/**
|
78 |
* @author jmvivo
|
79 |
*
|
80 |
*/
|
81 |
public abstract class FilesystemExplorerWizardPanel extends WizardPanel |
82 |
implements ActionListener, ListSelectionListener { |
83 |
|
84 |
/**
|
85 |
*
|
86 |
*/
|
87 |
private static final long serialVersionUID = -3371957786521876903L; |
88 |
|
89 |
private static final Logger LOG = LoggerFactory |
90 |
.getLogger(FilesystemExplorerWizardPanel.class); |
91 |
|
92 |
public static final String OPEN_LAYER_FILE_CHOOSER_ID = |
93 |
"OPEN_LAYER_FILE_CHOOSER_ID";
|
94 |
|
95 |
protected static final String ADD_COMMAND = "ADD"; |
96 |
protected static final String EDIT_COMMAND = "PROPERTIES"; |
97 |
protected static final String REMOVE_COMMAND = "REMOVE"; |
98 |
protected static final String UP_COMMAND = "UP"; |
99 |
protected static final String DOWN_COMMAND = "DOWN"; |
100 |
|
101 |
private static String lastPath = null; |
102 |
private static MyFileFilter lastFilter = null; |
103 |
private static final String DEFAULT_FILTER = "All_supported"; |
104 |
|
105 |
private JList fileList; |
106 |
private JScrollPane fileListScroll; |
107 |
private JPanel buttonsPanel; |
108 |
private JButton addButton; |
109 |
private JButton propertiesButton; |
110 |
private JButton removeButton; |
111 |
private JButton upButton; |
112 |
private JButton downButton; |
113 |
|
114 |
protected FilesystemServerExplorer explorer;
|
115 |
private ArrayList<MyFileFilter> filters; |
116 |
|
117 |
public void setTabName(String name) { |
118 |
super.setTabName(name);
|
119 |
} |
120 |
|
121 |
/*
|
122 |
* (non-Javadoc)
|
123 |
*
|
124 |
* @see com.iver.cit.gvsig.gui.WizardPanel#getParameters()
|
125 |
*/
|
126 |
@Override
|
127 |
public DataStoreParameters[] getParameters() { |
128 |
return ((FilesystemStoreListModel) getFileList().getModel())
|
129 |
.getParameters(); |
130 |
} |
131 |
|
132 |
/*
|
133 |
* (non-Javadoc)
|
134 |
*
|
135 |
* @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
|
136 |
*/
|
137 |
@Override
|
138 |
public void initWizard() { |
139 |
setTabName(PluginServices.getText(this, "Fichero")); |
140 |
if (lastPath == null) { |
141 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering"); |
142 |
lastPath = prefs.get("DataFolder", null); |
143 |
} |
144 |
|
145 |
DataManager dm = DALLocator.getDataManager(); |
146 |
FilesystemServerExplorerParameters param; |
147 |
try {
|
148 |
param = |
149 |
(FilesystemServerExplorerParameters) dm |
150 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
151 |
param.setInitialpath(lastPath); |
152 |
explorer = |
153 |
(FilesystemServerExplorer) dm.openServerExplorer( |
154 |
FilesystemServerExplorer.NAME, param); |
155 |
} catch (Exception e) { |
156 |
throw new RuntimeException(e); |
157 |
} |
158 |
|
159 |
int mode = FilesystemServerExplorer.MODE_ALL;
|
160 |
this.filters = new ArrayList<MyFileFilter>(); |
161 |
if (this.getMapCtrl() == null) { |
162 |
mode = FilesystemServerExplorer.MODE_FEATURE; |
163 |
} else {
|
164 |
mode = |
165 |
FilesystemServerExplorer.MODE_GEOMETRY |
166 |
| FilesystemServerExplorer.MODE_RASTER; |
167 |
} |
168 |
@SuppressWarnings("unchecked") |
169 |
Iterator<FilesystemFileFilter> iter = explorer.getFilters(mode);
|
170 |
while (iter.hasNext()) {
|
171 |
this.filters.add(new MyFileFilter(iter.next())); |
172 |
} |
173 |
this.filters.add(new MyFileFilter(explorer.getFilter(mode, |
174 |
Messages.get(DEFAULT_FILTER)))); |
175 |
initUI(); |
176 |
} |
177 |
|
178 |
private void initUI() { |
179 |
this.setLayout(new GridBagLayout()); |
180 |
GridBagConstraints constr = new GridBagConstraints(); |
181 |
|
182 |
constr.gridwidth = GridBagConstraints.RELATIVE;
|
183 |
constr.gridheight = GridBagConstraints.RELATIVE;
|
184 |
constr.fill = GridBagConstraints.BOTH;
|
185 |
constr.anchor = GridBagConstraints.FIRST_LINE_START;
|
186 |
constr.weightx = 1;
|
187 |
constr.weighty = 1;
|
188 |
constr.ipadx = 3;
|
189 |
constr.ipady = 3;
|
190 |
|
191 |
this.add(getFileListScroll(), constr);
|
192 |
|
193 |
constr.gridwidth = GridBagConstraints.REMAINDER;
|
194 |
constr.gridheight = GridBagConstraints.RELATIVE;
|
195 |
constr.fill = GridBagConstraints.NONE;
|
196 |
constr.anchor = GridBagConstraints.FIRST_LINE_END;
|
197 |
constr.weightx = 0;
|
198 |
constr.weighty = 0;
|
199 |
this.add(getButtonsPanel(), constr);
|
200 |
|
201 |
this.updateButtons();
|
202 |
this.updateContainingWizardAcceptButton();
|
203 |
|
204 |
} |
205 |
|
206 |
protected class FilesystemStoreListModel extends AbstractListModel { |
207 |
|
208 |
private static final long serialVersionUID = -726119349962990665L; |
209 |
private ArrayList<FilesystemStoreParameters> theList; |
210 |
|
211 |
public FilesystemStoreListModel() {
|
212 |
theList = new ArrayList<FilesystemStoreParameters>(); |
213 |
} |
214 |
|
215 |
public DataStoreParameters[] getParameters() { |
216 |
return theList.toArray(new DataStoreParameters[0]); |
217 |
} |
218 |
|
219 |
public Object getElementAt(int index) { |
220 |
return theList.get(index).getFile().getName();
|
221 |
} |
222 |
|
223 |
public FilesystemStoreParameters getStoreParameterAt(int index) { |
224 |
return theList.get(index);
|
225 |
} |
226 |
|
227 |
public int getSize() { |
228 |
return theList.size();
|
229 |
} |
230 |
|
231 |
public DynObject getDynObjectAt(int index) { |
232 |
return (DynObject) theList.get(index);
|
233 |
} |
234 |
|
235 |
public void add(DynObject dynObject) { |
236 |
this.theList.add((FilesystemStoreParameters) dynObject);
|
237 |
this.fireIntervalAdded(this, this.theList.size() - 1, |
238 |
this.theList.size() - 1); |
239 |
} |
240 |
|
241 |
public void addAll(List<FilesystemStoreParameters> toAdd) { |
242 |
int index0 = this.getSize() - 1; |
243 |
if (index0 < 0) { |
244 |
index0 = 0;
|
245 |
} |
246 |
this.theList.addAll(toAdd);
|
247 |
this.fireIntervalAdded(this, index0, this.theList.size() - 1); |
248 |
} |
249 |
|
250 |
public void remove(int i) { |
251 |
this.theList.remove(i);
|
252 |
this.fireIntervalRemoved(this, i, i); |
253 |
|
254 |
} |
255 |
|
256 |
public void up(FilesystemStoreParameters item) { |
257 |
int curIndex = this.theList.indexOf(item); |
258 |
if (curIndex < 1) { |
259 |
return;
|
260 |
} |
261 |
this.theList.remove(item);
|
262 |
this.theList.add(curIndex - 1, item); |
263 |
this.fireContentsChanged(this, curIndex, curIndex - 1); |
264 |
} |
265 |
|
266 |
public void down(FilesystemStoreParameters item) { |
267 |
int curIndex = this.theList.indexOf(item); |
268 |
if (curIndex < 0) { |
269 |
return;
|
270 |
} else
|
271 |
if (curIndex == this.theList.size() - 1) { |
272 |
return;
|
273 |
} |
274 |
this.theList.remove(item);
|
275 |
this.theList.add(curIndex + 1, item); |
276 |
this.fireContentsChanged(this, curIndex, curIndex + 1); |
277 |
} |
278 |
|
279 |
} |
280 |
|
281 |
protected JList getFileList() { |
282 |
if (fileList == null) { |
283 |
fileList = new JList(new FilesystemStoreListModel()); |
284 |
|
285 |
fileList.addListSelectionListener(this);
|
286 |
} |
287 |
return fileList;
|
288 |
} |
289 |
|
290 |
private JScrollPane getFileListScroll() { |
291 |
if (fileListScroll == null) { |
292 |
fileListScroll = new JScrollPane(); |
293 |
fileListScroll.setViewportView(getFileList()); |
294 |
fileListScroll |
295 |
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
296 |
fileListScroll |
297 |
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
298 |
|
299 |
} |
300 |
return fileListScroll;
|
301 |
} |
302 |
|
303 |
private Component getButtonsPanel() { |
304 |
if (buttonsPanel == null) { |
305 |
buttonsPanel = new JPanel(); |
306 |
|
307 |
buttonsPanel.setLayout(new GridBagLayout()); |
308 |
|
309 |
GridBagConstraints constr = new GridBagConstraints(); |
310 |
|
311 |
constr.anchor = GridBagConstraints.CENTER;
|
312 |
constr.fill = GridBagConstraints.NONE;
|
313 |
constr.ipadx = 3;
|
314 |
constr.ipady = 3;
|
315 |
constr.insets = new Insets(3, 3, 3, 3); |
316 |
constr.gridwidth = GridBagConstraints.REMAINDER;
|
317 |
|
318 |
buttonsPanel.add(getAddButton(), constr); |
319 |
buttonsPanel.add(getPropertiesButton(), constr); |
320 |
buttonsPanel.add(getRemoveButton(), constr); |
321 |
buttonsPanel.add(getUpButton(), constr); |
322 |
buttonsPanel.add(getDownButton(), constr); |
323 |
// buttonsPanel.add(new JLabel(), constrLbl);
|
324 |
} |
325 |
return buttonsPanel;
|
326 |
} |
327 |
|
328 |
private JButton getAddButton() { |
329 |
if (addButton == null) { |
330 |
addButton = |
331 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
332 |
addButton.setText(getLocalizedText("add"));
|
333 |
addButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
334 |
addButton.setActionCommand(ADD_COMMAND); |
335 |
addButton.addActionListener(this);
|
336 |
} |
337 |
return addButton;
|
338 |
} |
339 |
|
340 |
private JButton getPropertiesButton() { |
341 |
if (propertiesButton == null) { |
342 |
propertiesButton = |
343 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
344 |
propertiesButton.setText(getLocalizedText("properties"));
|
345 |
propertiesButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
346 |
propertiesButton.setActionCommand(EDIT_COMMAND); |
347 |
propertiesButton.addActionListener(this);
|
348 |
} |
349 |
return propertiesButton;
|
350 |
} |
351 |
|
352 |
private JButton getRemoveButton() { |
353 |
if (removeButton == null) { |
354 |
removeButton = |
355 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
356 |
removeButton.setText(getLocalizedText("remove"));
|
357 |
removeButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
358 |
removeButton.setActionCommand(REMOVE_COMMAND); |
359 |
removeButton.addActionListener(this);
|
360 |
} |
361 |
return removeButton;
|
362 |
} |
363 |
|
364 |
private JButton getUpButton() { |
365 |
if (upButton == null) { |
366 |
upButton = |
367 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
368 |
upButton.setText(getLocalizedText("up"));
|
369 |
upButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
370 |
upButton.setActionCommand(UP_COMMAND); |
371 |
upButton.addActionListener(this);
|
372 |
} |
373 |
return upButton;
|
374 |
} |
375 |
|
376 |
private JButton getDownButton() { |
377 |
if (downButton == null) { |
378 |
downButton = |
379 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
380 |
downButton.setText(getLocalizedText("down"));
|
381 |
downButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
382 |
downButton.setActionCommand(DOWN_COMMAND); |
383 |
downButton.addActionListener(this);
|
384 |
} |
385 |
return downButton;
|
386 |
} |
387 |
|
388 |
private String getLocalizedText(String txt) { |
389 |
try {
|
390 |
return PluginServices.getText(this, txt); |
391 |
} catch (Exception e) { |
392 |
return txt;
|
393 |
} |
394 |
} |
395 |
|
396 |
public void actionPerformed(ActionEvent e) { |
397 |
String command = e.getActionCommand();
|
398 |
FilesystemStoreListModel model = |
399 |
(FilesystemStoreListModel) getFileList().getModel(); |
400 |
|
401 |
if (command == ADD_COMMAND) {
|
402 |
List<FilesystemStoreParameters> toAdd = this.addFiles(); |
403 |
if (toAdd.isEmpty()) {
|
404 |
return;
|
405 |
} |
406 |
model.addAll(toAdd); |
407 |
|
408 |
getFileList().setModel(model); |
409 |
|
410 |
this.updateContainingWizardAcceptButton();
|
411 |
|
412 |
} else
|
413 |
if (command == EDIT_COMMAND) {
|
414 |
DynObject dynObject = |
415 |
model.getDynObjectAt(getFileList().getSelectedIndex()); |
416 |
|
417 |
try {
|
418 |
DynObjectEditor editor = new DynObjectEditor(dynObject);
|
419 |
editor.editObject(true);
|
420 |
} catch (ServiceException ex) {
|
421 |
LOG.error( |
422 |
"Error creating a Swing component for the DynObject: "
|
423 |
+ dynObject, ex); |
424 |
} |
425 |
|
426 |
} else
|
427 |
if (command == REMOVE_COMMAND) {
|
428 |
int[] selecteds = getFileList().getSelectedIndices(); |
429 |
for (int i = selecteds.length - 1; i > -1; i--) { |
430 |
model.remove(selecteds[i]); |
431 |
} |
432 |
getFileList().setSelectedIndex(-1);
|
433 |
|
434 |
this.updateContainingWizardAcceptButton();
|
435 |
|
436 |
} else
|
437 |
if (command == UP_COMMAND) {
|
438 |
List<FilesystemStoreParameters> items =
|
439 |
new ArrayList<FilesystemStoreParameters>(); |
440 |
int[] selecteds = getFileList().getSelectedIndices(); |
441 |
if (selecteds.length == 0 || selecteds[0] == 0) { |
442 |
return;
|
443 |
} |
444 |
for (int i = 0; i < selecteds.length; i++) { |
445 |
items.add(model.getStoreParameterAt(selecteds[i])); |
446 |
selecteds[i]--; |
447 |
} |
448 |
Iterator<FilesystemStoreParameters> iter =
|
449 |
items.iterator(); |
450 |
while (iter.hasNext()) {
|
451 |
model.up(iter.next()); |
452 |
} |
453 |
getFileList().setSelectedIndices(selecteds); |
454 |
|
455 |
} else
|
456 |
if (command == DOWN_COMMAND) {
|
457 |
List<FilesystemStoreParameters> items =
|
458 |
new ArrayList<FilesystemStoreParameters>(); |
459 |
int[] selecteds = |
460 |
getFileList().getSelectedIndices(); |
461 |
if (selecteds.length == 0 |
462 |
|| selecteds[selecteds.length - 1] == model
|
463 |
.getSize() - 1) {
|
464 |
return;
|
465 |
} |
466 |
for (int i = selecteds.length - 1; i > -1; i--) { |
467 |
items.add(model |
468 |
.getStoreParameterAt(selecteds[i])); |
469 |
selecteds[i]++; |
470 |
} |
471 |
Iterator<FilesystemStoreParameters> iter =
|
472 |
items.iterator(); |
473 |
while (iter.hasNext()) {
|
474 |
model.down(iter.next()); |
475 |
} |
476 |
getFileList().setSelectedIndices(selecteds); |
477 |
|
478 |
} else {
|
479 |
throw new IllegalArgumentException(command); |
480 |
} |
481 |
|
482 |
} |
483 |
|
484 |
/**
|
485 |
* check number of files already selected for adding
|
486 |
*/
|
487 |
private void updateContainingWizardAcceptButton() { |
488 |
int curr_add_file_count = getFileList().getModel().getSize();
|
489 |
this.callStateChanged(curr_add_file_count > 0); |
490 |
} |
491 |
|
492 |
|
493 |
public boolean areSettingsValid() { |
494 |
int curr_add_file_count = getFileList().getModel().getSize();
|
495 |
return (curr_add_file_count > 0); |
496 |
} |
497 |
|
498 |
public List<DynObject> getSelecteds() { |
499 |
ArrayList<DynObject> list = new ArrayList<DynObject>(); |
500 |
JList fList = this.getFileList(); |
501 |
int[] selecteds = fList.getSelectedIndices(); |
502 |
FilesystemStoreListModel model = |
503 |
(FilesystemStoreListModel) fList.getModel(); |
504 |
|
505 |
for (int index : selecteds) { |
506 |
list.add((DynObject) model.getStoreParameterAt(index)); |
507 |
} |
508 |
return list;
|
509 |
} |
510 |
|
511 |
public void valueChanged(ListSelectionEvent e) { |
512 |
this.updateButtons();
|
513 |
} |
514 |
|
515 |
public class MyFileFilter extends FileFilter { |
516 |
|
517 |
public FilesystemFileFilter filter = null; |
518 |
|
519 |
public MyFileFilter(FilesystemFileFilter params) {
|
520 |
this.filter = params;
|
521 |
} |
522 |
|
523 |
/**
|
524 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
525 |
*/
|
526 |
public boolean accept(File f) { |
527 |
if (f.isDirectory()) {
|
528 |
return true; |
529 |
} |
530 |
return filter.accept(f);
|
531 |
|
532 |
} |
533 |
|
534 |
/**
|
535 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
536 |
*/
|
537 |
public String getDescription() { |
538 |
return filter.getDescription();
|
539 |
} |
540 |
|
541 |
public String getName() { |
542 |
return filter.getDataStoreProviderName();
|
543 |
} |
544 |
} |
545 |
|
546 |
private List<FilesystemStoreParameters> addFiles() { |
547 |
|
548 |
// this.callStateChanged(true);
|
549 |
|
550 |
JFileChooser fileChooser =
|
551 |
new JFileChooser(OPEN_LAYER_FILE_CHOOSER_ID, |
552 |
explorer.getCurrentPath()); |
553 |
fileChooser.setMultiSelectionEnabled(true);
|
554 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
555 |
|
556 |
Iterator<MyFileFilter> iter = this.filters.iterator(); |
557 |
while (iter.hasNext()) {
|
558 |
fileChooser.addChoosableFileFilter(iter.next()); |
559 |
} |
560 |
|
561 |
if (lastFilter != null && filters.contains(lastFilter)) { |
562 |
fileChooser.setFileFilter(lastFilter); |
563 |
} |
564 |
|
565 |
int result = fileChooser.showOpenDialog(this); |
566 |
|
567 |
List<FilesystemStoreParameters> toAdd =
|
568 |
new ArrayList<FilesystemStoreParameters>(); |
569 |
|
570 |
if (result == JFileChooser.APPROVE_OPTION) { |
571 |
lastPath = fileChooser.getCurrentDirectory().getAbsolutePath(); |
572 |
try {
|
573 |
explorer.setCurrentPath(fileChooser.getCurrentDirectory()); |
574 |
} catch (FileNotFoundException e) { |
575 |
NotificationManager.addError(e); |
576 |
} |
577 |
lastFilter = (MyFileFilter) fileChooser.getFileFilter(); |
578 |
ApplicationManager appGvSIGMan = ApplicationLocator.getManager(); |
579 |
PrepareContext context = this.getPrepareDataStoreContext();
|
580 |
List<DataStoreParameters> paramList = new ArrayList<DataStoreParameters>(); |
581 |
List<DataStoreParameters> toAddParamList = null; |
582 |
for (File aFile : fileChooser.getSelectedFiles()) { |
583 |
try {
|
584 |
DataStoreParameters param = |
585 |
explorer.createStoreParameters(aFile, lastFilter |
586 |
.getDescription().compareTo(DEFAULT_FILTER) == 0
|
587 |
? null : lastFilter.getName());
|
588 |
if (param == null) { |
589 |
// TODO show warning
|
590 |
continue;
|
591 |
} |
592 |
|
593 |
paramList.add(param); |
594 |
|
595 |
} catch (DataException e) {
|
596 |
NotificationManager.addError(e); |
597 |
return null; |
598 |
} |
599 |
} |
600 |
|
601 |
try {
|
602 |
toAddParamList = |
603 |
appGvSIGMan.prepareOpenDataStoreParameters(paramList, context); |
604 |
} catch (Exception e) { |
605 |
NotificationManager.addError(e); |
606 |
} |
607 |
|
608 |
for (int i = 0; i < toAddParamList.size(); i++) { |
609 |
toAdd.add((FilesystemStoreParameters)toAddParamList.get(i)); |
610 |
} |
611 |
} |
612 |
return toAdd;
|
613 |
} |
614 |
|
615 |
protected abstract PrepareContext getPrepareDataStoreContext(); |
616 |
|
617 |
/**
|
618 |
* Refers to up/down/remove buttons etc. Called when selection changes
|
619 |
*/
|
620 |
private void updateButtons() { |
621 |
int selectedIndex = this.getFileList().getSelectedIndex(); |
622 |
int size = this.getFileList().getModel().getSize(); |
623 |
int[] selecteds = this.getFileList().getSelectedIndices(); |
624 |
if (size < 1) { |
625 |
this.getPropertiesButton().setEnabled(false); |
626 |
this.getRemoveButton().setEnabled(false); |
627 |
this.getUpButton().setEnabled(false); |
628 |
this.getDownButton().setEnabled(false); |
629 |
return;
|
630 |
} else
|
631 |
if (size == 1) { |
632 |
this.getUpButton().setEnabled(false); |
633 |
this.getDownButton().setEnabled(false); |
634 |
} else {
|
635 |
this.getUpButton().setEnabled(selectedIndex > 0); |
636 |
|
637 |
this.getDownButton().setEnabled(
|
638 |
selectedIndex > -1
|
639 |
&& selecteds[selecteds.length - 1] < size - 1); |
640 |
} |
641 |
this.getPropertiesButton().setEnabled(
|
642 |
selectedIndex > -1
|
643 |
&& this.getFileList().getSelectedIndices().length == 1); |
644 |
this.getRemoveButton().setEnabled(selectedIndex > -1); |
645 |
} |
646 |
|
647 |
public void close() { |
648 |
if (explorer != null) { |
649 |
explorer.dispose(); |
650 |
explorer = null;
|
651 |
} |
652 |
if (filters != null) { |
653 |
filters.clear(); |
654 |
filters = null;
|
655 |
} |
656 |
} |
657 |
} |