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 / extension / TableEditStartExtension.java @ 42966
History | View | Annotate | Download (3.84 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import org.gvsig.andami.IconThemeHelper; |
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.project.documents.table.TableDocument; |
30 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
31 |
import org.gvsig.fmap.dal.EditingNotification; |
32 |
import org.gvsig.fmap.dal.EditingNotificationManager; |
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
public class TableEditStartExtension extends AbstractTableEditExtension { |
40 |
|
41 |
private static final Logger logger = LoggerFactory.getLogger(TableEditStartExtension.class); |
42 |
|
43 |
public void initialize() { |
44 |
super.initialize();
|
45 |
IconThemeHelper.registerIcon("action", "table-start-editing", this); |
46 |
} |
47 |
|
48 |
public void execute(String actionCommand) { |
49 |
if ("table-start-editing".equals(actionCommand)) { |
50 |
try {
|
51 |
TableDocument doc = (TableDocument) table.getDocument(); |
52 |
EditingNotificationManager editingNotification = DALSwingLocator.getEditingNotificationManager(); |
53 |
EditingNotification notification = editingNotification.notifyObservers( |
54 |
this,
|
55 |
EditingNotification.BEFORE_ENTER_EDITING_STORE, |
56 |
doc, |
57 |
doc.getStore()); |
58 |
if (notification.isCanceled()) {
|
59 |
return;
|
60 |
} |
61 |
doc.getStore().edit(FeatureStore.MODE_FULLEDIT); |
62 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
63 |
editingNotification.notifyObservers( |
64 |
this,
|
65 |
EditingNotification.AFTER_ENTER_EDITING_STORE, |
66 |
doc, |
67 |
doc.getStore()); |
68 |
} catch (DataException e) {
|
69 |
logger.warn("Problems starting table editing.", e);
|
70 |
} |
71 |
} |
72 |
} |
73 |
|
74 |
public boolean isEnabled() { |
75 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
76 |
|
77 |
if (v == null) { |
78 |
return false; |
79 |
} |
80 |
if (v instanceof FeatureTableDocumentPanel) { |
81 |
FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v; |
82 |
FeatureStore fs = t.getModel().getStore(); |
83 |
return fs.allowWrite();
|
84 |
} |
85 |
return false; |
86 |
} |
87 |
|
88 |
public boolean isVisible() { |
89 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
90 |
|
91 |
if (v == null) { |
92 |
return false; |
93 |
} |
94 |
|
95 |
if (v instanceof FeatureTableDocumentPanel |
96 |
&& !((FeatureTableDocumentPanel) v).getModel().getStore().isEditing()) { |
97 |
table = (FeatureTableDocumentPanel) v; |
98 |
return true; |
99 |
} |
100 |
|
101 |
return false; |
102 |
} |
103 |
} |