Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / project / documents / table / gui / FeatureTableDocumentPanel.java @ 36481

History | View | Annotate | Download (5.6 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 org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

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

    
47
/**
48
 * Feature table visualization panel.
49
 * 
50
 * @author 2005- Vicente Caballero
51
 * @author 2009- gvSIG team
52
 */
53
public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements
54
    IDocumentWindow, IWindowTransform, Observer {
55

    
56
    private static final Logger LOG = LoggerFactory
57
        .getLogger(FeatureTableDocumentPanel.class);
58

    
59
    private static final long serialVersionUID = -1003263265311764630L;
60

    
61
    private static final int DEFAULT_HEIGHT = 450;
62

    
63
    private static final int DEFAULT_WIDTH = 700;
64

    
65
    private boolean isPalette = false;
66

    
67
    private WindowInfo windowInfo = null;
68

    
69
    private TableDocument model = null;
70

    
71
    private boolean selectionIsEmpty = true;
72

    
73
    public FeatureTableDocumentPanel(Document document) throws DataException {
74
        super(((TableDocument) document).getFeatureStoreModel());
75
        this.model = (TableDocument) document;
76
        initialize();
77
    }
78

    
79
    // IWindow interface
80

    
81
    public WindowInfo getWindowInfo() {
82
        if (windowInfo == null) {
83
            windowInfo =
84
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
85
                    | WindowInfo.RESIZABLE);
86

    
87
            if (this.model == null) {
88
                windowInfo.setTitle("Tabla");
89
            } else {
90
                windowInfo.setTitle(this.model.getName());
91
            }
92

    
93
            windowInfo.setWidth(DEFAULT_WIDTH);
94
            windowInfo.setHeight(DEFAULT_HEIGHT);
95
        }
96
        return windowInfo;
97
    }
98

    
99
    // SingletonWindow interface
100

    
101
    public Object getWindowModel() {
102
        return this.model;
103
    }
104

    
105
    public void toPalette() {
106
        isPalette = true;
107
        windowInfo.toPalette(true);
108
        windowInfo.setClosed(false);
109
        PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
110
    }
111

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

    
119
    public boolean isPalette() {
120
        return isPalette;
121
    }
122

    
123
    public TableDocument getModel() {
124
        return model;
125
    }
126

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

    
145
    private void initialize() throws DataException {
146
        getTablePanel().getTable().addObserver(this);
147
        getFeatureSelection().addObserver(this);
148
    }
149

    
150
    private FeatureSelection getFeatureSelection() throws DataException {
151
        return getTableModel().getFeatureStore().getFeatureSelection();
152
    }
153

    
154
    public Object getWindowProfile() {
155
        return WindowInfo.EDITOR_PROFILE;
156
    }
157

    
158
    public WindowLayout getWindowLayout() {
159
        return null;
160
    }
161

    
162
    public void setWindowLayout(WindowLayout layout) {
163

    
164
    }
165

    
166
    public void setDocument(Document document) {
167
        // FIXME: ?????????
168
    }
169

    
170
    public Document getDocument() {
171
        return model;
172
    }
173

    
174
    public void windowActivated() {
175
        // Do nothing
176
    }
177

    
178
    public void windowClosed() {
179
        // Do nothing
180
    }
181
}