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 @ 46876
History | View | Annotate | Download (6.33 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 JTextComponent txtRuleValidation; |
32 |
private final JButton btnRuleValidation; |
33 |
private final JButton btnRuleValidationBookmarks; |
34 |
private final JButton btnRuleValidationHistory; |
35 |
|
36 |
private ExpressionPickerController pickervalidation;
|
37 |
private FeatureStoreElement featureStoreElement;
|
38 |
private boolean ruleIsAExpression; |
39 |
private AggregateController.AggregateModel aggregateModel;
|
40 |
|
41 |
public FeatureRuleController(
|
42 |
JTextComponent txtRuleName,
|
43 |
JTextComponent txtRuleDescription,
|
44 |
JCheckBox chkRuleCheckAtFinishEditing,
|
45 |
JCheckBox chkRuleCheckAtUpdate,
|
46 |
JTextComponent txtRuleValidation,
|
47 |
JButton btnRuleValidation,
|
48 |
JButton btnRuleValidationBookmarks,
|
49 |
JButton btnRuleValidationHistory
|
50 |
) { |
51 |
this.txtRuleName = txtRuleName;
|
52 |
this.txtRuleDescription = txtRuleDescription;
|
53 |
this.chkRuleCheckAtFinishEditing = chkRuleCheckAtFinishEditing;
|
54 |
this.chkRuleCheckAtUpdate = chkRuleCheckAtUpdate;
|
55 |
this.txtRuleValidation = txtRuleValidation;
|
56 |
this.btnRuleValidation = btnRuleValidation;
|
57 |
this.btnRuleValidationBookmarks = btnRuleValidationBookmarks;
|
58 |
this.btnRuleValidationHistory = btnRuleValidationHistory;
|
59 |
|
60 |
this.ruleIsAExpression = false; |
61 |
this.initComponents();
|
62 |
} |
63 |
|
64 |
private void initComponents() { |
65 |
final ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
|
66 |
final DataSwingManager dataSwingManager = DALSwingLocator.getSwingManager();
|
67 |
final ExpressionEvaluatorSwingManager evaluatorSwingManager = ExpressionEvaluatorSwingLocator.getManager();
|
68 |
|
69 |
toolsSwingManager.addClearButton(this.txtRuleName);
|
70 |
toolsSwingManager.addClearButton(this.txtRuleDescription);
|
71 |
toolsSwingManager.setDefaultPopupMenu(this.txtRuleName);
|
72 |
toolsSwingManager.setDefaultPopupMenu(this.txtRuleDescription);
|
73 |
|
74 |
this.featureStoreElement = dataSwingManager.createFeatureStoreElement();
|
75 |
this.pickervalidation = evaluatorSwingManager.createExpressionPickerController(
|
76 |
this.txtRuleValidation,
|
77 |
this.btnRuleValidation,
|
78 |
this.btnRuleValidationBookmarks,
|
79 |
this.btnRuleValidationHistory
|
80 |
); |
81 |
this.pickervalidation.getConfig().addElement(this.featureStoreElement); |
82 |
|
83 |
|
84 |
} |
85 |
|
86 |
public void setFeatureStore(FeatureStore featureStore) { |
87 |
this.featureStoreElement.setFeatureStore(featureStore);
|
88 |
} |
89 |
|
90 |
@Override
|
91 |
public void setEnabled(boolean enabled) { |
92 |
if(!ruleIsAExpression) {
|
93 |
enabled = false;
|
94 |
} |
95 |
if( enabled && this.featureStoreElement.getFeatureStore()==null ) { |
96 |
this.pickervalidation.setEnabled(false); |
97 |
} else {
|
98 |
this.pickervalidation.setEnabled(enabled);
|
99 |
} |
100 |
this.txtRuleName.setEnabled(enabled);
|
101 |
this.txtRuleDescription.setEnabled(enabled);
|
102 |
this.chkRuleCheckAtFinishEditing.setEnabled(enabled);
|
103 |
this.chkRuleCheckAtUpdate.setEnabled(enabled);
|
104 |
} |
105 |
|
106 |
@Override
|
107 |
public void put(FeatureRule rule) { |
108 |
this.ruleIsAExpression = (rule instanceof FeatureRuleExpression); |
109 |
this.txtRuleName.setText(rule.getName());
|
110 |
this.txtRuleDescription.setText(rule.getDescription());
|
111 |
this.chkRuleCheckAtFinishEditing.setSelected(rule.checkAtFinishEditing());
|
112 |
this.chkRuleCheckAtUpdate.setSelected(rule.checkAtUpdate());
|
113 |
if( this.ruleIsAExpression ) { |
114 |
this.pickervalidation.set(((FeatureRuleExpression)rule).getExpression());
|
115 |
} |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public boolean fetch(FeatureRule rule) { |
120 |
if( !(rule instanceof FeatureRuleExpression) ) { |
121 |
return true; |
122 |
} |
123 |
FeatureRuleExpression theRule = (FeatureRuleExpression)rule; |
124 |
|
125 |
String s = this.txtRuleName.getText(); |
126 |
if( StringUtils.isBlank(s) ) {
|
127 |
return false; |
128 |
} |
129 |
theRule.setName(s); |
130 |
theRule.setDescription(this.txtRuleDescription.getText());
|
131 |
theRule.setCheckAtFinishEditing(this.chkRuleCheckAtFinishEditing.isSelected());
|
132 |
theRule.setCheckAtUpdate(this.chkRuleCheckAtUpdate.isSelected());
|
133 |
theRule.setExpression(this.pickervalidation.get());
|
134 |
return true; |
135 |
} |
136 |
|
137 |
@Override
|
138 |
public void clean() { |
139 |
this.ruleIsAExpression = false; |
140 |
this.txtRuleName.setText(""); |
141 |
this.txtRuleDescription.setText(""); |
142 |
this.chkRuleCheckAtFinishEditing.setSelected(false); |
143 |
this.chkRuleCheckAtUpdate.setSelected(false); |
144 |
this.pickervalidation.set(null); |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public boolean isEditing() { |
149 |
return this.txtRuleName.isEnabled(); |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public boolean isEnabled() { |
154 |
return this.txtRuleName.isEnabled(); |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public void setAggregateModel(AggregateController.AggregateModel model) { |
159 |
this.aggregateModel = model;
|
160 |
} |
161 |
|
162 |
} |