Statistics
| Revision:

gvsig-gdal / trunk / org.gvsig.gdal / org.gvsig.gdal.app / org.gvsig.gdal.app.ogr.mainplugin / src / main / java / org / gvsig / gdal / app / ogr / mainplugin / gui / OGRWizarPanel.java @ 400

History | View | Annotate | Download (3.97 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 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
 * 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.gdal.app.ogr.mainplugin.gui;
25

    
26
import java.awt.BorderLayout;
27
import java.util.List;
28

    
29
import javax.swing.JOptionPane;
30

    
31
import org.apache.commons.lang.StringUtils;
32
import org.gvsig.app.gui.WizardPanel;
33
import org.gvsig.fmap.dal.DataStoreParameters;
34
import org.gvsig.gdal.prov.ogr.OGRDataStoreParameters;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.i18n.I18nManager;
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

    
40
/**
41
 * 
42
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
43
 *
44
 */
45
public class OGRWizarPanel extends WizardPanel {
46

    
47
    private static final Logger LOG = LoggerFactory.getLogger(OGRWizarPanel.class);
48

    
49
    private static final long serialVersionUID = 678408522883979629L;
50

    
51
    private static final String TAB_NAME = "OGR";
52

    
53
    private final JOGRDataExplorer component;
54

    
55
    /**
56
     * 
57
     */
58
    public OGRWizarPanel() {
59
        super();
60

    
61
        this.component = new JOGRDataExplorerController();
62

    
63
        initWizard();
64
    }
65

    
66
    @Override
67
    public void close() {
68

    
69
    }
70

    
71
    @Override
72
    public void execute() {
73
        I18nManager i18n = ToolsLocator.getI18nManager();
74

    
75
        String connectionString = this.component.getConnectionString();
76

    
77
        if (StringUtils.isBlank(connectionString)) {
78
            return;
79
        }
80

    
81
        List<DataStoreParameters> layerProperties;
82
        try {
83
            layerProperties = this.component.getSelectedLayerProperties();
84
        } catch (Throwable e) {
85
            LOG.warn("Can not get properties of selected layers", e);
86

    
87
            JOptionPane.showMessageDialog(component.asJComponent(),
88
                i18n.getTranslation("error_getting_selected_layer_properties"),
89
                i18n.getTranslation("error"), JOptionPane.ERROR_MESSAGE);
90
            return;
91
        }
92
        
93
        if( layerProperties==null || layerProperties.isEmpty() ) {
94
            JOptionPane.showMessageDialog(component.asJComponent(),
95
                i18n.getTranslation("_You_must_select_at_least_one_layer")+"\n\n"+
96
                        i18n.getTranslation("_Make_sure_that_in_addition_to_selecting_a_file_click_on_the_open_button_and_you_have_selected_at_least_one_layer_from_the_list"),
97
                i18n.getTranslation("_Warning"), 
98
                JOptionPane.WARNING_MESSAGE);
99
            return;
100
        }
101
        for (DataStoreParameters parameters : layerProperties) {
102

    
103
            OGRDataStoreParameters ogrParameters = (OGRDataStoreParameters) parameters;
104
            
105
            if(ogrParameters.getCRS() == null){
106
                ogrParameters.setCRS(getMapContext().getProjection());
107
            }
108
            
109
            doAddLayer(ogrParameters.getLayerName(), ogrParameters);
110
        }
111
    }
112

    
113
    @Override
114
    public DataStoreParameters[] getParameters() {
115
        return null;
116
    }
117

    
118
    @Override
119
    public void initWizard() {
120
        I18nManager i18nManager = ToolsLocator.getI18nManager();
121
        setTabName(i18nManager.getTranslation(TAB_NAME));
122
        this.setLayout(new BorderLayout());
123
        this.add(this.component.asJComponent(), BorderLayout.CENTER);
124

    
125
    }
126
}