Statistics
| Revision:

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 @ 41707

History | View | Annotate | Download (4.79 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.ComboBoxModel;
7
import javax.swing.JComponent;
8
import org.gvsig.andami.LocaleManager;
9
import org.gvsig.andami.PluginsLocator;
10
import org.gvsig.app.project.documents.table.TableDocument;
11
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableConfigurationPanel;
12
import org.gvsig.propertypage.PropertiesPage;
13
import org.gvsig.tools.ToolsLocator;
14
import org.gvsig.tools.i18n.I18nManager;
15

    
16
public class GeneralTablePropertiesPage extends GeneralTablePropertiesPageLayout implements PropertiesPage {
17

    
18
    private static final long serialVersionUID = -8639908797829738997L;
19
    private final TableDocument tableDocument;
20
    private FeatureTableConfigurationPanel columnsConfigurationPanel = null;
21
    private LocaleManager localeManager;
22

    
23
    public GeneralTablePropertiesPage(TableDocument tableDocument) {
24
        this.tableDocument = tableDocument;
25
        this.localeManager = PluginsLocator.getLocaleManager();
26
        this.initComponents();
27
    }
28

    
29
    private void initComponents() {
30
        txtName.setText(tableDocument.getName());
31
        txtDate.setText(tableDocument.getCreationDate());
32
        txtOwner.setText(tableDocument.getOwner());
33
        txtComments.setText(tableDocument.getComment());
34
        
35
        pnlColumns.setLayout(new BorderLayout());
36
        pnlColumns.add(this.getColumnsConfigurationPanel(),BorderLayout.CENTER);
37
        
38
        Set<Locale> localeSet = localeManager.getInstalledLocales();
39
        for (Locale item : localeSet) {
40
            this.cboLocaleOfData.addItem(new LocaleComboBoxItem(item));
41
        }
42
        Locale localeOfData = tableDocument.getFeatureStoreModel().getCurrentFeatureTableModel().getLocaleOfData();
43
        if ( localeOfData != null ) {
44
            this.cboLocaleOfData.setSelectedItem(new LocaleComboBoxItem(localeOfData));
45
        }
46
        
47
        translate();
48
    }
49

    
50
    private void translate() {
51
        I18nManager i18nManager = ToolsLocator.getI18nManager();
52
        
53
        lblName.setText(i18nManager.getTranslation("nombre"));
54
        lblDate.setText(i18nManager.getTranslation("creation_date"));
55
        lblOwner.setText(i18nManager.getTranslation("owner"));
56
        lblLocaleOfData.setText(i18nManager.getTranslation("locale"));
57
        lblComments.setText(i18nManager.getTranslation("comentarios"));
58
        lblColumns.setText(i18nManager.getTranslation("_Column_information"));
59
        
60
    }
61

    
62
    public void accept() {
63

    
64
    }
65
    
66
    private Locale getLocaleOfData(){
67
            LocaleComboBoxItem item = (LocaleComboBoxItem) cboLocaleOfData.getSelectedItem();
68
            if (item==null){
69
                    return null;
70
            }
71
            return item.getLocale();
72
    }
73
    
74
    private FeatureTableConfigurationPanel getColumnsConfigurationPanel() {
75
        if (this.columnsConfigurationPanel == null) {
76
            this.columnsConfigurationPanel =
77
                new FeatureTableConfigurationPanel(tableDocument
78
                    .getFeatureStoreModel().getCurrentFeatureTableModel());
79
        }
80
        return this.columnsConfigurationPanel;
81
    }
82

    
83
    public String getTitle() {
84
        I18nManager i18nManager = ToolsLocator.getI18nManager();
85
        return i18nManager.getTranslation("General");
86
    }
87
    
88
    public int getPriority() {
89
        return 1000;
90
    }
91

    
92
    public JComponent asJComponent() {
93
        return this;
94
    }
95

    
96
    public boolean whenAccept() {
97
        return whenApply();
98
    }
99

    
100
    public boolean whenApply() {
101
        tableDocument.setName(txtName.getText());
102
        tableDocument.setCreationDate(txtDate.getText());
103
        tableDocument.setOwner(txtOwner.getText());
104
        tableDocument.setComment(txtComments.getText());
105
        tableDocument.getFeatureStoreModel().getCurrentFeatureTableModel()
106
                .setLocaleOfData(getLocaleOfData());
107
        getColumnsConfigurationPanel().accept();
108
        return true;
109
    }
110

    
111
    public boolean whenCancel() {
112
        return true;
113
    }
114

    
115
    
116
    private class LocaleComboBoxItem {
117

    
118
        private Locale locale;
119

    
120
        public LocaleComboBoxItem(Locale locale) {
121
            this.locale = locale;
122
        }
123

    
124
        public String toString() {
125
            return localeManager.getLanguageDisplayName(this.locale);
126
        }
127

    
128
        public Locale getLocale() {
129
            return this.locale;
130
        }
131

    
132
        public boolean equals(Object o) {
133
            if ( o == null ) {
134
                return false;
135
            }
136
            if ( o == this ) {
137
                return true;
138
            }
139
            if ( !(o instanceof LocaleComboBoxItem) ) {
140
                return false;
141
            }
142
            LocaleComboBoxItem item = (LocaleComboBoxItem) o;
143
            if ( !locale.equals(item.getLocale()) ) {
144
                return false;
145
            }
146
            return true;
147
        }
148
    }
149

    
150
}