Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2060 / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.file / src / main / java / org / gvsig / exportto / swing / prov / file / panel / SelectFileOptionPanel.java @ 39376

History | View | Annotate | Download (3.81 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
package org.gvsig.exportto.swing.prov.file.panel;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.io.File;
27

    
28
import javax.swing.JOptionPane;
29
import javax.swing.JPanel;
30

    
31
import org.gvsig.exportto.swing.ExporttoSwingLocator;
32
import org.gvsig.exportto.swing.ExporttoSwingManager;
33
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
34
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
35
import org.gvsig.i18n.Messages;
36

    
37
/**
38
 * @author gvSIG Team
39
 * @version $Id$
40
 * 
41
 */
42
public class SelectFileOptionPanel extends ExporttoSwingProviderPanel {
43

    
44
    private static final long serialVersionUID = -7417782279157857962L;
45
    private JPanel optionsPanel;
46

    
47
    private static final ExporttoSwingManager EXPORTTO_SWING_MANAGER =
48
        ExporttoSwingLocator.getSwingManager();
49

    
50
    private org.gvsig.gui.beans.wizard.panel.SelectFileOptionPanel selectFileOptionPanel;
51

    
52
    /**
53
     * @param fileText
54
     */
55
    public SelectFileOptionPanel() {
56
        this(null);
57
    }
58

    
59
    public SelectFileOptionPanel(JPanel optionsPanel) {
60
        super();
61
        this.setLayout(new BorderLayout());
62
        selectFileOptionPanel =
63
            new org.gvsig.gui.beans.wizard.panel.SelectFileOptionPanel(null);
64
        add(selectFileOptionPanel, BorderLayout.NORTH);
65
        if (optionsPanel != null) {
66
            optionsPanel.setBorder(javax.swing.BorderFactory
67
                .createCompoundBorder(javax.swing.BorderFactory
68
                    .createTitledBorder(Messages.getText("options")),
69
                    javax.swing.BorderFactory.createEmptyBorder(10, 5, 5, 5)));
70
            add(optionsPanel, BorderLayout.CENTER);
71
            this.optionsPanel = optionsPanel;
72
        }
73
    }
74

    
75
    @Override
76
    public String getPanelTitle() {
77
        return EXPORTTO_SWING_MANAGER.getTranslation("Seleccionar_fichero");
78
    }
79

    
80
    public File getSelectedFile() {
81
        return selectFileOptionPanel.getSelectedFile();
82
    }
83

    
84
    @Override
85
    public boolean isValidPanel() throws ExporttoPanelValidationException {
86
        File file = selectFileOptionPanel.getSelectedFile();
87
        if ((file == null) || (file.equals(""))) {
88
            throw new ExporttoPanelValidationException(
89
                EXPORTTO_SWING_MANAGER.getTranslation("_File_cannot_be_empty"));
90
        }
91
        if (file.exists()) {
92
            int resp =
93
                JOptionPane
94
                    .showConfirmDialog(
95
                        (Component) selectFileOptionPanel,
96
                        EXPORTTO_SWING_MANAGER
97
                            .getTranslation("fichero_ya_existe_seguro_desea_guardarlo"),
98
                        EXPORTTO_SWING_MANAGER.getTranslation("guardar"),
99
                        JOptionPane.YES_NO_OPTION);
100
            if (resp == JOptionPane.NO_OPTION) {
101
                return false;
102
            }
103
        }
104
        return true;
105
    }
106

    
107
    /**
108
     * @return the optionsPanel
109
     */
110
    public JPanel getOptionsPanel() {
111
        return optionsPanel;
112
    }
113
}