Statistics
| Revision:

root / tags / v2_0_0_Build_2047 / applications / appgvSIG / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerWizardPanel.java @ 38317

History | View | Annotate | Download (22 KB)

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