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.ConceptTagCharacteristic;
015: import org.jfolder.common.tagging.ConceptTagConstraint;
016: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
017: import org.jfolder.common.tagging.CoreConceptTag;
018: import org.jfolder.common.tagging.InitializeConceptTagContext;
019: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
020: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
021: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
022: import org.jfolder.common.utils.misc.CommonExpressions;
023:
024: //other classes
025:
026: public class StopWorkflowTemplateTag implements CoreConceptTag {
027:
028: //characteristics
029: private ConceptTagCharacteristic nameCtchar = null;
030: private ConceptTagCharacteristic xCordCtchar = null;
031: private ConceptTagCharacteristic yCordCtchar = null;
032:
033: //name details
034: private final static String NAME_CTCON = "name";
035: private final static String NAME_TITLE = "Name";
036: private final static String NAME_SHORT_DESCRIPTION = "Name of this start";
037:
038: //xCord details
039: private final static String X_CORD_CTCON = "x-cord";
040: private final static String X_CORD_TITLE = "X Coordinate";
041: private final static String X_CORD_SHORT_DESCRIPTION = "Distance (in pixels) from the left side "
042: + "of the workflow-template graph";
043:
044: //yCord details
045: private final static String Y_CORD_CTCON = "y-cord";
046: private final static String Y_CORD_TITLE = "Y Coordinate";
047: private final static String Y_CORD_SHORT_DESCRIPTION = "Distance (in pixels) from the top side "
048: + "of the workflow-template graph";
049:
050: public void initialize(InitializeConceptTagContext inIctc) {
051:
052: //
053: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
054: .newInstance(inIctc);
055:
056: //constrain "name"
057: ConceptTagConstraint nameCtcon = ConceptTagConstraint
058: .newInstance(NAME_CTCON, rootCtconh);
059: nameCtcon.setTitle(NAME_TITLE);
060: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
061: //
062: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
063: .newInstance(nameCtcon);
064: nameSctcc.setRegularExpression(CommonExpressions.JAVA_NAME);
065: //
066: nameSctcc.addDefaultValue("Stop");
067: //((InitializeConceptTagContextBean)inItc).registerStop(this.nameTc);
068:
069: //constrain "x-cord"
070: ConceptTagConstraint xCordCtcon = ConceptTagConstraint
071: .newInstance(X_CORD_CTCON, rootCtconh);
072: xCordCtcon.setTitle(X_CORD_TITLE);
073: xCordCtcon.setShortDescription(X_CORD_SHORT_DESCRIPTION);
074: //stc2.setDefaultValueAsString(ConceptTagHelper.RESET);
075: StaticConceptTagConstraintContext xCordSctcc = StaticConceptTagConstraintContext
076: .newInstance(xCordCtcon);
077: xCordSctcc
078: .setRegularExpression(CommonExpressions.POSITIVE_INTEGER);
079: //
080: xCordSctcc.addDefaultValue("0");
081: //((InitializeConceptTagContextBean)inItc).registerXCord(this.xCordTc);
082: //stc2.setDefaultValueAsString();//TO DO: implement this
083: //TO DO: dynamically determine value
084:
085: //constrain yCord
086: ConceptTagConstraint yCordCtcon = ConceptTagConstraint
087: .newInstance(Y_CORD_CTCON, rootCtconh);
088: yCordCtcon.setTitle(Y_CORD_TITLE);
089: yCordCtcon.setShortDescription(Y_CORD_SHORT_DESCRIPTION);
090: //stc3.setDefaultValueAsString(ConceptTagHelper.RESET);
091: StaticConceptTagConstraintContext yCordSctcc = StaticConceptTagConstraintContext
092: .newInstance(yCordCtcon);
093: yCordSctcc
094: .setRegularExpression(CommonExpressions.POSITIVE_INTEGER);
095: //
096: yCordSctcc.addDefaultValue("0");
097: //((InitializeConceptTagContextBean)inItc).registerYCord(this.yCordTc);
098: //stc3.setDefaultValueAsString();//TO DO: implement this
099: //TO DO: dynamically determine value
100:
101: inIctc.initialize();
102:
103: //create tag characteristic
104: this .nameCtchar = nameCtcon.getCharacteristic();
105: this .xCordCtchar = xCordCtcon.getCharacteristic();
106: this .yCordCtchar = yCordCtcon.getCharacteristic();
107:
108: }
109:
110: public void appraise(AppraiseConceptTagContext inCtic) {
111: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
112: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
113: sctiic.setInstanceTitle(this .nameCtchar.getValueAsString(0,
114: inCtic));
115: sctiic
116: .setInstanceDescription("Potential end point for a workflow-instance");
117: sctiic.setLocalInstanceIcon("stop");
118: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
119: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
120: scttic.setTypeTitle("Stop");
121: scttic
122: .setTypeDescription("Potential end point for a workflow-instance");
123: }
124: }
125:
126: public String getName() {
127: return this .nameCtchar.getValueAsString(0, null);
128: }
129:
130: public boolean isXCordValid() {
131: return isCordValid(this .xCordCtchar);
132: }
133:
134: public boolean isYCordValid() {
135: return isCordValid(this .yCordCtchar);
136: }
137:
138: private boolean isCordValid(ConceptTagCharacteristic inTc) {
139: boolean outValue = false;
140:
141: try {
142: if (inTc.getValueLength() > 0 && inTc.isStatic(0, null)) {
143: int value = Integer.parseInt(inTc.getValueAsString(0,
144: null));
145: outValue = (value > 1);
146: }
147: } catch (NumberFormatException nfe) {
148: //do nothing, return false;
149: }
150:
151: return outValue;
152: }
153:
154: public int getXCord() {
155: return Integer.parseInt(this .xCordCtchar.getValueAsString(0,
156: null));
157: }
158:
159: public int getYCord() {
160: return Integer.parseInt(this .yCordCtchar.getValueAsString(0,
161: null));
162: }
163:
164: public void setXCord(String inCord) {
165: this .xCordCtchar.addValue(0, inCord);
166: }
167:
168: public void setYCord(String inCord) {
169: this .yCordCtchar.addValue(0, inCord);
170: }
171: /*
172: public void getTagSummary(TagSummaryDescriptor tsd) {
173: //TO DO: placeholder, put meaningful description
174: if (tsd.getMimeType().equals(TagSummaryMimeType.TEXT_HTML)) {
175: tsd.appendData("<table width=\"100%\">");
176: tsd.appendData("<tr>");
177: tsd.appendData(
178: "<td width=\"30%\" style=\"font-size: 16;
179: // font-family: Arial; color: #000000;\">");
180: tsd.appendData(this.nameAttr[0]);
181: tsd.appendData("</td>");
182: tsd.appendData(
183: "<td width=\"20%\" style=\"font-size: 16;
184: // font-family: Arial; color: #000000;\">");
185: tsd.appendData("X = " + this.xCordAttr[0]);
186: tsd.appendData("</td>");
187: tsd.appendData(
188: "<td width=\"50%\" style=\"font-size: 16;
189: // font-family: Arial; color: #000000;\">");
190: tsd.appendData("Y = " + this.yCordAttr[0]);
191: tsd.appendData("</td>");
192: tsd.appendData("</tr>");
193: tsd.appendData("</table>");
194: }
195: }
196: */
197: }
|