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