Statistics
| Revision:

root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.app / org.gvsig.postgresql.app.export / src / main / java / org / gvsig / postgresql / exportto / panel / SelectPkPanel.java @ 61

History | View | Annotate | Download (3.59 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 modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.postgresql.exportto.panel;
24

    
25
import java.awt.BorderLayout;
26

    
27
import javax.swing.JLabel;
28
import javax.swing.JPanel;
29
import javax.swing.JTextField;
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.fmap.dal.feature.FeatureAttributeDescriptor;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37

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

    
45
    private static final long serialVersionUID = 2652404227373508779L;
46

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

    
50
    private FeatureType featType = null;
51
    protected JTextField textField = null;
52

    
53
    public SelectPkPanel() {
54
        super();
55
    }
56

    
57
    public SelectPkPanel(FeatureType ft) {
58
        super();
59
        featType = ft;
60
    }
61

    
62
    protected void initializeComponents() {
63
        this.setLayout(new BorderLayout());
64

    
65
        JPanel topPanel = new JPanel(new BorderLayout());
66
        textField = new JTextField();
67

    
68
        String msg = EXPORTTO_SWING_MANAGER.getTranslation(
69
                "_Enter_new_field_name_for_primary_key_or_blank_to_not_add_primary_key");
70
        topPanel.add(new JLabel(msg + ":"), BorderLayout.NORTH);
71
        topPanel.add(textField, BorderLayout.CENTER);
72
        // ==============================================
73
        add(topPanel, BorderLayout.NORTH);
74
    }
75

    
76
    public String getText() {
77
        String field = textField.getText();
78
        if ((field == null) || (field.trim().equals(""))) {
79
            return null;
80
        }
81
        return field;
82
    }
83

    
84
    @Override
85
    public String getPanelTitle() {
86
        return EXPORTTO_SWING_MANAGER.getTranslation("_Primary_key");
87
    }
88

    
89
    @Override
90
    public boolean isValidPanel() throws ExporttoPanelValidationException {
91
        String txt = this.getText();
92
        if (isFieldName(txt, featType)) {
93
            throw new ExporttoPanelValidationException(
94
                    EXPORTTO_SWING_MANAGER.getTranslation(
95
                            "_Field_name_already_exists"));
96
        }
97
        return true;
98
    }
99

    
100
    private boolean isFieldName(String txt, FeatureType ft) {
101

    
102
        if (ft == null || txt == null) {
103
            return false;
104
        }
105

    
106
        FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
107
        for (int i = 0; i < atts.length; i++) {
108
            if (atts[i].getName().equals(txt)) {
109
                return true;
110
            }
111
        }
112
        return false;
113
    }
114

    
115
}