Statistics
| Revision:

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 / TableEditChangeColumnsExtension.java @ 44616

History | View | Annotate | Download (3.81 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 org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.ApplicationManager;
31
import org.gvsig.app.project.documents.table.TableDocument;
32
import org.gvsig.app.project.documents.table.TableManager;
33
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
34
import org.gvsig.fmap.dal.DataStoreProviderFactory;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
38

    
39
/**
40
 * DOCUMENT ME!
41
 *
42
 * @author Vicente Caballero Navarro
43
 */
44
public class TableEditChangeColumnsExtension extends AbstractTableEditExtension {
45

    
46
    public void initialize() {
47
        super.initialize();
48
        IconThemeHelper.registerIcon("action", "table-rename-column", this);
49
        IconThemeHelper.registerIcon("action", "table-remove-column", this);
50
    }
51

    
52
    /**
53
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
54
     */
55
    public void execute(String actionCommand) {
56
        try {
57
            featureTableOperations.setTablePanel(table);
58
            if ("table-remove-column".equals(actionCommand)) {
59
                featureTableOperations.deleteAttributes(table.getTablePanel()
60
                        .getTable());
61
            } else if ("table-rename-column".equals(actionCommand)) {
62
                featureTableOperations.renameAttributes(table
63
                        .getTablePanel().getTable());
64
            }
65
        } catch (DataException e) {
66
            NotificationManager.showMessageError(
67
                    PluginServices.getText(this, "update_featuretype_error"), null);
68
        }
69

    
70
    }
71

    
72
    @Override
73
    public boolean isEnabled() {
74
        try {
75
            FeatureStore store = table.getFeatureStore();
76

    
77
            DataStoreProviderFactory factory = store.getProviderFactory();
78
            if (factory instanceof FeatureStoreProviderFactory) {
79
                FeatureStoreProviderFactory ffactory = (FeatureStoreProviderFactory) factory;
80
                if (ffactory.allowEditableFeatureType() == FeatureStoreProviderFactory.NO) {
81
                    return false;
82
                }
83
            }
84
            if (table.getTablePanel().getTable().getSelectedColumnCount() > 0) {
85
                return true;
86
            }
87
        } catch (DataException e) {
88
            return false;
89
        }
90
        return false;
91
    }
92

    
93
    @Override
94
    public boolean isVisible() {
95
        ApplicationManager application = ApplicationLocator.getManager();
96
        TableDocument tableDoc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME);
97
        if (tableDoc == null) {
98
            return false;
99
        }
100
        this.table = (FeatureTableDocumentPanel) tableDoc.getMainComponent();
101
        return true;
102
    }
103

    
104
}