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.dbf / src / main / java / org / gvsig / export / dbf / swing / panels / EncodingPanel.java @ 44386
History | View | Annotate | Download (4.69 KB)
1 |
/**
|
---|---|
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.dbf.swing.panels; |
25 |
|
26 |
import javax.swing.DefaultListModel; |
27 |
import javax.swing.JComponent; |
28 |
|
29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
30 |
|
31 |
import org.gvsig.tools.ToolsLocator; |
32 |
import org.gvsig.tools.dynobject.DynField; |
33 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
34 |
import org.gvsig.tools.dynobject.DynStruct; |
35 |
import org.gvsig.tools.i18n.I18nManager; |
36 |
import org.gvsig.tools.swing.api.ListElement; |
37 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
38 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
39 |
import org.gvsig.export.dbf.service.ExportDBFParameters; |
40 |
import org.gvsig.export.ExportParameters; |
41 |
import org.gvsig.export.swing.JExportProcessPanel; |
42 |
import org.gvsig.export.swing.spi.ExportPanel; |
43 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
44 |
import org.slf4j.Logger; |
45 |
import org.slf4j.LoggerFactory; |
46 |
|
47 |
/**
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*
|
51 |
*/
|
52 |
public class EncodingPanel |
53 |
extends EncodingPanelView
|
54 |
implements ExportPanel {
|
55 |
|
56 |
private static final Logger LOG = LoggerFactory.getLogger(EncodingPanel.class); |
57 |
|
58 |
private final ExportDBFParameters parameters; |
59 |
private final JExportProcessPanel processPanel; |
60 |
|
61 |
public EncodingPanel(JExportProcessPanel processPanel, ExportParameters parameters) {
|
62 |
super();
|
63 |
this.processPanel = processPanel;
|
64 |
this.parameters = (ExportDBFParameters) parameters;
|
65 |
this.initComponents();
|
66 |
} |
67 |
|
68 |
private void initComponents() { |
69 |
DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition("DBFStoreParameters");
|
70 |
DynField dynField = parametersDefinition.getDynField("Encoding");
|
71 |
|
72 |
DefaultListModel model = new DefaultListModel(); |
73 |
DynObjectValueItem[] encodings = dynField.getAvailableValues();
|
74 |
for (DynObjectValueItem encoding : encodings) {
|
75 |
model.addElement(new ListElement(encoding.getLabel(), encoding.getValue()));
|
76 |
} |
77 |
this.lstEncoding.setModel(model);
|
78 |
this.lstEncoding.setSelectedIndex(0); |
79 |
|
80 |
|
81 |
this.translate();
|
82 |
} |
83 |
|
84 |
private void translate() { |
85 |
ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
86 |
i18nc.translate(this.lblEncoding);
|
87 |
} |
88 |
|
89 |
public String getEncoding() { |
90 |
ListElement encoding = (ListElement) this.lstEncoding.getSelectedValue();
|
91 |
if (encoding == null) { |
92 |
return null; |
93 |
} |
94 |
return (String) encoding.getValue(); |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public JComponent asJComponent() { |
99 |
return this; |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public String getIdPanel() { |
104 |
return this.getClass().getSimpleName(); |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public String getTitlePanel() { |
109 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
110 |
return i18nManager.getTranslation("_Select_encoding"); |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public boolean validatePanel() throws ExportPanelValidationException { |
115 |
return true; |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public void enterPanel() { |
120 |
String sourceProviderName = this.parameters.getSourceFeatureStore().getProviderName(); |
121 |
if (sourceProviderName.equalsIgnoreCase("Shape") || sourceProviderName.equalsIgnoreCase("DBF")) { |
122 |
if (this.parameters.getEncoding() != null) { |
123 |
String encoding = this.parameters.getEncoding(); |
124 |
ListElement.setSelected(this.lstEncoding, encoding);
|
125 |
} else {
|
126 |
DataStoreParameters params = this.parameters.getSourceFeatureStore().getParameters();
|
127 |
String encoding = (String) params.getDynValue("Encoding"); |
128 |
ListElement.setSelected(this.lstEncoding, encoding);
|
129 |
} |
130 |
} |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public void previousPanel() { |
135 |
|
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void nextPanel() { |
140 |
this.parameters.setEncoding(this.getEncoding()); |
141 |
} |
142 |
} |