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

History | View | Annotate | Download (4.41 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

    
27
import org.gvsig.andami.IconThemeHelper;
28
import org.gvsig.andami.PluginServices;
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
import org.gvsig.fmap.dal.feature.FeatureType;
35

    
36
public class TableRowsOperations extends Extension {
37

    
38
    @Override
39
    public void initialize() {
40
        registerIcons();
41
    }
42

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

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

    
75
    /**
76
     * Flip the selection (inverts selection)
77
     * 
78
     * @param table
79
     */
80
    private void invertSelection(FeatureTableDocumentPanel table) {
81
        try {
82
            FeatureStore fs = getTableDocument().getModel().getStore();
83
            fs.getFeatureSelection().reverse();
84
        } catch (DataException e) {
85
            logger.warn("Can't invert selecction", e);
86
        }
87
    }
88

    
89
    @Override
90
    public boolean isEnabled() {
91
        FeatureTableDocumentPanel panel = getTableDocument();
92
        if( panel == null ) {
93
            return false;
94
        }
95
        FeatureStore store = panel.getFeatureStore();
96
        try {
97
            if( !store.getFeatureSelection().isAvailable() ) {
98
                return false;
99
            }
100
        } catch (Exception ex) {
101
        }                        
102
        
103
        return  true;
104
    }
105

    
106
    @Override
107
    public boolean isVisible() {
108
        return getTableDocument() != null;
109
    }
110

    
111
    private FeatureTableDocumentPanel getTableDocument() {
112
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
113
        if (v != null && v instanceof FeatureTableDocumentPanel) {
114
            return (FeatureTableDocumentPanel) v;
115
        }
116
        return null;
117
    }
118
    
119
    private boolean thereIsSelection(FeatureTableDocumentPanel tabledoc) {
120
        
121
        if (tabledoc != null) {
122
            try {
123
                return !tabledoc.getModel().getStore()
124
                    .getFeatureSelection().isEmpty();
125
            } catch (Exception e) {
126
                logger.warn("Can't check if table has a selecction", e);
127
            }
128
        }
129
        return false;
130
        
131
    }
132
}