Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / project / document / table / gui / FeatureTableDocumentPanel.java @ 27382

History | View | Annotate | Download (6.85 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {TableDocument implementation based on the gvSIG DAL API}
26
 */
27
package org.gvsig.project.document.table.gui;
28

    
29
import java.awt.BorderLayout;
30

    
31
import javax.swing.JButton;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.event.ListSelectionEvent;
35
import javax.swing.event.ListSelectionListener;
36
import javax.swing.event.TableModelEvent;
37
import javax.swing.event.TableModelListener;
38

    
39
import org.gvsig.fmap.dal.exception.DataException;
40
import org.gvsig.fmap.dal.feature.FeatureSelection;
41
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.data.feature.swing.FeatureTypesTablePanel;
43
import org.gvsig.fmap.data.feature.swing.table.notification.ColumnHeaderSelectionChangeNotification;
44
import org.gvsig.project.document.table.FeatureTableDocument;
45
import org.gvsig.tools.observer.Observable;
46
import org.gvsig.tools.observer.Observer;
47

    
48
import com.iver.andami.PluginServices;
49
import com.iver.andami.ui.mdiManager.IWindowTransform;
50
import com.iver.andami.ui.mdiManager.SingletonWindow;
51
import com.iver.andami.ui.mdiManager.WindowInfo;
52

    
53
/**
54
 * Feature table visualization panel.
55
 *
56
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
57
 */
58
public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements
59
        SingletonWindow, IWindowTransform, Observer, ListSelectionListener,
60
                TableModelListener {
61
    private boolean showTypes=false;
62
    private static final long serialVersionUID = -1003263265311764630L;
63

    
64
    private static final int DEFAULT_HEIGHT = 200;
65

    
66
    private static final int DEFAULT_WIDTH = 300;
67

    
68
    private boolean isPalette=false;
69

    
70
    private WindowInfo windowInfo = null;
71

    
72
    private FeatureTableDocument model = null;
73

    
74
        private JPanel jPanel;  //  @jve:decl-index=0:
75

    
76
        private JLabel jLabel;
77

    
78
        private JButton bShowFeatureTypes = null;
79

    
80
        public FeatureTableDocumentPanel(FeatureTableDocument document)
81
                        throws DataException {
82
                super(document.getStore());
83
                this.model = document;
84
                initialize();
85
        }
86

    
87
    // IWindow interface
88

    
89
        public WindowInfo getWindowInfo() {
90
                if (windowInfo == null) {
91
                        windowInfo = new WindowInfo(WindowInfo.ICONIFIABLE
92
                                        | WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
93

    
94
                        // TODO: RETURN MORE USEFUL INFO ABOUT DATA VIEWED AND ADD I18N FOR
95
                        // TEXTS
96
                        if (this.model == null) {
97
                                windowInfo.setTitle("Tabla");
98
                        } else {
99
                                windowInfo.setTitle(this.model.getName());
100
                        }
101

    
102
                        windowInfo.setWidth(DEFAULT_WIDTH);
103
                        windowInfo.setHeight(DEFAULT_HEIGHT);
104
                }
105
                return windowInfo;
106
        }
107

    
108
    // SingletonWindow interface
109

    
110
    public Object getWindowModel() {
111
        return this.model.getName();
112
    }
113

    
114
    public void toPalette() {
115
                isPalette=true;
116
                windowInfo.toPalette(true);
117
                windowInfo.setClosed(false);
118
                PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
119
        }
120

    
121
        public void restore() {
122
                isPalette=false;
123
                windowInfo.toPalette(false);
124
                windowInfo.setClosed(false);
125
                PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
126
        }
127

    
128
        public boolean isPalette() {
129
                return isPalette;
130
        }
131

    
132
        public FeatureTableDocument getModel() {
133
                return model;
134
        }
135

    
136
        public void update(Observable arg0, Object arg1) {
137

    
138
                if (arg1 instanceof ColumnHeaderSelectionChangeNotification) {
139
                        PluginServices.getMainFrame().enableControls();
140

    
141
                }
142

    
143
        }
144

    
145
        public void updateSelection() {
146
                try {
147
                        //                        ListSelectionModel sm = getTablePanel().getTable()
148
                        //                                        .getSelectionModel();
149
                        //                        sm.clearSelection();
150
                        //TODO falta que implentar como transformar la selecci?n del store en la selecci?n de la tabla.
151
                        FeatureSelection selection = (FeatureSelection) getModel()
152
                                        .getStore().getSelection();
153
                        jLabel.setText(selection.getSize()
154
                                        + " / "
155
                                        + getTableModel().getHelper().getTotalSize()
156
                                        + " "
157
                                        + PluginServices.getText(this,
158
                                                        "registros_seleccionados_total") + ".");
159
                } catch (DataException e) {
160
                        e.printStackTrace();
161
                }
162
        }
163

    
164
        /**
165
         * This method initializes jPanel
166
         *
167
         * @return javax.swing.JPanel
168
         */
169
        private JPanel getJPanel() {
170
                if (jPanel == null) {
171

    
172
                        jLabel = new JLabel();
173
                        jLabel.setText(PluginServices.getText(this,"seleccionados")+ ":   ");
174
                        try {
175
                                FeatureStore store=getModel().getStore();
176
                                FeatureSelection selection = (FeatureSelection)store.getSelection();
177
                                jLabel.setText(selection.getSize() + " / " + getTableModel().getHelper().getTotalSize() + " " +
178
                        PluginServices.getText(this, "registros_seleccionados_total") +
179
                        ".");
180
                                jPanel = new JPanel();
181
                                BorderLayout borderLayout=new BorderLayout();
182
//                                jPanel.setLayout(borderLayout);
183
                                jPanel.add(jLabel, BorderLayout.EAST);
184
                                jPanel.add(getBShowFeatureTypes(), BorderLayout.WEST);
185
                        } catch (DataException e) {
186
                                e.printStackTrace();
187
                        }
188
                }
189
                return jPanel;
190
        }
191
        private void initialize() throws DataException {
192
                add(getJPanel(),BorderLayout.SOUTH);
193
                getTablePanel().getTable().addObserver(this);
194
                getTablePanel().getTable().getSelectionModel()
195
                                .addListSelectionListener(this);
196
                getTableModel().addTableModelListener(this);
197
        }
198

    
199
        /**
200
         * This method initializes bShowFeatureTypes
201
         *
202
         * @return javax.swing.JButton
203
         */
204
        private JButton getBShowFeatureTypes() {
205
                if (bShowFeatureTypes == null) {
206
                        bShowFeatureTypes = new JButton();
207
                        bShowFeatureTypes.setText(PluginServices.getText(this,"show_types"));
208
                        bShowFeatureTypes.addActionListener(new java.awt.event.ActionListener() {
209
                                public void actionPerformed(java.awt.event.ActionEvent e) {
210
                                        showTypes=!showTypes;
211
                                        if (showTypes){
212
                                                bShowFeatureTypes.setText(PluginServices.getText(this,"hide_types"));
213
                                                showTypes();
214
                                        }else{
215
                                                bShowFeatureTypes.setText(PluginServices.getText(this,"show_types"));
216
                                                hideTypes();
217
                                        }
218
                                }
219
                        });
220
                }
221
                return bShowFeatureTypes;
222
        }
223

    
224
        public Object getWindowProfile() {
225
                return WindowInfo.EDITOR_PROFILE;
226
        }
227

    
228
        public void valueChanged(ListSelectionEvent e) {
229
                this.updateSelection();
230
                this.updateUI();
231

    
232
        }
233

    
234
        public void tableChanged(TableModelEvent e) {
235
                this.updateSelection();
236
                this.updateUI();
237
        }
238
}