Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2055 / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / TableEditStartExtension.java @ 38974

History | View | Annotate | Download (3.79 KB)

1
/* 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
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.project.documents.table.TableDocument.TableLink;
31
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34

    
35
/**
36
 * DOCUMENT ME!
37
 * 
38
 * @author Vicente Caballero Navarro
39
 */
40
public class TableEditStartExtension extends AbstractTableEditExtension {
41

    
42
        
43
        public void initialize() {
44
                super.initialize();
45
                IconThemeHelper.registerIcon("action", "table-start-editing", this);
46
        }
47
    /**
48
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
49
     */
50
    public void execute(String actionCommand) {
51
        if ("table-start-editing".equals(actionCommand)) {
52
            try {
53
                table.getModel().getStore().edit(FeatureStore.MODE_FULLEDIT);
54
                ApplicationLocator.getManager().refreshMenusAndToolBars();
55
            } catch (DataException e) {
56
                e.printStackTrace();
57
            }
58
        }
59
    }
60

    
61
    /**
62
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
63
     */
64
    public boolean isEnabled() {
65
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
66

    
67
        if (v == null) {
68
            return false;
69
        }
70
        if (v instanceof FeatureTableDocumentPanel) {
71
            FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v;
72
            FeatureStore fs = t.getModel().getStore();
73
            // FJP:
74
            // Si est? linkada, por ahora no dejamos editar
75
            // TODO: Esto evita la edici?n en un sentido, pero no en el otro
76
            // Hay que permitir la edici?n, pero evitar que toquen el/los
77
            // campos de uni?n. Para eso tendremos que a?adir alguna funci?n
78
            // que indique si un campo est? involucrado en alguna uni?n, o
79
            // quiz?s algo m?s gen?rico, algo que permita bloquear campos
80
            // para que no se puedan editar.
81
            List<TableLink> links = t.getModel().getLinks();
82
            if (links != null && links.size() > 0) {
83
                return false;
84
            }
85
            return fs.allowWrite();
86
        }
87
        return false;
88
    }
89

    
90
    /**
91
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
92
     */
93
    public boolean isVisible() {
94
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
95

    
96
        if (v == null) {
97
            return false;
98
        }
99

    
100
        if (v instanceof FeatureTableDocumentPanel
101
            && !((FeatureTableDocumentPanel) v).getModel().getStore()
102
                .isEditing()
103
            && ((FeatureTableDocumentPanel) v).getModel().getAssociatedLayer() == null) {
104
            table = (FeatureTableDocumentPanel) v;
105
            return true;
106
        }
107

    
108
        return false;
109
    }
110
}