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.csv / src / main / java / org / gvsig / export / csv / swing / panels / CSVExportParametersPanel.java @ 44411
History | View | Annotate | Download (9.32 KB)
1 | 44310 | omartinez | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | package org.gvsig.export.csv.swing.panels; |
||
25 | |||
26 | import javax.swing.DefaultComboBoxModel; |
||
27 | 44386 | omartinez | import javax.swing.JComboBox; |
28 | 44310 | omartinez | import javax.swing.JComponent; |
29 | 44411 | omartinez | import org.apache.commons.lang3.StringUtils; |
30 | 44310 | omartinez | import org.gvsig.tools.ToolsLocator; |
31 | import org.gvsig.tools.dynobject.DynField; |
||
32 | import org.gvsig.tools.dynobject.DynObjectValueItem; |
||
33 | import org.gvsig.tools.dynobject.DynStruct; |
||
34 | import org.gvsig.tools.i18n.I18nManager; |
||
35 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
36 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
37 | import org.gvsig.export.ExportParameters; |
||
38 | import org.gvsig.export.swing.JExportProcessPanel; |
||
39 | import org.gvsig.export.swing.spi.ExportPanel; |
||
40 | import org.gvsig.export.swing.spi.ExportPanelValidationException; |
||
41 | import org.slf4j.Logger; |
||
42 | import org.slf4j.LoggerFactory; |
||
43 | import org.gvsig.export.csv.service.ExportCSVParameters; |
||
44 | 44386 | omartinez | import org.gvsig.fmap.dal.DataStoreParameters; |
45 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
46 | 44310 | omartinez | |
47 | /**
|
||
48 | * @author gvSIG Team
|
||
49 | * @version $Id$
|
||
50 | *
|
||
51 | */
|
||
52 | public class CSVExportParametersPanel |
||
53 | extends CSVExportParametersPanelView
|
||
54 | implements ExportPanel {
|
||
55 | |||
56 | private static final Logger LOG = LoggerFactory.getLogger(CSVExportParametersPanel.class); |
||
57 | |||
58 | private final ExportCSVParameters parameters; |
||
59 | private final JExportProcessPanel processPanel; |
||
60 | |||
61 | public CSVExportParametersPanel(JExportProcessPanel processPanel, ExportParameters parameters) {
|
||
62 | super();
|
||
63 | this.processPanel = processPanel;
|
||
64 | this.parameters = (ExportCSVParameters) parameters;
|
||
65 | this.initComponents();
|
||
66 | } |
||
67 | |||
68 | class ComboItem { |
||
69 | |||
70 | private String key; |
||
71 | private String value; |
||
72 | |||
73 | public ComboItem(String key, String value) { |
||
74 | this.key = key;
|
||
75 | this.value = value;
|
||
76 | } |
||
77 | |||
78 | @Override
|
||
79 | public String toString() { |
||
80 | return key;
|
||
81 | } |
||
82 | |||
83 | public String getKey() { |
||
84 | return key;
|
||
85 | } |
||
86 | |||
87 | public String getValue() { |
||
88 | return value;
|
||
89 | } |
||
90 | } |
||
91 | |||
92 | private DefaultComboBoxModel fillComboBoxWithAvaibleParameters(String dynFieldValue) { |
||
93 | DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition("CSVNewStoreParameters");
|
||
94 | DynField dynField = parametersDefinition.getDynField(dynFieldValue); |
||
95 | |||
96 | DefaultComboBoxModel dcm = new DefaultComboBoxModel(); |
||
97 | DynObjectValueItem[] availableValues = dynField.getAvailableValues();
|
||
98 | for (DynObjectValueItem availableValue : availableValues) {
|
||
99 | |||
100 | Object item = new ComboItem(availableValue.getLabel(), (String) availableValue.getValue()); |
||
101 | dcm.addElement(item); |
||
102 | } |
||
103 | return dcm;
|
||
104 | |||
105 | } |
||
106 | |||
107 | private void initComponents() { |
||
108 | DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition("CSVNewStoreParameters");
|
||
109 | this.cmbProfile.setModel(this.fillComboBoxWithAvaibleParameters("profile")); |
||
110 | this.cmbProfile.setSelectedIndex(0); |
||
111 | 44395 | omartinez | |
112 | //TODO: set params from previous source store in case of null values
|
||
113 | //it can be null
|
||
114 | //DataStoreParameters params = this.parameters.getSourceFeatureStore().getParameters();
|
||
115 | 44386 | omartinez | // if (params instanceof CSVStoreParameters) {
|
116 | // CSVStoreParameters sparams = (CSVStoreParameters) params;
|
||
117 | // CsvPreference profile = CSVStoreParameters.getPredefinedCSVPreferences(sparams);
|
||
118 | //
|
||
119 | // CommentMatcher commentMarker = profile.getCommentMatcher();
|
||
120 | // this.txtCommentStartMarker.setText(commentMarker.toString());
|
||
121 | //
|
||
122 | // int delimeterChar = profile.getDelimiterChar();
|
||
123 | // this.txtDelimiter.setText(String.valueOf(delimeterChar));
|
||
124 | //
|
||
125 | // CsvEncoder encoder = profile.getEncoder();
|
||
126 | //
|
||
127 | // String endOfLineSymbols = profile.getEndOfLineSymbols();
|
||
128 | // this.txtEscapeCharacter.setText(endOfLineSymbols);
|
||
129 | //
|
||
130 | // int quoteChar = profile.getQuoteChar();
|
||
131 | // this.txtQuoteCharacter.setText(String.valueOf(quoteChar));
|
||
132 | //
|
||
133 | // QuoteMode quoteMode = profile.getQuoteMode();
|
||
134 | // this.txtQuoteCharacter.setText(quoteMode.toString());
|
||
135 | // } else {
|
||
136 | // // default values
|
||
137 | //
|
||
138 | // //this.cmbLocale.setSelectedItem(CSVStoreParameters.);
|
||
139 | // }
|
||
140 | 44310 | omartinez | |
141 | this.cmbQuotePolicy.setModel(this.fillComboBoxWithAvaibleParameters("quotePolicy")); |
||
142 | this.cmbQuotePolicy.setSelectedIndex(0); |
||
143 | |||
144 | this.cmbLocale.setModel(this.fillComboBoxWithAvaibleParameters("locale")); |
||
145 | this.cmbLocale.setSelectedIndex(0); |
||
146 | |||
147 | this.translate();
|
||
148 | } |
||
149 | |||
150 | private void translate() { |
||
151 | ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
||
152 | i18nc.translate(this.lblProfile);
|
||
153 | i18nc.translate(this.lblQuotePolicy);
|
||
154 | i18nc.translate(this.lblLocale);
|
||
155 | i18nc.translate(this.lblRecordSeparator);
|
||
156 | i18nc.translate(this.lblDelimiter);
|
||
157 | i18nc.translate(this.lblQuoteCharacter);
|
||
158 | i18nc.translate(this.lblCommentStartMarker);
|
||
159 | |||
160 | } |
||
161 | |||
162 | public String getParameterLocale() { |
||
163 | ComboItem item = (ComboItem) this.cmbLocale.getSelectedItem();
|
||
164 | if (item == null) { |
||
165 | return null; |
||
166 | } |
||
167 | return item.getValue();
|
||
168 | } |
||
169 | |||
170 | public String getParameterQuotePolicy() { |
||
171 | ComboItem item = (ComboItem) this.cmbQuotePolicy.getSelectedItem();
|
||
172 | if (item == null) { |
||
173 | return null; |
||
174 | } |
||
175 | return item.getValue();
|
||
176 | } |
||
177 | |||
178 | public String getParameterProfile() { |
||
179 | ComboItem item = (ComboItem) this.cmbProfile.getSelectedItem();
|
||
180 | if (item == null) { |
||
181 | return null; |
||
182 | } |
||
183 | return item.getValue();
|
||
184 | } |
||
185 | |||
186 | public String getParameterRecordSeparator() { |
||
187 | return this.txtRecordSeparator.getText(); |
||
188 | } |
||
189 | |||
190 | public String getParameterDelimiter() { |
||
191 | return this.txtDelimiter.getText(); |
||
192 | } |
||
193 | |||
194 | public String getParameterQuoteCharacter() { |
||
195 | return this.txtQuoteCharacter.getText(); |
||
196 | } |
||
197 | |||
198 | public String getParameterCommentStartMarker() { |
||
199 | return this.txtCommentStartMarker.getText(); |
||
200 | } |
||
201 | |||
202 | @Override
|
||
203 | public JComponent asJComponent() { |
||
204 | return this; |
||
205 | } |
||
206 | |||
207 | @Override
|
||
208 | public String getIdPanel() { |
||
209 | return this.getClass().getSimpleName(); |
||
210 | } |
||
211 | |||
212 | @Override
|
||
213 | public String getTitlePanel() { |
||
214 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
215 | return i18nManager.getTranslation("_Select_encoding"); |
||
216 | } |
||
217 | |||
218 | @Override
|
||
219 | public boolean validatePanel() throws ExportPanelValidationException { |
||
220 | return true; |
||
221 | } |
||
222 | |||
223 | @Override
|
||
224 | public void enterPanel() { |
||
225 | 44386 | omartinez | FeatureStore csvStore = this.parameters.getSourceFeatureStore();
|
226 | DataStoreParameters sparams = csvStore.getParameters(); |
||
227 | |||
228 | 44411 | omartinez | this.setSelectedStringValue(cmbProfile, this.parameters.getProfile()); |
229 | this.setSelectedStringValue(cmbLocale, this.parameters.getLocale()); |
||
230 | this.setSelectedStringValue(cmbQuotePolicy, this.parameters.getQuotePolicy()); |
||
231 | 44386 | omartinez | |
232 | 44315 | omartinez | this.txtRecordSeparator.setText(this.parameters.getRecordSeparator()); |
233 | this.txtDelimiter.setText(this.parameters.getDelimiter()); |
||
234 | this.txtQuoteCharacter.setText(this.parameters.getQuoteCharacter()); |
||
235 | this.txtCommentStartMarker.setText(this.parameters.getCommentStartMarker()); |
||
236 | 44310 | omartinez | } |
237 | |||
238 | @Override
|
||
239 | public void previousPanel() { |
||
240 | |||
241 | } |
||
242 | |||
243 | 44411 | omartinez | private void setSelectedStringValue(JComboBox comboBox, String value) { |
244 | 44386 | omartinez | |
245 | ComboItem item; |
||
246 | for (int i = 0; i < comboBox.getItemCount(); i++) { |
||
247 | item = (ComboItem) comboBox.getItemAt(i); |
||
248 | 44411 | omartinez | if (StringUtils.equals(item.getValue(),value)) {
|
249 | 44386 | omartinez | comboBox.setSelectedIndex(i); |
250 | break;
|
||
251 | } |
||
252 | } |
||
253 | } |
||
254 | |||
255 | 44310 | omartinez | @Override
|
256 | public void nextPanel() { |
||
257 | this.parameters.setProfile(this.getParameterProfile()); |
||
258 | this.parameters.setQuotePolicy(this.getParameterQuotePolicy()); |
||
259 | this.parameters.setLocale(this.getParameterLocale()); |
||
260 | 44386 | omartinez | if (this.getParameterRecordSeparator() != null) { |
261 | this.parameters.setRecordSeparator(this.getParameterRecordSeparator()); |
||
262 | } |
||
263 | if (this.getParameterDelimiter() != null) { |
||
264 | this.parameters.setDelimiter(this.getParameterDelimiter()); |
||
265 | } |
||
266 | if (this.getParameterCommentStartMarker() != null) { |
||
267 | this.parameters.setCommentStartMarker(this.getParameterCommentStartMarker()); |
||
268 | } |
||
269 | 44395 | omartinez | if (this.getParameterQuoteCharacter()!=null) { |
270 | this.parameters.setQuoteCharacter(this.getParameterQuoteCharacter()); |
||
271 | 44386 | omartinez | } |
272 | 44310 | omartinez | } |
273 | } |