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

History | View | Annotate | Download (4.24 KB)

1 40558 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3 40435 jjdelcerro
 *
4 40558 jjdelcerro
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 40435 jjdelcerro
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8 40558 jjdelcerro
 * as published by the Free Software Foundation; either version 3
9 40435 jjdelcerro
 * of the License, or (at your option) any later version.
10 40558 jjdelcerro
 *
11 40435 jjdelcerro
 * 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 40558 jjdelcerro
 *
16 40435 jjdelcerro
 * 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 40558 jjdelcerro
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 40435 jjdelcerro
 * MA  02110-1301, USA.
20 40558 jjdelcerro
 *
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 40435 jjdelcerro
 */
24
package org.gvsig.app.extension;
25
26 41013 jldominguez
27 40435 jjdelcerro
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 44437 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureType;
35 40435 jjdelcerro
36
public class TableRowsOperations extends Extension {
37
38 44437 jjdelcerro
    @Override
39 40435 jjdelcerro
    public void initialize() {
40
        registerIcons();
41
    }
42
43
    private void registerIcons() {
44
            IconThemeHelper.registerIcon("action", "selection-move-up", this);
45 41630 jjdelcerro
            IconThemeHelper.registerIcon("action", "selection-disable-move-up", this);
46 40435 jjdelcerro
            IconThemeHelper.registerIcon("action", "selection-reverse", this);
47
    }
48
49 44437 jjdelcerro
    @Override
50 40435 jjdelcerro
    public void execute(String actionCommand) {
51
        FeatureTableDocumentPanel tableDocument = getTableDocument();
52 41630 jjdelcerro
        if (actionCommand.equalsIgnoreCase("selection-disable-move-up") ) {
53
            tableDocument.setSelectionUp(false);
54
        }
55 40435 jjdelcerro
        if (actionCommand.equalsIgnoreCase("selection-move-up") ) {
56 41630 jjdelcerro
//            if (thereIsSelection(tableDocument)) {
57
                tableDocument.setSelectionUp(true);
58 41013 jldominguez
                tableDocument.getModel().setModified(true);
59 41630 jjdelcerro
//            } 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 41013 jldominguez
67 40435 jjdelcerro
        }
68
        if (actionCommand.equalsIgnoreCase("selection-reverse") ) {
69
            invertSelection(tableDocument);
70 41013 jldominguez
            tableDocument.getModel().setModified(true);
71 40435 jjdelcerro
        }
72 41013 jldominguez
73 40435 jjdelcerro
    }
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 44437 jjdelcerro
            logger.warn("Can't invert selecction", e);
86 40435 jjdelcerro
        }
87
    }
88
89 44437 jjdelcerro
    @Override
90 40435 jjdelcerro
    public boolean isEnabled() {
91 44437 jjdelcerro
        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 40435 jjdelcerro
    }
105
106 44437 jjdelcerro
    @Override
107 40435 jjdelcerro
    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 41013 jldominguez
119
    private boolean thereIsSelection(FeatureTableDocumentPanel tabledoc) {
120
121
        if (tabledoc != null) {
122 46277 jjdelcerro
            return !tabledoc.getModel().getStore().isFeatureSelectionEmpty();
123 41013 jldominguez
        }
124
        return false;
125
126
    }
127 40435 jjdelcerro
}