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