001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.function.v1;
009:
010: //base classes
011: import java.math.BigDecimal;
012:
013: //project specific classes
014: import org.jfolder.common.SelfArgumentlessConstructor;
015: import org.jfolder.common.StandardDataTypes;
016: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
017: import org.jfolder.common.function.WebPageTagInstanceViewContext;
018: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
019: import org.jfolder.common.tagging.AppraiseConceptTagContext;
020: import org.jfolder.common.tagging.ConceptTagCharacteristic;
021: import org.jfolder.common.tagging.ConceptTagConstraint;
022: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
023: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
024: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
025: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
027: import org.jfolder.common.tagging.InitializeConceptTagContext;
028: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
029: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
030: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
031: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
032: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
033: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
034: import org.jfolder.common.utils.misc.MiscHelper;
035:
036: //other classes
037:
038: public class CommonFunctionLiteralDecimalTag extends
039: BaseCommonFunctionCompatibilityTag implements
040: SelfArgumentlessConstructor {
041:
042: //
043: private ConceptTagCharacteristic valueCtchar = null;
044:
045: //value details
046: private final static String VALUE_CTCON = "value";
047: private final static String VALUE_TITLE = "Value";
048: private final static String VALUE_SHORT_DESCRIPTION = "Value of this decimal";
049:
050: public void initialize(InitializeConceptTagContext inIctc) {
051:
052: //
053: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
054: .newInstance(inIctc);
055: //
056: //rootCtconh.getAttributes().setStudioVisibleOnlyOnError(true);
057: //rootCtconh.getStyles().setStudioVisibleOnlyOnError(true);
058:
059: //constrain "value"
060: ConceptTagConstraint valueCtcon = ConceptTagConstraint
061: .newInstance(VALUE_CTCON, rootCtconh);
062: valueCtcon.setTitle(VALUE_TITLE);
063: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
064: //
065: StaticConceptTagConstraintContext valueSctcc = StaticConceptTagConstraintContext
066: .newInstance(valueCtcon);
067: //
068: valueSctcc.addDefaultValue("0");
069:
070: //constrain undefined
071: ConceptTagConstraint unconstrainedCtcon = rootCtconh
072: .getUndefinedConstraint();
073: //unconstrainedCtcon.setStudioVisibleOnlyOnError(true);
074:
075: //
076: ConceptTagFlagsHelper
077: .pushNonIterativeCommonFunctionDepth(inIctc);
078: inIctc.initialize();
079: ConceptTagFlagsHelper
080: .popNonIterativeCommonFunctionDepth(inIctc);
081:
082: //
083: this .valueCtchar = valueCtcon.getCharacteristic();
084: }
085:
086: public void appraise(AppraiseConceptTagContext inActc) {
087:
088: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
089:
090: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
091:
092: String displayValue = "(Unknown)";
093: if (this .valueCtchar.getValueLength() >= 1
094: && this .valueCtchar.isStatic(0, inActc)) {
095: displayValue = this .valueCtchar.getValueAsString(0,
096: inActc);
097: }
098: sctiic.setInstanceTitle(MiscHelper.shortenString(
099: displayValue, 15));
100: sctiic.setInstanceDescription(MiscHelper.shortenString(
101: displayValue, 200));
102: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
103:
104: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
105:
106: scttic.setTypeTitle("Decimal");
107: scttic
108: .setTypeDescription("Represents a literal decimal (e.g. 0.349, 10)");
109: } else if (inActc instanceof WebPageTagInstanceViewContext) {
110:
111: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
112:
113: WebPageTagInstanceViewContextInfo info = wptivc
114: .getInfoAsNonHtml();
115:
116: info.setNonHtmlContent("Decimal(", ")");
117: WebPageTagInstanceViewContext.displayView(this .valueCtchar,
118: info, wptivc, "???");
119: //info.setEndContent(")");
120: /*
121: String displayValue = "(Unknown)";
122: if (this.valueCtchar.getValueLength() >= 1
123: && this.valueCtchar.isStatic(0, inActc)) {
124: displayValue = this.valueCtchar.getValueAsString(0, inActc);
125: }
126: //wtivc.setStartContent("<!--" + wtivc.getStartContent() + "-->");
127: //wtivc.setEndContent("<!--" + wtivc.getEndContent() + "-->");
128: wptivc.appendContent(displayValue);
129: */
130: //wptivc.getInfo().setStartContent("");
131: //wptivc.getInfo().setMiddleContent(displayValue);
132: //wptivc.getInfo().setEndContent("");
133: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
134:
135: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
136:
137: scfrct.canReturnDecimal();
138: scfrct.declareFormatAsPlain();
139: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
140:
141: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
142: }
143: }
144:
145: public void determineValueAndClass(
146: DetermineValueAndClassConceptTagContext inDvacctc) {
147:
148: ValueAndClassForConceptTag vacfct = null;
149:
150: vacfct = ValueAndClassForConceptTag.newDecimal(new BigDecimal(
151: this .valueCtchar.getValueAsString(0, inDvacctc)));
152:
153: inDvacctc.setDetermineValueAndClass(vacfct);
154: }
155:
156: public void determineClass(DetermineClassConceptTagContext inDcctc) {
157:
158: inDcctc.setDetermineClass(StandardDataTypes.getDecimalClass());
159: }
160:
161: public Object createUninitializedSelf() {
162: return new CommonFunctionLiteralDecimalTag();
163: }
164: }
|