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 / FeatureRuleController.java @ 45739

History | View | Annotate | Download (5.87 KB)

1
package org.gvsig.fmap.dal.swing.impl.featuretype;
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.tools.swing.api.ToolsSwingLocator;
17
import org.gvsig.tools.swing.api.ToolsSwingManager;
18

    
19
/**
20
 *
21
 * @author gvSIG Team
22
 */
23
public class FeatureRuleController implements AggregateController.AggregateItemController<FeatureRule> {
24

    
25
    private final JTextComponent txtRuleName;
26
    private final JTextComponent txtRuleDescription;
27
    private final JCheckBox chkRuleCheckAtFinishEditing;
28
    private final JCheckBox chkRuleCheckAtUpdate;
29
    private final JTextComponent txtRuleValidation;
30
    private final JButton btnRuleValidation;
31
    private final JButton btnRuleValidationBookmarks;
32
    private final JButton btnRuleValidationHistory;
33

    
34
    private ExpressionPickerController pickervalidation;
35
    private FeatureStoreElement featureStoreElement;
36
    private boolean ruleIsAExpression;
37

    
38
    public FeatureRuleController(
39
            JTextComponent txtRuleName,
40
            JTextComponent txtRuleDescription,
41
            JCheckBox chkRuleCheckAtFinishEditing,
42
            JCheckBox chkRuleCheckAtUpdate,
43
            JTextComponent txtRuleValidation,
44
            JButton btnRuleValidation,
45
            JButton btnRuleValidationBookmarks,
46
            JButton btnRuleValidationHistory
47
        ) {
48
            this.txtRuleName = txtRuleName;
49
            this.txtRuleDescription = txtRuleDescription;
50
            this.chkRuleCheckAtFinishEditing = chkRuleCheckAtFinishEditing;
51
            this.chkRuleCheckAtUpdate = chkRuleCheckAtUpdate;
52
            this.txtRuleValidation = txtRuleValidation;
53
            this.btnRuleValidation = btnRuleValidation;
54
            this.btnRuleValidationBookmarks = btnRuleValidationBookmarks;
55
            this.btnRuleValidationHistory = btnRuleValidationHistory;
56

    
57
            this.ruleIsAExpression = false;
58
            this.initComponents();
59
    }
60

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

    
103
    @Override
104
    public void put(FeatureRule rule) {
105
        this.ruleIsAExpression = (rule instanceof FeatureRuleExpression);
106
        this.txtRuleName.setText(rule.getName());
107
        this.txtRuleDescription.setText(rule.getDescription());
108
        this.chkRuleCheckAtFinishEditing.setSelected(rule.checkAtFinishEditing());
109
        this.chkRuleCheckAtUpdate.setSelected(rule.checkAtUpdate());
110
        if( this.ruleIsAExpression ) {
111
            this.pickervalidation.set(((FeatureRuleExpression)rule).getExpression());
112
        }
113
    }
114

    
115
    @Override
116
    public boolean fetch(FeatureRule rule) {
117
        if( !(rule instanceof FeatureRuleExpression) ) {
118
            return true;
119
        }
120
        FeatureRuleExpression theRule = (FeatureRuleExpression)rule;
121
        
122
        String s = this.txtRuleName.getText();
123
        if( StringUtils.isBlank(s) ) {
124
            return false;
125
        }
126
        theRule.setName(s);
127
        theRule.setDescription(this.txtRuleDescription.getText());
128
        theRule.setCheckAtFinishEditing(this.chkRuleCheckAtFinishEditing.isSelected());
129
        theRule.setCheckAtUpdate(this.chkRuleCheckAtUpdate.isSelected());
130
        theRule.setExpression(this.pickervalidation.get());
131
        return true;
132
    }
133

    
134
    @Override
135
    public void clean() {
136
        this.ruleIsAExpression = false;
137
        this.txtRuleName.setText("");
138
        this.txtRuleDescription.setText("");
139
        this.chkRuleCheckAtFinishEditing.setSelected(false);
140
        this.chkRuleCheckAtUpdate.setSelected(false);
141
        this.pickervalidation.set(null);
142
    }
143

    
144
    @Override
145
    public boolean isEditing() {
146
        return this.txtRuleName.isEnabled();
147
    }
148
    
149
}