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