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.workflow.model.template.v1;
009:
010: //base classes
011:
012: //project specific classes
013: import org.jfolder.common.tagging.AppraiseConceptTagContext;
014: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
015: import org.jfolder.common.tagging.ConceptTagCharacteristic;
016: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
017: import org.jfolder.common.tagging.ConceptTagConstraint;
018: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
019: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
020: import org.jfolder.common.tagging.CoreConceptTag;
021: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
022: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
023: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
024: import org.jfolder.common.tagging.InitializeConceptTagContext;
025: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
026: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
027: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
028: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
029: import org.jfolder.common.utils.misc.CommonExpressions;
030:
031: //other classes
032:
033: public class StartWorkflowTemplateTag extends NodeWorkflowTemplateTag {
034:
035: //characteristics
036: private ConceptTagCharacteristic nameCtchar = null;
037: private ConceptTagCharacteristic xCordCtchar = null;
038: private ConceptTagCharacteristic yCordCtchar = null;
039: private ConceptTagCharacteristic triggerConditionCtchar = null;
040: //private ConceptTagCharacteristic ifTransitionCtchar = null;
041: //private ConceptTagCharacteristic transitionCtchar = null;
042: //private ConceptTagCharacteristic branchCtchar = null;
043:
044: //name details
045: private final static String NAME_CTCON = "name";
046: private final static String NAME_TITLE = "Name";
047: private final static String NAME_SHORT_DESCRIPTION = "Name of this start";
048:
049: //xCord details
050: private final static String X_CORD_CTCON = "x-cord";
051: private final static String X_CORD_TITLE = "X Coordinate";
052: private final static String X_CORD_SHORT_DESCRIPTION = "Distance"
053: + " (in pixels) from the left side of the workflow-template graph";
054:
055: //yCord details
056: private final static String Y_CORD_CTCON = "y-cord";
057: private final static String Y_CORD_TITLE = "Y Coordinate";
058: private final static String Y_CORD_SHORT_DESCRIPTION = "Distance"
059: + " (in pixels) from the top side of the workflow-template graph";
060:
061: //triggerCondition details
062: private final static String TRIGGER_CONDITION_CTCON = "trigger-condition";
063: private final static String TRIGGER_CONDITION_TITLE = "Trigger Condition";
064: private final static String TRIGGER_CONDITION_SHORT_DESCRIPTION = "If this condition evaluates to true, this start will be selected";
065:
066: /*
067: //ifTransition details
068: private final static String IF_TRANSITION_CTCON = "if-transition";
069: private final static String IF_TRANSITION_TITLE = "If Transitions";
070: private final static String IF_TRANSITION_SHORT_DESCRIPTION =
071: "Transition to take if condition is true";
072:
073: //ifTransition condition template
074: private final static String IF_TRANSITION_CTCON_CONDITION_CTCTEMP =
075: "condition";
076: private final static String IF_TRANSITION_CTCON_CONDITION_TITLE =
077: "Condition";
078: private final static String
079: IF_TRANSITION_CTCON_CONDITION_SHORT_DESCRIPTION =
080: "This path will be taken only if this condition evaluates to true";
081:
082: //ifTransition transition template
083: private final static String IF_TRANSITION_CTCON_TRANSITION_CTCTEMP =
084: "transition";
085: private final static String IF_TRANSITION_CTCON_TRANSITION_TITLE =
086: "Transition";
087: private final static String
088: IF_TRANSITION_CTCON_TRANSITION_SHORT_DESCRIPTION =
089: "This path to be taken";
090:
091: //transition details
092: private final static String TRANSITION_CTCON = "transition";
093: private final static String TRANSITION_TITLE = "Default Transition";
094: private final static String TRANSITION_SHORT_DESCRIPTION =
095: "Transition to take if none of the if transition conditions"
096: + " evaluate to true";
097:
098: //branch detail
099: private final static String BRANCH_CTCON = "branch";
100: private final static String BRANCH_TITLE = "Branch";
101: private final static String BRANCH_SHORT_DESCRIPTION =
102: "Simultaneous path to take";
103:
104: //branch ifTransition template
105: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP =
106: "if-transition";
107: private final static String BRANCH_CTCON_IF_TRANSITION_TITLE =
108: "If Transitions";
109: private final static String BRANCH_CTCON_IF_TRANSITION_SHORT_DESCRIPTION =
110: "Transition to take if condition is true";
111: //branch ifTransition template condition template
112: private final static String
113: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_CTCTEMP = "condition";
114: private final static String
115: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_TITLE = "Condition";
116: private final static String
117: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_SHORT_DESCRIPTION =
118: "This path will be taken only if this condition evaluates to true";
119: //branch ifTransition template transition template
120: private final static String
121: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_CTCTEMP = "transition";
122: private final static String
123: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_TITLE = "Transition";
124: private final static String
125: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_SHORT_DESCRIPTION =
126: "This path to be taken";
127: //branch transition template
128: private final static String BRANCH_CTCON_TRANSITION_CTCTEMP = "transition";
129: private final static String
130: BRANCH_CTCON_TRANSITION_TITLE = "Default Transition";
131: private final static String BRANCH_CTCON_TRANSITION_SHORT_DESCRIPTION =
132: "Transition to take if none of the if transition conditions"
133: + " evaluate to true";
134:
135: //TO DO: look into duplicate TC names!
136:
137: */
138:
139: public void initialize(InitializeConceptTagContext inIctc) {
140:
141: //
142: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
143: .newInstance(inIctc);
144:
145: //constrain "name"
146: ConceptTagConstraint nameCtcon = ConceptTagConstraint
147: .newInstance(NAME_CTCON, rootCtconh);
148: nameCtcon.setTitle(NAME_TITLE);
149: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
150: //
151: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
152: .newInstance(nameCtcon);
153: nameSctcc.setRegularExpression(CommonExpressions.JAVA_NAME);
154: //
155: nameSctcc.addDefaultValue("Start");
156: //((InitializeConceptTagContextBean)inItc).registerStart(this.nameTc);
157:
158: //constrain "x-cord"
159: ConceptTagConstraint xCordCtcon = ConceptTagConstraint
160: .newInstance(X_CORD_CTCON, rootCtconh);
161: xCordCtcon.setTitle(X_CORD_TITLE);
162: xCordCtcon.setShortDescription(X_CORD_SHORT_DESCRIPTION);
163: //stc2.setDefaultValueAsString(ConceptTagHelper.RESET);
164: StaticConceptTagConstraintContext xCordSctcc = StaticConceptTagConstraintContext
165: .newInstance(xCordCtcon);
166: xCordSctcc
167: .setRegularExpression(CommonExpressions.POSITIVE_INTEGER);
168: //
169: xCordSctcc.addDefaultValue("0");
170: //((InitializeConceptTagContextBean)inItc).registerXCord(this.xCordTc);
171: //stc2.setDefaultValueAsString();//TO DO: implement this
172: //TO DO: dynamically determine value
173:
174: //constrain "y-cord"
175: ConceptTagConstraint yCordCtcon = ConceptTagConstraint
176: .newInstance(Y_CORD_CTCON, rootCtconh);
177: yCordCtcon.setTitle(Y_CORD_TITLE);
178: yCordCtcon.setShortDescription(Y_CORD_SHORT_DESCRIPTION);
179: //stc3.setDefaultValueAsString(ConceptTagHelper.RESET);
180: StaticConceptTagConstraintContext yCordSctcc = StaticConceptTagConstraintContext
181: .newInstance(yCordCtcon);
182: yCordSctcc
183: .setRegularExpression(CommonExpressions.POSITIVE_INTEGER);
184: //
185: yCordSctcc.addDefaultValue("0");
186: //((InitializeConceptTagContextBean)inItc).registerYCord(this.yCordTc);
187: //stc3.setDefaultValueAsString();//TO DO: implement this
188: //TO DO: dynamically determine value
189:
190: //constrain "trigger-condition"
191: ConceptTagConstraint triggerConditionCtcon = ConceptTagConstraint
192: .newInstance(TRIGGER_CONDITION_CTCON, rootCtconh);
193: triggerConditionCtcon.setTitle(TRIGGER_CONDITION_TITLE);
194: triggerConditionCtcon
195: .setShortDescription(TRIGGER_CONDITION_SHORT_DESCRIPTION);
196: //
197: DynamicConceptTagConstraintContext triggerConditionDctcc = DynamicConceptTagConstraintContext
198: .newInstance(triggerConditionCtcon);
199: triggerConditionDctcc.getValidator().allowReturnOfOnlyBoolean();
200: //
201: triggerConditionDctcc
202: .addDefaultValue(IsTriggerFromApplicationWorkflowTemplateTag.class);
203: //
204: //((InitializeConceptTagContextBean)inItc).forbidAttributeUse(
205: // this.triggerConditionTc);
206: //sodtc1.setClassRestrictions(ReturnableTag.class);
207: //TO DO: validate text value
208:
209: super .initializeBase(inIctc);
210:
211: //initialize characteristics
212: this .nameCtchar = nameCtcon.getCharacteristic();
213: this .xCordCtchar = xCordCtcon.getCharacteristic();
214: this .yCordCtchar = yCordCtcon.getCharacteristic();
215: this .triggerConditionCtchar = triggerConditionCtcon
216: .getCharacteristic();
217: }
218:
219: public void appraise(AppraiseConceptTagContext inCtic) {
220: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
221: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
222: sctiic.setInstanceTitle("???(TagInstanceTitle)???");
223: sctiic
224: .setInstanceDescription("???(TagInstaceDescription)???");
225: if (this .nameCtchar.getValueLength() > 0
226: && this .nameCtchar.isStatic(0, inCtic)) {
227:
228: sctiic.setInstanceTitle(this .nameCtchar
229: .getValueAsString(0, inCtic));
230: sctiic.setInstanceDescription(this .nameCtchar
231: .getValueAsString(0, inCtic));
232: }
233: sctiic.setLocalInstanceIcon("start");
234: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
235: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
236: scttic.setTypeTitle("Start");
237: scttic
238: .setTypeDescription("Potential starting point for a workflow-instance");
239: }
240: }
241:
242: public boolean isTriggerConditionActive(
243: DetermineValueAndClassConceptTagContext inRvacc)
244: throws DetermineValueAndClassConceptTagException {
245:
246: Boolean outValue = null;
247:
248: ValueAndClassForConceptTag tcVac = this .triggerConditionCtchar
249: .getDetermineValueAndClass(0, inRvacc);
250:
251: outValue = (Boolean) tcVac.getValue();
252:
253: return outValue.booleanValue();
254: }
255:
256: public String getName() {
257: return this .nameCtchar.getValueAsString(0, null);
258: }
259:
260: public boolean isXCordValid() {
261: return isCordValid(this .xCordCtchar);
262: }
263:
264: public boolean isYCordValid() {
265: return isCordValid(this .yCordCtchar);
266: }
267:
268: private boolean isCordValid(ConceptTagCharacteristic inTc) {
269:
270: boolean outValue = false;
271:
272: try {
273: if (inTc.getValueLength() > 0 && inTc.isStatic(0, null)) {
274: int value = Integer.parseInt(inTc.getValueAsString(0,
275: null));
276: outValue = (value > 1);
277: }
278: } catch (NumberFormatException nfe) {
279: //do nothing, return false;
280: }
281:
282: return outValue;
283: }
284:
285: public int getXCord() {
286: return Integer.parseInt(this .xCordCtchar.getValueAsString(0,
287: null));
288: }
289:
290: public int getYCord() {
291: return Integer.parseInt(this .yCordCtchar.getValueAsString(0,
292: null));
293: }
294:
295: public void setXCord(String inCord) {
296: this .xCordCtchar.addValue(0, inCord);
297: }
298:
299: public void setYCord(String inCord) {
300: this .yCordCtchar.addValue(0, inCord);
301: }
302:
303: /*
304: public void getTagSummary(TagSummaryDescriptor tsd) {
305: //TO DO: placeholder, put meaningful description
306: if (tsd.getMimeType().equals(TagSummaryMimeType.TEXT_HTML)) {
307: tsd.appendData("<table width=\"100%\">");
308: tsd.appendData("<tr>");
309: tsd.appendData(
310: "<td width=\"30%\" style=\"font-size: 16;
311: // font-family: Arial; color: #000000;\">");
312: tsd.appendData(this.nameAttr[0]);
313: tsd.appendData("</td>");
314: tsd.appendData(
315: "<td width=\"20%\" style=\"font-size: 16;
316: // font-family: Arial; color: #000000;\">");
317: tsd.appendData("X = " + this.xCordAttr[0]);
318: tsd.appendData("</td>");
319: tsd.appendData(
320: "<td width=\"50%\" style=\"font-size: 16;
321: // font-family: Arial; color: #000000;\">");
322: tsd.appendData("Y = " + this.yCordAttr[0]);
323: tsd.appendData("</td>");
324: tsd.appendData("</tr>");
325:
326: //trigger condition
327: if (this.booleanTags.size() > 0) {
328: tsd.appendData("<tr >");
329: tsd.appendData("<td width=\"30%\">");
330: tsd.appendData("</td>");
331: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
332: tsd.appendData("<hr/>");
333: tsd.appendData("</td>");
334: tsd.appendData("</tr>");
335:
336: tsd.appendData("<tr>");
337: tsd.appendData("<td width=\"30%\">");
338: tsd.appendData("</td>");
339: tsd.appendData(
340: "<td width=\"70%\" colspan=\"2\" style=\"font-size:
341: // 14; font-family: Arial; color: #000000;\">");
342: tsd.appendData(
343: "Exclusively use this script and start here only if (");
344: ((Tag)(this.booleanTags.get(0))).getTagSummary(tsd);
345: tsd.appendData(")");
346: tsd.appendData("</td>");
347: tsd.appendData("</tr>");
348: }
349:
350: if (this.ifTransitionTags.size() > 0
351: || this.transitionTags.size() > 0) {
352: tsd.appendData("<tr >");
353: tsd.appendData("<td width=\"30%\">");
354: tsd.appendData("</td>");
355: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
356: tsd.appendData("<hr/>");
357: tsd.appendData("</td>");
358: tsd.appendData("</tr>");
359:
360: //if transitions
361: if (this.ifTransitionTags.size() > 0) {
362: for (int i = 0; i < this.ifTransitionTags.size(); i++) {
363: tsd.appendData("<tr>");
364: tsd.appendData("<td width=\"30%\">");
365: tsd.appendData("</td>");
366: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
367: ((Tag)(this.ifTransitionTags.get(i))
368: ).getTagSummary(tsd);
369: tsd.appendData("</td>");
370: tsd.appendData("</tr>");
371: }
372: }
373:
374: //transition
375: if (this.transitionTags.size() > 0) {
376: tsd.appendData("<tr>");
377: tsd.appendData("<td width=\"30%\">");
378: tsd.appendData("</td>");
379: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
380: ((Tag)(this.transitionTags.get(0))).getTagSummary(tsd);
381: tsd.appendData("</td>");
382: tsd.appendData("</tr>");
383: }
384: }
385:
386: //branches
387: if (this.branchTags.size() > 0) {
388: for (int i = 0; i < this.branchTags.size(); i++) {
389: tsd.appendData("<tr >");
390: tsd.appendData("<td width=\"30%\">");
391: tsd.appendData("</td>");
392: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
393: tsd.appendData("<hr/>");
394: tsd.appendData("</td>");
395: tsd.appendData("</tr>");
396:
397: tsd.appendData("<tr>");
398: tsd.appendData("<td width=\"30%\">");
399: tsd.appendData("</td>");
400: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
401: ((Tag)(this.branchTags.get(i))).getTagSummary(tsd);
402: tsd.appendData("</td>");
403: tsd.appendData("</tr>");
404: }
405: }
406:
407: tsd.appendData("</table>");
408: }
409: }
410: */
411: }
|