forked from kiegroup/guvnor
/
DecisionTableCellFactory.java
276 lines (231 loc) · 11.7 KB
/
DecisionTableCellFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Copyright 2011 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.drools.guvnor.client.decisiontable.widget;
import java.math.BigDecimal;
import org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.RuleAttributeWidget;
import org.drools.guvnor.client.decisiontable.cells.AnalysisCell;
import org.drools.guvnor.client.decisiontable.cells.PopupBoundPatternDropDownEditCell;
import org.drools.guvnor.client.decisiontable.cells.PopupDropDownEditCell;
import org.drools.guvnor.client.decisiontable.cells.RowNumberCell;
import org.drools.guvnor.client.widgets.drools.decoratedgrid.AbstractCellFactory;
import org.drools.guvnor.client.widgets.drools.decoratedgrid.DecoratedGridCellValueAdaptor;
import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngine;
import org.drools.ide.common.client.modeldriven.dt52.ActionCol52;
import org.drools.ide.common.client.modeldriven.dt52.ActionInsertFactCol52;
import org.drools.ide.common.client.modeldriven.dt52.ActionRetractFactCol52;
import org.drools.ide.common.client.modeldriven.dt52.ActionSetFieldCol52;
import org.drools.ide.common.client.modeldriven.dt52.ActionWorkItemCol52;
import org.drools.ide.common.client.modeldriven.dt52.ActionWorkItemInsertFactCol52;
import org.drools.ide.common.client.modeldriven.dt52.ActionWorkItemSetFieldCol52;
import org.drools.ide.common.client.modeldriven.dt52.Analysis;
import org.drools.ide.common.client.modeldriven.dt52.AnalysisCol52;
import org.drools.ide.common.client.modeldriven.dt52.AttributeCol52;
import org.drools.ide.common.client.modeldriven.dt52.BRLActionVariableColumn;
import org.drools.ide.common.client.modeldriven.dt52.BRLConditionVariableColumn;
import org.drools.ide.common.client.modeldriven.dt52.BRLRuleModel;
import org.drools.ide.common.client.modeldriven.dt52.BaseColumn;
import org.drools.ide.common.client.modeldriven.dt52.ConditionCol52;
import org.drools.ide.common.client.modeldriven.dt52.DTColumnConfig52;
import org.drools.ide.common.client.modeldriven.dt52.GuidedDecisionTable52;
import org.drools.ide.common.client.modeldriven.dt52.LimitedEntryBRLActionColumn;
import org.drools.ide.common.client.modeldriven.dt52.LimitedEntryCol;
import org.drools.ide.common.client.modeldriven.dt52.RowNumberCol52;
import com.google.gwt.event.shared.EventBus;
/**
* A Factory to provide the Cells for given coordinate for Decision Tables.
*/
public class DecisionTableCellFactory extends AbstractCellFactory<BaseColumn> {
private static String[] DIALECTS = {"java", "mvel"};
private GuidedDecisionTable52 model;
/**
* Construct a Cell Factory for a specific Decision Table
*
* @param sce
* SuggestionCompletionEngine to assist with drop-downs
* @param isReadOnly
* Should cells be created for a read-only mode of operation
* @param eventBus
* An EventBus on which cells can subscribe to events
*/
public DecisionTableCellFactory(SuggestionCompletionEngine sce,
boolean isReadOnly,
EventBus eventBus) {
super( sce,
isReadOnly,
eventBus );
}
/**
* Set the model for which cells will be created
*
* @param model
*/
public void setModel(GuidedDecisionTable52 model) {
if ( model == null ) {
throw new IllegalArgumentException( "model cannot be null" );
}
this.model = model;
}
/**
* Create a Cell for the given DTColumnConfig
*
* @param column
* The Decision Table model column
* @return A Cell
*/
public DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> getCell(BaseColumn column) {
//This is the cell that will be used to edit values; its type can differ to the "fieldType"
//of the underlying model. For example a "Guvnor-enum" requires a drop-down list of potential
//values whereas the "fieldType" may be a String.
DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> cell = makeTextCell();
if ( column instanceof RowNumberCol52 ) {
cell = makeRowNumberCell();
} else if ( column instanceof AttributeCol52 ) {
AttributeCol52 attrCol = (AttributeCol52) column;
String attrName = attrCol.getAttribute();
if ( attrName.equals( RuleAttributeWidget.SALIENCE_ATTR ) ) {
if ( attrCol.isUseRowNumber() ) {
cell = makeRowNumberCell();
} else {
cell = makeNumericCell();
}
} else if ( attrName.equals( RuleAttributeWidget.ENABLED_ATTR ) ) {
cell = makeBooleanCell();
} else if ( attrName.equals( RuleAttributeWidget.NO_LOOP_ATTR ) ) {
cell = makeBooleanCell();
} else if ( attrName.equals( RuleAttributeWidget.DURATION_ATTR ) ) {
cell = makeNumericCell();
} else if ( attrName.equals( RuleAttributeWidget.AUTO_FOCUS_ATTR ) ) {
cell = makeBooleanCell();
} else if ( attrName.equals( RuleAttributeWidget.LOCK_ON_ACTIVE_ATTR ) ) {
cell = makeBooleanCell();
} else if ( attrName.equals( RuleAttributeWidget.DATE_EFFECTIVE_ATTR ) ) {
cell = makeDateCell();
} else if ( attrName.equals( RuleAttributeWidget.DATE_EXPIRES_ATTR ) ) {
cell = makeDateCell();
} else if ( attrName.equals( RuleAttributeWidget.DIALECT_ATTR ) ) {
cell = makeDialectCell();
} else if ( attrName.equals( GuidedDecisionTable52.NEGATE_RULE_ATTR ) ) {
cell = makeBooleanCell();
}
} else if ( column instanceof BRLConditionVariableColumn ) {
cell = derieveCellFromCondition( (BRLConditionVariableColumn) column );
} else if ( column instanceof ConditionCol52 ) {
cell = derieveCellFromCondition( (ConditionCol52) column );
} else if ( column instanceof ActionWorkItemSetFieldCol52 ) {
//Before ActionSetFieldCol52 as this is a sub-class
cell = makeBooleanCell();
} else if ( column instanceof ActionWorkItemInsertFactCol52 ) {
//Before ActionInsertFactCol52 as this is a sub-class
cell = makeBooleanCell();
} else if ( column instanceof ActionSetFieldCol52 ) {
cell = derieveCellFromAction( (ActionSetFieldCol52) column );
} else if ( column instanceof ActionInsertFactCol52 ) {
cell = derieveCellFromAction( (ActionInsertFactCol52) column );
} else if ( column instanceof ActionRetractFactCol52 ) {
cell = derieveCellFromAction( (ActionRetractFactCol52) column );
} else if ( column instanceof ActionWorkItemCol52 ) {
cell = makeBooleanCell();
} else if ( column instanceof LimitedEntryBRLActionColumn ) {
cell = derieveCellFromAction( (LimitedEntryBRLActionColumn) column );
} else if ( column instanceof BRLActionVariableColumn ) {
cell = derieveCellFromAction( (BRLActionVariableColumn) column );
} else if ( column instanceof AnalysisCol52 ) {
cell = makeRowAnalysisCell();
}
return cell;
}
// Make a new Cell for Condition columns
private DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> derieveCellFromCondition(ConditionCol52 col) {
//Limited Entry are simply boolean
if ( col instanceof LimitedEntryCol ) {
return makeBooleanCell();
}
//Operators "is null" and "is not null" require a boolean cell
if ( col.getOperator() != null && (col.getOperator().equals( "== null" ) || col.getOperator().equals( "!= null" )) ) {
return makeBooleanCell();
}
return derieveCellFromModel( col );
}
// Make a new Cell for Actions columns
private DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> derieveCellFromAction(ActionCol52 col) {
//Limited Entry are simply boolean
if ( col instanceof LimitedEntryCol ) {
return makeBooleanCell();
}
return derieveCellFromModel( col );
}
// Make a new Cell for Actions columns
private DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> derieveCellFromAction(ActionRetractFactCol52 col) {
//Limited Entry are simply boolean
if ( col instanceof LimitedEntryCol ) {
return makeBooleanCell();
}
//Drop down of possible patterns
PopupBoundPatternDropDownEditCell pudd = new PopupBoundPatternDropDownEditCell( eventBus,
isReadOnly );
BRLRuleModel rm = new BRLRuleModel( model );
pudd.setFactBindings( rm.getLHSBoundFacts() );
return new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
}
//Get Cell applicable to Model's data-type
private DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> derieveCellFromModel(DTColumnConfig52 col) {
//Extended Entry...
DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> cell = makeTextCell();
String type = model.getType( col,
sce );
//Retrieve "Guvnor" enums
String[] vals = model.getValueList( col,
sce );
if ( vals.length == 0 ) {
//Null means the field is free-format
if ( type == null ) {
return cell;
}
if ( type.equals( SuggestionCompletionEngine.TYPE_NUMERIC ) ) {
cell = makeNumericCell();
} else if ( type.equals( SuggestionCompletionEngine.TYPE_BOOLEAN ) ) {
cell = makeBooleanCell();
} else if ( type.equals( SuggestionCompletionEngine.TYPE_DATE ) ) {
cell = makeDateCell();
}
} else {
// Columns with lists of values, enums etc are always Text (for now)
PopupDropDownEditCell pudd = new PopupDropDownEditCell( isReadOnly );
pudd.setItems( vals );
cell = new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
}
return cell;
}
// Make a new Cell for Dialect columns
private DecoratedGridCellValueAdaptor<String> makeDialectCell() {
PopupDropDownEditCell pudd = new PopupDropDownEditCell( isReadOnly );
pudd.setItems( DIALECTS );
return new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
}
// Make a new Cell for Row Number columns
private DecoratedGridCellValueAdaptor<BigDecimal> makeRowNumberCell() {
return new DecoratedGridCellValueAdaptor<BigDecimal>( new RowNumberCell(),
eventBus );
}
// Make a new Cell for Rule Analysis columns
private DecoratedGridCellValueAdaptor<Analysis> makeRowAnalysisCell() {
return new DecoratedGridCellValueAdaptor<Analysis>( new AnalysisCell(),
eventBus );
}
}