Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / toggle / AbstractTogglePropertyExtension.java @ 38707

History | View | Annotate | Download (3.83 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2012 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.editing.toggle;
24

    
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

    
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.view.gui.DefaultViewPanel;
32
import org.gvsig.editing.EditionUtilities;
33
import org.gvsig.fmap.mapcontrol.MapControl;
34

    
35

    
36
/**
37
 * @author jldominguez
38
 *
39
 */
40
public abstract class AbstractTogglePropertyExtension extends Extension {
41

    
42
    private static Logger logger =
43
        LoggerFactory.getLogger(AbstractTogglePropertyExtension.class);
44
    
45
    public void initialize() {
46
    }
47

    
48
    public boolean canQueryByAction() {
49
        return true;
50
    }
51
    
52
    public boolean isEnabled(String action) {
53
        return optionMustBeAvailable();
54
    }
55
    
56
    public boolean isVisible(String action) {
57
        
58
        if (!optionMustBeAvailable()) {
59
            return false;
60
        }
61
        
62
        boolean curr_value = isToggleActive();
63
        if (curr_value) {
64
            // now it is ON. The one that switches OFF Will be available
65
            return (action.compareTo(getActionCommand(false)) == 0);
66
        } else {
67
            // now it is OFF. The one that switches ON Will be available
68
            return (action.compareTo(getActionCommand(true)) == 0);
69
        }
70
        
71
    }
72
    
73
    public void execute(String actionCommand) {
74
        
75
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
76
        if (!(v instanceof org.gvsig.app.project.documents.view.gui.DefaultViewPanel)) {
77
            logger.info("Executing toggle extension when window is not view (?)");
78
            return;
79
        }
80
            
81
        MapControl mc=((DefaultViewPanel)v).getMapControl();
82
        
83
        boolean new_value = false;
84
        if (actionCommand.compareTo(getActionCommand(true)) == 0) {
85
            new_value = true;
86
        } else {
87
            if (actionCommand.compareTo(getActionCommand(false)) == 0) {
88
                new_value = false;
89
            } else {
90
                logger.info("Executing toggle extension. Unexpected command: " + actionCommand);
91
                return;
92
            }
93
        }
94
        
95
        doSetValue(mc, new_value);
96
        PluginServices.getMainFrame().enableControls();
97
    }
98

    
99
    protected abstract void doSetValue(MapControl mc, boolean new_value);
100

    
101
    public boolean isEnabled() {
102
        return false;
103
    }
104

    
105
    public boolean isVisible() {
106
        return false;
107
    }
108
    
109
    // ========================
110
    
111
    protected boolean optionMustBeAvailable() {
112
        return (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE);
113
    }
114
    
115
    protected abstract boolean isToggleActive();
116
    
117
    protected abstract String getActionCommand(boolean on_off);
118
    
119
    
120

    
121
}