Statistics
| Revision:

svn-gvsig-desktop / 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 / TableFieldOperations.java @ 38564

History | View | Annotate | Download (3.67 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 org.gvsig.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
29
import org.gvsig.fmap.dal.exception.DataException;
30
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel;
31
import org.gvsig.tools.exception.BaseException;
32

    
33
/**
34
 * Ascending or descending order operations.
35
 * 
36
 * @author Vicente Caballero Navarro
37
 */
38
public class TableFieldOperations extends Extension {
39

    
40
    private FeatureTableDocumentPanel table = null;
41

    
42
    /**
43
     * @see org.gvsig.andami.plugins.IExtension#initialize()
44
     */
45
    public void initialize() {
46
        IconThemeHelper.registerIcon("action", "table-order-desc", this);
47
        IconThemeHelper.registerIcon("action", "table-order-asc", this);
48
    }
49

    
50
    /**
51
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
52
     */
53
    public void execute(String actionCommand) {
54
        doExecute(actionCommand, table);
55
        table.getModel().setModified(true);
56
    }
57

    
58
    /**
59
     * "execute" method acction
60
     * 
61
     * @param actionCommand
62
     *            The acction command that executes this method
63
     * @param table
64
     *            Table to operate
65
     */
66
    protected void doExecute(String actionCommand,
67
        FeatureTableDocumentPanel table) {
68
        // FIXME
69
        ConfigurableFeatureTableModel cftm =
70
            table.getTablePanel().getTableModel();
71
        try {
72
            if ("table-order-asc".equals(actionCommand)) {
73
                cftm.orderByColumn(table.getTablePanel().getTable()
74
                    .getSelectedColumnsAttributeDescriptor()[0].getName(), true);
75
            } else
76
                if ("table-order-desc".equals(actionCommand)) {
77
                    cftm.orderByColumn(table.getTablePanel().getTable()
78
                        .getSelectedColumnsAttributeDescriptor()[0].getName(),
79
                        false);
80
                }
81
        } catch (BaseException e) {
82
            e.printStackTrace();
83
        }
84
    }
85

    
86
    /**
87
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
88
     */
89
    public boolean isEnabled() {
90
        try {
91
            return (table.getTablePanel().getTable().getSelectedColumnCount() == 1);
92
        } catch (DataException e) {
93
            e.printStackTrace();
94
        }
95
        return false;
96
    }
97

    
98
    /**
99
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
100
     */
101
    public boolean isVisible() {
102
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
103
        if (v != null && v instanceof FeatureTableDocumentPanel) {
104
            table = (FeatureTableDocumentPanel) v;
105
            return true;
106
        }
107
        return false;
108
    }
109

    
110
}