Statistics
| Revision:

root / tags / v2_0_0_Build_2049 / 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 @ 38497

History | View | Annotate | Download (5.91 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 java.lang.reflect.InvocationTargetException;
30

    
31
import javax.swing.SwingUtilities;
32

    
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

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

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

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

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

    
65
    private static final int DEFAULT_HEIGHT = 450;
66

    
67
    private static final int DEFAULT_WIDTH = 700;
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(Document document) throws DataException {
78
        super(((TableDocument) document).getFeatureStoreModel());
79
        this.model = (TableDocument) document;
80
        initialize();
81
    }
82

    
83
    // IWindow interface
84

    
85
    public WindowInfo getWindowInfo() {
86
        if (windowInfo == null) {
87
            windowInfo =
88
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
89
                    | 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;
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
                                enableControls(notification);
139
                }
140
            } catch (DataException e) {
141
                LOG.error("Error getting the current selection", e);
142
            }
143
                } else if (notification instanceof ColumnHeaderSelectionChangeNotification) {
144
                        enableControls(notification);
145
                }
146
    }
147

    
148
        private void enableControls(Object notification) {
149
                try {
150
                        SwingUtilities.invokeLater(new Runnable() {
151
                                public void run() {
152
                                        PluginServices.getMainFrame().enableControls();
153
                                }
154
                        });
155
                } catch (Exception e) {
156
                        LOG.warn("Error calling enableControls() after notification: "
157
                                        + notification, e);
158
                }
159
        }
160

    
161
    private void initialize() throws DataException {
162
        getTablePanel().getTable().addObserver(this);
163
        getFeatureSelection().addObserver(this);
164
    }
165

    
166
    private FeatureSelection getFeatureSelection() throws DataException {
167
        return getTableModel().getFeatureStore().getFeatureSelection();
168
    }
169

    
170
    public Object getWindowProfile() {
171
        return WindowInfo.EDITOR_PROFILE;
172
    }
173

    
174
    public WindowLayout getWindowLayout() {
175
        return null;
176
    }
177

    
178
    public void setWindowLayout(WindowLayout layout) {
179

    
180
    }
181

    
182
    public void setDocument(Document document) {
183
        // FIXME: ?????????
184
    }
185

    
186
    public Document getDocument() {
187
        return model;
188
    }
189

    
190
    public void windowActivated() {
191
        // Do nothing
192
    }
193

    
194
    public void windowClosed() {
195
        // Do nothing
196
    }
197
}