Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerWizardPanel.java @ 41122

History | View | Annotate | Download (24.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing;
25

    
26
import java.awt.Component;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.Insets;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.io.File;
33
import java.util.ArrayList;
34
import java.util.Iterator;
35
import java.util.List;
36
import java.util.prefs.Preferences;
37

    
38
import javax.swing.AbstractListModel;
39
import javax.swing.JButton;
40
import javax.swing.JComponent;
41
import javax.swing.JList;
42
import javax.swing.JPanel;
43
import javax.swing.JScrollPane;
44
import javax.swing.ScrollPaneConstants;
45
import javax.swing.SwingUtilities;
46
import javax.swing.event.ListSelectionEvent;
47
import javax.swing.event.ListSelectionListener;
48
import javax.swing.filechooser.FileFilter;
49

    
50
import org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.messages.Messages;
52
import org.gvsig.andami.messages.NotificationManager;
53
import org.gvsig.app.ApplicationLocator;
54
import org.gvsig.app.ApplicationManager;
55
import org.gvsig.app.gui.WizardPanel;
56
import org.gvsig.app.prepareAction.PrepareContext;
57
import org.gvsig.fmap.dal.DALLocator;
58
import org.gvsig.fmap.dal.DataManager;
59
import org.gvsig.fmap.dal.DataStoreParameters;
60
import org.gvsig.fmap.dal.exception.DataException;
61
import org.gvsig.fmap.dal.exception.FileNotFoundException;
62
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter;
63
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
64
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
65
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
66
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
67
import org.gvsig.gui.beans.swing.JFileChooser;
68
import org.gvsig.tools.dynobject.DynObject;
69
import org.gvsig.tools.service.ServiceException;
70
import org.gvsig.tools.swing.api.ToolsSwingLocator;
71
import org.slf4j.Logger;
72
import org.slf4j.LoggerFactory;
73

    
74
/**
75
 * @author jmvivo
76
 * 
77
 */
78
public abstract class FilesystemExplorerWizardPanel extends WizardPanel
79
    implements ActionListener, ListSelectionListener {
80

    
81
    /**
82
         *
83
         */
84
    private static final long serialVersionUID = -3371957786521876903L;
85

    
86
    private static final Logger LOG = LoggerFactory
87
        .getLogger(FilesystemExplorerWizardPanel.class);
88

    
89
    public static final String OPEN_LAYER_FILE_CHOOSER_ID =
90
        "OPEN_LAYER_FILE_CHOOSER_ID";
91

    
92
    protected static final String ADD_COMMAND = "ADD";
93
    protected static final String EDIT_COMMAND = "PROPERTIES";
94
    protected static final String REMOVE_COMMAND = "REMOVE";
95
    protected static final String UP_COMMAND = "UP";
96
    protected static final String DOWN_COMMAND = "DOWN";
97

    
98
    private static String lastPath = null;
99
    private static MyFileFilter lastFilter = null;
100
    private static final String DEFAULT_FILTER = "All_supported";
101

    
102
    private JList fileList;
103
    private JScrollPane fileListScroll;
104
    private JPanel buttonsPanel;
105
    private JButton addButton;
106
    private JButton propertiesButton;
107
    private JButton removeButton;
108
    private JButton upButton;
109
    private JButton downButton;
110

    
111
    protected FilesystemServerExplorer explorer;
112
    private ArrayList<MyFileFilter> filters;
113
    
114
    public void setTabName(String name) {
115
        super.setTabName(name);
116
    }
117

    
118
    /*
119
     * (non-Javadoc)
120
     * 
121
     * @see com.iver.cit.gvsig.gui.WizardPanel#getParameters()
122
     */
123
    @Override
124
    public DataStoreParameters[] getParameters() {
125
        return ((FilesystemStoreListModel) getFileList().getModel())
126
            .getParameters();
127
    }
128

    
129
    /*
130
     * (non-Javadoc)
131
     * 
132
     * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
133
     */
134
    @Override
135
    public void initWizard() {
136
        setTabName(PluginServices.getText(this, "Fichero"));
137
        if (lastPath == null) {
138
            Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
139
            lastPath = prefs.get("DataFolder", null);
140
        }
141

    
142
        DataManager dm = DALLocator.getDataManager();
143
        FilesystemServerExplorerParameters param;
144
        try {
145
            param =
146
                (FilesystemServerExplorerParameters) dm
147
                    .createServerExplorerParameters(FilesystemServerExplorer.NAME);
148
            param.setInitialpath(lastPath);
149
            explorer =
150
                (FilesystemServerExplorer) dm.openServerExplorer(
151
                    FilesystemServerExplorer.NAME, param);
152
        } catch (Exception e) {
153
            throw new RuntimeException(e);
154
        }
155

    
156
        int mode = FilesystemServerExplorer.MODE_ALL;
157
        this.filters = new ArrayList<MyFileFilter>();
158
        if (this.getMapCtrl() == null) {
159
            mode = FilesystemServerExplorer.MODE_FEATURE;
160
        } else {
161
            mode =
162
                FilesystemServerExplorer.MODE_GEOMETRY
163
                    | FilesystemServerExplorer.MODE_RASTER;
164
        }
165
        
166
        // First filter in list will be 'All formats' filter
167
        this.filters.add(new MyFileFilter(explorer.getFilter(mode,
168
            Messages.get(DEFAULT_FILTER))));
169

    
170
        @SuppressWarnings("unchecked")
171
        Iterator<FilesystemFileFilter> iter = explorer.getFilters(mode);
172
        while (iter.hasNext()) {
173
            this.filters.add(new MyFileFilter(iter.next()));
174
        }
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
        public void forceUpdate(int index) {
280
            this.fireContentsChanged(this, index, index);
281
        }
282

    
283
    }
284

    
285
    protected JList getFileList() {
286
        if (fileList == null) {
287
            fileList = new JList(new FilesystemStoreListModel());
288

    
289
            fileList.addListSelectionListener(this);
290
        }
291
        return fileList;
292
    }
293

    
294
    private JScrollPane getFileListScroll() {
295
        if (fileListScroll == null) {
296
            fileListScroll = new JScrollPane();
297
            fileListScroll.setViewportView(getFileList());
298
            fileListScroll
299
                .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
300
            fileListScroll
301
                .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
302

    
303
        }
304
        return fileListScroll;
305
    }
306

    
307
    private Component getButtonsPanel() {
308
        if (buttonsPanel == null) {
309
            buttonsPanel = new JPanel();
310

    
311
            buttonsPanel.setLayout(new GridBagLayout());
312

    
313
            GridBagConstraints constr = new GridBagConstraints();
314

    
315
            constr.anchor = GridBagConstraints.CENTER;
316
            constr.fill = GridBagConstraints.NONE;
317
            constr.ipadx = 3;
318
            constr.ipady = 3;
319
            constr.insets = new Insets(3, 3, 3, 3);
320
            constr.gridwidth = GridBagConstraints.REMAINDER;
321

    
322
            buttonsPanel.add(getAddButton(), constr);
323
            buttonsPanel.add(getPropertiesButton(), constr);
324
            buttonsPanel.add(getRemoveButton(), constr);
325
            buttonsPanel.add(getUpButton(), constr);
326
            buttonsPanel.add(getDownButton(), constr);
327
            // buttonsPanel.add(new JLabel(), constrLbl);
328
        }
329
        return buttonsPanel;
330
    }
331

    
332
    private JButton getAddButton() {
333
        if (addButton == null) {
334
            addButton =
335
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
336
            addButton.setText(getLocalizedText("add"));
337
            addButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
338
            addButton.setActionCommand(ADD_COMMAND);
339
            addButton.addActionListener(this);
340
        }
341
        return addButton;
342
    }
343

    
344
    private JButton getPropertiesButton() {
345
        if (propertiesButton == null) {
346
            propertiesButton =
347
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
348
            propertiesButton.setText(getLocalizedText("properties"));
349
            propertiesButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
350
            propertiesButton.setActionCommand(EDIT_COMMAND);
351
            propertiesButton.addActionListener(this);
352
        }
353
        return propertiesButton;
354
    }
355

    
356
    private JButton getRemoveButton() {
357
        if (removeButton == null) {
358
            removeButton =
359
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
360
            removeButton.setText(getLocalizedText("remove"));
361
            removeButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
362
            removeButton.setActionCommand(REMOVE_COMMAND);
363
            removeButton.addActionListener(this);
364
        }
365
        return removeButton;
366
    }
367

    
368
    private JButton getUpButton() {
369
        if (upButton == null) {
370
            upButton =
371
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
372
            upButton.setText(getLocalizedText("up"));
373
            upButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
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.setMargin(new java.awt.Insets(2, 2, 2, 2));
386
            downButton.setActionCommand(DOWN_COMMAND);
387
            downButton.addActionListener(this);
388
        }
389
        return downButton;
390
    }
391

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

    
400
    public void actionPerformed(ActionEvent e) {
401
        String command = e.getActionCommand();
402
        FilesystemStoreListModel model =
403
            (FilesystemStoreListModel) getFileList().getModel();
404

    
405
        if (command == ADD_COMMAND) {
406
            List<FilesystemStoreParameters> toAdd = this.addFiles();
407
            if (toAdd.isEmpty()) {
408
                return;
409
            }
410
            model.addAll(toAdd);
411

    
412
            getFileList().setModel(model);
413
            
414
            this.updateContainingWizardAcceptButton();
415
            try {
416
                    fileList.setSelectedIndex(fileList.getModel().getSize()-1);
417
            } catch(Exception ex) {
418
                    // Ignore errors
419
            }
420
        } else
421
            if (command == EDIT_COMMAND) {
422
                DynObject dynObject =
423
                    model.getDynObjectAt(getFileList().getSelectedIndex());
424

    
425
                try {
426
                    DynObjectEditor editor = new DynObjectEditor(dynObject);
427
                    editor.editObject(true);
428
                    
429
                    RefreshThread st = new RefreshThread(getFileList(), 500);
430
                    st.start();
431
                    
432
                } catch (ServiceException ex) {
433
                    LOG.error(
434
                        "Error creating a Swing component for the DynObject: "
435
                            + dynObject, ex);
436
                }
437

    
438
            } else
439
                if (command == REMOVE_COMMAND) {
440
                    int[] selecteds = getFileList().getSelectedIndices();
441
                    for (int i = selecteds.length - 1; i > -1; i--) {
442
                        model.remove(selecteds[i]);
443
                    }
444
                    getFileList().setSelectedIndex(-1);
445
                    
446
                    this.updateContainingWizardAcceptButton();
447

    
448
                } else
449
                    if (command == UP_COMMAND) {
450
                        List<FilesystemStoreParameters> items =
451
                            new ArrayList<FilesystemStoreParameters>();
452
                        int[] selecteds = getFileList().getSelectedIndices();
453
                        if (selecteds.length == 0 || selecteds[0] == 0) {
454
                            return;
455
                        }
456
                        for (int i = 0; i < selecteds.length; i++) {
457
                            items.add(model.getStoreParameterAt(selecteds[i]));
458
                            selecteds[i]--;
459
                        }
460
                        Iterator<FilesystemStoreParameters> iter =
461
                            items.iterator();
462
                        while (iter.hasNext()) {
463
                            model.up(iter.next());
464
                        }
465
                        getFileList().setSelectedIndices(selecteds);
466

    
467
                    } else
468
                        if (command == DOWN_COMMAND) {
469
                            List<FilesystemStoreParameters> items =
470
                                new ArrayList<FilesystemStoreParameters>();
471
                            int[] selecteds =
472
                                getFileList().getSelectedIndices();
473
                            if (selecteds.length == 0
474
                                || selecteds[selecteds.length - 1] == model
475
                                    .getSize() - 1) {
476
                                return;
477
                            }
478
                            for (int i = selecteds.length - 1; i > -1; i--) {
479
                                items.add(model
480
                                    .getStoreParameterAt(selecteds[i]));
481
                                selecteds[i]++;
482
                            }
483
                            Iterator<FilesystemStoreParameters> iter =
484
                                items.iterator();
485
                            while (iter.hasNext()) {
486
                                model.down(iter.next());
487
                            }
488
                            getFileList().setSelectedIndices(selecteds);
489

    
490
                        } else {
491
                            throw new IllegalArgumentException(command);
492
                        }
493

    
494
    }
495

    
496
    /**
497
     * check number of files already selected for adding
498
     */
499
    private void updateContainingWizardAcceptButton() {
500
        int curr_add_file_count = getFileList().getModel().getSize();
501
        this.callStateChanged(curr_add_file_count > 0);
502
    }
503

    
504
    
505
    public boolean areSettingsValid() {
506
        int curr_add_file_count = getFileList().getModel().getSize();
507
        return (curr_add_file_count > 0);
508
    }
509

    
510
    public List<DynObject> getSelecteds() {
511
        ArrayList<DynObject> list = new ArrayList<DynObject>();
512
        JList fList = this.getFileList();
513
        int[] selecteds = fList.getSelectedIndices();
514
        FilesystemStoreListModel model =
515
            (FilesystemStoreListModel) fList.getModel();
516

    
517
        for (int index : selecteds) {
518
            list.add((DynObject) model.getStoreParameterAt(index));
519
        }
520
        return list;
521
    }
522

    
523
    public void valueChanged(ListSelectionEvent e) {
524
        this.updateButtons();
525
    }
526

    
527
    public class MyFileFilter extends FileFilter {
528

    
529
        public FilesystemFileFilter filter = null;
530

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

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

    
544
        }
545

    
546
        /**
547
         * @see javax.swing.filechooser.FileFilter#getDescription()
548
         */
549
        public String getDescription() {
550
            return filter.getDescription();
551
        }
552

    
553
        public String getName() {
554
            return filter.getDataStoreProviderName();
555
        }
556
    }
557

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

    
568
        Iterator<MyFileFilter> iter = this.filters.iterator();
569
        while (iter.hasNext()) {
570
            fileChooser.addChoosableFileFilter(iter.next());
571
        }
572
        
573
        if (filters.size() > 0) {
574
            MyFileFilter firstf = filters.get(0);
575
            // Set first filter
576
            fileChooser.setFileFilter(firstf);
577
        }
578

    
579
        // If there is a last filter, use it
580
        if (lastFilter != null && filters.contains(lastFilter)) {
581
            fileChooser.setFileFilter(lastFilter);
582
        }
583

    
584
        int result = fileChooser.showOpenDialog(this);
585

    
586
        List<FilesystemStoreParameters> toAdd =
587
            new ArrayList<FilesystemStoreParameters>();
588

    
589
        if (result == JFileChooser.APPROVE_OPTION) {
590
            lastPath = fileChooser.getCurrentDirectory().getAbsolutePath();
591
            JFileChooser.setLastPath(OPEN_LAYER_FILE_CHOOSER_ID, fileChooser.getCurrentDirectory());
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
            if(toAddParamList != null) {
629
                    for (int i = 0; i < toAddParamList.size(); i++) {
630
                            toAdd.add((FilesystemStoreParameters)toAddParamList.get(i));
631
                    }
632
            }
633
        }
634
        return toAdd;
635
    }
636

    
637
    protected abstract PrepareContext getPrepareDataStoreContext();
638

    
639
    /**
640
     * Refers to up/down/remove buttons etc. Called when selection changes
641
     */
642
    private void updateButtons() {
643
        int selectedIndex = this.getFileList().getSelectedIndex();
644
        int size = this.getFileList().getModel().getSize();
645
        int[] selecteds = this.getFileList().getSelectedIndices();
646
        if (size < 1) {
647
            this.getPropertiesButton().setEnabled(false);
648
            this.getRemoveButton().setEnabled(false);
649
            this.getUpButton().setEnabled(false);
650
            this.getDownButton().setEnabled(false);
651
            return;
652
        } else
653
            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.getPropertiesButton().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
    
680
    
681

    
682
    class RefreshThread extends Thread {
683
        
684
        private int waitt = 0;
685
        private JList comp = null;
686
        
687
        public RefreshThread(JList c, int t) {
688
            waitt = t;
689
            comp = c;
690
        }
691
        public void run() {
692
            
693
            try {
694
                /*
695
                 * We might need to wait a bit because the GUI thread needs
696
                 * some time to update (this is because we have used a modal dialog
697
                 * and we refresh after that dialog is closed)
698
                 */
699
                Thread.sleep(waitt);
700
            } catch (Exception exc) {
701
                
702
            }
703
            
704
            SwingUtilities.invokeLater(new Runnable() {
705
                public void run() {
706
                    try {
707
                        // System.out.println("REFRESH");
708
                        comp.clearSelection();
709
                    } catch (Exception exc) {
710
                        LOG.info("Error while refreshing components.", exc);
711
                    }
712
                }
713
            });
714
        }
715
    }    
716
    
717
}