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 @ 41638
History | View | Annotate | Download (4.81 KB)
1 |
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 |
import org.gvsig.exportto.swing.prov.jdbc.ExporttoJDBCOptions; |
8 |
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 |
private final ExporttoJDBCOptions provider; |
20 |
|
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 |
public CheckGeometriesPanel(ExporttoJDBCOptions provider) {
|
46 |
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 |
this.rdbCheckNone.setSelected(true); |
71 |
} |
72 |
|
73 |
public String getPanelTitle() { |
74 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
75 |
return i18nManager.getTranslation("check_geometries_before_export"); |
76 |
} |
77 |
|
78 |
public boolean isValidPanel() throws ExporttoPanelValidationException { |
79 |
return true; |
80 |
} |
81 |
|
82 |
public void enterPanel() { |
83 |
// Default do nothing
|
84 |
} |
85 |
|
86 |
public JComponent asJComponent() { |
87 |
return this; |
88 |
} |
89 |
|
90 |
public int getGeometryChecks() { |
91 |
if( this.rdbCheckIsCorrupt.isSelected() ) { |
92 |
return ExporrtoJDBCService.CHECK_IF_CORRUPT;
|
93 |
} else if( this.rdbCheckIsValid.isSelected()) { |
94 |
return ExporrtoJDBCService.CHECK_IF_VALID;
|
95 |
} else {
|
96 |
return ExporrtoJDBCService.CHECK_NONE;
|
97 |
} |
98 |
} |
99 |
|
100 |
public int getGeometryChecksAction() { |
101 |
try {
|
102 |
if( this.rdbCheckIsCorrupt.isSelected() ) { |
103 |
CheckAction checkAction = (CheckAction)(this.cboActionIsCorrupt.getSelectedItem());
|
104 |
return checkAction.getCode();
|
105 |
} else if( this.rdbCheckIsValid.isSelected()) { |
106 |
CheckAction checkAction = (CheckAction)(this.cboActionIsValid.getSelectedItem());
|
107 |
return checkAction.getCode();
|
108 |
} else {
|
109 |
return ExporrtoJDBCService.ACTION_ABORT;
|
110 |
} |
111 |
} catch(Exception ex) { |
112 |
logger.warn("Can't get action for geometry check in export to JDBC.",ex);
|
113 |
return ExporrtoJDBCService.ACTION_ABORT;
|
114 |
} |
115 |
} |
116 |
|
117 |
public boolean getTryToFixGeometry() { |
118 |
return this.chkTryFixGeometry.isSelected(); |
119 |
} |
120 |
|
121 |
private void onChangeRadioButtons() { |
122 |
if( this.rdbCheckNone.isSelected() ) { |
123 |
this.cboActionIsCorrupt.setEnabled(false); |
124 |
this.cboActionIsValid.setEnabled(false); |
125 |
this.chkTryFixGeometry.setEnabled(false); |
126 |
} else if( this.rdbCheckIsCorrupt.isSelected() ) { |
127 |
this.cboActionIsCorrupt.setEnabled(true); |
128 |
this.cboActionIsValid.setEnabled(false); |
129 |
this.chkTryFixGeometry.setEnabled(false); |
130 |
} else if( this.rdbCheckIsValid.isSelected()) { |
131 |
this.cboActionIsCorrupt.setEnabled(false); |
132 |
this.cboActionIsValid.setEnabled(true); |
133 |
this.chkTryFixGeometry.setEnabled(true); |
134 |
} |
135 |
} |
136 |
} |