Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2030 / applications / appgvSIG / src / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerWizardPanel.java @ 35872

History | View | Annotate | Download (19.4 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

    
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing;
32

    
33
import java.awt.Component;
34
import java.awt.GridBagConstraints;
35
import java.awt.GridBagLayout;
36
import java.awt.Insets;
37
import java.awt.event.ActionEvent;
38
import java.awt.event.ActionListener;
39
import java.io.File;
40
import java.util.ArrayList;
41
import java.util.Iterator;
42
import java.util.List;
43
import java.util.prefs.Preferences;
44

    
45
import javax.swing.AbstractListModel;
46
import javax.swing.JList;
47
import javax.swing.JPanel;
48
import javax.swing.JScrollPane;
49
import javax.swing.ScrollPaneConstants;
50
import javax.swing.event.ListSelectionEvent;
51
import javax.swing.event.ListSelectionListener;
52
import javax.swing.filechooser.FileFilter;
53

    
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
56

    
57
import org.gvsig.andami.PluginServices;
58
import org.gvsig.andami.messages.NotificationManager;
59
import org.gvsig.app.ApplicationLocator;
60
import org.gvsig.app.ApplicationManager;
61
import org.gvsig.app.gui.WizardPanel;
62
import org.gvsig.app.prepareAction.PrepareContext;
63
import org.gvsig.fmap.dal.DALLocator;
64
import org.gvsig.fmap.dal.DataManager;
65
import org.gvsig.fmap.dal.DataStoreParameters;
66
import org.gvsig.fmap.dal.exception.DataException;
67
import org.gvsig.fmap.dal.exception.FileNotFoundException;
68
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter;
69
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
70
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
71
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
72
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
73
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectViewer;
74
import org.gvsig.gui.beans.swing.JButton;
75
import org.gvsig.gui.beans.swing.JFileChooser;
76
import org.gvsig.tools.dynobject.DynObject;
77
import org.gvsig.tools.service.ServiceException;
78

    
79

    
80
/**
81
 * @author jmvivo
82
 *
83
 */
84
public abstract class FilesystemExplorerWizardPanel extends WizardPanel
85
                implements
86
                ActionListener, ListSelectionListener {
87

    
88
        /**
89
         *
90
         */
91
        private static final long serialVersionUID = -3371957786521876903L;
92

    
93
    private static final Logger LOG = LoggerFactory
94
        .getLogger(FilesystemExplorerWizardPanel.class);
95

    
96
        public static final String OPEN_LAYER_FILE_CHOOSER_ID = "OPEN_LAYER_FILE_CHOOSER_ID";
97

    
98
        protected static final String ADD_COMMAND = "ADD";
99
        protected static final String EDIT_COMMAND = "EDIT";
100
        protected static final String REMOVE_COMMAND = "REMOVE";
101
        protected static final String UP_COMMAND = "UP";
102
        protected static final String DOWN_COMMAND = "DOWN";
103

    
104
        private static String lastPath = null;
105
        private static MyFileFilter lastFilter = null;
106
        private static final String DEFAULT_FILTER = "All supporteds";
107

    
108
        private JList fileList;
109
        private JScrollPane fileListScroll;
110
        private JPanel buttonsPanel;
111
        private JButton addButton;
112
        private JButton editButton;
113
        private JButton removeButton;
114
        private JButton upButton;
115
        private JButton downButton;
116
        private JScrollPane paramsListScroll;
117
        private JPanel paramsList;
118
        private GridBagConstraints paramsListLabelConstraint;
119
        private GridBagConstraints paramsListValueConstraint;
120

    
121
        protected FilesystemServerExplorer explorer;
122
        private ArrayList<MyFileFilter> filters;
123

    
124
        private GridBagConstraints paramsListFillConstraint;
125

    
126
        public void setTabName(String name) {
127
                super.setTabName(name);
128
        }
129

    
130
        /*
131
         * (non-Javadoc)
132
         *
133
         * @see com.iver.cit.gvsig.gui.WizardPanel#getParameters()
134
         */
135
        @Override
136
        public DataStoreParameters[] getParameters() {
137
                return ((FilesystemStoreListModel) getFileList().getModel())
138
                                .getParameters();
139
        }
140

    
141
        /*
142
         * (non-Javadoc)
143
         *
144
         * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
145
         */
146
        @Override
147
        public void initWizard() {
148
                setTabName(PluginServices.getText(this, "Fichero"));
149
                if (lastPath == null) {
150
                        Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
151
                        lastPath = prefs.get("DataFolder", null);
152
                }
153

    
154
                DataManager dm = DALLocator.getDataManager();
155
                FilesystemServerExplorerParameters param;
156
                try {
157
                        param = (FilesystemServerExplorerParameters) dm
158
                                        .createServerExplorerParameters(FilesystemServerExplorer.NAME);
159
                        param.setInitialpath(lastPath);
160
                        explorer = (FilesystemServerExplorer) dm
161
                                        .createServerExplorer(param);
162
                } catch (Exception e) {
163
                        throw new RuntimeException(e);
164
                }
165

    
166
                int mode=FilesystemServerExplorer.MODE_ALL;
167
                this.filters = new ArrayList<MyFileFilter>();
168
                if( this.getMapCtrl()==null ) {
169
                        mode = FilesystemServerExplorer.MODE_FEATURE;
170
                } else {
171
                        mode = FilesystemServerExplorer.MODE_GEOMETRY | FilesystemServerExplorer.MODE_RASTER;
172
                }
173
                Iterator<FilesystemFileFilter> iter = explorer.getFilters(mode);
174
                while (iter.hasNext()) {
175
                        this.filters.add(new MyFileFilter(iter.next()));
176
                }
177
                this.filters.add(new MyFileFilter(explorer.getFilter(mode, DEFAULT_FILTER)));
178
                initUI();
179
        }
180

    
181
        private void initUI() {
182
                this.setLayout(new GridBagLayout());
183
                GridBagConstraints constr = new GridBagConstraints();
184

    
185
                constr.gridwidth = GridBagConstraints.RELATIVE;
186
                constr.gridheight = GridBagConstraints.RELATIVE;
187
                constr.fill = GridBagConstraints.BOTH;
188
                constr.anchor = GridBagConstraints.FIRST_LINE_START;
189
                constr.weightx = 1;
190
                constr.weighty = 1;
191
                constr.ipadx = 3;
192
                constr.ipady = 3;
193

    
194
                this.add(getFileListScroll(), constr);
195

    
196
                constr.gridwidth = GridBagConstraints.REMAINDER;
197
                constr.gridheight = GridBagConstraints.RELATIVE;
198
                constr.fill = GridBagConstraints.NONE;
199
                constr.anchor = GridBagConstraints.FIRST_LINE_END;
200
                constr.weightx = 0;
201
                constr.weighty = 0;
202
                this.add(getButtonsPanel(), constr);
203

    
204
                constr.gridwidth = GridBagConstraints.REMAINDER;
205
                constr.gridheight = GridBagConstraints.REMAINDER;
206
                constr.fill = GridBagConstraints.BOTH;
207
                constr.anchor = GridBagConstraints.FIRST_LINE_START;
208
                constr.weightx = 1;
209
                constr.weighty = 1;
210
                this.add(getParamsListScroll(), constr);
211

    
212
                this.updateButtons();
213

    
214
        }
215

    
216
        protected class FilesystemStoreListModel extends AbstractListModel {
217
                /**
218
                 *
219
                 */
220
                private static final long serialVersionUID = -726119349962990665L;
221
                private ArrayList<FilesystemStoreParameters> theList;
222

    
223
                public FilesystemStoreListModel() {
224
                        theList = new ArrayList<FilesystemStoreParameters>();
225
                }
226

    
227
                public DataStoreParameters[] getParameters() {
228
                        return theList.toArray(new DataStoreParameters[0]);
229
                }
230

    
231
                public Object getElementAt(int index) {
232
                        return theList.get(index).getFile().getName();
233
                }
234

    
235
                public FilesystemStoreParameters getStoreParameterAt(int index) {
236
                        return theList.get(index);
237
                }
238

    
239
                public int getSize() {
240
                        return theList.size();
241
                }
242

    
243
                public DynObject getDynObjectAt(int index) {
244
                        return (DynObject) theList.get(index);
245
                }
246

    
247
                public void add(DynObject dynObject) {
248
                        this.theList.add((FilesystemStoreParameters) dynObject);
249
                        this.fireIntervalAdded(this, this.theList.size() - 1, this.theList
250
                                        .size() - 1);
251
                }
252

    
253
                public void addAll(List<FilesystemStoreParameters> toAdd) {
254
                        int index0 = this.getSize() - 1;
255
                        if (index0 < 0) {
256
                                index0 = 0;
257
                        }
258
                        this.theList.addAll(toAdd);
259
                        this.fireIntervalAdded(this, index0, this.theList.size() - 1);
260
                }
261

    
262
                public void remove(int i) {
263
                        this.theList.remove(i);
264
                        this.fireIntervalRemoved(this, i, i);
265

    
266
                }
267

    
268
                public void up(FilesystemStoreParameters item) {
269
                        int curIndex = this.theList.indexOf(item);
270
                        if (curIndex < 1){
271
                                return;
272
                        }
273
                        this.theList.remove(item);
274
                        this.theList.add(curIndex - 1, item);
275
                        this.fireContentsChanged(this, curIndex, curIndex - 1);
276
                }
277

    
278
                public void down(FilesystemStoreParameters item) {
279
                        int curIndex = this.theList.indexOf(item);
280
                        if (curIndex < 0) {
281
                                return;
282
                        } else if (curIndex == this.theList.size() - 1) {
283
                                return;
284
                        }
285
                        this.theList.remove(item);
286
                        this.theList.add(curIndex + 1, item);
287
                        this.fireContentsChanged(this, curIndex, curIndex + 1);
288
                }
289

    
290
        }
291

    
292
        protected JList getFileList() {
293
                if (fileList == null) {
294
                        fileList = new JList(new FilesystemStoreListModel());
295

    
296
                        fileList.addListSelectionListener(this);
297
                }
298
                return fileList;
299
        }
300

    
301
        private JScrollPane getFileListScroll() {
302
                if (fileListScroll == null) {
303
                        fileListScroll = new JScrollPane();
304
                        fileListScroll.setViewportView(getFileList());
305
                        fileListScroll
306
                                        .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
307
                        fileListScroll
308
                                        .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
309

    
310
                }
311
                return fileListScroll;
312
        }
313

    
314
        private Component getButtonsPanel() {
315
                if (buttonsPanel == null) {
316
                        buttonsPanel = new JPanel();
317

    
318
                        buttonsPanel.setLayout(new GridBagLayout());
319

    
320
                        GridBagConstraints constr = new GridBagConstraints();
321

    
322
                        constr.anchor = GridBagConstraints.CENTER;
323
                        constr.fill = GridBagConstraints.NONE;
324
                        constr.ipadx = 3;
325
                        constr.ipady = 3;
326
                        constr.insets = new Insets(3, 3, 3, 3);
327
                        constr.gridwidth = GridBagConstraints.REMAINDER;
328

    
329
                        buttonsPanel.add(getAddButton(), constr);
330
                        buttonsPanel.add(getEditButton(), constr);
331
                        buttonsPanel.add(getRemoveButton(), constr);
332
                        buttonsPanel.add(getUpButton(), constr);
333
                        buttonsPanel.add(getDownButton(), constr);
334
                        //                        buttonsPanel.add(new JLabel(), constrLbl);
335
                }
336
                return buttonsPanel;
337
        }
338

    
339
        private JButton getAddButton() {
340
                if (addButton == null) {
341
                        addButton = new JButton();
342
                        addButton.setText(getLocalizedText("add"));
343
                        addButton.setActionCommand(ADD_COMMAND);
344
                        addButton.addActionListener(this);
345
                }
346
                return addButton;
347
        }
348

    
349
        private JButton getEditButton() {
350
                if (editButton == null) {
351
                        editButton = new JButton();
352
                        editButton.setText(getLocalizedText("edit"));
353
                        editButton.setActionCommand(EDIT_COMMAND);
354
                        editButton.addActionListener(this);
355
                }
356
                return editButton;
357
        }
358

    
359
        private JButton getRemoveButton() {
360
                if (removeButton == null) {
361
                        removeButton = new JButton();
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 = new JButton();
372
                        upButton.setText(getLocalizedText("up"));
373
                        upButton.setActionCommand(UP_COMMAND);
374
                        upButton.addActionListener(this);
375
                }
376
                return upButton;
377
        }
378

    
379
        private JButton getDownButton() {
380
                if (downButton == null) {
381
                        downButton = new JButton();
382
                        downButton.setText(getLocalizedText("down"));
383
                        downButton.setActionCommand(DOWN_COMMAND);
384
                        downButton.addActionListener(this);
385
                }
386
                return downButton;
387
        }
388

    
389
        private String getLocalizedText(String txt) {
390
                try {
391
                        return PluginServices.getText(this, txt);
392
                } catch (Exception e) {
393
                        return txt;
394
                }
395
        }
396

    
397
        private Component getParamsListScroll() {
398
                if (paramsListScroll == null) {
399
                        paramsListScroll = new JScrollPane();
400
                        paramsListScroll.setBorder(null);
401
                        paramsListScroll.setViewportView(getParamsList());
402
                        paramsListScroll
403
                                        .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
404
                        paramsListScroll
405
                                        .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
406
                }
407
                return paramsListScroll;
408
        }
409

    
410
        private JPanel getParamsList() {
411
                if (paramsList == null) {
412
                        paramsList = new DynObjectViewer();
413
                }
414
                return paramsList;
415

    
416
        }
417

    
418
        protected void loadParamsList(DynObject dynObj) {
419
                DynObjectViewer panel = (DynObjectViewer) getParamsList();
420

    
421
                panel.load(dynObj);
422
        }
423

    
424
        public void actionPerformed(ActionEvent e) {
425
                String command = e.getActionCommand();
426
                FilesystemStoreListModel model = (FilesystemStoreListModel) getFileList()
427
                                .getModel();
428

    
429

    
430
                if (command == ADD_COMMAND) {
431
                        List<FilesystemStoreParameters> toAdd = this.addFiles();
432
                        if (toAdd.isEmpty()){
433
                                return;
434
                        }
435
                        model.addAll(toAdd);
436

    
437
                        getFileList().setModel(model);
438

    
439

    
440
                } else if (command == EDIT_COMMAND) {
441
                        DynObject dynObject = model.getDynObjectAt(getFileList()
442
                                        .getSelectedIndex());
443

    
444
                        try {
445
                DynObjectEditor editor = new DynObjectEditor(dynObject);
446
                editor.editObject(true);
447
                this.loadParamsList(dynObject);
448
                } catch (ServiceException ex) {
449
                    LOG.error(
450
                        "Error creating a Swing component for the DynObject: "
451
                            + dynObject, ex);
452
            }
453

    
454
                } else if (command == REMOVE_COMMAND) {
455
                        int[] selecteds = getFileList().getSelectedIndices();
456
                        for (int i = selecteds.length - 1; i > -1; i--) {
457
                                model.remove(selecteds[i]);
458
                        }
459
                        getFileList().setSelectedIndex(-1);
460
                        this.loadParamsList(null);
461

    
462

    
463
                } else if (command == UP_COMMAND) {
464
                        List<FilesystemStoreParameters> items = new ArrayList<FilesystemStoreParameters>();
465
                        int[] selecteds = getFileList().getSelectedIndices();
466
                        if (selecteds.length == 0 || selecteds[0] == 0) {
467
                                return;
468
                        }
469
                        for (int i = 0; i < selecteds.length; i++) {
470
                                items.add(model.getStoreParameterAt(selecteds[i]));
471
                                selecteds[i]--;
472
                        }
473
                        Iterator<FilesystemStoreParameters> iter = items.iterator();
474
                        while (iter.hasNext()) {
475
                                model.up(iter.next());
476
                        }
477
                        getFileList().setSelectedIndices(selecteds);
478

    
479
                } else if (command == DOWN_COMMAND) {
480
                        List<FilesystemStoreParameters> items = new ArrayList<FilesystemStoreParameters>();
481
                        int[] selecteds = getFileList().getSelectedIndices();
482
                        if (selecteds.length == 0
483
                                        || selecteds[selecteds.length - 1] == model.getSize() - 1) {
484
                                return;
485
                        }
486
                        for (int i = selecteds.length - 1; i > -1; i--) {
487
                                items.add(model.getStoreParameterAt(selecteds[i]));
488
                                selecteds[i]++;
489
                        }
490
                        Iterator<FilesystemStoreParameters> iter = items.iterator();
491
                        while (iter.hasNext()) {
492
                                model.down(iter.next());
493
                        }
494
                        getFileList().setSelectedIndices(selecteds);
495

    
496
                } else {
497
                        throw new IllegalArgumentException(command);
498
                }
499

    
500
        }
501

    
502
        public List<DynObject> getSelecteds() {
503
                ArrayList<DynObject> list = new ArrayList<DynObject>();
504
                JList fList = this.getFileList();
505
                int[] selecteds = fList.getSelectedIndices();
506
                FilesystemStoreListModel model = (FilesystemStoreListModel) fList
507
                                .getModel();
508

    
509
                for (int index : selecteds) {
510
                        list.add((DynObject) model.getStoreParameterAt(index));
511
                }
512
                return list;
513
        }
514

    
515
        public void valueChanged(ListSelectionEvent e) {
516
                int index = getFileList().getSelectedIndex();
517
                if (index < 0) {
518
                        loadParamsList(null);
519
                } else {
520
                        FilesystemStoreListModel model = ((FilesystemStoreListModel) getFileList()
521
                                        .getModel());
522
                        this.loadParamsList((DynObject) model.getStoreParameterAt(index));
523
                }
524
                this.updateButtons();
525
        }
526

    
527
        public class MyFileFilter extends FileFilter {
528
                public FilesystemFileFilter filter = null;
529

    
530
                public MyFileFilter(FilesystemFileFilter params) {
531
                        this.filter = params;
532
                }
533

    
534
                /**
535
                 * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
536
                 */
537
                public boolean accept(File f) {
538
                        if (f.isDirectory()) {
539
                                return true;
540
                        }
541
                        return filter.accept(f);
542

    
543
                }
544

    
545
                /**
546
                 * @see javax.swing.filechooser.FileFilter#getDescription()
547
                 */
548
                public String getDescription() {
549
                        return filter.getDescription();
550
                }
551
                
552
                public String getName() {
553
                        return filter.getDataStoreProviderName();
554
                }
555
        }
556

    
557
        private List<FilesystemStoreParameters> addFiles() {
558
                this.callStateChanged(true);
559
                JFileChooser fileChooser = new JFileChooser(OPEN_LAYER_FILE_CHOOSER_ID,
560
                                explorer.getCurrentPath());
561
                fileChooser.setMultiSelectionEnabled(true);
562
                fileChooser.setAcceptAllFileFilterUsed(false);
563

    
564
                Iterator<MyFileFilter> iter = this.filters.iterator();
565
                while (iter.hasNext()) {
566
                        fileChooser.addChoosableFileFilter(iter.next());
567
                }
568

    
569
                if (lastFilter != null && filters.contains(lastFilter)) {
570
                        fileChooser.setFileFilter(lastFilter);
571
                }
572

    
573
                int result = fileChooser.showOpenDialog(this);
574

    
575
                List<FilesystemStoreParameters> toAdd = new ArrayList<FilesystemStoreParameters>();
576

    
577
                if (result == JFileChooser.APPROVE_OPTION) {
578
                        lastPath = fileChooser.getCurrentDirectory().getAbsolutePath();
579
                        try {
580
                                explorer.setCurrentPath(fileChooser.getCurrentDirectory());
581
                        } catch (FileNotFoundException e) {
582
                                NotificationManager.addError(e);
583
                        }
584
                        lastFilter = (MyFileFilter) fileChooser.getFileFilter();
585
                        DataStoreParameters param, toAddParam;
586
                        ApplicationManager appGvSIGMan = ApplicationLocator
587
                                        .getManager();
588
                        PrepareContext context = this.getPrepareDataStoreContext();
589
                        for (File aFile : fileChooser.getSelectedFiles()) {
590
                                try {
591
                                        param = explorer.createStoreParameters(aFile, 
592
                                                        lastFilter.getDescription().compareTo(DEFAULT_FILTER) == 0 ? null : lastFilter.getName());
593
                                        if (param == null) {
594
                                                // TODO show warning
595
                                                continue;
596
                                        }
597

    
598
                                        try {
599
                                                toAddParam = appGvSIGMan
600
                                                                .prepareOpenDataStoreParameters(param, context);
601
                                        } catch (Exception e) {
602
                                                NotificationManager.addError(e);
603
                                                continue;
604
                                        }
605

    
606
                                        toAdd.add((FilesystemStoreParameters) toAddParam);
607
                                } catch (DataException e) {
608
                                        NotificationManager.addError(e);
609
                                        return null;
610
                                }
611
                        }
612

    
613
                        //                        IFileOpen lastFileOpen = null;
614
                        //                        for (int i = 0; i < listFileOpen.size(); i++) {
615
                        //                                IFileOpen fileOpen = listFileOpen.get(i);
616
                        //                                List<FileFilter> aux = fileOpen.getFileFilter();
617
                        //                                for (int j = 0; j < aux.size(); j++) {
618
                        //                                        if (fileChooser.getFileFilter() == aux.get(j)) {
619
                        //                                                for (int iFile = 0; iFile < newFiles.length; iFile++) {
620
                        //                                                        newFiles[iFile] = fileOpen.post(newFiles[iFile]);
621
                        //                                                }
622
                        //                                                lastFileOpen = fileOpen;
623
                        //                                                break;
624
                        //                                        }
625
                        //                                }
626
                        //                        }
627
                        //
628
                        //                        for (int ind = 0; ind < newFiles.length; ind++) {
629
                        //                                if (newFiles[ind] == null) {
630
                        //                                        break;
631
                        //                                }
632
                        //                                toAdd.add(new MyFile(newFiles[ind], (fileChooser
633
                        //                                                .getFileFilter()), lastFileOpen));
634
                        //                        }
635
                        //
636
                        //                        return toAdd.toArray();
637
                }
638
                return toAdd;
639
        }
640

    
641
        protected abstract PrepareContext getPrepareDataStoreContext();
642

    
643
        private void updateButtons() {
644
                int selectedIndex =this.getFileList().getSelectedIndex();
645
                int size =this.getFileList().getModel().getSize();
646
                int[] selecteds = this.getFileList().getSelectedIndices();
647
                if ( size < 1) {
648
                        this.getEditButton().setEnabled(false);
649
                        this.getRemoveButton().setEnabled(false);
650
                        this.getUpButton().setEnabled(false);
651
                        this.getDownButton().setEnabled(false);
652
                        return;
653
                } else if (size == 1) {
654
                        this.getUpButton().setEnabled(false);
655
                        this.getDownButton().setEnabled(false);
656
                } else {
657
                        this.getUpButton().setEnabled(selectedIndex > 0);
658

    
659
                        this.getDownButton().setEnabled(
660
                                        selectedIndex > -1
661
                                                        && selecteds[selecteds.length - 1] < size - 1);
662
                }
663
                this.getEditButton().setEnabled(
664
                                selectedIndex > -1
665
                                                && this.getFileList().getSelectedIndices().length == 1);
666
                this.getRemoveButton().setEnabled(selectedIndex > -1);
667
        }
668

    
669
        public void close() {
670
                if (explorer != null) {
671
                        explorer.dispose();
672
                        explorer = null;
673
                }
674
                if (filters != null) {
675
                        filters.clear();
676
                        filters = null;
677
                }
678
        }
679
}