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 @ 43020
History | View | Annotate | Download (6.4 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.exportto.swing.prov.jdbc.panel; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import javax.swing.DefaultListModel; |
28 |
import javax.swing.JComponent; |
29 |
import org.apache.commons.lang3.StringUtils; |
30 |
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCOptions; |
31 |
|
32 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
33 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
37 |
import org.gvsig.tools.ToolsLocator; |
38 |
import org.gvsig.tools.i18n.I18nManager; |
39 |
|
40 |
/**
|
41 |
* @author gvSIG Team
|
42 |
* @version $Id$
|
43 |
*
|
44 |
*/
|
45 |
public class SelectPkPanel extends SelectPkPanelLayout implements ExporttoSwingProviderPanel { |
46 |
|
47 |
private static final long serialVersionUID = 2652404227373508779L; |
48 |
|
49 |
private ExporttoJDBCOptions provider;
|
50 |
|
51 |
public SelectPkPanel(ExporttoJDBCOptions provider) {
|
52 |
this.provider = provider;
|
53 |
initComponents(); |
54 |
} |
55 |
|
56 |
protected void initComponents() { |
57 |
this.rdoCreatePrimaryNewKey.addActionListener(new ActionListener() { |
58 |
public void actionPerformed(ActionEvent e) { |
59 |
onSelect(); |
60 |
} |
61 |
}); |
62 |
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 |
this.rdoCreatePrimaryNewKey.setSelected(true); |
73 |
this.translate();
|
74 |
} |
75 |
|
76 |
private void translate() { |
77 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
78 |
|
79 |
this.lblHeader.setText("<html>"+i18nManager.getTranslation("_Primary_key_header")+"</html>"); |
80 |
this.lblQuestion.setText(i18nManager.getTranslation("_Desea_crear_una_clave_primaria")); |
81 |
this.rdoCreatePrimaryNewKey.setText(i18nManager.getTranslation("_Generar_una_clave_primaria_con_un_serial")); |
82 |
this.lblPrimaryKeyName.setText(i18nManager.getTranslation("_Indique_el_nombre_a_usar_para_la_clave_primaria")); |
83 |
this.rdoUseExistingFieldAsPrimariKey.setText(i18nManager.getTranslation("_Utilizar_un_campo_existente_como_clave_primaria")); |
84 |
this.lblSelectFieldAsPrimaryKey.setText(i18nManager.getTranslation("_Seleccione_el_campo_a_usar_como_clave_primaria")); |
85 |
this.rdoDoNotCreatePrimaryKey.setText(i18nManager.getTranslation("_No_hacer_nada_en_relacion_a_la_creacion_de_la_clave_primaria")); |
86 |
} |
87 |
|
88 |
|
89 |
private void onSelect() { |
90 |
if (this.rdoCreatePrimaryNewKey.isSelected()) { |
91 |
this.txtPrimaryKeyName.setEnabled(true); |
92 |
this.lstFields.setEnabled(false); |
93 |
} else if (this.rdoUseExistingFieldAsPrimariKey.isSelected()) { |
94 |
this.txtPrimaryKeyName.setEnabled(false); |
95 |
this.lstFields.setEnabled(true); |
96 |
} else if (this.rdoDoNotCreatePrimaryKey.isSelected()) { |
97 |
this.txtPrimaryKeyName.setEnabled(false); |
98 |
this.lstFields.setEnabled(false); |
99 |
} |
100 |
} |
101 |
|
102 |
public String getPrimaryKeyName() { |
103 |
String pkname = null; |
104 |
if (this.rdoCreatePrimaryNewKey.isSelected()) { |
105 |
pkname = this.txtPrimaryKeyName.getText();
|
106 |
|
107 |
} else if (this.rdoUseExistingFieldAsPrimariKey.isSelected()) { |
108 |
pkname = (String) this.lstFields.getSelectedValue(); |
109 |
} |
110 |
if (StringUtils.isBlank(pkname)) {
|
111 |
return null; |
112 |
} |
113 |
return pkname.trim();
|
114 |
} |
115 |
|
116 |
public String getPanelTitle() { |
117 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
118 |
return i18nManager.getTranslation("_Primary_key"); |
119 |
} |
120 |
|
121 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
122 |
return true; |
123 |
} |
124 |
|
125 |
public void enterPanel() { |
126 |
this.fillListOfFields();
|
127 |
if( !this.provider.canCreatetable() ) { |
128 |
this.rdoCreatePrimaryNewKey.setEnabled(false); |
129 |
this.rdoUseExistingFieldAsPrimariKey.setEnabled(false); |
130 |
this.rdoDoNotCreatePrimaryKey.setEnabled(false); |
131 |
|
132 |
this.rdoCreatePrimaryNewKey.setSelected(false); |
133 |
this.rdoUseExistingFieldAsPrimariKey.setSelected(false); |
134 |
this.rdoDoNotCreatePrimaryKey.setSelected(false); |
135 |
} else {
|
136 |
this.rdoCreatePrimaryNewKey.setEnabled(true); |
137 |
this.rdoUseExistingFieldAsPrimariKey.setEnabled(true); |
138 |
this.rdoDoNotCreatePrimaryKey.setEnabled(true); |
139 |
|
140 |
if (! this.rdoCreatePrimaryNewKey.isSelected() |
141 |
&& ! this.rdoUseExistingFieldAsPrimariKey.isSelected()
|
142 |
&& ! this.rdoDoNotCreatePrimaryKey.isSelected()) {
|
143 |
this.rdoCreatePrimaryNewKey.setSelected(true); |
144 |
} |
145 |
} |
146 |
} |
147 |
|
148 |
public JComponent asJComponent() { |
149 |
return this; |
150 |
} |
151 |
|
152 |
private void fillListOfFields() { |
153 |
try {
|
154 |
FeatureStore source = this.provider.getSource();
|
155 |
FeatureType sourceFeatureType = source.getDefaultFeatureType(); |
156 |
DefaultListModel model = new DefaultListModel(); |
157 |
for (int i = 0; i < sourceFeatureType.size(); i++) { |
158 |
model.addElement(sourceFeatureType.getAttributeDescriptor(i).getName()); |
159 |
} |
160 |
this.lstFields.setModel(model);
|
161 |
} catch (Exception ex) { |
162 |
throw new RuntimeException(ex); |
163 |
} |
164 |
} |
165 |
} |