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 @ 41630

History | View | Annotate | Download (4.23 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 javax.swing.JOptionPane;
27

    
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.messages.NotificationManager;
31
import org.gvsig.andami.plugins.Extension;
32
import org.gvsig.andami.ui.mdiManager.IWindow;
33
import org.gvsig.app.ApplicationLocator;
34
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.i18n.Messages;
38

    
39
public class TableRowsOperations extends Extension {
40

    
41
    public void initialize() {
42
        registerIcons();
43
    }
44

    
45
    private void registerIcons() {
46
            IconThemeHelper.registerIcon("action", "selection-move-up", this);
47
            IconThemeHelper.registerIcon("action", "selection-disable-move-up", this);
48
            IconThemeHelper.registerIcon("action", "selection-reverse", this);    
49
    }
50

    
51
    public void execute(String actionCommand) {
52
        FeatureTableDocumentPanel tableDocument = getTableDocument();
53
        if (actionCommand.equalsIgnoreCase("selection-disable-move-up") ) {
54
            tableDocument.setSelectionUp(false);
55
        }
56
        if (actionCommand.equalsIgnoreCase("selection-move-up") ) {
57
//            if (thereIsSelection(tableDocument)) {
58
                tableDocument.setSelectionUp(true);
59
                tableDocument.getModel().setModified(true);
60
//            } else {
61
//                JOptionPane.showMessageDialog(
62
//                    ApplicationLocator.getManager().getRootComponent(),
63
//                    Messages.getText("_There_are_no_selected_rows"),
64
//                    Messages.getText("_Move_up_selection"),
65
//                    JOptionPane.INFORMATION_MESSAGE);
66
//            }
67
            
68
        }
69
        if (actionCommand.equalsIgnoreCase("selection-reverse") ) {
70
            invertSelection(tableDocument);
71
            tableDocument.getModel().setModified(true);
72
        }
73
        
74
    }
75

    
76
    /**
77
     * Flip the selection (inverts selection)
78
     * 
79
     * @param table
80
     */
81
    private void invertSelection(FeatureTableDocumentPanel table) {
82
        try {
83
            FeatureStore fs = getTableDocument().getModel().getStore();
84
            fs.getFeatureSelection().reverse();
85
        } catch (DataException e) {
86
            e.printStackTrace();
87
            NotificationManager.addError(e);
88
        }
89
    }
90

    
91
//    private void showsSelectedRows(FeatureTableDocumentPanel table) {
92
//        table.setSelectionUp(true);
93
//    }
94

    
95
    public boolean isEnabled() {
96
        return getTableDocument() != null;
97
    }
98

    
99
    public boolean isVisible() {
100
        return getTableDocument() != null;
101
    }
102

    
103
    private FeatureTableDocumentPanel getTableDocument() {
104
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
105
        if (v != null && v instanceof FeatureTableDocumentPanel) {
106
            return (FeatureTableDocumentPanel) v;
107
        }
108
        return null;
109
    }
110
    
111
    private boolean thereIsSelection(FeatureTableDocumentPanel tabledoc) {
112
        
113
        if (tabledoc != null) {
114
            try {
115
                return !tabledoc.getModel().getStore()
116
                    .getFeatureSelection().isEmpty();
117
            } catch (DataException e) {
118
                NotificationManager.addError(e);
119
            }
120
        }
121
        return false;
122
        
123
    }
124
}