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