forked from kiegroup/guvnor
/
TemplateDataCellFactory.java
88 lines (75 loc) · 3.19 KB
/
TemplateDataCellFactory.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
/*
* 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.asseteditor.drools.modeldriven.ui.templates;
import org.drools.guvnor.client.decisiontable.cells.PopupDropDownEditCell;
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 com.google.gwt.event.shared.EventBus;
public class TemplateDataCellFactory extends AbstractCellFactory<TemplateDataColumn> {
/**
* Construct a Cell Factory for a specific Template Data Widget
*
* @param sce
* SuggestionCompletionEngine to assist with drop-downs
* @param eventBus
* EventBus to which cells can send update events
*/
public TemplateDataCellFactory(SuggestionCompletionEngine sce,
EventBus eventBus) {
super( sce,
false,
eventBus );
}
/**
* Create a Cell for the given TemplateDataColumn
*
* @param column
* The Template Data Table model column
* @return A Cell
*/
public DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> getCell(TemplateDataColumn column) {
DecoratedGridCellValueAdaptor< ? extends Comparable< ? >> cell = null;
//Check if the column has an enumeration
String[] vals = null;
String factType = column.getFactType();
String factField = column.getFactField();
//Check for enumerations
if ( factType != null && factField != null ) {
vals = sce.getEnumValues( factType,
factField );
}
//Make a drop-down or plain cell
if ( vals != null && vals.length > 0 ) {
PopupDropDownEditCell pudd = new PopupDropDownEditCell( isReadOnly );
pudd.setItems( vals );
cell = new DecoratedGridCellValueAdaptor<String>( pudd,
eventBus );
} else {
String dataType = column.getDataType();
if ( column.getDataType().equals( SuggestionCompletionEngine.TYPE_BOOLEAN ) ) {
cell = makeBooleanCell();
} else if ( column.getDataType().equals( SuggestionCompletionEngine.TYPE_DATE ) ) {
cell = makeDateCell();
} else if ( dataType.equals( SuggestionCompletionEngine.TYPE_NUMERIC ) ) {
cell = makeNumericCell();
} else {
cell = makeTextCell();
}
}
return cell;
}
}