svn-gvsig-desktop / 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 @ 36443
History | View | Annotate | Download (5.88 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.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
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.FeatureSelection; |
45 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTypesTablePanel; |
46 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.notification.ColumnHeaderSelectionChangeNotification; |
47 |
import org.gvsig.tools.observer.Observable; |
48 |
import org.gvsig.tools.observer.Observer; |
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, ListSelectionListener, |
58 |
TableModelListener {
|
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 = 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(Document document) throws DataException { |
78 |
super(((TableDocument) document).getTableModel());
|
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 |
PluginServices.getMainFrame().enableControls(); |
139 |
} |
140 |
} catch (DataException e) {
|
141 |
LOG.error("Error getting the current selection", e);
|
142 |
} |
143 |
} else
|
144 |
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(this);
|
155 |
} |
156 |
|
157 |
private FeatureSelection getFeatureSelection() throws DataException { |
158 |
return getTableModel().getFeatureStore().getFeatureSelection();
|
159 |
} |
160 |
|
161 |
public Object getWindowProfile() { |
162 |
return WindowInfo.EDITOR_PROFILE;
|
163 |
} |
164 |
|
165 |
public WindowLayout getWindowLayout() {
|
166 |
return null; |
167 |
} |
168 |
|
169 |
public void setWindowLayout(WindowLayout layout) { |
170 |
|
171 |
} |
172 |
|
173 |
public void setDocument(Document document) { |
174 |
// FIXME: ?????????
|
175 |
} |
176 |
|
177 |
public Document getDocument() { |
178 |
return model;
|
179 |
} |
180 |
|
181 |
public void windowActivated() { |
182 |
// Do nothing
|
183 |
} |
184 |
|
185 |
public void windowClosed() { |
186 |
// Do nothing
|
187 |
} |
188 |
} |