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 @ 42775
History | View | Annotate | Download (4.13 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 |
package org.gvsig.app.extension; |
25 |
|
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
30 |
import org.gvsig.app.ApplicationLocator; |
31 |
import org.gvsig.app.project.documents.table.TableDocument; |
32 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
33 |
import org.gvsig.fmap.dal.EditingNotification; |
34 |
import org.gvsig.fmap.dal.EditingNotificationManager; |
35 |
import org.gvsig.fmap.dal.exception.DataException; |
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
/**
|
42 |
* DOCUMENT ME!
|
43 |
*
|
44 |
* @author Vicente Caballero Navarro
|
45 |
*/
|
46 |
public class TableEditStartExtension extends AbstractTableEditExtension { |
47 |
private static final Logger logger = LoggerFactory.getLogger(TableEditStartExtension.class); |
48 |
|
49 |
public void initialize() { |
50 |
super.initialize();
|
51 |
IconThemeHelper.registerIcon("action", "table-start-editing", this); |
52 |
} |
53 |
/**
|
54 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
55 |
*/
|
56 |
public void execute(String actionCommand) { |
57 |
if ("table-start-editing".equals(actionCommand)) { |
58 |
try {
|
59 |
TableDocument doc = (TableDocument) table.getDocument(); |
60 |
EditingNotificationManager editingNotification = DALSwingLocator.getEditingNotificationManager(); |
61 |
EditingNotification notification = editingNotification.notifyObservers( |
62 |
this,
|
63 |
EditingNotification.BEFORE_ENTER_EDITING_STORE, |
64 |
doc, |
65 |
doc.getStore()); |
66 |
if( notification.isCanceled() ) {
|
67 |
return;
|
68 |
} |
69 |
doc.getStore().edit(FeatureStore.MODE_FULLEDIT); |
70 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
71 |
editingNotification.notifyObservers( |
72 |
this,
|
73 |
EditingNotification.AFTER_ENTER_EDITING_STORE, |
74 |
doc, |
75 |
doc.getStore()); |
76 |
} catch (DataException e) {
|
77 |
logger.warn("Problems starting table editing.",e);
|
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
/**
|
83 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
84 |
*/
|
85 |
public boolean isEnabled() { |
86 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
87 |
|
88 |
if (v == null) { |
89 |
return false; |
90 |
} |
91 |
if (v instanceof FeatureTableDocumentPanel) { |
92 |
FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v; |
93 |
FeatureStore fs = t.getModel().getStore(); |
94 |
return fs.allowWrite();
|
95 |
} |
96 |
return false; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
101 |
*/
|
102 |
public boolean isVisible() { |
103 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
104 |
|
105 |
if (v == null) { |
106 |
return false; |
107 |
} |
108 |
|
109 |
if (v instanceof FeatureTableDocumentPanel |
110 |
&& !((FeatureTableDocumentPanel) v).getModel().getStore().isEditing()) { |
111 |
table = (FeatureTableDocumentPanel) v; |
112 |
return true; |
113 |
} |
114 |
|
115 |
return false; |
116 |
} |
117 |
} |