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