root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / TableEditStartExtension.java @ 38564
History | View | Annotate | Download (3.68 KB)
1 | 36443 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | package org.gvsig.app.extension; |
||
23 | |||
24 | import java.util.List; |
||
25 | |||
26 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
27 | 36443 | cordinyana | import org.gvsig.andami.PluginServices; |
28 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
29 | import org.gvsig.app.project.documents.table.TableDocument.TableLink; |
||
30 | import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
||
31 | import org.gvsig.fmap.dal.exception.DataException; |
||
32 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
33 | |||
34 | /**
|
||
35 | * DOCUMENT ME!
|
||
36 | *
|
||
37 | * @author Vicente Caballero Navarro
|
||
38 | */
|
||
39 | public class TableEditStartExtension extends AbstractTableEditExtension { |
||
40 | |||
41 | 38564 | jjdelcerro | |
42 | public void initialize() { |
||
43 | super.initialize();
|
||
44 | IconThemeHelper.registerIcon("action", "table-start-editing", this); |
||
45 | } |
||
46 | 36443 | cordinyana | /**
|
47 | * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
||
48 | */
|
||
49 | public void execute(String actionCommand) { |
||
50 | 38564 | jjdelcerro | if ("table-start-editing".equals(actionCommand)) { |
51 | 36443 | cordinyana | try {
|
52 | table.getModel().getStore().edit(FeatureStore.MODE_FULLEDIT); |
||
53 | } catch (DataException e) {
|
||
54 | e.printStackTrace(); |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /**
|
||
60 | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
||
61 | */
|
||
62 | public boolean isEnabled() { |
||
63 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
64 | |||
65 | if (v == null) { |
||
66 | return false; |
||
67 | } |
||
68 | if (v instanceof FeatureTableDocumentPanel) { |
||
69 | FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v; |
||
70 | FeatureStore fs = t.getModel().getStore(); |
||
71 | // FJP:
|
||
72 | // Si est? linkada, por ahora no dejamos editar
|
||
73 | // TODO: Esto evita la edici?n en un sentido, pero no en el otro
|
||
74 | // Hay que permitir la edici?n, pero evitar que toquen el/los
|
||
75 | // campos de uni?n. Para eso tendremos que a?adir alguna funci?n
|
||
76 | // que indique si un campo est? involucrado en alguna uni?n, o
|
||
77 | // quiz?s algo m?s gen?rico, algo que permita bloquear campos
|
||
78 | // para que no se puedan editar.
|
||
79 | List<TableLink> links = t.getModel().getLinks();
|
||
80 | if (links != null && links.size() > 0) { |
||
81 | return false; |
||
82 | } |
||
83 | return fs.allowWrite();
|
||
84 | } |
||
85 | return false; |
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * @see org.gvsig.andami.plugins.IExtension#isVisible()
|
||
90 | */
|
||
91 | public boolean isVisible() { |
||
92 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
93 | |||
94 | if (v == null) { |
||
95 | return false; |
||
96 | } |
||
97 | |||
98 | if (v instanceof FeatureTableDocumentPanel |
||
99 | && !((FeatureTableDocumentPanel) v).getModel().getStore() |
||
100 | .isEditing() |
||
101 | && ((FeatureTableDocumentPanel) v).getModel().getAssociatedLayer() == null) {
|
||
102 | table = (FeatureTableDocumentPanel) v; |
||
103 | return true; |
||
104 | } |
||
105 | |||
106 | return false; |
||
107 | } |
||
108 | } |