Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.newlayer / org.gvsig.newlayer.prov / org.gvsig.newlayer.prov.file / src / main / java / org / gvsig / newlayer / prov / file / NewLayerFileProviderPanel.java @ 40560

History | View | Annotate | Download (3.27 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.newlayer.prov.file;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.io.File;
29

    
30
import javax.swing.JOptionPane;
31

    
32
import org.gvsig.gui.beans.wizard.panel.SelectFileOptionPanel;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.newlayer.NewLayerException;
35
import org.gvsig.newlayer.NewLayerProviderPanel;
36

    
37
public class NewLayerFileProviderPanel extends NewLayerProviderPanel{
38
    private SelectFileOptionPanel selectFileOptionPanel; 
39
    
40
        protected NewLayerFileProviderPanel(AbstractNewLayerFileProvider provider) {
41
                super(provider);
42
                this.setLayout(new BorderLayout());
43
        selectFileOptionPanel =
44
            new org.gvsig.gui.beans.wizard.panel.SelectFileOptionPanel(null);
45
        add(selectFileOptionPanel, BorderLayout.NORTH);
46
        }
47

    
48
        public AbstractNewLayerFileProvider getProvider() {
49
                return (AbstractNewLayerFileProvider) this.provider;
50
        }
51
        
52
        public File getSelectedFile(){
53
            return selectFileOptionPanel.getSelectedFile();
54
        }
55

    
56
    @Override
57
    public String getTitle() {
58
        return Messages.getText("output_file");
59
    }
60

    
61
    @Override
62
    public boolean isValidPanel() throws NewLayerException {
63
        File file = selectFileOptionPanel.getSelectedFile();
64
        if ((file == null) || (file.equals(""))) {
65
            throw new NotEmptyFileException();
66
        }
67
        if (file.exists()) {
68
            int resp =
69
                JOptionPane
70
                    .showConfirmDialog(
71
                        (Component) selectFileOptionPanel.getParent(),
72
                        Messages.getText("fichero_ya_existe_seguro_desea_guardarlo"),
73
                        Messages.getText("guardar"),
74
                        JOptionPane.YES_NO_OPTION);
75
            if (resp == JOptionPane.NO_OPTION) {
76
                return false;
77
            }
78
        }
79
        return true;       
80
    }
81
    
82
    class NotEmptyFileException extends NewLayerException {
83
        private static final long serialVersionUID = -3619912245694177044L;
84
        private final static String MESSAGE_FORMAT = "The file can not be empty.";
85
        private final static String MESSAGE_KEY = "_file_can_not_be_empty_exception";
86

    
87
        public NotEmptyFileException() {
88
            super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
89
        }
90
    }
91

    
92
    @Override
93
    public void updatePanel() {
94
        // TODO Auto-generated method stub
95
        
96
    }
97

    
98
}