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 @ 40558
History | View | Annotate | Download (5.91 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 javax.swing.SwingUtilities; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindowTransform; |
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 |
IDocumentWindow, IWindowTransform, Observer {
|
58 |
|
59 |
private static final Logger LOG = LoggerFactory |
60 |
.getLogger(FeatureTableDocumentPanel.class); |
61 |
|
62 |
private static final long serialVersionUID = -1003263265311764630L; |
63 |
|
64 |
private static final int DEFAULT_HEIGHT = 450; |
65 |
|
66 |
private static final int DEFAULT_WIDTH = 700; |
67 |
|
68 |
private boolean isPalette = false; |
69 |
|
70 |
private WindowInfo windowInfo = null; |
71 |
|
72 |
private TableDocument model = null; |
73 |
|
74 |
private boolean selectionIsEmpty = true; |
75 |
|
76 |
public FeatureTableDocumentPanel(Document document) throws DataException { |
77 |
super(((TableDocument) document).getFeatureStoreModel());
|
78 |
this.model = (TableDocument) document;
|
79 |
initialize(); |
80 |
} |
81 |
|
82 |
// IWindow interface
|
83 |
|
84 |
public WindowInfo getWindowInfo() {
|
85 |
if (windowInfo == null) { |
86 |
windowInfo = |
87 |
new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
|
88 |
| WindowInfo.RESIZABLE); |
89 |
|
90 |
if (this.model == null) { |
91 |
windowInfo.setTitle("Tabla");
|
92 |
} else {
|
93 |
windowInfo.setTitle(this.model.getName());
|
94 |
} |
95 |
|
96 |
windowInfo.setWidth(DEFAULT_WIDTH); |
97 |
windowInfo.setHeight(DEFAULT_HEIGHT); |
98 |
} |
99 |
return windowInfo;
|
100 |
} |
101 |
|
102 |
// SingletonWindow interface
|
103 |
|
104 |
public Object getWindowModel() { |
105 |
return this.model; |
106 |
} |
107 |
|
108 |
public void toPalette() { |
109 |
isPalette = true;
|
110 |
windowInfo.toPalette(true);
|
111 |
windowInfo.setClosed(false);
|
112 |
PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
|
113 |
} |
114 |
|
115 |
public void restore() { |
116 |
isPalette = false;
|
117 |
windowInfo.toPalette(false);
|
118 |
windowInfo.setClosed(false);
|
119 |
PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
|
120 |
} |
121 |
|
122 |
public boolean isPalette() { |
123 |
return isPalette;
|
124 |
} |
125 |
|
126 |
public TableDocument getModel() {
|
127 |
return model;
|
128 |
} |
129 |
|
130 |
public void update(Observable observable, Object notification) { |
131 |
// If selection changes from nothing selected to anything selected
|
132 |
// or the reverse, enable controls
|
133 |
if (DataStoreNotification.SELECTION_CHANGE.equals(notification)) {
|
134 |
try {
|
135 |
if (selectionIsEmpty != getFeatureSelection().isEmpty()) {
|
136 |
selectionIsEmpty = !selectionIsEmpty; |
137 |
enableControls(notification); |
138 |
} |
139 |
} catch (DataException e) {
|
140 |
LOG.error("Error getting the current selection", e);
|
141 |
} |
142 |
} else if (notification instanceof ColumnHeaderSelectionChangeNotification) { |
143 |
enableControls(notification); |
144 |
} |
145 |
} |
146 |
|
147 |
private void enableControls(Object notification) { |
148 |
try {
|
149 |
SwingUtilities.invokeLater(new Runnable() { |
150 |
public void run() { |
151 |
PluginServices.getMainFrame().enableControls(); |
152 |
} |
153 |
}); |
154 |
} catch (Exception e) { |
155 |
LOG.warn("Error calling enableControls() after notification: "
|
156 |
+ notification, e); |
157 |
} |
158 |
} |
159 |
|
160 |
private void initialize() throws DataException { |
161 |
getTablePanel().getTable().addObserver(this);
|
162 |
getFeatureSelection().addObserver(this);
|
163 |
} |
164 |
|
165 |
private FeatureSelection getFeatureSelection() throws DataException { |
166 |
return getTableModel().getFeatureStore().getFeatureSelection();
|
167 |
} |
168 |
|
169 |
public Object getWindowProfile() { |
170 |
return WindowInfo.EDITOR_PROFILE;
|
171 |
} |
172 |
|
173 |
public WindowLayout getWindowLayout() {
|
174 |
return null; |
175 |
} |
176 |
|
177 |
public void setWindowLayout(WindowLayout layout) { |
178 |
|
179 |
} |
180 |
|
181 |
public void setDocument(Document document) { |
182 |
// FIXME: ?????????
|
183 |
} |
184 |
|
185 |
public Document getDocument() { |
186 |
return model;
|
187 |
} |
188 |
|
189 |
public void windowActivated() { |
190 |
// Do nothing
|
191 |
} |
192 |
|
193 |
public void windowClosed() { |
194 |
// Do nothing
|
195 |
} |
196 |
} |