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 @ 42967
History | View | Annotate | Download (4.13 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 42966 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
11 | 42966 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 42966 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
20 | 42966 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
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 | 41323 | jjdelcerro | import org.gvsig.app.project.documents.table.TableDocument; |
30 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
31 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.EditingNotification; |
32 | import org.gvsig.fmap.dal.EditingNotificationManager; |
||
33 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.exception.DataException; |
34 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
35 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
36 | 42967 | jjdelcerro | import org.gvsig.tools.util.ArrayUtils; |
37 | 41323 | jjdelcerro | import org.slf4j.Logger; |
38 | import org.slf4j.LoggerFactory; |
||
39 | 40435 | jjdelcerro | |
40 | public class TableEditStartExtension extends AbstractTableEditExtension { |
||
41 | 42146 | fdiaz | |
42 | 42966 | jjdelcerro | private static final Logger logger = LoggerFactory.getLogger(TableEditStartExtension.class); |
43 | |||
44 | 42967 | jjdelcerro | @Override
|
45 | 42966 | jjdelcerro | public void initialize() { |
46 | super.initialize();
|
||
47 | IconThemeHelper.registerIcon("action", "table-start-editing", this); |
||
48 | } |
||
49 | |||
50 | 40435 | jjdelcerro | public void execute(String actionCommand) { |
51 | 42967 | jjdelcerro | this.execute(actionCommand,null); |
52 | } |
||
53 | |||
54 | @Override
|
||
55 | public void execute(String actionCommand, Object[] args) { |
||
56 | 40435 | jjdelcerro | if ("table-start-editing".equals(actionCommand)) { |
57 | try {
|
||
58 | 42967 | jjdelcerro | TableDocument doc = (TableDocument)ArrayUtils.get(args,0);
|
59 | if( doc == null ) { |
||
60 | doc = (TableDocument) table.getDocument(); |
||
61 | } |
||
62 | 42775 | jjdelcerro | EditingNotificationManager editingNotification = DALSwingLocator.getEditingNotificationManager(); |
63 | 41323 | jjdelcerro | EditingNotification notification = editingNotification.notifyObservers( |
64 | 42146 | fdiaz | this,
|
65 | EditingNotification.BEFORE_ENTER_EDITING_STORE, |
||
66 | 41323 | jjdelcerro | doc, |
67 | doc.getStore()); |
||
68 | 42966 | jjdelcerro | if (notification.isCanceled()) {
|
69 | 41323 | jjdelcerro | return;
|
70 | } |
||
71 | doc.getStore().edit(FeatureStore.MODE_FULLEDIT); |
||
72 | 40435 | jjdelcerro | ApplicationLocator.getManager().refreshMenusAndToolBars(); |
73 | 41323 | jjdelcerro | editingNotification.notifyObservers( |
74 | 42146 | fdiaz | this,
|
75 | EditingNotification.AFTER_ENTER_EDITING_STORE, |
||
76 | 41323 | jjdelcerro | doc, |
77 | doc.getStore()); |
||
78 | 40435 | jjdelcerro | } catch (DataException e) {
|
79 | 42966 | jjdelcerro | logger.warn("Problems starting table editing.", e);
|
80 | 40435 | jjdelcerro | } |
81 | } |
||
82 | } |
||
83 | |||
84 | public boolean isEnabled() { |
||
85 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
86 | |||
87 | if (v == null) { |
||
88 | return false; |
||
89 | } |
||
90 | if (v instanceof FeatureTableDocumentPanel) { |
||
91 | FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v; |
||
92 | FeatureStore fs = t.getModel().getStore(); |
||
93 | return fs.allowWrite();
|
||
94 | } |
||
95 | return false; |
||
96 | } |
||
97 | |||
98 | public boolean isVisible() { |
||
99 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
100 | |||
101 | if (v == null) { |
||
102 | return false; |
||
103 | } |
||
104 | |||
105 | if (v instanceof FeatureTableDocumentPanel |
||
106 | 42966 | jjdelcerro | && !((FeatureTableDocumentPanel) v).getModel().getStore().isEditing()) { |
107 | 40435 | jjdelcerro | table = (FeatureTableDocumentPanel) v; |
108 | return true; |
||
109 | } |
||
110 | |||
111 | return false; |
||
112 | } |
||
113 | } |