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.web.page.v1;
009:
010: //base classes
011: import java.util.HashMap;
012:
013: //project specific classes
014: import org.jfolder.common.StandardDataTypes;
015: import org.jfolder.common.function.BaseWebPageTag;
016: import org.jfolder.common.function.WebPageTagInstanceViewContext;
017: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
018: import org.jfolder.common.function.WebPageTagInstanceViewContextSubHtmlInfo;
019: import org.jfolder.common.tagging.AppraiseConceptTagContext;
020: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
021: import org.jfolder.common.tagging.ConceptTag;
022: import org.jfolder.common.tagging.ConceptTagCharacteristic;
023: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
024: import org.jfolder.common.tagging.ConceptTagConstraint;
025: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
026: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
027: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
028: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
029: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
030: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
031: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
032: import org.jfolder.common.tagging.InitializeConceptTagContext;
033: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
034: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
035: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
037: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
038: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
039: import org.jfolder.common.utils.xml.XMLHelper;
040:
041: //other classes
042:
043: public class DynamicTableRowWebPageTag extends BaseWebPageTag {
044:
045: //characteristics
046: private ConceptTagCharacteristic cellCtchar = null;
047: private ConceptTagCharacteristic widthCtchar = null;
048: private ConceptTagCharacteristic heightCtchar = null;
049: private ConceptTagCharacteristic alignCtchar = null;
050: private ConceptTagCharacteristic valignCtchar = null;
051: //
052: private ConceptTagCharacteristic actionCtchar = null;
053:
054: //cell details
055: public final static String CELL_CTCON = "cell";
056: private final static String CELL_TITLE = "Cell";
057: private final static String CELL_SHORT_DESCRIPTION = "Cell";
058: //
059:
060: //
061: //width details
062: private final static String WIDTH_CTCON = "width";
063: private final static String WIDTH_TITLE = "Width";
064: private final static String WIDTH_SHORT_DESCRIPTION = "Width";
065: //
066: //height details
067: public final static String HEIGHT_CTCON = "height";
068: private final static String HEIGHT_TITLE = "Height";
069: private final static String HEIGHT_SHORT_DESCRIPTION = "Height";
070: //
071: //align details
072: private final static String ALIGN_CTCON = "align";
073: private final static String ALIGN_TITLE = "Align";
074: private final static String ALIGN_SHORT_DESCRIPTION = "Align";
075: //
076: //valign details
077: public final static String VALIGN_CTCON = "valign";
078: private final static String VALIGN_TITLE = "Vertical Align";
079: private final static String VALIGN_SHORT_DESCRIPTION = "Vertical Align";
080: //
081: //action details
082: private final static String ACTION_CTCON = "action";
083: private final static String ACTION_TITLE = "Action";
084: private final static String ACTION_SHORT_DESCRIPTION = "Action";
085:
086: public void initialize(InitializeConceptTagContext inIctc) {
087:
088: //
089: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
090: .newInstance(inIctc);
091:
092: //
093: //constrain "action"
094: ConceptTagConstraint actionCtcon = ConceptTagConstraint
095: .newInstance(ACTION_CTCON, rootCtconh);
096: //
097: actionCtcon.setMinimumLength(0);
098: actionCtcon.setLengthUnbounded(true);
099: //
100: actionCtcon.setTitle(ACTION_TITLE);
101: actionCtcon.setShortDescription(ACTION_SHORT_DESCRIPTION);
102: //
103: DynamicConceptTagConstraintContext actionDctcc = DynamicConceptTagConstraintContext
104: .newInstance(actionCtcon);
105:
106: //
107: //constrain "cell"
108: ConceptTagConstraint cellCtcon = ConceptTagConstraint
109: .newInstance(CELL_CTCON, rootCtconh);
110: cellCtcon.setTitle(CELL_TITLE);
111: cellCtcon.setShortDescription(CELL_SHORT_DESCRIPTION);
112: cellCtcon.setDisplayAsBranch(false);
113: //
114: DynamicConceptTagConstraintContext cellDctcc = DynamicConceptTagConstraintContext
115: .newInstance(cellCtcon);
116: cellDctcc.getValidator().allowOnlyTheseClasses(
117: DynamicTableCellWebPageTag.class,
118: "Only cells are permissable here");
119: cellDctcc.getValidator().assertCanBeIterativeStructure();
120: cellDctcc.getValidator().useOrConjunction();
121:
122: //
123: //constraint "width"
124: ConceptTagConstraint widthCtcon = ConceptTagConstraint
125: .newInstance(WIDTH_CTCON, rootCtconh);
126: widthCtcon.setTitle(WIDTH_TITLE);
127: widthCtcon.setShortDescription(WIDTH_SHORT_DESCRIPTION);
128: //
129: widthCtcon.setMinimumLength(0);
130: widthCtcon.setMaximumLength(1);
131: //
132: StaticConceptTagConstraintContext widthSctcc = StaticConceptTagConstraintContext
133: .newInstance(widthCtcon);
134:
135: //
136: //constraint "height"
137: ConceptTagConstraint heightCtcon = ConceptTagConstraint
138: .newInstance(HEIGHT_CTCON, rootCtconh);
139: heightCtcon.setTitle(HEIGHT_TITLE);
140: heightCtcon.setShortDescription(HEIGHT_SHORT_DESCRIPTION);
141: //
142: heightCtcon.setMinimumLength(0);
143: heightCtcon.setMaximumLength(1);
144: //
145: StaticConceptTagConstraintContext heightSctcc = StaticConceptTagConstraintContext
146: .newInstance(heightCtcon);
147:
148: //
149: //constraint "align"
150: ConceptTagConstraint alignCtcon = ConceptTagConstraint
151: .newInstance(ALIGN_CTCON, rootCtconh);
152: alignCtcon.setTitle(ALIGN_TITLE);
153: alignCtcon.setShortDescription(ALIGN_SHORT_DESCRIPTION);
154: //
155: alignCtcon.setMinimumLength(0);
156: alignCtcon.setMaximumLength(1);
157: //
158: StaticConceptTagConstraintContext alignSctcc = StaticConceptTagConstraintContext
159: .newInstance(alignCtcon);
160:
161: //
162: //constraint "valign"
163: ConceptTagConstraint valignCtcon = ConceptTagConstraint
164: .newInstance(VALIGN_CTCON, rootCtconh);
165: valignCtcon.setTitle(VALIGN_TITLE);
166: valignCtcon.setShortDescription(VALIGN_SHORT_DESCRIPTION);
167: //
168: valignCtcon.setMinimumLength(0);
169: valignCtcon.setMaximumLength(1);
170: //
171: StaticConceptTagConstraintContext valignSctcc = StaticConceptTagConstraintContext
172: .newInstance(valignCtcon);
173:
174: //
175: inIctc.initialize();
176:
177: //
178: this .cellCtchar = cellCtcon.getCharacteristic();
179: this .widthCtchar = widthCtcon.getCharacteristic();
180: this .heightCtchar = heightCtcon.getCharacteristic();
181: this .alignCtchar = alignCtcon.getCharacteristic();
182: this .valignCtchar = valignCtcon.getCharacteristic();
183: //
184: this .actionCtchar = actionCtcon.getCharacteristic();
185: }
186:
187: public void appraise(AppraiseConceptTagContext inActc) {
188:
189: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
190:
191: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
192:
193: sctiic.setInstanceTitle("Row");
194: sctiic.setInstanceDescription("Row");
195: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
196:
197: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
198:
199: scttic.setTypeTitle("Row");
200: scttic.setTypeDescription("Row");
201: } else if (inActc instanceof WebPageTagInstanceViewContext) {
202:
203: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
204:
205: //
206: //
207: HashMap attrs = new HashMap();
208: //attrs.put("border", "1");
209: CommonV1WebPageTagHelper.addAttr(attrs, "width",
210: this .widthCtchar, wptivc);
211: CommonV1WebPageTagHelper.addAttr(attrs, "height",
212: this .heightCtchar, wptivc);
213: CommonV1WebPageTagHelper.addAttr(attrs, "align",
214: this .alignCtchar, wptivc);
215: CommonV1WebPageTagHelper.addAttr(attrs, "valign",
216: this .valignCtchar, wptivc);
217: //
218: attrs.put("cellspacing", "2px");
219: attrs.put("cellpadding", "2px");
220: attrs.put("width", "100%");
221: //
222: WebPageTagInstanceViewContextInfo info = wptivc
223: .getInfoAsHtml();
224:
225: info.declareMouseOutBorderAsPurple();
226: info.declareMouseOutBorderAsTwoPixel();
227: info.declareMouseOutBorderAsSolid();
228: //
229: //
230: //
231: //
232: WebPageTagInstanceViewContextInfo metaInfo = info
233: .createEarmarkInfo();
234: //
235: DynamicTableCellWebPageTag.prepareActionEarmark(
236: this .actionCtchar, metaInfo, wptivc);
237: //
238: metaInfo.createSubNonHtmlInfo(wptivc, this .widthCtchar,
239: "Width - ");
240: metaInfo.createSubNonHtmlInfo(wptivc, this .heightCtchar,
241: "Height - ");
242: metaInfo.createSubNonHtmlInfo(wptivc, this .alignCtchar,
243: "Align - ");
244: metaInfo.createSubNonHtmlInfo(wptivc, this .valignCtchar,
245: "Valign - ");
246: //metaInfo.createSubNonHtmlInfo(
247: // wptivc, this.colspanCtchar, "Colspan - ");
248: //
249: //
250: //
251: //
252: info
253: .setHtmlContent(WebPageTagInstanceViewContextSubHtmlInfo
254: .newInstance("table", attrs));
255: // "<tr " + XMLHelper.convertAttrs(attrs) + ">");
256: //
257: //
258: WebPageTagInstanceViewContextInfo subInfo = info
259: .createHtmlInfo();
260: subInfo.setHtmlContent("<tr>", "</tr>", true);
261: //
262: for (int i = 0; i < this .cellCtchar.getValueLength(); i++) {
263: WebPageTagInstanceViewContextInfo nextInfo = subInfo
264: .createHtmlInfo();
265: nextInfo.setHtmlContent("<td>", "</td>", true);
266: WebPageTagInstanceViewContext.displayView(
267: this .cellCtchar, nextInfo, wptivc, i, i + 1);
268: //nextInfo.setEndContent("</td>");
269: }
270: if (this .cellCtchar.getValueLength() == 0) {
271: //
272: WebPageTagInstanceViewContextInfo nextInfo = subInfo
273: .createHtmlInfo();
274: nextInfo.setHtmlContent("<td>", "</td>", true);
275: //
276: WebPageTagInstanceViewContextInfo subTextInfo = nextInfo
277: .createHtmlInfo(CELL_CTCON);
278: subTextInfo.setHtmlContent("(Empty Row)", true);
279: }
280: //
281: //
282: //
283: //subInfo.setEndContent("</tr>");
284: //
285: //info.setEndContent("</table>");
286:
287: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
288:
289: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
290:
291: scfrct.canReturnNothing();
292: scfrct.declareFormatAsHtml();
293: ConceptTagFlagsHelper.registerAsHtmlConceptTag(scfrct);
294: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
295:
296: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
297: }
298: }
299:
300: public void determineValueAndClass(
301: DetermineValueAndClassConceptTagContext inDvacctc) {
302:
303: try {
304:
305: //
306: //
307: //first, evaluate actions
308: this .actionCtchar.processIterativeStructure(inDvacctc,
309: false);
310:
311: //
312: HashMap attrs = new HashMap();
313: //attrs.put("border", "1");
314: CommonV1WebPageTagHelper.addAttr(attrs, "width",
315: this .widthCtchar, inDvacctc);
316: CommonV1WebPageTagHelper.addAttr(attrs, "height",
317: this .heightCtchar, inDvacctc);
318: CommonV1WebPageTagHelper.addAttr(attrs, "align",
319: this .alignCtchar, inDvacctc);
320: CommonV1WebPageTagHelper.addAttr(attrs, "valign",
321: this .valignCtchar, inDvacctc);
322: //
323: ConceptTagFlagsHelper.addVacToParDetVacRes(inDvacctc,
324: ValueAndClassForConceptTag.newHtml("<tr "
325: + XMLHelper.convertAttrs(attrs) + ">"));
326: //
327: this .cellCtchar.processIterativeStructure(inDvacctc);
328: //
329: ConceptTagFlagsHelper.addVacToParDetVacRes(inDvacctc,
330: ValueAndClassForConceptTag.newHtml("</tr>"));
331: //
332: inDvacctc
333: .setDetermineValueAndClass(ValueAndClassForConceptTag
334: .newNothing());
335: } catch (DetermineValueAndClassConceptTagException dvaccte) {
336: inDvacctc.setDetermineException(dvaccte);
337: }
338: }
339:
340: public void determineClass(DetermineClassConceptTagContext inDcctc) {
341:
342: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
343: }
344: }
|