001: /**
002: *
003: */package org.drools.reteoo;
004:
005: import org.drools.base.ClassFieldExtractor;
006: import org.drools.rule.LiteralConstraint;
007: import org.drools.spi.AlphaNodeFieldConstraint;
008: import org.drools.spi.Constraint;
009: import org.drools.spi.FieldExtractor;
010: import org.eclipse.draw2d.ColorConstants;
011: import org.eclipse.swt.graphics.Color;
012:
013: /**
014: * Wraps {@link AlphaNode} and adds visual extras like color information
015: *
016: */
017: public class AlphaNodeVertex extends BaseVertex {
018:
019: private final AlphaNode node;
020:
021: private final String NODE_NAME = "AlphaNode";
022:
023: /**
024: * Constructor
025: *
026: * @param node node to be wrapped
027: */
028: public AlphaNodeVertex(final AlphaNode node) {
029: super ();
030: this .node = node;
031: }
032:
033: /* (non-Javadoc)
034: * @see org.drools.reteoo.BaseNodeVertex#getHtml()
035: */
036: public String getHtml() {
037: AlphaNodeFieldConstraint constraint = this .node.getConstraint();
038: if (constraint instanceof LiteralConstraint) {
039: LiteralConstraint literalConstraint = (LiteralConstraint) constraint;
040: FieldExtractor extractor = literalConstraint
041: .getFieldExtractor();
042: if (extractor instanceof ClassFieldExtractor) {
043: ClassFieldExtractor classFieldExtractor = (ClassFieldExtractor) extractor;
044: return NODE_NAME + "<BR/>field : "
045: + classFieldExtractor.getFieldName()
046: + "<BR/>evaluator : "
047: + literalConstraint.getEvaluator()
048: + "<BR/>value : "
049: + literalConstraint.getField();
050: }
051: }
052: return NODE_NAME + "<BR/>";
053: }
054:
055: /* (non-Javadoc)
056: * @see org.drools.eclipse.editors.rete.model.BaseVertex#toString()
057: */
058: public String toString() {
059: return this .node.toString();
060: }
061:
062: /* (non-Javadoc)
063: * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
064: */
065: public Color getFillColor() {
066: return ColorConstants.blue;
067: }
068:
069: /**
070: * Constraint has field extractor and this method is returning fieldName
071: * it.
072: *
073: * @return field name
074: */
075: public String getFieldName() {
076: AlphaNodeFieldConstraint constraint = this .node.getConstraint();
077: if (constraint instanceof LiteralConstraint) {
078: LiteralConstraint literalConstraint = (LiteralConstraint) constraint;
079: FieldExtractor extractor = literalConstraint
080: .getFieldExtractor();
081: if (extractor instanceof ClassFieldExtractor) {
082: return ((ClassFieldExtractor) extractor).getFieldName();
083: }
084: }
085: return null;
086: }
087:
088: /**
089: * Constraint's evaluator string
090: *
091: * @return evaluator string
092: */
093: public String getEvaluator() {
094: AlphaNodeFieldConstraint constraint = this .node.getConstraint();
095: if (constraint instanceof LiteralConstraint) {
096: LiteralConstraint literalConstraint = (LiteralConstraint) constraint;
097: return literalConstraint.getEvaluator().toString();
098: }
099: return null;
100: }
101:
102: /**
103: * Constraint field string
104: *
105: * @return field string
106: */
107: public String getValue() {
108: AlphaNodeFieldConstraint constraint = this .node.getConstraint();
109: if (constraint instanceof LiteralConstraint) {
110: LiteralConstraint literalConstraint = (LiteralConstraint) constraint;
111: return literalConstraint.getField().toString();
112: }
113: return null;
114: }
115:
116: /**
117: * Constraint
118: *
119: * @return constraint
120: */
121: public Constraint getConstraint() {
122: return this.node.getConstraint();
123: }
124:
125: }
|