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.console.macro.v1;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.HashMap;
013:
014: //project specific classes
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.tagging.AppraiseConceptTagContext;
017: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
018: import org.jfolder.common.tagging.ConceptTagCharacteristic;
019: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
020: import org.jfolder.common.tagging.ConceptTagConstraint;
021: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
022: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
023: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
024: import org.jfolder.common.tagging.InitializeConceptTagContext;
025: import org.jfolder.common.tagging.RootConceptTagHolder;
026: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
027: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
028: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
029: import org.jfolder.common.utils.misc.MiscHelper;
030: import org.jfolder.common.utils.xml.XMLHelper;
031: import org.jfolder.common.web.template.ConsoleTemplateContext;
032: import org.jfolder.common.web.template.ConsoleTemplateSession;
033: import org.jfolder.common.web.template.PageSetupContext;
034: import org.jfolder.console.macro.ConsoleMacro;
035: import org.jfolder.console.macro.ConsoleMacroTag;
036:
037: //other classes
038:
039: public class AssignStaticValueConsoleMacroTag implements
040: ConsoleMacroTag {
041:
042: ////characteristics
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";
049:
050: ///////////////////////////////////
051:
052: public void initialize(InitializeConceptTagContext inIctc) {
053:
054: //
055: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
056: .newInstance(inIctc);
057:
058: //constrain "value"
059: ConceptTagConstraint valueCtcon = ConceptTagConstraint
060: .newInstance(VALUE_CTCON, rootCtconh);
061: valueCtcon.setTitle(VALUE_TITLE);
062: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
063: //
064: StaticConceptTagConstraintContext valueSctcc = StaticConceptTagConstraintContext
065: .newInstance(valueCtcon);
066:
067: //
068: inIctc.initialize();
069:
070: //
071: this .valueCtchar = valueCtcon.getCharacteristic();
072: }
073:
074: //
075: public void appraise(AppraiseConceptTagContext inCtic) {
076: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
077: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
078: sctiic.setInstanceTitle("Assign Static Value");
079: sctiic.setInstanceDescription("Assign Static Value");
080: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
081: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
082: scttic.setTypeTitle("Assign Static Value");
083: scttic.setTypeDescription("Assign Static Value");
084: }
085: }
086:
087: //
088: public final static AssignStaticValueConsoleMacroTag newInstance(
089: ConceptTagCharacteristic inCtchar, String inValue) {
090: //
091: AssignStaticValueConsoleMacroTag outValue = null;
092:
093: outValue = new AssignStaticValueConsoleMacroTag();
094: //
095: ConceptTagCharacteristicHolder nextCtcharh = inCtchar.addValue(
096: inCtchar.getValueLength(), outValue, true);
097: //
098: ConceptTagCharacteristic nextValueCtchar = nextCtcharh
099: .registerCharacteristic(VALUE_CTCON);
100: nextValueCtchar.addValue(0, inValue);
101:
102: return outValue;
103: }
104:
105: //
106: public void generateMacroCommands(PageSetupContext inPsc,
107: ConsoleTemplateSession inCts, RootConceptTagHolder inRcth,
108: HashMap inVars, String inFromHandle,
109: String inAliasFromHandle, String inSourcePage,
110: String inDestinationPage) {
111: //
112: //
113: final int STATIC_SECTION_INDEX = 2;
114: //try {
115: String value = this .valueCtchar.getValueAsString(0, null);
116: value = XMLHelper.fromStringToJSCData(value);
117: //
118: //text box (1)
119: //
120: prepareCalls(
121: inPsc,
122: ConsoleTemplateContext
123: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
124: + ",CONSOLE_CREATION_STRUCTURE_1_"
125: + STATIC_SECTION_INDEX),
126: ConsoleTemplateContext
127: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
128: + ",CONSOLE_CREATION_STRUCTURE_1_"
129: + STATIC_SECTION_INDEX
130: + ",[TEXT_BOX]"
131: + ",TEXT_BOX__NEXT_TEXT_VALUE"), null,
132: ConsoleTemplateContext.singleQuotes(value), false);
133: //
134: //text area (2)
135: //
136: prepareCalls(
137: inPsc,
138: ConsoleTemplateContext
139: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
140: + ",CONSOLE_CREATION_STRUCTURE_2_"
141: + STATIC_SECTION_INDEX),
142: ConsoleTemplateContext
143: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
144: + ",CONSOLE_CREATION_STRUCTURE_2_"
145: + STATIC_SECTION_INDEX
146: + ",[TEXT_AREA]"
147: + ",TEXT_AREA__NEXT_TEXT_VALUE"), null,
148: ConsoleTemplateContext.singleQuotes(value), false);
149: //
150: //inclusive (3)
151: //
152: prepareCalls(
153: inPsc,
154: ConsoleTemplateContext
155: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
156: + ",CONSOLE_CREATION_STRUCTURE_3_"
157: + STATIC_SECTION_INDEX),
158: ConsoleTemplateContext
159: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
160: + ",CONSOLE_CREATION_STRUCTURE_3_"
161: + STATIC_SECTION_INDEX
162: + ",[DROP_DOWN_BOX]"
163: + ",DROP_DOWN_BOX__INCLUSIVE_VALUE"),
164: ConsoleTemplateContext
165: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
166: + ",CONSOLE_CREATION_STRUCTURE_3_"
167: + STATIC_SECTION_INDEX
168: + ",[TEXT_BOX]"
169: + ",DROP_DOWN_BOX__INCLUSIVE_OTHER_VALUE"),
170: ConsoleTemplateContext.singleQuotes(value), true);
171: //
172: //exclusive (4)
173: //
174: prepareCalls(
175: inPsc,
176: ConsoleTemplateContext
177: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
178: + ",CONSOLE_CREATION_STRUCTURE_4_"
179: + STATIC_SECTION_INDEX),
180: ConsoleTemplateContext
181: .singleQuotes("(main),[DONT_RECORD_THIS_BRANCH],(CREATION_OF_CONCEPT_TAG)"
182: + ",CONSOLE_CREATION_STRUCTURE_4_"
183: + STATIC_SECTION_INDEX
184: + ",[DROP_DOWN_BOX]"
185: + ",DROP_DOWN_BOX__EXCLUSIVE_VALUE"),
186: null, ConsoleTemplateContext.singleQuotes(value), true);
187: //}
188: //catch (IOException ioe) {
189: // throw new UnexpectedSystemException(ioe);
190: //}
191: }
192:
193: private final static void prepareCalls(PageSetupContext inPsc,
194: String inSectionId, String inTargetId,
195: String inAlternateTargetId, String inValue,
196: boolean inCheckAvailability) {
197: //
198: //macroGoToIfAvailable(
199: // inSectionId, inTargetId, inAlternateTarget,
200: // inValue, inCheckAvailibility)
201: //macroClickIfOpen(inSource)
202: //macroChangeValueIfAvailable(
203: // inSectionId, inTargetId, inAlternateTarget,
204: // inValue, inCheckAvailibility)
205: //
206: inPsc.addMacroCommand("macroGoToIfAvailable(" + inSectionId
207: + ", " + inTargetId + ", " + inAlternateTargetId + ", "
208: + inValue + ", " + inCheckAvailability + ")");
209: inPsc.addMacroCommand("macroClickIfOpen(" + inSectionId + ")");
210: inPsc.addMacroCommand("macroChangeValueIfAvailable("
211: + inSectionId + ", " + inTargetId + ", "
212: + inAlternateTargetId + ", " + inValue + ", "
213: + inCheckAvailability + ")");
214: }
215: }
|