svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / panels / CheckGeometriesPanel.java @ 43968
History | View | Annotate | Download (8.97 KB)
1 |
package org.gvsig.export.swing.impl.panels; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import javax.swing.JComponent; |
6 |
import org.gvsig.export.ExportParameters; |
7 |
import org.gvsig.tools.ToolsLocator; |
8 |
import org.gvsig.tools.i18n.I18nManager; |
9 |
import org.slf4j.Logger; |
10 |
import org.slf4j.LoggerFactory; |
11 |
import org.gvsig.export.ExportParametersGeometry; |
12 |
import org.gvsig.export.swing.JExportProcessPanel; |
13 |
import org.gvsig.export.swing.spi.ExportPanel; |
14 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
15 |
import org.gvsig.export.swing.spi.ExportPanelsManager; |
16 |
|
17 |
public class CheckGeometriesPanel |
18 |
extends CheckGeometriesPanelView
|
19 |
implements ExportPanel
|
20 |
{ |
21 |
|
22 |
private final static Logger logger = LoggerFactory.getLogger(CheckGeometriesPanel.class); |
23 |
|
24 |
private final CheckAction[] checkActions = { |
25 |
new CheckAction("_Set_geometry_to_null", ExportParametersGeometry.CHECKGEOMETRYACTION_SET_GEOMETRY_TO_NULL), |
26 |
new CheckAction("_Skip_entire_feature", ExportParametersGeometry.CHECKGEOMETRYACTION_SKIP_FEATURE), |
27 |
new CheckAction("_Abort_process", ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT) |
28 |
}; |
29 |
private final ExportParametersGeometry parameters; |
30 |
private boolean updateComponents; |
31 |
|
32 |
private static class CheckAction { |
33 |
|
34 |
private final String label; |
35 |
private final int code; |
36 |
|
37 |
public CheckAction(String label, int code) { |
38 |
this.code = code;
|
39 |
this.label = ToolsLocator.getI18nManager().getTranslation(label);
|
40 |
} |
41 |
@Override
|
42 |
public String toString() { |
43 |
return this.label; |
44 |
} |
45 |
public int getCode() { |
46 |
return this.code; |
47 |
} |
48 |
} |
49 |
|
50 |
public CheckGeometriesPanel(
|
51 |
JExportProcessPanel processPanel, |
52 |
ExportParameters parameters |
53 |
) { |
54 |
this.parameters = (ExportParametersGeometry) parameters;
|
55 |
this.parameters.setGeometryChecks(ExportParametersGeometry.CHECKGEOMETRY_NONE);
|
56 |
this.parameters.setGeometryChecksAction(ExportParametersGeometry.CHECKGEOMETRYACTION_SET_GEOMETRY_TO_NULL);
|
57 |
this.parameters.setTryToFixGeometry(true); |
58 |
this.updateComponents = true; |
59 |
initComponents(); |
60 |
} |
61 |
|
62 |
private void initComponents() { |
63 |
this.rdbCheckIsCorrupt.addActionListener(new ActionListener() { |
64 |
@Override
|
65 |
public void actionPerformed(ActionEvent e) { |
66 |
onChangeRadioButtons(); |
67 |
} |
68 |
}); |
69 |
this.rdbCheckIsValid.addActionListener(new ActionListener() { |
70 |
@Override
|
71 |
public void actionPerformed(ActionEvent e) { |
72 |
onChangeRadioButtons(); |
73 |
} |
74 |
}); |
75 |
this.rdbCheckNone.addActionListener(new ActionListener() { |
76 |
@Override
|
77 |
public void actionPerformed(ActionEvent e) { |
78 |
onChangeRadioButtons(); |
79 |
} |
80 |
}); |
81 |
for (CheckAction checkAction : checkActions) {
|
82 |
this.cboActionIsCorrupt.addItem(checkAction);
|
83 |
this.cboActionIsValid.addItem(checkAction);
|
84 |
} |
85 |
this.rdbCheckNone.setSelected(true); |
86 |
this.rdbCheckIsValid.setSelected(true); |
87 |
this.cboActionIsValid.setSelectedItem(checkActions[2]); |
88 |
this.translate();
|
89 |
} |
90 |
|
91 |
private void translate() { |
92 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
93 |
|
94 |
this.lblHeader.setText("<html>"+i18nManager.getTranslation("_check_geometries_before_export_header")+"</html>"); |
95 |
this.rdbCheckNone.setText(i18nManager.getTranslation("_No_realizar_ninguna_comprobacion_sobre_las_geometrias")); |
96 |
this.rdbCheckIsCorrupt.setText(i18nManager.getTranslation("_Comprobar_que_la_geometria_no_este_corrupta")); |
97 |
this.rdbCheckIsValid.setText(i18nManager.getTranslation("_Comprobar_la_validez_de_las_geometrias_antes_de_insertarlas")); |
98 |
this.lblCheckIsCorrupt.setText(i18nManager.getTranslation("_Cuando_la_geometria_este_corrupta")); |
99 |
this.lblCheckIsvalid.setText(i18nManager.getTranslation("_Cuando_la_geometria_no_sea_valida")); |
100 |
this.chkTryFixGeometry.setText(i18nManager.getTranslation("_Intentar_reparar_la_geometria")); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public String getIdPanel() { |
105 |
return ExportPanelsManager.PANEL_CHECK_GEOMETRIES;
|
106 |
} |
107 |
|
108 |
@Override
|
109 |
public String getTitlePanel() { |
110 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
111 |
return i18nManager.getTranslation("_check_geometries_before_export"); |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public boolean validatePanel() throws ExportPanelValidationException { |
116 |
return true; |
117 |
} |
118 |
|
119 |
@Override
|
120 |
public void nextPanel() { |
121 |
this.parameters.setGeometryChecks(this.getGeometryChecks()); |
122 |
this.parameters.setGeometryChecksAction(this.getGeometryChecksAction()); |
123 |
this.parameters.setTryToFixGeometry(this.getTryToFixGeometry()); |
124 |
} |
125 |
|
126 |
@Override
|
127 |
public void previousPanel() { |
128 |
|
129 |
} |
130 |
|
131 |
@Override
|
132 |
public void enterPanel() { |
133 |
if( this.updateComponents ) { |
134 |
switch(this.parameters.getGeometryChecks()) { |
135 |
case ExportParametersGeometry.CHECKGEOMETRY_NONE:
|
136 |
this.rdbCheckNone.setSelected(true); |
137 |
this.rdbCheckIsCorrupt.setSelected(false); |
138 |
this.cboActionIsCorrupt.setEnabled(false); |
139 |
this.rdbCheckIsValid.setSelected(false); |
140 |
this.cboActionIsValid.setEnabled(false); |
141 |
this.chkTryFixGeometry.setEnabled(false); |
142 |
break;
|
143 |
case ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_VALID:
|
144 |
this.rdbCheckNone.setSelected(false); |
145 |
this.rdbCheckIsCorrupt.setSelected(false); |
146 |
this.cboActionIsCorrupt.setEnabled(false); |
147 |
this.rdbCheckIsValid.setSelected(true); |
148 |
this.cboActionIsValid.setEnabled(true); |
149 |
this.chkTryFixGeometry.setEnabled(true); |
150 |
break;
|
151 |
case ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_CORRUPT:
|
152 |
this.rdbCheckNone.setSelected(false); |
153 |
this.rdbCheckIsCorrupt.setSelected(true); |
154 |
this.cboActionIsCorrupt.setEnabled(true); |
155 |
this.rdbCheckIsValid.setSelected(false); |
156 |
this.cboActionIsValid.setEnabled(false); |
157 |
this.chkTryFixGeometry.setEnabled(false); |
158 |
break;
|
159 |
} |
160 |
this.chkTryFixGeometry.setSelected( this.parameters.getTryToFixGeometry() ); |
161 |
} |
162 |
this.updateComponents = false; |
163 |
if( this.parameters.getSourceGeometryFieldName()==null ) { |
164 |
this.rdbCheckIsCorrupt.setEnabled(false); |
165 |
this.rdbCheckIsValid.setEnabled(false); |
166 |
this.rdbCheckNone.setEnabled(false); |
167 |
} else {
|
168 |
this.rdbCheckIsCorrupt.setEnabled(true); |
169 |
this.rdbCheckIsValid.setEnabled(true); |
170 |
this.rdbCheckNone.setEnabled(true); |
171 |
} |
172 |
} |
173 |
|
174 |
@Override
|
175 |
public JComponent asJComponent() { |
176 |
return this; |
177 |
} |
178 |
|
179 |
public int getGeometryChecks() { |
180 |
if( this.rdbCheckIsCorrupt.isSelected() ) { |
181 |
return ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_CORRUPT;
|
182 |
} else if( this.rdbCheckIsValid.isSelected()) { |
183 |
return ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_VALID;
|
184 |
} else {
|
185 |
return ExportParametersGeometry.CHECKGEOMETRY_NONE;
|
186 |
} |
187 |
} |
188 |
|
189 |
public int getGeometryChecksAction() { |
190 |
try {
|
191 |
if( this.rdbCheckIsCorrupt.isSelected() ) { |
192 |
CheckAction checkAction = (CheckAction)(this.cboActionIsCorrupt.getSelectedItem());
|
193 |
return checkAction.getCode();
|
194 |
} else if( this.rdbCheckIsValid.isSelected()) { |
195 |
CheckAction checkAction = (CheckAction)(this.cboActionIsValid.getSelectedItem());
|
196 |
return checkAction.getCode();
|
197 |
} else {
|
198 |
return ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT;
|
199 |
} |
200 |
} catch(Exception ex) { |
201 |
logger.warn("Can't get action for geometry check in export to JDBC.",ex);
|
202 |
return ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT;
|
203 |
} |
204 |
} |
205 |
|
206 |
public boolean getTryToFixGeometry() { |
207 |
return this.chkTryFixGeometry.isSelected(); |
208 |
} |
209 |
|
210 |
private void onChangeRadioButtons() { |
211 |
if( this.rdbCheckNone.isSelected() ) { |
212 |
this.cboActionIsCorrupt.setEnabled(false); |
213 |
this.cboActionIsValid.setEnabled(false); |
214 |
this.chkTryFixGeometry.setEnabled(false); |
215 |
} else if( this.rdbCheckIsCorrupt.isSelected() ) { |
216 |
this.cboActionIsCorrupt.setEnabled(true); |
217 |
this.cboActionIsValid.setEnabled(false); |
218 |
this.chkTryFixGeometry.setEnabled(false); |
219 |
} else if( this.rdbCheckIsValid.isSelected()) { |
220 |
this.cboActionIsCorrupt.setEnabled(false); |
221 |
this.cboActionIsValid.setEnabled(true); |
222 |
this.chkTryFixGeometry.setEnabled(true); |
223 |
} |
224 |
} |
225 |
} |