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.console.base;
009:
010: //base classes
011:
012: //project specific classes
013: import org.jfolder.common.UnexpectedSystemException;
014: import org.jfolder.common.tagging.ConceptTagCharacteristic;
015: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
016: import org.jfolder.common.tagging.ConceptTagConstraint;
017: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
018: import org.jfolder.common.tagging.ConceptTagMenuBranch;
019: import org.jfolder.common.tagging.ConceptTagMenuOption;
020: import org.jfolder.common.tagging.ConceptTagPreferences;
021: import org.jfolder.common.tagging.ConceptTagSetHolder;
022: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContextHolder;
023: import org.jfolder.common.web.template.ConsoleParameterContext;
024: import org.jfolder.common.web.template.ConsoleTemplateContext;
025: import org.jfolder.common.web.template.ConsoleTemplateFunctionsContext;
026: import org.jfolder.common.web.template.MenuBranch;
027: import org.jfolder.common.web.template.MenuLeaf;
028: import org.jfolder.common.web.template.SubmitActionContext;
029:
030: //other classes
031:
032: public class ConsolePageHelper {
033:
034: //
035: private ConsolePageHelper() {
036: }
037:
038: //
039: public final static boolean isConstraintHolderEmpty(
040: ConceptTagConstraintHolder inCtconh) {
041: //
042: boolean outValue = true;
043:
044: if (inCtconh != null) {
045: //
046: ConceptTagConstraintHolder attrsCtconh = inCtconh
047: .getAttributes();
048: outValue &= isConstraintHolderEmpty(attrsCtconh);
049: //
050: ConceptTagConstraintHolder styleCtconh = inCtconh
051: .getStyles();
052: outValue &= isConstraintHolderEmpty(styleCtconh);
053: //
054: //
055: for (int i = 0; i < inCtconh.getConstraintCount(); i++) {
056: ConceptTagConstraint nextCtcon = inCtconh
057: .getConstraint(i);
058: outValue &= isConstraintEmpty(nextCtcon);
059: }
060: //
061: outValue &= isConstraintEmpty(inCtconh
062: .getUndefinedConstraint());
063:
064: //
065: ConceptTagCharacteristicHolder ctcharh = inCtconh
066: .getCharacteristicHolder();
067: outValue &= !ctcharh.getParentMessageHolder()
068: .isErrorPresent();
069: } else {
070: outValue = true;
071: }
072:
073: return outValue;
074: }
075:
076: //
077: public final static boolean isConstraintEmpty(
078: ConceptTagConstraint inCtcon) {
079: //
080: boolean outValue = true;
081:
082: if (inCtcon != null) {
083: //
084: ConceptTagCharacteristic ctchar = inCtcon
085: .getCharacteristic();
086: //
087: //
088: if (inCtcon.getMinimumLength() > 0) {
089: outValue &= false;
090: } else if (inCtcon.getMaximumLength() > 0) {
091: outValue &= false;
092: } else if (inCtcon.isLengthUnbounded()) {
093: outValue &= false;
094: } else if (ctchar.getValueLength() > 0) {
095: outValue &= false;
096: } else {
097: //
098: }
099:
100: //
101: outValue &= !ctchar.getParentMessageHolder()
102: .isErrorPresent();
103: } else {
104: outValue = true;
105: }
106:
107: return outValue;
108: }
109:
110: //
111: //
112: //
113: //
114: //
115: //
116: //
117: //
118: //
119: //
120: //
121: //
122: //
123: //
124: public final static MenuBranch constructMenu(
125: ConceptTagConstraint inCtcon, ConceptTagMenuBranch inCtmb,
126: ConceptTagSetHolder inCtsh, String inCode, int inIndex,
127: String inAction, String inSubAction,
128: ConsoleTemplateContext inCpc) {
129:
130: MenuBranch outValue = null;
131:
132: outValue = MenuBranch.newInstance("Root");
133:
134: constructMenu(outValue, inCtcon, inCtmb, inCtsh, inCode,
135: inIndex, inAction, inSubAction, inCpc);
136:
137: return outValue;
138: }
139:
140: private final static void constructMenu(MenuBranch inMb,
141: ConceptTagConstraint inCtcon, ConceptTagMenuBranch inCtmb,
142: ConceptTagSetHolder inCtsh, String inCode, int inIndex,
143: String inFirstAction, String inSecondAction,
144: ConsoleTemplateContext inCpc) {
145:
146: for (int i = 0; i < inCtmb.getChildNodeCount(); i++) {
147: if (inCtmb.isChildNodeBranch(i)) {
148: ConceptTagMenuBranch nextCtmb = inCtmb
149: .getChildNodeAsBranch(i);
150: String branchName = nextCtmb.getName();
151: MenuBranch nextBranch = MenuBranch
152: .newInstance(branchName);
153: inMb.add(nextBranch);
154: constructMenu(nextBranch, inCtcon, nextCtmb, inCtsh,
155: inCode, inIndex, inFirstAction, inSecondAction,
156: inCpc);
157: } else if (inCtmb.isChildNodeOption(i)) {
158: ConceptTagMenuOption nextCtmo = inCtmb
159: .getChildNodeAsOption(i);
160: String leafName = getConceptTagLabel(nextCtmo
161: .getNamespace(), nextCtmo.getName(), inCtsh);
162: //String leafName = "Change This";
163:
164: SubmitActionContext sac = SubmitActionContext
165: .newInstance(inCpc);
166: initializeCreateConceptTag(sac, true, nextCtmo
167: .getNamespace(), nextCtmo.getName(),
168: inFirstAction, inSecondAction, inCode, inIndex);
169:
170: MenuLeaf nextLeaf = MenuLeaf.newInstance(leafName, sac
171: .submitActionCall(true));
172: inMb.add(nextLeaf);
173: } else {
174: UnexpectedSystemException.unknownState();
175: }
176: }
177: }
178:
179: public final static void initializeCreateConceptTag(
180: SubmitActionContext inSac, boolean inUseQuotes,
181: String inCtNs, String inCtName,
182: String inUnquotedFirstAction, String inSecondAction,
183: String inCode, int inIndex) {
184: //
185: //
186: inSac.addAction(ConsoleParameterContext.FIRST_INPUT,
187: inUnquotedFirstAction);
188: if (inSecondAction != null) {
189: inSac.addAction(ConsoleParameterContext.SECOND_INPUT,
190: ConsoleTemplateFunctionsContext.singleQuotes(
191: inSecondAction, inUseQuotes));
192: }
193: //
194: inSac.addParameter(ConsoleParameterContext.FIRST_INPUT,
195: ConsoleTemplateFunctionsContext.singleQuotes(inCode,
196: inUseQuotes));
197: inSac.addParameter(ConsoleParameterContext.SECOND_INPUT,
198: ConsoleTemplateFunctionsContext.singleQuotes(inIndex
199: + "", inUseQuotes));
200: //
201: if (inCtNs != null) {
202: inSac.addParameter(ConsoleParameterContext.THIRD_INPUT,
203: ConsoleTemplateFunctionsContext.singleQuotes(
204: inCtNs, inUseQuotes));
205: } else {
206: inSac.addParameter(ConsoleParameterContext.THIRD_INPUT,
207: ConsoleTemplateFunctionsContext.singleQuotes("",
208: inUseQuotes));
209: }
210: inSac.addParameter(ConsoleParameterContext.FOURTH_INPUT,
211: ConsoleTemplateFunctionsContext.singleQuotes(inCtName,
212: inUseQuotes));
213: }
214:
215: //protected final static String createConceptTagSac()
216:
217: private final static String getConceptTagLabel(String inNs,
218: String inN, ConceptTagSetHolder inCtsh) {
219:
220: String outValue = null;
221:
222: if (inCtsh.isConceptTagSetClassPresent(inNs, inN)) {
223: String tagClass = inCtsh.getConceptTagClassAsString(inNs,
224: inN);
225: outValue = inCtsh.getTypeTitle(tagClass);
226: } else {
227: outValue = "Unknown";
228: }
229:
230: return outValue;
231: }
232:
233: //////////////////////////////////////////////////////////////////
234: public final static MenuBranch constructMenu(
235: ConceptTagMenuBranch inCtmb, ConceptTagSetHolder inCtsh,
236: ConsoleTemplateContext inCpc, ConceptTagPreferences inCtp) {
237:
238: MenuBranch outValue = null;
239:
240: outValue = MenuBranch.newInstance("Root");
241:
242: constructMenu(outValue, inCtmb, inCtsh, inCpc, inCtp);
243:
244: return outValue;
245: }
246:
247: private final static void constructMenu(MenuBranch inMb,
248: ConceptTagMenuBranch inCtmb, ConceptTagSetHolder inCtsh,
249: ConsoleTemplateContext inCpc, ConceptTagPreferences inCtp) {
250:
251: for (int i = 0; i < inCtmb.getChildNodeCount(); i++) {
252: //
253: if (inCtmb.isChildNodeBranch(i)) {
254: //
255: ConceptTagMenuBranch nextCtmb = inCtmb
256: .getChildNodeAsBranch(i);
257: String branchName = nextCtmb.getName();
258: MenuBranch nextBranch = MenuBranch
259: .newInstance(branchName);
260: inMb.add(nextBranch);
261: constructMenu(nextBranch, nextCtmb, inCtsh, inCpc,
262: inCtp);
263: } else if (inCtmb.isChildNodeOption(i)) {
264: //
265: ConceptTagMenuOption nextCtmo = inCtmb
266: .getChildNodeAsOption(i);
267: String leafName = getConceptTagLabel(nextCtmo
268: .getNamespace(), nextCtmo.getName(), inCtsh);
269: //
270: //String leafName = "Change This";
271: //SubmitActionContext sac =
272: // SubmitActionContext.newInstance(inCpc);
273: //initializeCreateConceptTag(
274: // sac, true, nextCtmo.getNamespace(), nextCtmo.getName(),
275: // inFirstAction, inSecondAction, inCode, inIndex);
276: StudioConceptTagCreParInfoContextHolder localScpch = inCtp
277: .getCreationParameters();
278: //
279: //
280: String nextCtNs = nextCtmo.getNamespace();
281: String nextCtName = nextCtmo.getName();
282: //
283: int nextScpchIndex = -1;
284:
285: if (localScpch.isConstraintHeirarchyPresent(nextCtNs,
286: nextCtName, new String[0])) {
287: //
288: nextScpchIndex = localScpch.getIndex(nextCtNs,
289: nextCtName, new String[0]);
290: }
291:
292: MenuLeaf nextLeaf = null;
293:
294: if (nextCtNs != null) {
295: nextLeaf = MenuLeaf.newInstance(leafName,
296: "studioSelectConceptTag('" + nextCtNs
297: + "', '" + nextCtName + "', "
298: + nextScpchIndex + ")");
299: } else {
300: nextLeaf = MenuLeaf.newInstance(leafName,
301: "studioSelectConceptTag(null, '"
302: + nextCtName + "', "
303: + nextScpchIndex + ")");
304: }
305: //sac.submitActionCall());
306: inMb.add(nextLeaf);
307: } else {
308: UnexpectedSystemException.unknownState();
309: }
310: }
311: }
312: }
|