Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / panels / FeatureTypePanel.java @ 47433

History | View | Annotate | Download (4.54 KB)

1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

    
23
package org.gvsig.newlayer.impl.panels;
24

    
25
import javax.swing.JComponent;
26
import javax.swing.JOptionPane;
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.feature.EditableFeatureType;
30
import org.gvsig.fmap.dal.swing.DALSwingLocator;
31
import org.gvsig.fmap.dal.swing.DataSwingManager;
32
import static org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel.MODE_EDIT_ALL;
33
import org.gvsig.newlayer.NewLayerProvider;
34
import org.gvsig.newlayer.NewLayerProviderPanel;
35
import org.gvsig.newlayer.NewLayerWizard;
36
import org.gvsig.newlayer.spi.NewLayerPanelValidationException;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.i18n.I18nManager;
39
import org.gvsig.tools.swing.api.ToolsSwingLocator;
40
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
41

    
42
/**
43
 *
44
 * @author gvSIG Team
45
 */
46
public class FeatureTypePanel implements NewLayerProviderPanel {
47

    
48
    private final NewLayerProvider provider;
49
    private final NewLayerWizard wizard;
50
    private org.gvsig.fmap.dal.swing.featuretype.FeatureTypePanel featureTypeEditor;
51

    
52
    public FeatureTypePanel(NewLayerWizard wizard, NewLayerProvider provider) {
53
        this.provider = provider;
54
        this.wizard = wizard;
55
        initComponents();
56
    }
57

    
58
    private void initComponents() {
59
        DataManager dataManager = DALLocator.getDataManager();
60
        DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager();
61
        EditableFeatureType ft = dataManager.createFeatureType();
62
        this.featureTypeEditor = dataSwingManager.createFeatureTypePanel();
63
        this.featureTypeEditor.setDefaultProjection(this.wizard.getService().getDefaultProjection());
64
        this.featureTypeEditor.setMode(MODE_EDIT_ALL);
65
        this.featureTypeEditor.put(ft);
66
    }
67

    
68
    @Override
69
    public void previousPanel() {
70
        EditableFeatureType ft = this.provider.getFeatureType();
71
        this.featureTypeEditor.fetch(ft);
72
    }
73

    
74
    @Override
75
    public void enterPanel() {
76
        this.featureTypeEditor.setDefaultProjection(this.wizard.getService().getDefaultProjection());
77
        EditableFeatureType ft = this.provider.getFeatureType();
78
        if (ft!= null) {
79
            this.featureTypeEditor.put(ft);
80
        }
81
    }
82

    
83
    @Override
84
    public String getIdPanel() {
85
        return this.getClass().getCanonicalName();
86
    }
87

    
88
    @Override
89
    public String getTitlePanel() {
90
        I18nManager i18n = ToolsLocator.getI18nManager();
91
        return i18n.getTranslation("_Columns_definition");
92
    }
93

    
94
    @Override
95
    public void nextPanel() {
96
        EditableFeatureType ft = this.provider.getFeatureType();
97
        this.featureTypeEditor.fetch(ft);
98
    }
99

    
100
    @Override
101
    public boolean validatePanel() throws NewLayerPanelValidationException {
102
        try { 
103
            if( this.featureTypeEditor.isEditing()) {
104
                ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager();
105
                I18nManager i18n = ToolsLocator.getI18nManager();
106
                dialogs.messageDialog(
107
                        i18n.getTranslation("_Accept_o_discard_the_attribute_changes_to_continue"), 
108
                        i18n.getTranslation("_Columns_definition"), 
109
                        JOptionPane.INFORMATION_MESSAGE
110
                );
111
                return false;
112
            }
113
            EditableFeatureType ft = this.provider.getFeatureType();
114
            this.featureTypeEditor.fetch(ft);
115
            if( ft.size()==0 ) {
116
                return false;
117
            }
118
            return true;
119
        } catch (Exception ex) {
120
            return false;
121
        }
122
    }
123

    
124
    @Override
125
    public JComponent asJComponent() {
126
        return this.featureTypeEditor.asJComponent();
127
    }
128

    
129
}