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 / TableRowsOperations.java @ 40558

History | View | Annotate | Download (3.36 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.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
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
public class TableRowsOperations extends Extension {
36

    
37
    public void initialize() {
38
        registerIcons();
39
    }
40

    
41
    private void registerIcons() {
42
            IconThemeHelper.registerIcon("action", "selection-move-up", this);
43
            IconThemeHelper.registerIcon("action", "selection-reverse", this);    
44
    }
45

    
46
    public void execute(String actionCommand) {
47
        FeatureTableDocumentPanel tableDocument = getTableDocument();
48
        if (actionCommand.equalsIgnoreCase("selection-move-up") ) {
49
            showsSelectedRows(tableDocument);
50
        }
51
        if (actionCommand.equalsIgnoreCase("selection-reverse") ) {
52
            invertSelection(tableDocument);
53
        }
54
        tableDocument.getModel().setModified(true);
55
    }
56

    
57
    /**
58
     * Flip the selection (inverts selection)
59
     * 
60
     * @param table
61
     */
62
    private void invertSelection(FeatureTableDocumentPanel table) {
63
        try {
64
            FeatureStore fs = getTableDocument().getModel().getStore();
65
            fs.getFeatureSelection().reverse();
66
        } catch (DataException e) {
67
            e.printStackTrace();
68
            NotificationManager.addError(e);
69
        }
70
    }
71

    
72
    private void showsSelectedRows(FeatureTableDocumentPanel table) {
73
        table.setSelectionUp(true);
74
    }
75

    
76
    public boolean isEnabled() {
77
        FeatureTableDocumentPanel tableDocument = getTableDocument();
78

    
79
        if (tableDocument != null) {
80
            try {
81
                return !tableDocument.getModel().getStore()
82
                    .getFeatureSelection().isEmpty();
83
            } catch (DataException e) {
84
                NotificationManager.addError(e);
85
            }
86
        }
87

    
88
        return false;
89
    }
90

    
91
    public boolean isVisible() {
92
        return getTableDocument() != null;
93
    }
94

    
95
    private FeatureTableDocumentPanel getTableDocument() {
96
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
97
        if (v != null && v instanceof FeatureTableDocumentPanel) {
98
            return (FeatureTableDocumentPanel) v;
99
        }
100
        return null;
101
    }
102
}