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 @ 44262
History | View | Annotate | Download (7.42 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40558 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40558 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
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 | 42691 | jjdelcerro | import java.util.logging.Level; |
32 | 41248 | jjdelcerro | import javax.swing.JComponent; |
33 | 40435 | jjdelcerro | 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 | 42691 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
45 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureSelection; |
46 | 44252 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
47 | 43354 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
48 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTypesTablePanel; |
49 | import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.notification.ColumnHeaderSelectionChangeNotification; |
||
50 | 44262 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
51 | 40435 | jjdelcerro | import org.gvsig.tools.observer.Observable; |
52 | import org.gvsig.tools.observer.Observer; |
||
53 | 41248 | jjdelcerro | import org.gvsig.tools.swing.api.Component; |
54 | 40435 | jjdelcerro | import org.slf4j.Logger; |
55 | import org.slf4j.LoggerFactory; |
||
56 | |||
57 | /**
|
||
58 | * Feature table visualization panel.
|
||
59 | *
|
||
60 | * @author 2005- Vicente Caballero
|
||
61 | * @author 2009- gvSIG team
|
||
62 | */
|
||
63 | public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements |
||
64 | 41248 | jjdelcerro | IDocumentWindow, IWindowTransform, Observer, Component { |
65 | 40435 | jjdelcerro | |
66 | private static final Logger LOG = LoggerFactory |
||
67 | .getLogger(FeatureTableDocumentPanel.class); |
||
68 | |||
69 | private static final long serialVersionUID = -1003263265311764630L; |
||
70 | |||
71 | private static final int DEFAULT_HEIGHT = 450; |
||
72 | |||
73 | private static final int DEFAULT_WIDTH = 700; |
||
74 | |||
75 | private boolean isPalette = false; |
||
76 | |||
77 | private WindowInfo windowInfo = null; |
||
78 | |||
79 | private TableDocument model = null; |
||
80 | |||
81 | private boolean selectionIsEmpty = true; |
||
82 | |||
83 | public FeatureTableDocumentPanel(Document document) throws DataException { |
||
84 | super(((TableDocument) document).getFeatureStoreModel());
|
||
85 | this.model = (TableDocument) document;
|
||
86 | initialize(); |
||
87 | 43354 | jjdelcerro | try {
|
88 | FeatureType featureType = model.getFeatureStore().getDefaultFeatureType(); |
||
89 | for( FeatureAttributeDescriptor descriptor : featureType) {
|
||
90 | this.getTableModel().setFormattingPattern(
|
||
91 | descriptor.getName(), |
||
92 | model.getFormattingPattern(descriptor.getName()) |
||
93 | ); |
||
94 | } |
||
95 | } catch (DataException ex) {
|
||
96 | LOG.warn("Can't initialize columns formating patters",ex);
|
||
97 | } |
||
98 | |||
99 | 40435 | jjdelcerro | } |
100 | |||
101 | 44252 | jjdelcerro | public FeatureStore getFeatureStore() {
|
102 | return this.getTablePanel().getFeatureStore(); |
||
103 | } |
||
104 | |||
105 | 41248 | jjdelcerro | public JComponent asJComponent() { |
106 | return this; |
||
107 | } |
||
108 | |||
109 | 40435 | jjdelcerro | // IWindow interface
|
110 | |||
111 | public WindowInfo getWindowInfo() {
|
||
112 | if (windowInfo == null) { |
||
113 | windowInfo = |
||
114 | new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
|
||
115 | | WindowInfo.RESIZABLE); |
||
116 | |||
117 | if (this.model == null) { |
||
118 | windowInfo.setTitle("Tabla");
|
||
119 | 44262 | jjdelcerro | } else if(this.model.getAssociatedLayer()!=null ) { |
120 | windowInfo.setTitle( |
||
121 | ToolsLocator.getI18nManager().getTranslation("Tabla_de_Atributos") +
|
||
122 | ":" +
|
||
123 | this.model.getName()
|
||
124 | ); |
||
125 | 40435 | jjdelcerro | } else {
|
126 | windowInfo.setTitle(this.model.getName());
|
||
127 | } |
||
128 | |||
129 | windowInfo.setWidth(DEFAULT_WIDTH); |
||
130 | windowInfo.setHeight(DEFAULT_HEIGHT); |
||
131 | } |
||
132 | return windowInfo;
|
||
133 | } |
||
134 | |||
135 | // SingletonWindow interface
|
||
136 | |||
137 | public Object getWindowModel() { |
||
138 | return this.model; |
||
139 | } |
||
140 | |||
141 | public void toPalette() { |
||
142 | isPalette = true;
|
||
143 | windowInfo.toPalette(true);
|
||
144 | windowInfo.setClosed(false);
|
||
145 | PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
|
||
146 | } |
||
147 | |||
148 | public void restore() { |
||
149 | isPalette = false;
|
||
150 | windowInfo.toPalette(false);
|
||
151 | windowInfo.setClosed(false);
|
||
152 | PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
|
||
153 | } |
||
154 | |||
155 | public boolean isPalette() { |
||
156 | return isPalette;
|
||
157 | } |
||
158 | |||
159 | public TableDocument getModel() {
|
||
160 | return model;
|
||
161 | } |
||
162 | |||
163 | public void update(Observable observable, Object notification) { |
||
164 | // If selection changes from nothing selected to anything selected
|
||
165 | // or the reverse, enable controls
|
||
166 | if (DataStoreNotification.SELECTION_CHANGE.equals(notification)) {
|
||
167 | try {
|
||
168 | if (selectionIsEmpty != getFeatureSelection().isEmpty()) {
|
||
169 | selectionIsEmpty = !selectionIsEmpty; |
||
170 | enableControls(notification); |
||
171 | } |
||
172 | } catch (DataException e) {
|
||
173 | LOG.error("Error getting the current selection", e);
|
||
174 | } |
||
175 | } else if (notification instanceof ColumnHeaderSelectionChangeNotification) { |
||
176 | enableControls(notification); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | private void enableControls(Object notification) { |
||
181 | try {
|
||
182 | SwingUtilities.invokeLater(new Runnable() { |
||
183 | public void run() { |
||
184 | PluginServices.getMainFrame().enableControls(); |
||
185 | } |
||
186 | }); |
||
187 | } catch (Exception e) { |
||
188 | LOG.warn("Error calling enableControls() after notification: "
|
||
189 | + notification, e); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | private void initialize() throws DataException { |
||
194 | getTablePanel().getTable().addObserver(this);
|
||
195 | getFeatureSelection().addObserver(this);
|
||
196 | } |
||
197 | |||
198 | private FeatureSelection getFeatureSelection() throws DataException { |
||
199 | return getTableModel().getFeatureStore().getFeatureSelection();
|
||
200 | } |
||
201 | |||
202 | public Object getWindowProfile() { |
||
203 | return WindowInfo.EDITOR_PROFILE;
|
||
204 | } |
||
205 | |||
206 | public WindowLayout getWindowLayout() {
|
||
207 | return null; |
||
208 | } |
||
209 | |||
210 | public void setWindowLayout(WindowLayout layout) { |
||
211 | |||
212 | } |
||
213 | |||
214 | public void setDocument(Document document) { |
||
215 | // FIXME: ?????????
|
||
216 | } |
||
217 | |||
218 | public Document getDocument() { |
||
219 | return model;
|
||
220 | } |
||
221 | |||
222 | public void windowActivated() { |
||
223 | // Do nothing
|
||
224 | } |
||
225 | |||
226 | public void windowClosed() { |
||
227 | // Do nothing
|
||
228 | } |
||
229 | 42691 | jjdelcerro | |
230 | public FeatureAttributeDescriptor[] getSelectedColumnsDescriptors() { |
||
231 | try {
|
||
232 | return this.getTablePanel().getTable().getSelectedColumnsAttributeDescriptor(); |
||
233 | } catch (DataException ex) {
|
||
234 | return null; |
||
235 | } |
||
236 | } |
||
237 | 40435 | jjdelcerro | } |