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 / CheckGeometriesPanel.java @ 43020
History | View | Annotate | Download (5.85 KB)
1 | 41487 | jjdelcerro | package org.gvsig.exportto.swing.prov.jdbc.panel; |
---|---|---|---|
2 | |||
3 | import java.awt.event.ActionEvent; |
||
4 | import java.awt.event.ActionListener; |
||
5 | import javax.swing.JComponent; |
||
6 | import org.gvsig.exportto.swing.prov.jdbc.ExporrtoJDBCService; |
||
7 | 41598 | jjdelcerro | import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCOptions; |
8 | 41487 | jjdelcerro | import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
9 | import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
||
10 | import org.gvsig.tools.ToolsLocator; |
||
11 | import org.gvsig.tools.i18n.I18nManager; |
||
12 | import org.slf4j.Logger; |
||
13 | import org.slf4j.LoggerFactory; |
||
14 | |||
15 | public class CheckGeometriesPanel extends CheckGeometriesPanelLayout implements ExporttoSwingProviderPanel { |
||
16 | |||
17 | private final static Logger logger = LoggerFactory.getLogger(CheckGeometriesPanel.class); |
||
18 | |||
19 | 41598 | jjdelcerro | private final ExporttoJDBCOptions provider; |
20 | 41487 | jjdelcerro | |
21 | private final CheckAction[] checkActions = { |
||
22 | new CheckAction("_Set_geometry_to_null", ExporrtoJDBCService.ACTION_SET_GEOMETRY_TO_NULL), |
||
23 | new CheckAction("_Skip_entire_feature", ExporrtoJDBCService.ACTION_SKIP_FEATURE), |
||
24 | new CheckAction("_Abort_process", ExporrtoJDBCService.ACTION_ABORT) |
||
25 | }; |
||
26 | |||
27 | private static class CheckAction { |
||
28 | |||
29 | private final String label; |
||
30 | private final int code; |
||
31 | |||
32 | public CheckAction(String label, int code) { |
||
33 | this.code = code;
|
||
34 | this.label = ToolsLocator.getI18nManager().getTranslation(label);
|
||
35 | } |
||
36 | @Override
|
||
37 | public String toString() { |
||
38 | return this.label; |
||
39 | } |
||
40 | public int getCode() { |
||
41 | return this.code; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | 41598 | jjdelcerro | public CheckGeometriesPanel(ExporttoJDBCOptions provider) {
|
46 | 41487 | jjdelcerro | this.provider = provider;
|
47 | initComponents(); |
||
48 | } |
||
49 | |||
50 | private void initComponents() { |
||
51 | this.rdbCheckIsCorrupt.addActionListener(new ActionListener() { |
||
52 | public void actionPerformed(ActionEvent e) { |
||
53 | onChangeRadioButtons(); |
||
54 | } |
||
55 | }); |
||
56 | this.rdbCheckIsValid.addActionListener(new ActionListener() { |
||
57 | public void actionPerformed(ActionEvent e) { |
||
58 | onChangeRadioButtons(); |
||
59 | } |
||
60 | }); |
||
61 | this.rdbCheckNone.addActionListener(new ActionListener() { |
||
62 | public void actionPerformed(ActionEvent e) { |
||
63 | onChangeRadioButtons(); |
||
64 | } |
||
65 | }); |
||
66 | for (CheckAction checkAction : checkActions) {
|
||
67 | this.cboActionIsCorrupt.addItem(checkAction);
|
||
68 | this.cboActionIsValid.addItem(checkAction);
|
||
69 | } |
||
70 | 41492 | jjdelcerro | this.rdbCheckNone.setSelected(true); |
71 | 43020 | jjdelcerro | this.rdbCheckIsValid.setSelected(true); |
72 | this.cboActionIsValid.setSelectedItem(checkActions[2]); |
||
73 | 41728 | jjdelcerro | this.translate();
|
74 | 41487 | jjdelcerro | } |
75 | |||
76 | 41728 | jjdelcerro | private void translate() { |
77 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
78 | |||
79 | this.lblHeader.setText("<html>"+i18nManager.getTranslation("_check_geometries_before_export_header")+"</html>"); |
||
80 | this.rdbCheckNone.setText(i18nManager.getTranslation("_No_realizar_ninguna_comprobacion_sobre_las_geometrias")); |
||
81 | this.rdbCheckIsCorrupt.setText(i18nManager.getTranslation("_Comprobar_que_la_geometria_no_este_corrupta")); |
||
82 | this.rdbCheckIsValid.setText(i18nManager.getTranslation("_Comprobar_la_validez_de_las_geometrias_antes_de_insertarlas")); |
||
83 | this.lblCheckIsCorrupt.setText(i18nManager.getTranslation("_Cuando_la_geometria_este_corrupta")); |
||
84 | this.lblCheckIsvalid.setText(i18nManager.getTranslation("_Cuando_la_geometria_no_sea_valida")); |
||
85 | this.chkTryFixGeometry.setText(i18nManager.getTranslation("_Intentar_reparar_la_geometria")); |
||
86 | } |
||
87 | |||
88 | 41487 | jjdelcerro | public String getPanelTitle() { |
89 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
90 | 41728 | jjdelcerro | return i18nManager.getTranslation("_check_geometries_before_export"); |
91 | 41638 | jjdelcerro | } |
92 | 41487 | jjdelcerro | |
93 | public boolean isValidPanel() throws ExporttoPanelValidationException { |
||
94 | return true; |
||
95 | } |
||
96 | 41488 | jjdelcerro | |
97 | public void enterPanel() { |
||
98 | // Default do nothing
|
||
99 | } |
||
100 | |||
101 | 41487 | jjdelcerro | public JComponent asJComponent() { |
102 | return this; |
||
103 | } |
||
104 | |||
105 | public int getGeometryChecks() { |
||
106 | if( this.rdbCheckIsCorrupt.isSelected() ) { |
||
107 | return ExporrtoJDBCService.CHECK_IF_CORRUPT;
|
||
108 | } else if( this.rdbCheckIsValid.isSelected()) { |
||
109 | return ExporrtoJDBCService.CHECK_IF_VALID;
|
||
110 | } else {
|
||
111 | return ExporrtoJDBCService.CHECK_NONE;
|
||
112 | } |
||
113 | } |
||
114 | |||
115 | public int getGeometryChecksAction() { |
||
116 | try {
|
||
117 | if( this.rdbCheckIsCorrupt.isSelected() ) { |
||
118 | CheckAction checkAction = (CheckAction)(this.cboActionIsCorrupt.getSelectedItem());
|
||
119 | return checkAction.getCode();
|
||
120 | } else if( this.rdbCheckIsValid.isSelected()) { |
||
121 | CheckAction checkAction = (CheckAction)(this.cboActionIsValid.getSelectedItem());
|
||
122 | return checkAction.getCode();
|
||
123 | } else {
|
||
124 | return ExporrtoJDBCService.ACTION_ABORT;
|
||
125 | } |
||
126 | } catch(Exception ex) { |
||
127 | logger.warn("Can't get action for geometry check in export to JDBC.",ex);
|
||
128 | return ExporrtoJDBCService.ACTION_ABORT;
|
||
129 | } |
||
130 | } |
||
131 | |||
132 | 41488 | jjdelcerro | public boolean getTryToFixGeometry() { |
133 | return this.chkTryFixGeometry.isSelected(); |
||
134 | } |
||
135 | |||
136 | 41487 | jjdelcerro | private void onChangeRadioButtons() { |
137 | if( this.rdbCheckNone.isSelected() ) { |
||
138 | this.cboActionIsCorrupt.setEnabled(false); |
||
139 | this.cboActionIsValid.setEnabled(false); |
||
140 | 41488 | jjdelcerro | this.chkTryFixGeometry.setEnabled(false); |
141 | 41487 | jjdelcerro | } else if( this.rdbCheckIsCorrupt.isSelected() ) { |
142 | this.cboActionIsCorrupt.setEnabled(true); |
||
143 | this.cboActionIsValid.setEnabled(false); |
||
144 | 41488 | jjdelcerro | this.chkTryFixGeometry.setEnabled(false); |
145 | 41487 | jjdelcerro | } else if( this.rdbCheckIsValid.isSelected()) { |
146 | this.cboActionIsCorrupt.setEnabled(false); |
||
147 | this.cboActionIsValid.setEnabled(true); |
||
148 | 41488 | jjdelcerro | this.chkTryFixGeometry.setEnabled(true); |
149 | 41487 | jjdelcerro | } |
150 | } |
||
151 | } |