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 / SelectCharsetPanel.java @ 44395
History | View | Annotate | Download (4 KB)
1 | 44395 | omartinez | /*
|
---|---|---|---|
2 | * To change this license header, choose License Headers in Project Properties.
|
||
3 | * To change this template file, choose Tools | Templates
|
||
4 | * and open the template in the editor.
|
||
5 | */
|
||
6 | package org.gvsig.export.swing.impl.panels; |
||
7 | |||
8 | import java.nio.charset.Charset; |
||
9 | import java.util.Map; |
||
10 | import java.util.SortedMap; |
||
11 | import javax.swing.DefaultListModel; |
||
12 | import javax.swing.JComponent; |
||
13 | import org.apache.commons.lang3.StringUtils; |
||
14 | import org.gvsig.export.ExportCharsetParameters; |
||
15 | import org.gvsig.export.ExportParameters; |
||
16 | import org.gvsig.export.swing.JExportProcessPanel; |
||
17 | import org.gvsig.export.swing.spi.ExportPanel; |
||
18 | import org.gvsig.export.swing.spi.ExportPanelValidationException; |
||
19 | import org.gvsig.tools.ToolsLocator; |
||
20 | import org.gvsig.tools.dynobject.DynField; |
||
21 | import org.gvsig.tools.dynobject.DynStruct; |
||
22 | import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
||
23 | import org.gvsig.tools.i18n.I18nManager; |
||
24 | import org.gvsig.tools.swing.api.ListElement; |
||
25 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
26 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
27 | import org.slf4j.Logger; |
||
28 | import org.slf4j.LoggerFactory; |
||
29 | |||
30 | /**
|
||
31 | *
|
||
32 | * @author osc
|
||
33 | */
|
||
34 | public class SelectCharsetPanel extends SelectCharsetPanelView |
||
35 | implements ExportPanel {
|
||
36 | |||
37 | private static final Logger LOG = LoggerFactory.getLogger(SelectCharsetPanel.class); |
||
38 | |||
39 | private final JExportProcessPanel processPanel; |
||
40 | private final ExportParameters parameters; |
||
41 | |||
42 | public SelectCharsetPanel(JExportProcessPanel processPanel, ExportParameters parameters) {
|
||
43 | super();
|
||
44 | this.processPanel = processPanel;
|
||
45 | this.parameters = parameters;
|
||
46 | this.initComponents();
|
||
47 | } |
||
48 | |||
49 | private void initComponents() { |
||
50 | DynStruct parametersDefinition = ToolsLocator.getPersistenceManager().getDefinition("DBFStoreParameters");
|
||
51 | DynField dynField = parametersDefinition.getDynField("Encoding");
|
||
52 | |||
53 | DefaultListModel model = new DefaultListModel(); |
||
54 | SortedMap<String, Charset> availableCharsets = Charset.availableCharsets(); |
||
55 | for (Map.Entry<String, Charset> charset : availableCharsets.entrySet()) { |
||
56 | model.addElement(charset.getKey()); |
||
57 | } |
||
58 | |||
59 | this.lstCharset.setModel(model);
|
||
60 | this.lstCharset.setSelectedIndex(0); |
||
61 | |||
62 | this.translate();
|
||
63 | } |
||
64 | |||
65 | private void translate() { |
||
66 | ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
||
67 | i18nc.translate(this.lblCharset);
|
||
68 | } |
||
69 | |||
70 | @Override
|
||
71 | public JComponent asJComponent() { |
||
72 | return this; |
||
73 | } |
||
74 | |||
75 | @Override
|
||
76 | public String getIdPanel() { |
||
77 | return this.getClass().getSimpleName(); |
||
78 | } |
||
79 | |||
80 | @Override
|
||
81 | public String getTitlePanel() { |
||
82 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
83 | return i18nManager.getTranslation("_Select_encoding"); |
||
84 | } |
||
85 | |||
86 | @Override
|
||
87 | public boolean validatePanel() throws ExportPanelValidationException { |
||
88 | return true; |
||
89 | } |
||
90 | |||
91 | @Override
|
||
92 | public void enterPanel() { |
||
93 | ExportCharsetParameters params = (ExportCharsetParameters) this.parameters;
|
||
94 | if (!StringUtils.isEmpty(params.getCharset())) {
|
||
95 | String charset = params.getCharset();
|
||
96 | ListElement.setSelected(this.lstCharset, charset);
|
||
97 | return;
|
||
98 | } |
||
99 | try {
|
||
100 | // TODO ?
|
||
101 | //CSVStoreParameters;
|
||
102 | String sourceCharset = (String) this.parameters.getSourceFeatureStore().getParameters().getDynValue("charset"); |
||
103 | if (sourceCharset != null) { |
||
104 | this.lstCharset.setSelectedValue(sourceCharset, true); |
||
105 | return;
|
||
106 | } |
||
107 | } catch (DynFieldNotFoundException e) {
|
||
108 | LOG.info("Can't find charset dyn value from source store");
|
||
109 | } |
||
110 | |||
111 | this.lstCharset.setSelectedValue(Charset.forName("UTF-8").displayName(), true); |
||
112 | |||
113 | } |
||
114 | |||
115 | @Override
|
||
116 | public void previousPanel() { |
||
117 | |||
118 | } |
||
119 | |||
120 | @Override
|
||
121 | public void nextPanel() { |
||
122 | ExportCharsetParameters params = (ExportCharsetParameters) this.parameters;
|
||
123 | params.setCharset((String) this.lstCharset.getSelectedValue()); |
||
124 | } |
||
125 | } |