Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.jdbc / src / main / java / org / gvsig / exportto / swing / prov / jdbc / panel / SelectPkPanel.java @ 41632

History | View | Annotate | Download (4.67 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40559 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5 40435 jjdelcerro
 *
6 41488 jjdelcerro
 * 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 40435 jjdelcerro
 *
11 41488 jjdelcerro
 * 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 40435 jjdelcerro
 *
16 41488 jjdelcerro
 * 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 40435 jjdelcerro
 *
20 41488 jjdelcerro
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22 40435 jjdelcerro
 */
23
package org.gvsig.exportto.swing.prov.jdbc.panel;
24
25 41486 jjdelcerro
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27 41488 jjdelcerro
import javax.swing.DefaultListModel;
28 41486 jjdelcerro
import javax.swing.JComponent;
29
import org.apache.commons.lang3.StringUtils;
30 41598 jjdelcerro
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCOptions;
31 41127 jldominguez
32 40435 jjdelcerro
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
33 41486 jjdelcerro
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
34 41127 jldominguez
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
35 41488 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
36 41127 jldominguez
import org.gvsig.fmap.dal.feature.FeatureType;
37 41486 jjdelcerro
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.i18n.I18nManager;
39 40435 jjdelcerro
40
/**
41
 * @author gvSIG Team
42
 * @version $Id$
43 41488 jjdelcerro
 *
44 40435 jjdelcerro
 */
45 41486 jjdelcerro
public class SelectPkPanel extends SelectPkPanelLayout implements ExporttoSwingProviderPanel {
46 40435 jjdelcerro
47
    private static final long serialVersionUID = 2652404227373508779L;
48 41488 jjdelcerro
49 41598 jjdelcerro
    private ExporttoJDBCOptions provider;
50 41488 jjdelcerro
51 41598 jjdelcerro
    public SelectPkPanel(ExporttoJDBCOptions provider) {
52 41486 jjdelcerro
        this.provider = provider;
53 41492 jjdelcerro
        initComponents();
54 41127 jldominguez
    }
55 41488 jjdelcerro
56 41486 jjdelcerro
    protected void initComponents() {
57 41488 jjdelcerro
        this.rdoCreatePrimaryNewKey.addActionListener(new ActionListener() {
58 41486 jjdelcerro
            public void actionPerformed(ActionEvent e) {
59 41488 jjdelcerro
                onSelect();
60 41486 jjdelcerro
            }
61
        });
62 41488 jjdelcerro
        this.rdoUseExistingFieldAsPrimariKey.addActionListener(new ActionListener() {
63
            public void actionPerformed(ActionEvent e) {
64
                onSelect();
65
            }
66
        });
67
        this.rdoDoNotCreatePrimaryKey.addActionListener(new ActionListener() {
68
            public void actionPerformed(ActionEvent e) {
69
                onSelect();
70
            }
71
        });
72 41492 jjdelcerro
        this.rdoCreatePrimaryNewKey.setSelected(true);
73 41486 jjdelcerro
        this.translateControls();
74
    }
75 41488 jjdelcerro
76
    private void onSelect() {
77
        if (this.rdoCreatePrimaryNewKey.isSelected()) {
78
            this.txtPrimaryKeyName.setEnabled(true);
79
            this.lstFields.setEnabled(false);
80
        } else if (this.rdoUseExistingFieldAsPrimariKey.isSelected()) {
81
            this.txtPrimaryKeyName.setEnabled(false);
82
            this.lstFields.setEnabled(true);
83
        } else if (this.rdoDoNotCreatePrimaryKey.isSelected()) {
84
            this.txtPrimaryKeyName.setEnabled(false);
85
            this.lstFields.setEnabled(false);
86
        }
87 41486 jjdelcerro
    }
88 41488 jjdelcerro
89 41486 jjdelcerro
    protected void translateControls() {
90
        I18nManager i18nManager = ToolsLocator.getI18nManager();
91 41488 jjdelcerro
92 41127 jldominguez
    }
93 40435 jjdelcerro
94 41488 jjdelcerro
    public String getPrimaryKeyName() {
95
        String pkname = null;
96
        if (this.rdoCreatePrimaryNewKey.isSelected()) {
97
            pkname = this.txtPrimaryKeyName.getText();
98
99
        } else if (this.rdoUseExistingFieldAsPrimariKey.isSelected()) {
100
            pkname = (String) this.lstFields.getSelectedValue();
101 41127 jldominguez
        }
102 41488 jjdelcerro
        if (StringUtils.isBlank(pkname)) {
103 41486 jjdelcerro
            return null;
104
        }
105
        return pkname.trim();
106 41127 jldominguez
    }
107
108 40435 jjdelcerro
    public String getPanelTitle() {
109 41486 jjdelcerro
        I18nManager i18nManager = ToolsLocator.getI18nManager();
110
        return i18nManager.getTranslation("_Primary_key");
111 40435 jjdelcerro
    }
112
113
    public boolean isValidPanel() throws ExporttoPanelValidationException {
114
        return true;
115
    }
116 41127 jldominguez
117 41488 jjdelcerro
    public void enterPanel() {
118
        this.fillListOfFields();
119 41127 jldominguez
    }
120 41486 jjdelcerro
121
    public JComponent asJComponent() {
122
        return this;
123
    }
124 41488 jjdelcerro
125
    private void fillListOfFields() {
126
        try {
127
            FeatureStore source = this.provider.getSource();
128
            FeatureType sourceFeatureType = source.getDefaultFeatureType();
129
            DefaultListModel model = new DefaultListModel();
130
            for (int i = 0; i < sourceFeatureType.size(); i++) {
131
                model.addElement(sourceFeatureType.getAttributeDescriptor(i).getName());
132
            }
133
            this.lstFields.setModel(model);
134
        } catch (Exception ex) {
135
            throw new RuntimeException(ex);
136
        }
137
    }
138 40435 jjdelcerro
}