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 / FeatureTableDocumentPanel.java @ 43354

History | View | Annotate | Download (6.95 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {TableDocument implementation based on the gvSIG DAL API}
27
 */
28
package org.gvsig.app.project.documents.table.gui;
29

    
30

    
31
import java.util.logging.Level;
32
import javax.swing.JComponent;
33
import javax.swing.SwingUtilities;
34

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

    
55
/**
56
 * Feature table visualization panel.
57
 * 
58
 * @author 2005- Vicente Caballero
59
 * @author 2009- gvSIG team
60
 */
61
public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements
62
    IDocumentWindow, IWindowTransform, Observer, Component {
63

    
64
    private static final Logger LOG = LoggerFactory
65
        .getLogger(FeatureTableDocumentPanel.class);
66

    
67
    private static final long serialVersionUID = -1003263265311764630L;
68

    
69
    private static final int DEFAULT_HEIGHT = 450;
70

    
71
    private static final int DEFAULT_WIDTH = 700;
72

    
73
    private boolean isPalette = false;
74

    
75
    private WindowInfo windowInfo = null;
76

    
77
    private TableDocument model = null;
78

    
79
    private boolean selectionIsEmpty = true;
80

    
81
    public FeatureTableDocumentPanel(Document document) throws DataException {
82
        super(((TableDocument) document).getFeatureStoreModel());
83
        this.model = (TableDocument) document;
84
        initialize();
85
        try {
86
            FeatureType featureType = model.getFeatureStore().getDefaultFeatureType();
87
            for( FeatureAttributeDescriptor descriptor : featureType) {
88
                this.getTableModel().setFormattingPattern(
89
                    descriptor.getName(), 
90
                    model.getFormattingPattern(descriptor.getName())
91
                );
92
            }
93
        } catch (DataException ex) {
94
            LOG.warn("Can't initialize columns formating patters",ex);
95
        }
96
        
97
    }
98

    
99
    public JComponent asJComponent() {
100
        return this;
101
    }
102
    
103
    // IWindow interface
104

    
105
    public WindowInfo getWindowInfo() {
106
        if (windowInfo == null) {
107
            windowInfo =
108
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
109
                    | WindowInfo.RESIZABLE);
110

    
111
            if (this.model == null) {
112
                windowInfo.setTitle("Tabla");
113
            } else {
114
                windowInfo.setTitle(this.model.getName());
115
            }
116

    
117
            windowInfo.setWidth(DEFAULT_WIDTH);
118
            windowInfo.setHeight(DEFAULT_HEIGHT);
119
        }
120
        return windowInfo;
121
    }
122

    
123
    // SingletonWindow interface
124

    
125
    public Object getWindowModel() {
126
        return this.model;
127
    }
128

    
129
    public void toPalette() {
130
        isPalette = true;
131
        windowInfo.toPalette(true);
132
        windowInfo.setClosed(false);
133
        PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
134
    }
135

    
136
    public void restore() {
137
        isPalette = false;
138
        windowInfo.toPalette(false);
139
        windowInfo.setClosed(false);
140
        PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
141
    }
142

    
143
    public boolean isPalette() {
144
        return isPalette;
145
    }
146

    
147
    public TableDocument getModel() {
148
        return model;
149
    }
150

    
151
    public void update(Observable observable, Object notification) {
152
        // If selection changes from nothing selected to anything selected
153
        // or the reverse, enable controls
154
        if (DataStoreNotification.SELECTION_CHANGE.equals(notification)) {
155
            try {
156
                if (selectionIsEmpty != getFeatureSelection().isEmpty()) {
157
                    selectionIsEmpty = !selectionIsEmpty;
158
                                enableControls(notification);
159
                }
160
            } catch (DataException e) {
161
                LOG.error("Error getting the current selection", e);
162
            }
163
                } else if (notification instanceof ColumnHeaderSelectionChangeNotification) {
164
                        enableControls(notification);
165
                }
166
    }
167

    
168
        private void enableControls(Object notification) {
169
                try {
170
                        SwingUtilities.invokeLater(new Runnable() {
171
                                public void run() {
172
                                        PluginServices.getMainFrame().enableControls();
173
                                }
174
                        });
175
                } catch (Exception e) {
176
                        LOG.warn("Error calling enableControls() after notification: "
177
                                        + notification, e);
178
                }
179
        }
180

    
181
    private void initialize() throws DataException {
182
        getTablePanel().getTable().addObserver(this);
183
        getFeatureSelection().addObserver(this);
184
    }
185

    
186
    private FeatureSelection getFeatureSelection() throws DataException {
187
        return getTableModel().getFeatureStore().getFeatureSelection();
188
    }
189

    
190
    public Object getWindowProfile() {
191
        return WindowInfo.EDITOR_PROFILE;
192
    }
193

    
194
    public WindowLayout getWindowLayout() {
195
        return null;
196
    }
197

    
198
    public void setWindowLayout(WindowLayout layout) {
199

    
200
    }
201

    
202
    public void setDocument(Document document) {
203
        // FIXME: ?????????
204
    }
205

    
206
    public Document getDocument() {
207
        return model;
208
    }
209

    
210
    public void windowActivated() {
211
        // Do nothing
212
    }
213

    
214
    public void windowClosed() {
215
        // Do nothing
216
    }
217
    
218
    public FeatureAttributeDescriptor[] getSelectedColumnsDescriptors() {
219
        try {
220
            return this.getTablePanel().getTable().getSelectedColumnsAttributeDescriptor();
221
        } catch (DataException ex) {
222
            return null;
223
        }
224
    }
225
}