Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / table / gui / FeatureTableDocumentPanel.java @ 34833

History | View | Annotate | Download (5.39 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (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.app.project.documents.table.gui;
28

    
29
import javax.swing.event.ListSelectionListener;
30
import javax.swing.event.TableModelListener;
31

    
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.ui.mdiManager.IWindowTransform;
34
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
35
import org.gvsig.andami.ui.mdiManager.WindowInfo;
36
import org.gvsig.app.project.documents.Document;
37
import org.gvsig.app.project.documents.gui.IDocumentWindow;
38
import org.gvsig.app.project.documents.gui.WindowLayout;
39
import org.gvsig.app.project.documents.table.TableDocument;
40
import org.gvsig.fmap.dal.DataStoreNotification;
41
import org.gvsig.fmap.dal.exception.DataException;
42
import org.gvsig.fmap.dal.feature.FeatureSelection;
43
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTypesTablePanel;
44
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.notification.ColumnHeaderSelectionChangeNotification;
45
import org.gvsig.tools.observer.Observable;
46
import org.gvsig.tools.observer.Observer;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

    
50
/**
51
 * Feature table visualization panel.
52
 * 
53
 * @author 2005- Vicente Caballero
54
 * @author 2009- gvSIG team
55
 */
56
public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements
57
        SingletonWindow, IWindowTransform, Observer, ListSelectionListener,
58
                TableModelListener, IDocumentWindow {
59

    
60
        private static final Logger LOG =
61
                        LoggerFactory.getLogger(FeatureTableDocumentPanel.class);
62

    
63
    private static final long serialVersionUID = -1003263265311764630L;
64

    
65
    private static final int DEFAULT_HEIGHT = 200;
66

    
67
    private static final int DEFAULT_WIDTH = 300;
68

    
69
    private boolean isPalette=false;
70

    
71
    private WindowInfo windowInfo = null;
72

    
73
    private TableDocument model = null;
74

    
75
        private boolean selectionIsEmpty = true;
76

    
77
        public FeatureTableDocumentPanel(TableDocument document)
78
                        throws DataException {
79
                super(document.getTableModel());
80
                this.model = document;
81
                initialize();
82
        }
83

    
84
    // IWindow interface
85

    
86
        public WindowInfo getWindowInfo() {
87
                if (windowInfo == null) {
88
                        windowInfo = new WindowInfo(WindowInfo.ICONIFIABLE
89
                                        | WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
90

    
91
                        if (this.model == null) {
92
                                windowInfo.setTitle("Tabla");
93
                        } else {
94
                                windowInfo.setTitle(this.model.getName());
95
                        }
96

    
97
                        windowInfo.setWidth(DEFAULT_WIDTH);
98
                        windowInfo.setHeight(DEFAULT_HEIGHT);
99
                }
100
                return windowInfo;
101
        }
102

    
103
    // SingletonWindow interface
104

    
105
    public Object getWindowModel() {
106
        return this.model.getName();
107
    }
108

    
109
    public void toPalette() {
110
                isPalette=true;
111
                windowInfo.toPalette(true);
112
                windowInfo.setClosed(false);
113
                PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
114
        }
115

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

    
123
        public boolean isPalette() {
124
                return isPalette;
125
        }
126

    
127
        public TableDocument getModel() {
128
                return model;
129
        }
130

    
131
        public void update(Observable observable, Object notification) {
132
                // If selection changes from nothing selected to anything selected
133
                // or the reverse, enable controls
134
                if (DataStoreNotification.SELECTION_CHANGE.equals(notification)) {
135
                        try {
136
                                if (selectionIsEmpty != getFeatureSelection().isEmpty()) {
137
                                        selectionIsEmpty = !selectionIsEmpty;
138
                                        PluginServices.getMainFrame().enableControls();
139
                                }
140
                        } catch (DataException e) {
141
                                LOG.error("Error getting the current selection", e);
142
                        }
143
                } 
144
                else if (notification instanceof ColumnHeaderSelectionChangeNotification) {
145
                        PluginServices.getMainFrame().enableControls();
146
                }
147
        }
148

    
149
        private void initialize() throws DataException {
150
                getTablePanel().getTable().addObserver(this);
151
                getTablePanel().getTable().getSelectionModel()
152
                                .addListSelectionListener(this);
153
                getTableModel().addTableModelListener(this);
154
                getFeatureSelection().addObserver(
155
                                this);
156
        }
157

    
158
        private FeatureSelection getFeatureSelection() throws DataException {
159
                return getTableModel().getFeatureStore().getFeatureSelection();
160
        }
161

    
162
        public Object getWindowProfile() {
163
                return WindowInfo.EDITOR_PROFILE;
164
        }
165

    
166
        public WindowLayout getWindowLayout() {
167
                // TODO Auto-generated method stub
168
                return null;
169
        }
170

    
171
        public void setWindowLayout(WindowLayout layout) {
172
                // TODO Auto-generated method stub
173
                
174
        }
175

    
176
        public void setDocument(Document document) {
177
                // TODO Auto-generated method stub
178
                
179
        }
180

    
181
        public Document getDocument() {
182
                return model;
183
        }
184
}