svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / project / documents / table / gui / GeneralTablePropertiesPage.java @ 43913
History | View | Annotate | Download (6.78 KB)
1 |
package org.gvsig.app.project.documents.table.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.util.Locale; |
5 |
import java.util.Set; |
6 |
import javax.swing.JComponent; |
7 |
import org.gvsig.andami.LocaleManager; |
8 |
import org.gvsig.andami.PluginsLocator; |
9 |
import org.gvsig.app.project.documents.table.TableDocument; |
10 |
import org.gvsig.fmap.dal.exception.DataException; |
11 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
13 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
14 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableConfigurationPanel; |
15 |
import org.gvsig.propertypage.PropertiesPage; |
16 |
import org.gvsig.tools.ToolsLocator; |
17 |
import org.gvsig.tools.i18n.I18nManager; |
18 |
import org.slf4j.Logger; |
19 |
import org.slf4j.LoggerFactory; |
20 |
|
21 |
public class GeneralTablePropertiesPage extends GeneralTablePropertiesPageLayout implements PropertiesPage { |
22 |
|
23 |
private static final Logger logger = LoggerFactory.getLogger(GeneralTablePropertiesPage.class); |
24 |
|
25 |
private static final long serialVersionUID = -8639908797829738997L; |
26 |
private final TableDocument tableDocument; |
27 |
private FeatureTableConfigurationPanel columnsConfigurationPanel = null; |
28 |
private LocaleManager localeManager;
|
29 |
|
30 |
public GeneralTablePropertiesPage(TableDocument tableDocument) {
|
31 |
this.tableDocument = tableDocument;
|
32 |
this.localeManager = PluginsLocator.getLocaleManager();
|
33 |
this.initComponents();
|
34 |
try {
|
35 |
FeatureType featureType = tableDocument.getFeatureStore().getDefaultFeatureType(); |
36 |
for( FeatureAttributeDescriptor descriptor : featureType) {
|
37 |
this.columnsConfigurationPanel.setFormattingPattern(
|
38 |
descriptor.getName(), |
39 |
tableDocument.getFormattingPattern(descriptor.getName()) |
40 |
); |
41 |
} |
42 |
} catch (DataException ex) {
|
43 |
logger.warn("Can't initialize columns formating patters",ex);
|
44 |
} |
45 |
} |
46 |
|
47 |
@Override
|
48 |
public void setData(Object data) { |
49 |
|
50 |
} |
51 |
|
52 |
private void initComponents() { |
53 |
txtName.setText(tableDocument.getName()); |
54 |
txtDate.setText(tableDocument.getCreationDate()); |
55 |
txtOwner.setText(tableDocument.getOwner()); |
56 |
txtComments.setText(tableDocument.getComment()); |
57 |
|
58 |
pnlColumns.setLayout(new BorderLayout()); |
59 |
pnlColumns.add(this.getColumnsConfigurationPanel(),BorderLayout.CENTER); |
60 |
|
61 |
Set<Locale> localeSet = localeManager.getInstalledLocales(); |
62 |
for (Locale item : localeSet) { |
63 |
this.cboLocaleOfData.addItem(new LocaleComboBoxItem(item)); |
64 |
} |
65 |
Locale localeOfData = tableDocument.getFeatureStoreModel().getCurrentFeatureTableModel().getLocaleOfData();
|
66 |
if ( localeOfData != null ) { |
67 |
this.cboLocaleOfData.setSelectedItem(new LocaleComboBoxItem(localeOfData)); |
68 |
} |
69 |
if( tableDocument.getFeatureStore().getParameters() instanceof FilesystemStoreParameters ) { |
70 |
FilesystemStoreParameters params = (FilesystemStoreParameters) tableDocument.getFeatureStore().getParameters(); |
71 |
this.txtDataSource.setText(params.getFile().getAbsolutePath());
|
72 |
} else {
|
73 |
this.txtDataSource.setText(tableDocument.getFeatureStore().getFullName());
|
74 |
} |
75 |
translate(); |
76 |
} |
77 |
|
78 |
private void translate() { |
79 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
80 |
|
81 |
lblName.setText(i18nManager.getTranslation("Nombre_XcolonX"));
|
82 |
lblDate.setText(i18nManager.getTranslation("creation_date_XcolonX"));
|
83 |
lblOwner.setText(i18nManager.getTranslation("owner_XcolonX"));
|
84 |
lblLocaleOfData.setText(i18nManager.getTranslation("locale_XcolonX"));
|
85 |
lblComments.setText(i18nManager.getTranslation("comentarios_XcolonX"));
|
86 |
lblColumns.setText(i18nManager.getTranslation("_Column_information_XcolonX"));
|
87 |
lblDataSource.setText(i18nManager.getTranslation("Data_source"));
|
88 |
|
89 |
} |
90 |
|
91 |
public void accept() { |
92 |
|
93 |
} |
94 |
|
95 |
private Locale getLocaleOfData(){ |
96 |
LocaleComboBoxItem item = (LocaleComboBoxItem) cboLocaleOfData.getSelectedItem(); |
97 |
if (item==null){ |
98 |
return null; |
99 |
} |
100 |
return item.getLocale();
|
101 |
} |
102 |
|
103 |
private FeatureTableConfigurationPanel getColumnsConfigurationPanel() {
|
104 |
if (this.columnsConfigurationPanel == null) { |
105 |
this.columnsConfigurationPanel =
|
106 |
new FeatureTableConfigurationPanel(tableDocument
|
107 |
.getFeatureStoreModel().getCurrentFeatureTableModel()); |
108 |
} |
109 |
return this.columnsConfigurationPanel; |
110 |
} |
111 |
|
112 |
public String getTitle() { |
113 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
114 |
return i18nManager.getTranslation("General"); |
115 |
} |
116 |
|
117 |
public int getPriority() { |
118 |
return 1000; |
119 |
} |
120 |
|
121 |
public JComponent asJComponent() { |
122 |
return this; |
123 |
} |
124 |
|
125 |
public boolean whenAccept() { |
126 |
return whenApply();
|
127 |
} |
128 |
|
129 |
@Override
|
130 |
public boolean whenApply() { |
131 |
tableDocument.setName(txtName.getText()); |
132 |
tableDocument.setCreationDate(txtDate.getText()); |
133 |
tableDocument.setOwner(txtOwner.getText()); |
134 |
tableDocument.setComment(txtComments.getText()); |
135 |
tableDocument.getFeatureStoreModel().getCurrentFeatureTableModel() |
136 |
.setLocaleOfData(getLocaleOfData()); |
137 |
getColumnsConfigurationPanel().accept(); |
138 |
try {
|
139 |
FeatureType featureType = tableDocument.getFeatureStore().getDefaultFeatureType(); |
140 |
for( FeatureAttributeDescriptor descriptor : featureType) {
|
141 |
tableDocument.setFormattingPattern( |
142 |
descriptor.getName(), |
143 |
this.columnsConfigurationPanel.getFormattingPattern(descriptor.getName())
|
144 |
); |
145 |
} |
146 |
} catch (DataException ex) {
|
147 |
logger.warn("Can't set columns formating patters in the table document",ex);
|
148 |
} |
149 |
|
150 |
return true; |
151 |
} |
152 |
|
153 |
public boolean whenCancel() { |
154 |
return true; |
155 |
} |
156 |
|
157 |
|
158 |
private class LocaleComboBoxItem { |
159 |
|
160 |
private Locale locale; |
161 |
|
162 |
public LocaleComboBoxItem(Locale locale) { |
163 |
this.locale = locale;
|
164 |
} |
165 |
|
166 |
public String toString() { |
167 |
return localeManager.getLocaleDisplayName(this.locale); |
168 |
} |
169 |
|
170 |
public Locale getLocale() { |
171 |
return this.locale; |
172 |
} |
173 |
|
174 |
public boolean equals(Object o) { |
175 |
if ( o == null ) { |
176 |
return false; |
177 |
} |
178 |
if ( o == this ) { |
179 |
return true; |
180 |
} |
181 |
if ( !(o instanceof LocaleComboBoxItem) ) { |
182 |
return false; |
183 |
} |
184 |
LocaleComboBoxItem item = (LocaleComboBoxItem) o; |
185 |
if ( !locale.equals(item.getLocale()) ) {
|
186 |
return false; |
187 |
} |
188 |
return true; |
189 |
} |
190 |
} |
191 |
|
192 |
} |