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 / TableManager.java @ 47326
History | View | Annotate | Download (21.6 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 |
package org.gvsig.app.project.documents.table; |
26 |
|
27 |
import java.awt.Dimension; |
28 |
import java.util.Collections; |
29 |
import java.util.Iterator; |
30 |
import java.util.List; |
31 |
import javax.swing.ImageIcon; |
32 |
import javax.swing.JOptionPane; |
33 |
import org.gvsig.andami.IconThemeHelper; |
34 |
import org.gvsig.andami.PluginServices; |
35 |
import org.gvsig.andami.messages.NotificationManager; |
36 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
37 |
import org.gvsig.app.ApplicationLocator; |
38 |
import org.gvsig.app.addlayer.AddLayerDialog; |
39 |
import org.gvsig.app.gui.WizardPanel; |
40 |
import org.gvsig.app.project.Project; |
41 |
import org.gvsig.app.project.ProjectManager; |
42 |
import org.gvsig.app.project.documents.AbstractDocument; |
43 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
44 |
import org.gvsig.app.project.documents.Document; |
45 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
46 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
47 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
48 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
49 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
50 |
import org.gvsig.app.project.documents.table.TableDocument.TableLink; |
51 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
52 |
import org.gvsig.app.project.documents.table.gui.TableProperties; |
53 |
import org.gvsig.fmap.dal.AbstractStoresRepository; |
54 |
import org.gvsig.fmap.dal.DALLocator; |
55 |
import org.gvsig.fmap.dal.DataManager; |
56 |
import org.gvsig.fmap.dal.DataStore; |
57 |
import org.gvsig.fmap.dal.DataStoreParameters; |
58 |
import org.gvsig.fmap.dal.exception.DataException; |
59 |
import org.gvsig.fmap.dal.exception.InitializeException; |
60 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
61 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
62 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
63 |
import org.gvsig.fmap.dal.feature.FeatureQueryOrder; |
64 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
65 |
import org.gvsig.fmap.dal.feature.FeatureType; |
66 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel; |
67 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
68 |
import org.gvsig.fmap.mapcontext.layers.vectorial.VectorLayer; |
69 |
import org.gvsig.tools.ToolsLocator; |
70 |
import org.gvsig.tools.dispose.DisposeUtils; |
71 |
import org.gvsig.tools.dynobject.DynObjectManager; |
72 |
import org.gvsig.tools.dynobject.DynStruct; |
73 |
import org.gvsig.tools.evaluator.Evaluator; |
74 |
import org.gvsig.tools.i18n.I18nManager; |
75 |
import org.gvsig.tools.persistence.PersistenceManager; |
76 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
77 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
78 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
79 |
import org.gvsig.tools.util.Invocable; |
80 |
import org.gvsig.tools.util.MappedIterator; |
81 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
82 |
import org.slf4j.LoggerFactory; |
83 |
|
84 |
/**
|
85 |
* Factory of Table.
|
86 |
*
|
87 |
* @author gvSIG Tem
|
88 |
*
|
89 |
*/
|
90 |
@SuppressWarnings("UseSpecificCatch") |
91 |
public class TableManager extends AbstractDocumentManager { |
92 |
|
93 |
final static private org.slf4j.Logger LOGGER = LoggerFactory.getLogger(TableDocument.class); |
94 |
|
95 |
private static class TableDocumentStoresRepository extends AbstractStoresRepository { |
96 |
|
97 |
public TableDocumentStoresRepository(String name, String label) { |
98 |
super(name, label);
|
99 |
} |
100 |
|
101 |
@Override
|
102 |
protected DataStoreParameters getMyParameters(String name) { |
103 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
104 |
TableDocument tableDoc = (TableDocument) project.getDocument(name, TYPENAME); |
105 |
if( tableDoc==null || tableDoc.getFeatureStore()==null) { |
106 |
return null; |
107 |
} |
108 |
return tableDoc.getFeatureStore().getParameters();
|
109 |
} |
110 |
|
111 |
@Override
|
112 |
protected FeatureType getMyFeatureType(String name) { |
113 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
114 |
TableDocument tableDoc = (TableDocument) project.getDocument(name, TYPENAME); |
115 |
if( tableDoc==null || tableDoc.getFeatureStore()==null) { |
116 |
return null; |
117 |
} |
118 |
return tableDoc.getFeatureStore().getDefaultFeatureTypeQuietly();
|
119 |
} |
120 |
|
121 |
@Override
|
122 |
protected boolean isEmptyMyRepository() { |
123 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
124 |
return project.getDocuments(TableManager.TYPENAME).isEmpty();
|
125 |
} |
126 |
|
127 |
@Override
|
128 |
protected int getMySize() { |
129 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
130 |
int sz = project.getDocuments(TableManager.TYPENAME).size();
|
131 |
return sz;
|
132 |
} |
133 |
|
134 |
@Override
|
135 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
136 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
137 |
final List<Document> docs = project.getDocuments(TableManager.TYPENAME); |
138 |
if( docs==null ) { |
139 |
return UnmodifiableBasicSet.EMPTY_UNMODIFIABLEBASICSET;
|
140 |
} |
141 |
UnmodifiableBasicSet<String> x = new UnmodifiableBasicSet<String>() { |
142 |
@Override
|
143 |
public boolean isEmpty() { |
144 |
return docs.isEmpty();
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public int size() { |
149 |
return docs.size();
|
150 |
} |
151 |
|
152 |
@Override
|
153 |
public Iterator<String> iterator() { |
154 |
return new MappedIterator<>(docs.iterator(), (Document t) -> { |
155 |
if( t==null ) { |
156 |
return null; |
157 |
} |
158 |
return ((TableDocument)t).getName();
|
159 |
}); |
160 |
} |
161 |
}; |
162 |
return x;
|
163 |
} |
164 |
|
165 |
|
166 |
@Override
|
167 |
public Iterator<DataStoreParameters> iterator() { |
168 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
169 |
List<Document> docs = project.getDocuments(TableManager.TYPENAME); |
170 |
if( docs==null ) { |
171 |
return Collections.EMPTY_LIST.iterator(); |
172 |
} |
173 |
return new MappedIterator<>(docs.iterator(), (Document t) -> { |
174 |
if( t==null || ((TableDocument)t).getFeatureStore()==null ) { |
175 |
return null; |
176 |
} |
177 |
return ((TableDocument)t).getFeatureStore().getParameters();
|
178 |
}); |
179 |
} |
180 |
|
181 |
@Override
|
182 |
public void add(String name, DataStoreParameters parameters) { |
183 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
184 |
TableDocument doc = (TableDocument) ProjectManager.getInstance().createDocument(TYPENAME); |
185 |
doc.setName(name); |
186 |
//FIXME:
|
187 |
DataManager dataManager = DALLocator.getDataManager(); |
188 |
FeatureStore store; |
189 |
try {
|
190 |
store = (FeatureStore) dataManager.openStore( |
191 |
parameters.getProviderName(), |
192 |
parameters |
193 |
); |
194 |
doc.setStore(store); |
195 |
project.addDocument(doc); |
196 |
} catch (InitializeException | ProviderNotRegisteredException | ValidateDataParametersException ex) {
|
197 |
LOGGER.warn("Can't add table to project", ex);
|
198 |
} |
199 |
|
200 |
} |
201 |
|
202 |
@Override
|
203 |
public void add(String name, FeatureStore store) { |
204 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
205 |
TableDocument doc = (TableDocument) ProjectManager.getInstance().createDocument(TYPENAME); |
206 |
doc.setName(name); |
207 |
doc.setStore(store); |
208 |
project.addDocument(doc); |
209 |
} |
210 |
|
211 |
@Override
|
212 |
public DataStore getStore(String name) { |
213 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
214 |
TableDocument tableDoc = (TableDocument) project.getDocument(name, TYPENAME); |
215 |
if( tableDoc==null || tableDoc.getFeatureStore()==null) { |
216 |
return null; |
217 |
} |
218 |
FeatureStore store = tableDoc.getFeatureStore(); |
219 |
DisposeUtils.bind(store); |
220 |
return store;
|
221 |
} |
222 |
|
223 |
} |
224 |
|
225 |
public static final String PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME = |
226 |
"TableDocument";
|
227 |
public static final String PERSISTENCE_TABLELINK_DEFINITION_NAME = |
228 |
"TableLink";
|
229 |
|
230 |
public static String TYPENAME = "project.document.table"; |
231 |
|
232 |
private DynStruct persistenceDefinition = null; |
233 |
|
234 |
@Override
|
235 |
public ImageIcon getIcon() { |
236 |
return IconThemeHelper.getImageIcon("document-table-icon"); |
237 |
} |
238 |
|
239 |
@Override
|
240 |
public ImageIcon getIconSelected() { |
241 |
return IconThemeHelper.getImageIcon("document-table-icon-sel"); |
242 |
} |
243 |
|
244 |
@Override
|
245 |
public String getTitle() { |
246 |
return PluginServices.getText(this, "Tabla"); |
247 |
} |
248 |
|
249 |
@Override
|
250 |
public String getTypeName() { |
251 |
return TYPENAME;
|
252 |
} |
253 |
|
254 |
@Override
|
255 |
public int getPriority() { |
256 |
return 1; |
257 |
} |
258 |
|
259 |
@Override
|
260 |
public Iterator<? extends Document> createDocumentsByUser() { |
261 |
return this.createDocumentsByUser(null); |
262 |
} |
263 |
|
264 |
@Override
|
265 |
public Iterator<? extends Document> createDocumentsByUser(Invocable whenDocumentsLoaded) { |
266 |
AddLayerDialog fopen = null;
|
267 |
try {
|
268 |
fopen = |
269 |
new AddLayerDialog(PluginServices.getText(this, "Nueva_tabla")); |
270 |
List<WizardPanel> wizards =
|
271 |
ApplicationLocator.getManager().getWizardPanels(); |
272 |
|
273 |
Dimension preferredSize = fopen.getPreferredSize();
|
274 |
WizardPanel panel; |
275 |
Iterator<WizardPanel> iter = wizards.iterator();
|
276 |
while (iter.hasNext()) {
|
277 |
panel = iter.next(); |
278 |
panel.initWizard(); |
279 |
Dimension dim = panel.getPreferredSize();
|
280 |
if( dim.height>preferredSize.height ) {
|
281 |
preferredSize.height = dim.height; |
282 |
} |
283 |
if( dim.width>preferredSize.width ) {
|
284 |
preferredSize.width = dim.width; |
285 |
} |
286 |
|
287 |
fopen.addWizardTab(panel.getTabName(), panel); |
288 |
} |
289 |
|
290 |
preferredSize.height += ToolsSwingUtils.rows2px(4);
|
291 |
preferredSize.width += ToolsSwingUtils.cols2px(2);
|
292 |
|
293 |
fopen.setPreferredSize(preferredSize); |
294 |
|
295 |
ToolsSwingUtils.ensureRowsCols(fopen, -1, -1, 30, 100); |
296 |
|
297 |
PluginServices.getMDIManager().addWindow(fopen); |
298 |
if (fopen.isAccepted()) {
|
299 |
WizardPanel selectedPanel = (WizardPanel) fopen.getSelectedTab(); |
300 |
if( whenDocumentsLoaded==null ) { |
301 |
List<TableDocument> docs = (List) selectedPanel.executeWizard(); |
302 |
this.checkDocuments(docs);
|
303 |
return docs.iterator();
|
304 |
} |
305 |
Thread task = new Thread(() -> { |
306 |
List<TableDocument> docs = (List) selectedPanel.executeWizard(); |
307 |
checkDocuments(docs); |
308 |
whenDocumentsLoaded.call(docs.iterator()); |
309 |
}, "DocumentTableLoader");
|
310 |
task.start(); |
311 |
return Collections.EMPTY_LIST.iterator(); |
312 |
} |
313 |
} catch (Exception e) { |
314 |
NotificationManager.addError(e); |
315 |
} finally {
|
316 |
if (fopen != null) { |
317 |
fopen.dispose(); |
318 |
fopen = null;
|
319 |
} |
320 |
} |
321 |
return null; |
322 |
} |
323 |
|
324 |
private void checkDocuments(List<TableDocument> docs) { |
325 |
if( docs==null ) { |
326 |
return;
|
327 |
} |
328 |
for (TableDocument doc : docs) {
|
329 |
try {
|
330 |
FeatureStore store = ((TableDocument)doc).getDataStore(); |
331 |
FeatureType type = store.getDefaultFeatureType(); |
332 |
if( ! type.supportReferences() ) {
|
333 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
334 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
335 |
dialogs.messageDialog( |
336 |
"\""+ doc.getName() + "\"\n"+ |
337 |
i18n.getTranslation("_The_table_has_no_primary_key_or_OID") +"\n" + |
338 |
i18n.getTranslation("_Many_features_selection_deletion_modification_will_not_be_available_as_they_require_it_for_proper_operation"),
|
339 |
null,
|
340 |
i18n.getTranslation("_Warning"),
|
341 |
JOptionPane.WARNING_MESSAGE,
|
342 |
"TableDoNotSupportReferences"
|
343 |
); |
344 |
} |
345 |
} catch (Exception ex) { |
346 |
|
347 |
} |
348 |
} |
349 |
} |
350 |
|
351 |
@Override
|
352 |
public AbstractDocument createDocumentByUser() { |
353 |
return (AbstractDocument) createDocumentsByUser().next(); |
354 |
} |
355 |
|
356 |
/**
|
357 |
* Registers in the points of extension the Factory with alias.
|
358 |
*
|
359 |
*/
|
360 |
public static void register() { |
361 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
362 |
|
363 |
TableManager factory = new TableManager();
|
364 |
// A?adimos nuestra extension para el tratamiento de la apertura de
|
365 |
// ficheros
|
366 |
// dentro de gvSIG
|
367 |
ToolsLocator.getExtensionPointManager().add("FileTableOpenDialog", "") |
368 |
.append("FileOpenTable", "", FilesystemExplorerWizardPanel.class); |
369 |
|
370 |
IconThemeHelper.registerIcon("document", "document-table-icon", TableManager.class); |
371 |
IconThemeHelper.registerIcon("document", "document-table-icon-sel", TableManager.class); |
372 |
IconThemeHelper.registerIcon("document", "document-table-icon-small", TableManager.class); |
373 |
|
374 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
375 |
manager.registerFactory(factory); |
376 |
|
377 |
if (factory.persistenceDefinition == null) { |
378 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
379 |
factory.persistenceDefinition = |
380 |
dynman.createDynClass(PersistenceManager.PERSISTENCE_NAMESPACE, |
381 |
PERSISTENCE_TABLE_DOCUMENT_DEFINITION_NAME, |
382 |
"Table document Persistence definition");
|
383 |
factory.persistenceDefinition.extend(manager |
384 |
.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
385 |
|
386 |
factory.persistenceDefinition.addDynFieldObject("store")
|
387 |
.setClassOfValue(FeatureStore.class).setMandatory(true);
|
388 |
factory.persistenceDefinition.addDynFieldString("featureTypeId")
|
389 |
.setMandatory(false);
|
390 |
factory.persistenceDefinition.addDynFieldArray("attributeNames")
|
391 |
.setClassOfItems(String.class).setMandatory(false); |
392 |
factory.persistenceDefinition.addDynFieldObject("associatedLayer")
|
393 |
.setClassOfValue(FLyrVect.class).setMandatory(false);
|
394 |
factory.persistenceDefinition.addDynFieldObject("query")
|
395 |
.setClassOfValue(FeatureQuery.class).setMandatory(false);
|
396 |
factory.persistenceDefinition.addDynFieldObject("baseFilter")
|
397 |
.setClassOfValue(Evaluator.class).setMandatory(false);
|
398 |
factory.persistenceDefinition.addDynFieldObject("baseOrder")
|
399 |
.setClassOfValue(FeatureQueryOrder.class).setMandatory(false);
|
400 |
factory.persistenceDefinition.addDynFieldList("linkTable")
|
401 |
.setClassOfItems(TableLink.class).setMandatory(false);
|
402 |
factory.persistenceDefinition.addDynFieldMap("patterns")
|
403 |
.setClassOfItems(String.class).setMandatory(false); |
404 |
} |
405 |
|
406 |
//Register also the TableLink
|
407 |
if (manager.getDefinition(PERSISTENCE_TABLELINK_DEFINITION_NAME) == null){ |
408 |
DynStruct tableLinkDefinition = |
409 |
manager.addDefinition(TableLink.class, |
410 |
PERSISTENCE_TABLELINK_DEFINITION_NAME, |
411 |
"TableLink Persistence definition", null, null); |
412 |
|
413 |
tableLinkDefinition.addDynFieldObject("source")
|
414 |
.setClassOfValue(TableDocument.class).setMandatory(true);
|
415 |
tableLinkDefinition.addDynFieldObject("target")
|
416 |
.setClassOfValue(TableDocument.class).setMandatory(true);
|
417 |
tableLinkDefinition.addDynFieldString("fieldSource").setMandatory(true); |
418 |
tableLinkDefinition.addDynFieldString("fieldTarget").setMandatory(true); |
419 |
tableLinkDefinition.addDynFieldBoolean("enabled").setMandatory(true); |
420 |
} |
421 |
|
422 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
423 |
|
424 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
425 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
426 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
427 |
|
428 |
DataManager dataManager = DALLocator.getDataManager(); |
429 |
dataManager.getStoresRepository().addRepository( |
430 |
new TableDocumentStoresRepository(
|
431 |
"PROJECT_TABLES",
|
432 |
i18n.getTranslation("_Project_tables")
|
433 |
) |
434 |
); |
435 |
} |
436 |
|
437 |
/**
|
438 |
* Create a new table document.
|
439 |
*
|
440 |
* @return TableDocument.
|
441 |
*/
|
442 |
@Override
|
443 |
public AbstractDocument createDocument() { |
444 |
AbstractDocument doc = new TableDocument(this); |
445 |
if( this.notifyObservers(NOTIFY_AFTER_CREATEDOCUMENT,doc).isCanceled() ) { |
446 |
return null; |
447 |
} |
448 |
return doc;
|
449 |
} |
450 |
|
451 |
@Override
|
452 |
public Class<? extends IDocumentWindow> getMainWindowClass() { |
453 |
return FeatureTableDocumentPanel.class;
|
454 |
} |
455 |
|
456 |
@Override
|
457 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
458 |
IDocumentWindow win = (IDocumentWindow) super.getMainWindow(doc, layout);
|
459 |
if (win == null) { |
460 |
try {
|
461 |
win = (IDocumentWindow) this.createDocumentWindow(doc);
|
462 |
} catch(Throwable t){ |
463 |
} |
464 |
if(win == null){ |
465 |
try {
|
466 |
((TableDocument)doc).getFeatureStore().refresh(); |
467 |
} catch (DataException ex) {
|
468 |
throw new RuntimeException(ex); |
469 |
} |
470 |
win = (IDocumentWindow) this.createDocumentWindow(doc);
|
471 |
} |
472 |
if (layout != null && win != null) { |
473 |
win.setWindowLayout(layout); |
474 |
} |
475 |
} |
476 |
if( this.notifyObservers(NOTIFY_AFTER_GETMAINWINDOW,win).isCanceled() ) { |
477 |
return null; |
478 |
} |
479 |
return win;
|
480 |
} |
481 |
|
482 |
@Override
|
483 |
public IWindow getPropertiesWindow(Document doc) { |
484 |
IWindow win = super.getPropertiesWindow(doc);
|
485 |
if( win == null ) { |
486 |
win = new TableProperties((TableDocument) doc);
|
487 |
} |
488 |
if( this.notifyObservers(NOTIFY_AFTER_GETPROPERTIESWINDOW,win).isCanceled() ) { |
489 |
return null; |
490 |
} |
491 |
return win;
|
492 |
} |
493 |
|
494 |
@Override
|
495 |
protected Class<? extends Document> getDocumentClass() { |
496 |
return TableDocument.class;
|
497 |
} |
498 |
|
499 |
@Override
|
500 |
public DynStruct getDefinition(String className) { |
501 |
|
502 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
503 |
return this.persistenceDefinition; |
504 |
} |
505 |
if (this.persistenceDefinition.getFullName() |
506 |
.equalsIgnoreCase(className)) { |
507 |
return this.persistenceDefinition; |
508 |
} |
509 |
if (this.getDocumentClass().getName().equals(className)) { |
510 |
return this.persistenceDefinition; |
511 |
} |
512 |
return null; |
513 |
} |
514 |
|
515 |
@Override
|
516 |
public boolean manages(Object object) { |
517 |
return object instanceof TableDocument; |
518 |
} |
519 |
|
520 |
public TableDocument getTableDocument(VectorLayer layer) {
|
521 |
if (layer == null) { |
522 |
return null; |
523 |
} |
524 |
List<Document> tableDocs = |
525 |
getProject().getDocuments(TableManager.TYPENAME); |
526 |
for (Document document : tableDocs) { |
527 |
if (layer == ((TableDocument) document).getAssociatedLayer()) {
|
528 |
return (TableDocument) document;
|
529 |
} |
530 |
} |
531 |
return null; |
532 |
} |
533 |
|
534 |
public void removeTableDocument(VectorLayer layer) { |
535 |
TableDocument doc = getTableDocument(layer); |
536 |
// Only remove it if it exists
|
537 |
if (doc != null) { |
538 |
PluginServices.getMDIManager().closeSingletonWindow(doc); |
539 |
getProject().remove(doc); |
540 |
} |
541 |
} |
542 |
|
543 |
private Project getProject() {
|
544 |
return ProjectManager.getInstance().getCurrentProject();
|
545 |
} |
546 |
} |