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.UnexpectedSystemException;
016: import org.jfolder.common.function.BaseWebPageTag;
017: import org.jfolder.common.function.WebPageTagInstanceViewContext;
018: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
019: import org.jfolder.common.function.WebPageTagInstanceViewContextSubHtmlInfo;
020: import org.jfolder.common.tagging.AppraiseConceptTagContext;
021: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
022: import org.jfolder.common.tagging.ConceptTag;
023: import org.jfolder.common.tagging.ConceptTagCharacteristic;
024: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
025: import org.jfolder.common.tagging.ConceptTagConstraint;
026: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
027: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
028: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
029: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
030: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
031: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
032: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
033: import org.jfolder.common.tagging.InitializeConceptTagContext;
034: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
035: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
036: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
037: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
038: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
039: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
040: import org.jfolder.common.utils.xml.XMLHelper;
041:
042: //other classes
043:
044: public class DynamicTableCellWebPageTag extends BaseWebPageTag {
045:
046: //characteristics
047: private ConceptTagCharacteristic contentCtchar = null;
048: private ConceptTagCharacteristic widthCtchar = null;
049: private ConceptTagCharacteristic heightCtchar = null;
050: private ConceptTagCharacteristic alignCtchar = null;
051: private ConceptTagCharacteristic valignCtchar = null;
052: private ConceptTagCharacteristic colspanCtchar = null;
053: //
054: private ConceptTagCharacteristic fontFamilyCtchar = null;
055: private ConceptTagCharacteristic fontSizeCtchar = null;
056: //
057: private ConceptTagCharacteristic actionCtchar = null;
058:
059: //content details
060: public final static String CONTENT_CTCON = "content";
061: private final static String CONTENT_TITLE = "Content";
062: private final static String CONTENT_SHORT_DESCRIPTION = "Content";
063: //
064: //
065: //width details
066: public final static String WIDTH_CTCON = "width";
067: private final static String WIDTH_TITLE = "Width";
068: private final static String WIDTH_SHORT_DESCRIPTION = "Width";
069: //
070: //height details
071: public final static String HEIGHT_CTCON = "height";
072: private final static String HEIGHT_TITLE = "Height";
073: private final static String HEIGHT_SHORT_DESCRIPTION = "Height";
074: //
075: //align details
076: public final static String ALIGN_CTCON = "align";
077: private final static String ALIGN_TITLE = "Align";
078: private final static String ALIGN_SHORT_DESCRIPTION = "Align";
079: //
080: //valign details
081: public final static String VALIGN_CTCON = "valign";
082: private final static String VALIGN_TITLE = "Vertical Align";
083: private final static String VALIGN_SHORT_DESCRIPTION = "Vertical Align";
084: //
085: //colspan details
086: public final static String COLSPAN_CTCON = "colspan";
087: private final static String COLSPAN_TITLE = "Column Span";
088: private final static String COLSPAN_SHORT_DESCRIPTION = "Column Span";
089: //
090: //action details
091: private final static String ACTION_CTCON = "action";
092: private final static String ACTION_TITLE = "Action";
093: private final static String ACTION_SHORT_DESCRIPTION = "Action";
094:
095: public void initialize(InitializeConceptTagContext inIctc) {
096:
097: //
098: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
099: .newInstance(inIctc);
100:
101: //
102: //constrain "action"
103: ConceptTagConstraint actionCtcon = ConceptTagConstraint
104: .newInstance(ACTION_CTCON, rootCtconh);
105: //
106: actionCtcon.setMinimumLength(0);
107: actionCtcon.setLengthUnbounded(true);
108: //
109: actionCtcon.setTitle(ACTION_TITLE);
110: actionCtcon.setShortDescription(ACTION_SHORT_DESCRIPTION);
111: //
112: DynamicConceptTagConstraintContext actionDctcc = DynamicConceptTagConstraintContext
113: .newInstance(actionCtcon);
114:
115: //
116: //constrain "content"
117: ConceptTagConstraint contentCtcon = ConceptTagConstraint
118: .newInstance(CONTENT_CTCON, rootCtconh);
119: contentCtcon.setTitle(CONTENT_TITLE);
120: contentCtcon.setShortDescription(CONTENT_SHORT_DESCRIPTION);
121: contentCtcon.setDisplayAsBranch(false);
122: contentCtcon.setMergeAdjacentTextNodes(true);
123: //
124: DynamicConceptTagConstraintContext contentDctcc = DynamicConceptTagConstraintContext
125: .newInstance(contentCtcon);
126: contentDctcc.getValidator().filterDirectChildOfRoot();
127: //
128: StaticConceptTagConstraintContext contentSctcc = StaticConceptTagConstraintContext
129: .newInstance(contentCtcon);
130: contentSctcc.setMultiLine(true);
131:
132: //
133: //constraint "width"
134: ConceptTagConstraint widthCtcon = ConceptTagConstraint
135: .newInstance(WIDTH_CTCON, rootCtconh);
136: widthCtcon.setTitle(WIDTH_TITLE);
137: widthCtcon.setShortDescription(WIDTH_SHORT_DESCRIPTION);
138: //
139: widthCtcon.setMinimumLength(0);
140: widthCtcon.setMaximumLength(1);
141: //
142: StaticConceptTagConstraintContext widthSctcc = StaticConceptTagConstraintContext
143: .newInstance(widthCtcon);
144:
145: //
146: //constraint "height"
147: ConceptTagConstraint heightCtcon = ConceptTagConstraint
148: .newInstance(HEIGHT_CTCON, rootCtconh);
149: heightCtcon.setTitle(HEIGHT_TITLE);
150: heightCtcon.setShortDescription(HEIGHT_SHORT_DESCRIPTION);
151: //
152: heightCtcon.setMinimumLength(0);
153: heightCtcon.setMaximumLength(1);
154: //
155: StaticConceptTagConstraintContext heightSctcc = StaticConceptTagConstraintContext
156: .newInstance(heightCtcon);
157:
158: //
159: //constraint "align"
160: ConceptTagConstraint alignCtcon = ConceptTagConstraint
161: .newInstance(ALIGN_CTCON, rootCtconh);
162: alignCtcon.setTitle(ALIGN_TITLE);
163: alignCtcon.setShortDescription(ALIGN_SHORT_DESCRIPTION);
164: //
165: alignCtcon.setMinimumLength(0);
166: alignCtcon.setMaximumLength(1);
167: //
168: StaticConceptTagConstraintContext alignSctcc = StaticConceptTagConstraintContext
169: .newInstance(alignCtcon);
170:
171: //
172: //constraint "valign"
173: ConceptTagConstraint valignCtcon = ConceptTagConstraint
174: .newInstance(VALIGN_CTCON, rootCtconh);
175: valignCtcon.setTitle(VALIGN_TITLE);
176: valignCtcon.setShortDescription(VALIGN_SHORT_DESCRIPTION);
177: //
178: valignCtcon.setMinimumLength(0);
179: valignCtcon.setMaximumLength(1);
180: //
181: StaticConceptTagConstraintContext valignSctcc = StaticConceptTagConstraintContext
182: .newInstance(valignCtcon);
183:
184: //
185: //constraint "colspan"
186: ConceptTagConstraint colspanCtcon = ConceptTagConstraint
187: .newInstance(COLSPAN_CTCON, rootCtconh);
188: colspanCtcon.setTitle(COLSPAN_TITLE);
189: colspanCtcon.setShortDescription(COLSPAN_SHORT_DESCRIPTION);
190: //
191: colspanCtcon.setMinimumLength(0);
192: colspanCtcon.setMaximumLength(1);
193: //
194: StaticConceptTagConstraintContext colspanSctcc = StaticConceptTagConstraintContext
195: .newInstance(colspanCtcon);
196:
197: //
198: //constrain "font-family"
199: ConceptTagConstraint fontFamilyCtcon = DynamicStyleWebPageTag
200: .getFontFamilyCtcon(rootCtconh);
201:
202: //
203: //constrain "font-size"
204: ConceptTagConstraint fontSizeCtcon = DynamicStyleWebPageTag
205: .getFontStyleCtcon(rootCtconh);
206:
207: //
208: inIctc.initialize();
209:
210: //
211: this .contentCtchar = contentCtcon.getCharacteristic();
212: this .widthCtchar = widthCtcon.getCharacteristic();
213: this .heightCtchar = heightCtcon.getCharacteristic();
214: this .alignCtchar = alignCtcon.getCharacteristic();
215: this .valignCtchar = valignCtcon.getCharacteristic();
216: this .colspanCtchar = colspanCtcon.getCharacteristic();
217: //
218: this .fontFamilyCtchar = fontFamilyCtcon.getCharacteristic();
219: this .fontSizeCtchar = fontSizeCtcon.getCharacteristic();
220: //
221: this .actionCtchar = actionCtcon.getCharacteristic();
222: }
223:
224: public void appraise(AppraiseConceptTagContext inActc) {
225:
226: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
227:
228: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
229:
230: sctiic.setInstanceTitle("Cell");
231: sctiic.setInstanceDescription("Cell");
232:
233: //
234: ConceptTagCharacteristic formatCtchar[] = new ConceptTagCharacteristic[] { this .contentCtchar };
235: ConceptTagFlagsHelper.setWebPageFormatCtchars(sctiic,
236: formatCtchar);
237: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
238:
239: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
240:
241: scttic.setTypeTitle("Cell");
242: scttic.setTypeDescription("Cell");
243: } else if (inActc instanceof WebPageTagInstanceViewContext) {
244:
245: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
246:
247: //
248: //
249: HashMap attrs = new HashMap();
250: //attrs.put("border", "1");
251: CommonV1WebPageTagHelper.addAttr(attrs, "width",
252: this .widthCtchar, wptivc);
253: CommonV1WebPageTagHelper.addAttr(attrs, "height",
254: this .heightCtchar, wptivc);
255: CommonV1WebPageTagHelper.addAttr(attrs, "align",
256: this .alignCtchar, wptivc);
257: CommonV1WebPageTagHelper.addAttr(attrs, "valign",
258: this .valignCtchar, wptivc);
259: CommonV1WebPageTagHelper.addAttr(attrs, "colspan",
260: this .colspanCtchar, wptivc);
261: //
262: attrs.put("cellspacing", "2px");
263: attrs.put("cellpadding", "2px");
264: //
265: HashMap styles = new HashMap();
266: CommonV1WebPageTagHelper.addAttr(styles, "font-family",
267: this .fontFamilyCtchar, wptivc);
268: CommonV1WebPageTagHelper.addAttr(styles, "font-size",
269: this .fontSizeCtchar, wptivc);
270: //
271: WebPageTagInstanceViewContextInfo
272: .getMousePointerActions(attrs);
273: //
274: WebPageTagInstanceViewContextInfo info = wptivc
275: .getInfoAsHtml();
276:
277: info.declareMouseOutBorderAsOlive();
278: info.declareMouseOutBorderAsTwoPixel();
279: info.declareMouseOutBorderAsSolid();
280: //
281: //
282: //
283: WebPageTagInstanceViewContextInfo metaInfo = info
284: .createEarmarkInfo();
285: //
286: DynamicTableCellWebPageTag.prepareActionEarmark(
287: this .actionCtchar, metaInfo, wptivc);
288: //
289: metaInfo.createSubNonHtmlInfo(wptivc, this .widthCtchar,
290: "Width - ");
291: metaInfo.createSubNonHtmlInfo(wptivc, this .heightCtchar,
292: "Height - ");
293: metaInfo.createSubNonHtmlInfo(wptivc, this .alignCtchar,
294: "Align - ");
295: metaInfo.createSubNonHtmlInfo(wptivc, this .valignCtchar,
296: "Valign - ");
297: metaInfo.createSubNonHtmlInfo(wptivc, this .colspanCtchar,
298: "Colspan - ");
299: //
300: //
301: info
302: .setHtmlContent(WebPageTagInstanceViewContextSubHtmlInfo
303: .newInstance("table", attrs, styles));
304: // "<td " + XMLHelper.convertAttrs(attrs)
305: // + " onclick=\"", "\">");
306: //
307: WebPageTagInstanceViewContextInfo subInfo = info
308: .createHtmlInfo();
309: subInfo.setHtmlContent("<tr><td>", "</td></tr>", true);
310: //if (this.contentCtchar.getValueLength() > 0) {
311: // subInfo.setHtmlContent("<tr><td>", "</td></tr>", true);
312: //}
313: //else {
314: // subInfo.setHtmlContent(
315: // "<tr><td>", "(Empty Cell)</td></tr>", true);
316: //}
317: //
318: //
319: WebPageTagInstanceViewContext
320: .displayView(this .contentCtchar, subInfo, wptivc,
321: "(Empty Cell)");
322: //
323: //
324: //subInfo.setEndContent("</td></tr>");
325: //
326: //
327: //info.setEndContent("</table>");
328:
329: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
330:
331: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
332:
333: scfrct.canReturnNothing();
334: scfrct.declareFormatAsHtml();
335: ConceptTagFlagsHelper.registerAsHtmlConceptTag(scfrct);
336: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
337:
338: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
339: }
340: }
341:
342: //
343: protected final static void prepareActionEarmark(
344: ConceptTagCharacteristic inActionCtchar,
345: WebPageTagInstanceViewContextInfo inMetaInfo,
346: WebPageTagInstanceViewContext inWptivc) {
347: //
348: if (inMetaInfo.isEarmarkToParent()) {
349: //
350: WebPageTagInstanceViewContextInfo actionStartInfo[] = new WebPageTagInstanceViewContextInfo[1];
351: WebPageTagInstanceViewContextInfo actionMiddleInfo[] = new WebPageTagInstanceViewContextInfo[1];
352: WebPageTagInstanceViewContextInfo actionEndInfo[] = new WebPageTagInstanceViewContextInfo[1];
353: //
354: WebPageTagInstanceViewContextInfo parentIterInfo = inMetaInfo
355: .createIterativeNonHtmlInfo();
356: parentIterInfo.createIterativeSubParts(actionStartInfo,
357: actionMiddleInfo, actionEndInfo);
358: //
359: //
360: //mid part
361: //
362: if (inActionCtchar.getValueLength() > 0) {
363: //
364: WebPageTagInstanceViewContext.displayView(
365: inActionCtchar, actionMiddleInfo[0], inWptivc);
366: } else {
367: WebPageTagInstanceViewContextInfo emptyActionInfo = (actionMiddleInfo[0])
368: .createNonHtmlInfo(inActionCtchar
369: .getConstraintName());
370: emptyActionInfo
371: .setNonHtmlContent("No Action - Click Here To Create");
372: }
373: //
374: //
375: //start info
376: //
377: (actionStartInfo[0])
378: .setNonHtmlContent("Process these actions before rendering content {");
379: //
380: //
381: //end info
382: //
383: (actionEndInfo[0]).setNonHtmlContent("}");
384: } else {
385: throw UnexpectedSystemException.unknownState();
386: }
387: }
388:
389: //
390: public void determineValueAndClass(
391: DetermineValueAndClassConceptTagContext inDvacctc) {
392:
393: try {
394:
395: //
396: //
397: //first, evaluate actions
398: this .actionCtchar.processIterativeStructure(inDvacctc,
399: false);
400:
401: //
402: HashMap attrs = new HashMap();
403: //attrs.put("border", "1");
404: CommonV1WebPageTagHelper.addAttr(attrs, "width",
405: this .widthCtchar, inDvacctc);
406: CommonV1WebPageTagHelper.addAttr(attrs, "height",
407: this .heightCtchar, inDvacctc);
408: CommonV1WebPageTagHelper.addAttr(attrs, "align",
409: this .alignCtchar, inDvacctc);
410: CommonV1WebPageTagHelper.addAttr(attrs, "valign",
411: this .valignCtchar, inDvacctc);
412: CommonV1WebPageTagHelper.addAttr(attrs, "colspan",
413: this .colspanCtchar, inDvacctc);
414: //
415: //
416: HashMap styles = new HashMap();
417: //attrs.put("border", "1");
418: CommonV1WebPageTagHelper.addAttr(styles, "font-family",
419: this .fontFamilyCtchar, inDvacctc);
420: CommonV1WebPageTagHelper.addAttr(styles, "font-size",
421: this .fontSizeCtchar, inDvacctc);
422: //
423: attrs.put("style", XMLHelper.fromStylesToAttr(styles));
424: //
425: //
426: //
427: ConceptTagFlagsHelper.addVacToParDetVacRes(inDvacctc,
428: ValueAndClassForConceptTag.newHtml("<td "
429: + XMLHelper.convertAttrs(attrs) + ">"));
430: //
431: this .contentCtchar.processIterativeStructure(inDvacctc);
432: //
433: ConceptTagFlagsHelper.addVacToParDetVacRes(inDvacctc,
434: ValueAndClassForConceptTag.newHtml("</td>"));
435: //
436: inDvacctc
437: .setDetermineValueAndClass(ValueAndClassForConceptTag
438: .newNothing());
439: } catch (DetermineValueAndClassConceptTagException dvaccte) {
440: inDvacctc.setDetermineException(dvaccte);
441: }
442: }
443:
444: public void determineClass(DetermineClassConceptTagContext inDcctc) {
445:
446: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
447: }
448: }
|