Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / featuretype / featurerule / FeatureRuleController.java @ 47378

History | View | Annotate | Download (6.84 KB)

1
package org.gvsig.fmap.dal.swing.impl.featuretype.featurerule;
2

    
3
import javax.swing.JButton;
4
import javax.swing.JCheckBox;
5
import javax.swing.text.JTextComponent;
6
import org.apache.commons.lang3.StringUtils;
7
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator;
8
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager;
9
import org.gvsig.expressionevaluator.swing.ExpressionPickerController;
10
import org.gvsig.fmap.dal.feature.FeatureRule;
11
import org.gvsig.fmap.dal.feature.FeatureRuleExpression;
12
import org.gvsig.fmap.dal.feature.FeatureStore;
13
import org.gvsig.fmap.dal.swing.DALSwingLocator;
14
import org.gvsig.fmap.dal.swing.DataSwingManager;
15
import org.gvsig.fmap.dal.swing.expressionevaluator.FeatureStoreElement;
16
import org.gvsig.fmap.dal.swing.impl.featuretype.AggregateController;
17
import org.gvsig.fmap.dal.swing.impl.featuretype.AggregateController.AggregateItemController;
18
import org.gvsig.tools.swing.api.ToolsSwingLocator;
19
import org.gvsig.tools.swing.api.ToolsSwingManager;
20

    
21
/**
22
 *
23
 * @author gvSIG Team
24
 */
25
public class FeatureRuleController implements AggregateItemController<FeatureRule> {
26

    
27
    private final JTextComponent txtRuleName;
28
    private final JTextComponent txtRuleDescription;
29
    private final JCheckBox chkRuleCheckAtFinishEditing;
30
    private final JCheckBox chkRuleCheckAtUpdate;
31
    private final JCheckBox chkRuleCheckAtEditFeature;
32
    private final JTextComponent txtRuleValidation;
33
    private final JButton btnRuleValidation;
34
    private final JButton btnRuleValidationBookmarks;
35
    private final JButton btnRuleValidationHistory;
36

    
37
    private ExpressionPickerController pickervalidation;
38
    private FeatureStoreElement featureStoreElement;
39
    private boolean ruleIsAExpression;
40
    private AggregateController.AggregateModel aggregateModel;
41

    
42
    public FeatureRuleController(
43
            JTextComponent txtRuleName,
44
            JTextComponent txtRuleDescription,
45
            JCheckBox chkRuleCheckAtFinishEditing,
46
            JCheckBox chkRuleCheckAtUpdate,
47
            JCheckBox chkRuleCheckAtEditFeature,
48
            JTextComponent txtRuleValidation,
49
            JButton btnRuleValidation,
50
            JButton btnRuleValidationBookmarks,
51
            JButton btnRuleValidationHistory
52
        ) {
53
            this.txtRuleName = txtRuleName;
54
            this.txtRuleDescription = txtRuleDescription;
55
            this.chkRuleCheckAtFinishEditing = chkRuleCheckAtFinishEditing;
56
            this.chkRuleCheckAtUpdate = chkRuleCheckAtUpdate;
57
            this.chkRuleCheckAtEditFeature = chkRuleCheckAtEditFeature;
58
            this.txtRuleValidation = txtRuleValidation;
59
            this.btnRuleValidation = btnRuleValidation;
60
            this.btnRuleValidationBookmarks = btnRuleValidationBookmarks;
61
            this.btnRuleValidationHistory = btnRuleValidationHistory;
62

    
63
            this.ruleIsAExpression = false;
64
            this.initComponents();
65
    }
66

    
67
    private void initComponents() {
68
        final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
69
        final DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager();
70
        final ExpressionEvaluatorSwingManager evaluatorSwingManager = ExpressionEvaluatorSwingLocator.getManager();
71
        
72
        toolsSwingManager.addClearButton(this.txtRuleName);
73
        toolsSwingManager.addClearButton(this.txtRuleDescription);
74
        toolsSwingManager.setDefaultPopupMenu(this.txtRuleName);
75
        toolsSwingManager.setDefaultPopupMenu(this.txtRuleDescription);
76
        
77
        this.featureStoreElement = dataSwingManager.createFeatureStoreElement();
78
        this.pickervalidation = evaluatorSwingManager.createExpressionPickerController(
79
                        this.txtRuleValidation, 
80
                        this.btnRuleValidation,
81
                        this.btnRuleValidationBookmarks, 
82
                        this.btnRuleValidationHistory
83
                );
84
        this.pickervalidation.getConfig().addElement(this.featureStoreElement);
85
                
86
        
87
    }
88
    
89
    public void setFeatureStore(FeatureStore featureStore) {
90
        this.featureStoreElement.setFeatureStore(featureStore);
91
    }
92
    
93
    @Override
94
    public void setEnabled(boolean enabled) {
95
        if(!ruleIsAExpression) {
96
            enabled = false;
97
        }
98
        if( enabled && this.featureStoreElement.getFeatureStore()==null ) {
99
            this.pickervalidation.setEnabled(false);
100
        } else {
101
            this.pickervalidation.setEnabled(enabled);
102
        }
103
        this.txtRuleName.setEnabled(enabled);
104
        this.txtRuleDescription.setEnabled(enabled);
105
        this.chkRuleCheckAtFinishEditing.setEnabled(enabled);
106
        this.chkRuleCheckAtUpdate.setEnabled(enabled);
107
        this.chkRuleCheckAtEditFeature.setEnabled(enabled);
108
    }
109

    
110
    @Override
111
    public void put(FeatureRule rule) {
112
        this.ruleIsAExpression = (rule instanceof FeatureRuleExpression);
113
        this.txtRuleName.setText(rule.getName());
114
        this.txtRuleDescription.setText(rule.getDescription());
115
        this.chkRuleCheckAtFinishEditing.setSelected(rule.checkAtFinishEditing());
116
        this.chkRuleCheckAtUpdate.setSelected(rule.checkAtUpdate());
117
        this.chkRuleCheckAtEditFeature.setSelected(rule.checkWhen(FeatureRule.CHECK_WHEN_USER_EDIT_FEATURE));
118
        if( this.ruleIsAExpression ) {
119
            this.pickervalidation.set(((FeatureRuleExpression)rule).getExpression());
120
        }
121
    }
122

    
123
    @Override
124
    public boolean fetch(FeatureRule rule) {
125
        if( !(rule instanceof FeatureRuleExpression) ) {
126
            return true;
127
        }
128
        FeatureRuleExpression theRule = (FeatureRuleExpression)rule;
129
        
130
        String s = this.txtRuleName.getText();
131
        if( StringUtils.isBlank(s) ) {
132
            return false;
133
        }
134
        theRule.setName(s);
135
        theRule.setDescription(this.txtRuleDescription.getText());
136
        theRule.setCheckAtFinishEditing(this.chkRuleCheckAtFinishEditing.isSelected());
137
        theRule.setCheckAtUpdate(this.chkRuleCheckAtUpdate.isSelected());
138
        theRule.setCheckWhen(this.chkRuleCheckAtEditFeature.isSelected()?FeatureRule.CHECK_WHEN_USER_EDIT_FEATURE:0);
139
        theRule.setExpression(this.pickervalidation.get());
140
        return true;
141
    }
142

    
143
    @Override
144
    public void clean() {
145
        this.ruleIsAExpression = false;
146
        this.txtRuleName.setText("");
147
        this.txtRuleDescription.setText("");
148
        this.chkRuleCheckAtFinishEditing.setSelected(false);
149
        this.chkRuleCheckAtUpdate.setSelected(false);
150
        this.chkRuleCheckAtEditFeature.setSelected(false);
151
        this.pickervalidation.set(null);
152
    }
153

    
154
    @Override
155
    public boolean isEditing() {
156
        return this.txtRuleName.isEnabled();
157
    }
158

    
159
    @Override
160
    public boolean isEnabled() {
161
        return this.txtRuleName.isEnabled();
162
    }
163

    
164
    @Override
165
    public void setAggregateModel(AggregateController.AggregateModel model) {
166
        this.aggregateModel = model;
167
    }
168
        
169
}