Statistics
| Revision:

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 @ 43936

History | View | Annotate | Download (8.92 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 exitPanel() {
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 enterPanel() {
128
        if( this.updateComponents ) {
129
            switch(this.parameters.getGeometryChecks()) {
130
                case ExportParametersGeometry.CHECKGEOMETRY_NONE:
131
                    this.rdbCheckNone.setSelected(true);
132
                    this.rdbCheckIsCorrupt.setSelected(false);
133
                    this.cboActionIsCorrupt.setEnabled(false);
134
                    this.rdbCheckIsValid.setSelected(false);
135
                    this.cboActionIsValid.setEnabled(false);
136
                    this.chkTryFixGeometry.setEnabled(false);
137
                    break;
138
                case ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_VALID:
139
                    this.rdbCheckNone.setSelected(false);
140
                    this.rdbCheckIsCorrupt.setSelected(false);
141
                    this.cboActionIsCorrupt.setEnabled(false);
142
                    this.rdbCheckIsValid.setSelected(true);
143
                    this.cboActionIsValid.setEnabled(true);
144
                    this.chkTryFixGeometry.setEnabled(true);
145
                    break;
146
                case ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_CORRUPT:
147
                    this.rdbCheckNone.setSelected(false);
148
                    this.rdbCheckIsCorrupt.setSelected(true);
149
                    this.cboActionIsCorrupt.setEnabled(true);
150
                    this.rdbCheckIsValid.setSelected(false);
151
                    this.cboActionIsValid.setEnabled(false);
152
                    this.chkTryFixGeometry.setEnabled(false);
153
                    break;
154
            }
155
            this.chkTryFixGeometry.setSelected( this.parameters.getTryToFixGeometry() );
156
        }
157
        this.updateComponents = false;
158
        if( this.parameters.getSourceGeometryFieldName()==null ) {
159
            this.rdbCheckIsCorrupt.setEnabled(false);
160
            this.rdbCheckIsValid.setEnabled(false);
161
            this.rdbCheckNone.setEnabled(false);
162
        } else {
163
            this.rdbCheckIsCorrupt.setEnabled(true);
164
            this.rdbCheckIsValid.setEnabled(true);
165
            this.rdbCheckNone.setEnabled(true);
166
        }
167
    }
168
    
169
    @Override
170
    public JComponent asJComponent() {
171
        return this;
172
    }
173

    
174
    public int getGeometryChecks() {
175
        if( this.rdbCheckIsCorrupt.isSelected() ) {
176
            return ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_CORRUPT;
177
        } else if( this.rdbCheckIsValid.isSelected()) {
178
            return ExportParametersGeometry.CHECKGEOMETRY_CHECK_IF_VALID;
179
        } else {
180
            return ExportParametersGeometry.CHECKGEOMETRY_NONE;
181
        }
182
    }
183

    
184
    public int getGeometryChecksAction() {
185
        try {
186
            if( this.rdbCheckIsCorrupt.isSelected() ) {
187
                CheckAction checkAction = (CheckAction)(this.cboActionIsCorrupt.getSelectedItem());
188
                return checkAction.getCode();
189
            } else if( this.rdbCheckIsValid.isSelected()) {
190
                CheckAction checkAction = (CheckAction)(this.cboActionIsValid.getSelectedItem());
191
                return checkAction.getCode();
192
            } else {
193
                return ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT;
194
            }
195
        } catch(Exception ex) {
196
            logger.warn("Can't get action for geometry check in export to JDBC.",ex);
197
            return ExportParametersGeometry.CHECKGEOMETRYACTION_ABORT;
198
        }
199
    }
200

    
201
    public boolean getTryToFixGeometry() {
202
        return this.chkTryFixGeometry.isSelected();
203
    }
204
    
205
    private void onChangeRadioButtons() {
206
        if( this.rdbCheckNone.isSelected() ) {
207
            this.cboActionIsCorrupt.setEnabled(false);
208
            this.cboActionIsValid.setEnabled(false);
209
            this.chkTryFixGeometry.setEnabled(false);
210
        } else if( this.rdbCheckIsCorrupt.isSelected() ) {
211
            this.cboActionIsCorrupt.setEnabled(true);
212
            this.cboActionIsValid.setEnabled(false);
213
            this.chkTryFixGeometry.setEnabled(false);
214
        } else if( this.rdbCheckIsValid.isSelected()) {
215
            this.cboActionIsCorrupt.setEnabled(false);
216
            this.cboActionIsValid.setEnabled(true);
217
            this.chkTryFixGeometry.setEnabled(true);
218
        }
219
    }
220
}