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 / export / jdbc / swing / panels / SelectPkPanel.java @ 44198
History | View | Annotate | Download (7.37 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 | 43925 | jjdelcerro | package org.gvsig.export.jdbc.swing.panels; |
24 | 40435 | jjdelcerro | |
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 | 43397 | jjdelcerro | import org.apache.commons.lang3.ArrayUtils; |
30 | 41486 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
31 | 43925 | jjdelcerro | import org.gvsig.export.jdbc.service.ExportJDBCParameters; |
32 | import org.gvsig.export.swing.JExportProcessPanel; |
||
33 | import org.gvsig.export.swing.spi.ExportPanel; |
||
34 | import org.gvsig.export.swing.spi.ExportPanelValidationException; |
||
35 | 41127 | jldominguez | |
36 | 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 | 43925 | jjdelcerro | public class SelectPkPanel |
46 | extends SelectPkPanelLayout
|
||
47 | implements ExportPanel
|
||
48 | { |
||
49 | 40435 | jjdelcerro | |
50 | private static final long serialVersionUID = 2652404227373508779L; |
||
51 | 41488 | jjdelcerro | |
52 | 43925 | jjdelcerro | private final ExportJDBCParameters parameters; |
53 | private final JExportProcessPanel processPanel; |
||
54 | 41488 | jjdelcerro | |
55 | 43925 | jjdelcerro | public SelectPkPanel(
|
56 | JExportProcessPanel processPanel, |
||
57 | ExportJDBCParameters parameters |
||
58 | ) { |
||
59 | this.processPanel = processPanel;
|
||
60 | this.parameters = parameters;
|
||
61 | 41492 | jjdelcerro | initComponents(); |
62 | 41127 | jldominguez | } |
63 | 41488 | jjdelcerro | |
64 | 43925 | jjdelcerro | private void initComponents() { |
65 | 41488 | jjdelcerro | this.rdoCreatePrimaryNewKey.addActionListener(new ActionListener() { |
66 | 43397 | jjdelcerro | @Override
|
67 | 41486 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
68 | 41488 | jjdelcerro | onSelect(); |
69 | 41486 | jjdelcerro | } |
70 | }); |
||
71 | 41488 | jjdelcerro | this.rdoUseExistingFieldAsPrimariKey.addActionListener(new ActionListener() { |
72 | 43397 | jjdelcerro | @Override
|
73 | 41488 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
74 | onSelect(); |
||
75 | } |
||
76 | }); |
||
77 | this.rdoDoNotCreatePrimaryKey.addActionListener(new ActionListener() { |
||
78 | 43397 | jjdelcerro | @Override
|
79 | 41488 | jjdelcerro | public void actionPerformed(ActionEvent e) { |
80 | onSelect(); |
||
81 | } |
||
82 | }); |
||
83 | 43397 | jjdelcerro | if( this.hasSourcePrimaryKey() ) { |
84 | this.rdoDoNotCreatePrimaryKey.setSelected(true); |
||
85 | } else {
|
||
86 | this.rdoCreatePrimaryNewKey.setSelected(true); |
||
87 | } |
||
88 | 41728 | jjdelcerro | this.translate();
|
89 | 41486 | jjdelcerro | } |
90 | 41728 | jjdelcerro | |
91 | private void translate() { |
||
92 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
93 | |||
94 | this.lblHeader.setText("<html>"+i18nManager.getTranslation("_Primary_key_header")+"</html>"); |
||
95 | this.lblQuestion.setText(i18nManager.getTranslation("_Desea_crear_una_clave_primaria")); |
||
96 | this.rdoCreatePrimaryNewKey.setText(i18nManager.getTranslation("_Generar_una_clave_primaria_con_un_serial")); |
||
97 | this.lblPrimaryKeyName.setText(i18nManager.getTranslation("_Indique_el_nombre_a_usar_para_la_clave_primaria")); |
||
98 | this.rdoUseExistingFieldAsPrimariKey.setText(i18nManager.getTranslation("_Utilizar_un_campo_existente_como_clave_primaria")); |
||
99 | this.lblSelectFieldAsPrimaryKey.setText(i18nManager.getTranslation("_Seleccione_el_campo_a_usar_como_clave_primaria")); |
||
100 | this.rdoDoNotCreatePrimaryKey.setText(i18nManager.getTranslation("_No_hacer_nada_en_relacion_a_la_creacion_de_la_clave_primaria")); |
||
101 | } |
||
102 | 41488 | jjdelcerro | |
103 | 41728 | jjdelcerro | |
104 | 41488 | jjdelcerro | private void onSelect() { |
105 | if (this.rdoCreatePrimaryNewKey.isSelected()) { |
||
106 | this.txtPrimaryKeyName.setEnabled(true); |
||
107 | this.lstFields.setEnabled(false); |
||
108 | } else if (this.rdoUseExistingFieldAsPrimariKey.isSelected()) { |
||
109 | this.txtPrimaryKeyName.setEnabled(false); |
||
110 | this.lstFields.setEnabled(true); |
||
111 | } else if (this.rdoDoNotCreatePrimaryKey.isSelected()) { |
||
112 | this.txtPrimaryKeyName.setEnabled(false); |
||
113 | this.lstFields.setEnabled(false); |
||
114 | } |
||
115 | 41486 | jjdelcerro | } |
116 | 41488 | jjdelcerro | |
117 | public String getPrimaryKeyName() { |
||
118 | String pkname = null; |
||
119 | if (this.rdoCreatePrimaryNewKey.isSelected()) { |
||
120 | pkname = this.txtPrimaryKeyName.getText();
|
||
121 | |||
122 | } else if (this.rdoUseExistingFieldAsPrimariKey.isSelected()) { |
||
123 | pkname = (String) this.lstFields.getSelectedValue(); |
||
124 | 41127 | jldominguez | } |
125 | 41488 | jjdelcerro | if (StringUtils.isBlank(pkname)) {
|
126 | 41486 | jjdelcerro | return null; |
127 | } |
||
128 | return pkname.trim();
|
||
129 | 41127 | jldominguez | } |
130 | |||
131 | 43397 | jjdelcerro | @Override
|
132 | 43925 | jjdelcerro | public String getIdPanel() { |
133 | return this.getClass().getCanonicalName(); |
||
134 | } |
||
135 | |||
136 | @Override
|
||
137 | public String getTitlePanel() { |
||
138 | 41486 | jjdelcerro | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
139 | return i18nManager.getTranslation("_Primary_key"); |
||
140 | 40435 | jjdelcerro | } |
141 | |||
142 | 43397 | jjdelcerro | @Override
|
143 | 43968 | jjdelcerro | public void previousPanel() { |
144 | |||
145 | } |
||
146 | |||
147 | @Override
|
||
148 | public void nextPanel() { |
||
149 | 43925 | jjdelcerro | this.parameters.setPrimaryKey(this.getPrimaryKeyName()); |
150 | } |
||
151 | |||
152 | @Override
|
||
153 | public boolean validatePanel() throws ExportPanelValidationException { |
||
154 | 40435 | jjdelcerro | return true; |
155 | } |
||
156 | 43397 | jjdelcerro | |
157 | private boolean hasSourcePrimaryKey() { |
||
158 | 43925 | jjdelcerro | FeatureType featureType = this.parameters.getSourceFeatureType();
|
159 | 43920 | jjdelcerro | return ! ArrayUtils.isEmpty(featureType.getPrimaryKey());
|
160 | 43397 | jjdelcerro | } |
161 | 41127 | jldominguez | |
162 | 43397 | jjdelcerro | @Override
|
163 | 41488 | jjdelcerro | public void enterPanel() { |
164 | this.fillListOfFields();
|
||
165 | 43925 | jjdelcerro | if( !this.parameters.canCreatetable() ) { |
166 | 41654 | jjdelcerro | this.rdoCreatePrimaryNewKey.setEnabled(false); |
167 | this.rdoUseExistingFieldAsPrimariKey.setEnabled(false); |
||
168 | this.rdoDoNotCreatePrimaryKey.setEnabled(false); |
||
169 | |||
170 | this.rdoCreatePrimaryNewKey.setSelected(false); |
||
171 | this.rdoUseExistingFieldAsPrimariKey.setSelected(false); |
||
172 | this.rdoDoNotCreatePrimaryKey.setSelected(false); |
||
173 | } else {
|
||
174 | this.rdoCreatePrimaryNewKey.setEnabled(true); |
||
175 | this.rdoUseExistingFieldAsPrimariKey.setEnabled(true); |
||
176 | this.rdoDoNotCreatePrimaryKey.setEnabled(true); |
||
177 | |||
178 | if (! this.rdoCreatePrimaryNewKey.isSelected() |
||
179 | && ! this.rdoUseExistingFieldAsPrimariKey.isSelected()
|
||
180 | && ! this.rdoDoNotCreatePrimaryKey.isSelected()) {
|
||
181 | 43397 | jjdelcerro | if( this.hasSourcePrimaryKey() ) { |
182 | this.rdoDoNotCreatePrimaryKey.setSelected(true); |
||
183 | } else {
|
||
184 | this.rdoCreatePrimaryNewKey.setSelected(true); |
||
185 | } |
||
186 | 41654 | jjdelcerro | } |
187 | } |
||
188 | 41127 | jldominguez | } |
189 | 41486 | jjdelcerro | |
190 | 43397 | jjdelcerro | @Override
|
191 | 41486 | jjdelcerro | public JComponent asJComponent() { |
192 | return this; |
||
193 | } |
||
194 | 41488 | jjdelcerro | |
195 | private void fillListOfFields() { |
||
196 | try {
|
||
197 | 43925 | jjdelcerro | FeatureType sourceFeatureType = this.parameters.getSourceFeatureType();
|
198 | 41488 | jjdelcerro | DefaultListModel model = new DefaultListModel(); |
199 | for (int i = 0; i < sourceFeatureType.size(); i++) { |
||
200 | model.addElement(sourceFeatureType.getAttributeDescriptor(i).getName()); |
||
201 | } |
||
202 | this.lstFields.setModel(model);
|
||
203 | } catch (Exception ex) { |
||
204 | throw new RuntimeException(ex); |
||
205 | } |
||
206 | } |
||
207 | 40435 | jjdelcerro | } |