Revision 38764 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/toggle/AbstractTogglePropertyExtension.java

View differences:

AbstractTogglePropertyExtension.java
45 45
    public void initialize() {
46 46
    }
47 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 48
    public void execute(String actionCommand) {
74 49
        
75 50
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
......
77 52
            logger.info("Executing toggle extension when window is not view (?)");
78 53
            return;
79 54
        }
80
            
81
        MapControl mc=((DefaultViewPanel)v).getMapControl();
82 55
        
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
            }
56
        if (actionCommand.compareTo(getActionCommand()) != 0) {
57
            logger.info("Executing toggle extension. Unexpected command: " + actionCommand
58
                + ". Expected: " + getActionCommand());
59
            return;
93 60
        }
94
        
95
        doSetValue(mc, new_value);
96
        PluginServices.getMainFrame().enableControls();
61
            
62
        MapControl mc=((DefaultViewPanel)v).getMapControl();
63
        doToggleValue(mc);
97 64
    }
98 65

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

  
101 67
    public boolean isEnabled() {
102
        return false;
68
        return isVisible();
103 69
    }
104 70

  
105 71
    public boolean isVisible() {
106
        return false;
72
        return optionMustBeAvailable();
107 73
    }
108 74
    
109 75
    // ========================
......
112 78
        return (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE);
113 79
    }
114 80
    
115
    protected abstract boolean isToggleActive();
116
    
117
    protected abstract String getActionCommand(boolean on_off);
118
    
119
    
81
    protected abstract String getActionCommand();
82
    protected abstract void doToggleValue(MapControl mc);
120 83

  
121 84
}

Also available in: Unified diff