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.web.develop.web.page;
009:
010: //base classes
011: import java.io.IOException;
012: import java.util.ArrayList;
013: import java.util.HashMap;
014:
015: //project specific classes
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.common.tagging.ConceptTagPreferences;
018: import org.jfolder.common.tagging.RootConceptTagHolder;
019: import org.jfolder.common.utils.xml.XMLHelper;
020: import org.jfolder.common.web.template.ConsoleParameterContext;
021: import org.jfolder.common.web.template.MenuBranch;
022: import org.jfolder.common.web.template.MenuLeaf;
023: import org.jfolder.common.web.template.PageSetupContext;
024: import org.jfolder.common.web.template.SubmitActionContext;
025: import org.jfolder.common.web.template.SubmitActionParameters;
026: import org.jfolder.console.base.BaseRcthStudioServlet;
027: import org.jfolder.console.base.ConsolePageContext;
028: import org.jfolder.console.base.ConsolePageParameters;
029: import org.jfolder.console.base.ConsolePageSession;
030: import org.jfolder.console.base.NamesForParentCpc;
031: import org.jfolder.console.base.StudioPageContext;
032: import org.jfolder.console.base.context.SubMessageHolderConsolePageContext;
033: import org.jfolder.console.config.ConsoleConfig;
034: import org.jfolder.console.config.ConsoleConfigTagHelper;
035:
036: //other classes
037:
038: public class DevelopWebPageContext extends StudioPageContext {
039:
040: //
041: //private final static String BUTTON__SAVE = "BUTTON__SAVE";
042: //private final static String BUTTON__CANCEL = "BUTTON__CANCEL";
043: //private final static String BUTTON__REFRESH = "BUTTON__REFRESH";
044: //
045: private final static String MENU__FILE = "MENU__FILE";
046: private final static String MENU__EDIT = "MENU__EDIT";
047: private final static String MENU__VIEW = "MENU__VIEW";
048: private final static String MENU__TOOLS = "MENU__TOOLS";
049:
050: //
051: //
052: private String studioMenuId = null;
053:
054: //
055: private DevelopWebPageContext(ConsolePageSession inCps) {
056:
057: super (inCps);
058: ConceptTagPreferences localCtp = inCps
059: .getCurrentApplicationRootHolder().getPreferences();
060: //setTreeState(ConsolePageParameters.BRANCH_SEPARATOR
061: // + localCtp.getRootHandle()
062: // + ConsolePageParameters.BRANCH_SEPARATOR);
063: setTreeState(localCtp.getRootHandle());
064: setHighlightHandle(localCtp.getRootHandle());
065: }
066:
067: public final static DevelopWebPageContext newInstance(
068: ConsolePageSession inCps) {
069:
070: DevelopWebPageContext outValue = null;
071:
072: if (inCps.isConsolePageContextPresent(NamesForParentCpc
073: .getDevelopWebPageCpcName(inCps))) {
074: //
075: Object o = inCps.getConsolePageContext(NamesForParentCpc
076: .getDevelopWebPageCpcName(inCps));
077: outValue = (DevelopWebPageContext) o;
078: } else {
079: outValue = new DevelopWebPageContext(inCps);
080: ConceptTagPreferences localCtp = inCps
081: .getCurrentApplicationRootHolder().getPreferences();
082: String rootHandle = localCtp.getRootHandle();
083: outValue.setDefaultHighlightHandle(rootHandle);
084: inCps.registerConsolePageContext(NamesForParentCpc
085: .getDevelopWebPageCpcName(inCps), outValue);
086: }
087:
088: return outValue;
089: }
090:
091: public String getFromPage() {
092: return ConsolePageParameters.SERVLET_DEVELOP_WEB_PAGE;
093: }
094:
095: protected void renderConsolePage() throws IOException {
096: //
097: ConsolePageSession localCps = getConsolePageSession();
098: PageSetupContext localPsc = getPageSetupContext();
099: localPsc.setTitle("JFolder ("
100: + localCps.getCurrentApplicationWebDocDirectory()
101: + localCps.getCurrentApplicationWebDocFile() + ")");
102: //
103: //
104: startCommonPage();
105: //
106: generateStudioUsabilityComponents();
107: //
108: if (true) {
109: int baseToggleLinkListLength = getConsolePageSession()
110: .getToggleLinkAsArrayList().size();
111: //
112: //
113: MenuBranch rootMb = MenuBranch.newInstance("Root");
114: //
115: MenuBranch fileMb = MenuBranch.newInstance("File");
116: getFileMenu(fileMb, true);
117: rootMb.add(fileMb);
118: //
119: MenuBranch editMb = MenuBranch.newInstance("Edit");
120: getEditMenu(editMb);
121: rootMb.add(editMb);
122: //
123: MenuBranch viewMb = MenuBranch.newInstance("View");
124: getViewMenu(viewMb);
125: rootMb.add(viewMb);
126: //
127: MenuBranch toolsMb = MenuBranch.newInstance("Tools");
128: getToolsMenu(toolsMb);
129: rootMb.add(toolsMb);
130: //
131: HashMap menuTableAttrs = new HashMap();
132: menuTableAttrs.put("width", "125");
133: HashMap menuTableStyles = new HashMap();
134: HashMap menuCellAttrs = new HashMap();
135: menuCellAttrs.put("width", "125");
136: HashMap menuCellStyles = new HashMap();
137: //
138: this .studioMenuId = getMenu(getConsolePageSession(),
139: MENU__TOOLS, fileMb, menuTableAttrs,
140: menuTableStyles, menuCellAttrs, menuCellStyles,
141: new Integer(15), null);
142: //getLaunchPoint(MENU__TOOLS, destinationToolsId, "Tools", true,
143: // null, null, null, null);
144: //
145: //
146: renderWebPageTagInstanceViewContext(baseToggleLinkListLength);
147: } else {
148: this .studioMenuId = null;
149: subRenderConsolePage();
150: }
151: //
152: //
153: endCommonPage();
154: }
155:
156: //
157: protected String getStudioMenuId() {
158: return this .studioMenuId;
159: }
160:
161: //
162: protected void subRenderConsolePage() throws IOException {
163:
164: //
165: //
166: //
167: ConsolePageSession localCps = getConsolePageSession();
168: //
169: RootConceptTagHolder webPageConfigRcth = localCps
170: .getConsoleConfig();
171: // ConsoleConfigTagHelper.getDefaultConsoleConfigForWebPage();
172: ConsoleConfig webPageConfig = ((ConsoleConfig) webPageConfigRcth
173: .getFirstChildConceptTag());
174: //
175: //
176: //
177: //
178: //
179: int mainWidth = (webPageConfig.getMainWidth() / getColumnWidth());
180: if (mainWidth < 4) {
181: mainWidth = 4;
182: }
183:
184: String fileName = localCps
185: .getCurrentApplicationWebDocDirectory()
186: + localCps.getCurrentApplicationWebDocFile();
187: //
188: //
189: //
190: startEnclosingTableAndRowAndCell(alignCenter(null));
191: //
192: startAndEndStretchTableAndRowAndCell("<hr/>");
193: startTable(mainWidth);
194: startRow();
195: startAndEndCell(mainWidth, fileName, alignCenter(getFontStyle(
196: 14, ARIAL, BLACK)));
197: endRow();
198: endTable();
199: //
200: //
201: SubMessageHolderConsolePageContext
202: .renderMessagesIfPresent(this );
203: //
204: startAndEndStretchTableAndRowAndCell("<hr/>");
205: //startTable(4);
206: //startRow();
207: //startCell(4, alignCenter(null));
208: //
209: //RootConceptTagHolder localRcth =
210: // getConsolePageSession().getCurrentApplicationRootHolder();
211: //String currentContent = createTextArea(
212: // "", localRcth.getXMLRepresentation(true),
213: // null, null, new Integer(5), new Integer(60), null);
214: //simpleAndPrint(currentContent);
215: //
216: //endCell();
217: //endRow();
218: //endTable();
219: ////
220: //startAndEndStretchTableAndRowAndCell("<hr/>");
221: //
222: //
223: //
224: //
225: //
226: //
227: //
228: //
229: //startEnclosingTableAndRowAndCell(alignCenter(null));
230: //
231: //
232: //
233: MenuBranch fileMenuMb = getFileMenu(null, false);
234: //
235: //
236: MenuBranch editMenuMb = getEditMenu(null);
237: //
238: //
239: MenuBranch viewMenuMb = getViewMenu(null);
240: //
241: //
242: MenuBranch toolsMenuMb = getToolsMenu(null);
243: //
244: //
245: startTable(mainWidth);
246: startRow();
247: startCell(mainWidth, alignCenter(null));
248: //
249: //
250: HashMap menuTableAttrs = new HashMap();
251: menuTableAttrs.put("width", "125");
252: HashMap menuTableStyles = new HashMap();
253: HashMap menuCellAttrs = new HashMap();
254: menuCellAttrs.put("width", "125");
255: HashMap menuCellStyles = new HashMap();
256: //
257: printAndIndent("<table cellspacing=\"0\" cellpadding=\"0\">");
258: printAndIndent("<tr>");
259: printAndIndent("<td>");
260: String destinationFileId = getMenu(getConsolePageSession(),
261: MENU__FILE, fileMenuMb, menuTableAttrs,
262: menuTableStyles, menuCellAttrs, menuCellStyles,
263: new Integer(15), null);
264: getLaunchPoint(MENU__FILE, destinationFileId, "File", true,
265: null, null, null, null);
266: revertAndPrint("</td>");
267: printAndIndent("<td>");
268: String destinationEditId = getMenu(getConsolePageSession(),
269: MENU__EDIT, editMenuMb, menuTableAttrs,
270: menuTableStyles, menuCellAttrs, menuCellStyles,
271: new Integer(15), null);
272: getLaunchPoint(MENU__EDIT, destinationEditId, "Edit", true,
273: null, null, null, null);
274: revertAndPrint("</td>");
275: printAndIndent("<td>");
276: String destinationViewId = getMenu(getConsolePageSession(),
277: MENU__VIEW, viewMenuMb, menuTableAttrs,
278: menuTableStyles, menuCellAttrs, menuCellStyles,
279: new Integer(15), null);
280: getLaunchPoint(MENU__VIEW, destinationViewId, "View", true,
281: null, null, null, null);
282: revertAndPrint("</td>");
283: printAndIndent("<td>");
284: String destinationToolsId = getMenu(getConsolePageSession(),
285: MENU__TOOLS, toolsMenuMb, menuTableAttrs,
286: menuTableStyles, menuCellAttrs, menuCellStyles,
287: new Integer(15), null);
288: getLaunchPoint(MENU__TOOLS, destinationToolsId, "Tools", true,
289: null, null, null, null);
290: revertAndPrint("</td>");
291: revertAndPrint("</tr>");
292: revertAndPrint("</table>");
293: //
294: //int localColWidth = (getColumnWidth()*4)/3;
295: //simpleAndPrint("<table align=\"center\">");
296: //simpleAndPrint("<tr>");
297: //simpleAndPrint("<td width=\"" + localColWidth
298: // + "\" align=\"center\">");
299: //createButton(BUTTON__SAVE, "Save", 75,
300: // sacSave.submitActionCall(), null, null, null, null);
301: //simpleAndPrint("</td>");
302: ////endCell();
303: ////startCell(1);
304: //simpleAndPrint("<td width=\"" + localColWidth
305: // + "\" align=\"center\">");
306: //createButton(BUTTON__CANCEL, "Cancel", 75,
307: // sacCancel.submitActionCall(), null, null, null, null);
308: //simpleAndPrint("</td>");
309: ////endCell();
310: ////startCell(1);
311: //simpleAndPrint("<td width=\"" + localColWidth
312: // + "\" align=\"center\">");
313: //createButton(BUTTON__REFRESH, "Refresh", 75,
314: // sacRefresh.submitActionCall(), null, null, null, null);
315: //simpleAndPrint("</td>");
316: //simpleAndPrint("</tr>");
317: //simpleAndPrint("</table>");
318: //
319: //
320: endCell();
321: endRow();
322: endTable();
323: //endEnclosingTableAndRowAndCell();
324: //
325: //startAndEndStretchTableAndRowAndCell("<hr/>");
326: //
327: //startTable(4);
328: //startRow();
329: //startCell(4);
330: //simpleAndPrint("Graph Buttons");
331: //endCell();
332: //endRow();
333: //endTable();
334: //
335: startAndEndStretchTableAndRowAndCell("<hr/>");
336: //
337: startEnclosingTableAndRowAndCell(null, null, alignCenter(null));
338: //
339: RenderWebPageContextHelper.renderWebPageContext(this ,
340: webPageConfig);
341: //DevelopWebPageUpDownContext.newInstance(this, "view", "other");
342: //
343: endEnclosingTableAndRowAndCell();
344: //
345: startAndEndStretchTableAndRowAndCell("<hr/>");
346: //
347: endEnclosingTableAndRowAndCell();
348: //
349:
350: }
351:
352: //////////
353: private MenuBranch getFileMenu(MenuBranch inMb, boolean inAlwaysCall) {
354:
355: MenuBranch outValue = null;
356:
357: //
358: if (inMb != null) {
359: outValue = inMb;
360: } else {
361: outValue = MenuBranch.newInstance("Root");
362: }
363: //
364: //
365: //
366: SubmitActionContext sacSave = SubmitActionContext
367: .newInstance(this );
368: sacSave.addAction(ConsoleParameterContext.FIRST_INPUT,
369: singleQuotes(SubmitActionParameters.SAVE));
370: //
371: SubmitActionContext sacCancel = SubmitActionContext
372: .newInstance(this );
373: sacCancel.addAction(ConsoleParameterContext.FIRST_INPUT,
374: singleQuotes(SubmitActionParameters.RETURN));
375: sacCancel.setGoToPage(ConsolePageParameters.SERVLET_CONSOLE);
376: //
377: //
378: MenuLeaf saveFileMenuMb = MenuLeaf.newInstance("Save",
379: submitActionCall(sacSave, inAlwaysCall));
380: outValue.add(saveFileMenuMb);
381: //
382: MenuLeaf cancelFileMenuMb = MenuLeaf.newInstance("Leave",
383: submitActionCall(sacCancel, inAlwaysCall));
384: outValue.add(cancelFileMenuMb);
385:
386: return outValue;
387: }
388:
389: //////////
390: private MenuBranch getEditMenu(MenuBranch inMb) {
391:
392: MenuBranch outValue = null;
393:
394: //
395: if (inMb != null) {
396: outValue = inMb;
397: } else {
398: outValue = MenuBranch.newInstance("Root");
399: }
400: //
401: SubmitActionContext sacRefresh = SubmitActionContext
402: .newInstance(this );
403: sacRefresh.addAction(ConsoleParameterContext.FIRST_INPUT,
404: singleQuotes(SubmitActionParameters.REFRESH));
405: MenuLeaf refreshEditMenuMb = MenuLeaf.newInstance("Refresh",
406: submitActionCall(sacRefresh));
407: outValue.add(refreshEditMenuMb);
408:
409: return outValue;
410: }
411:
412: //////////
413: private MenuBranch getViewMenu(MenuBranch inMb) {
414:
415: MenuBranch outValue = null;
416:
417: //
418: if (inMb != null) {
419: outValue = inMb;
420: } else {
421: outValue = MenuBranch.newInstance("Root");
422: }
423: //
424: RootConceptTagHolder localRcth = getConsolePageSession()
425: .getCurrentApplicationRootHolder();
426: ArrayList availablePanes = ConsoleConfigTagHelper
427: .getAvailableScreens(localRcth.getPreferences());
428:
429: //
430: RootConceptTagHolder webPageConfigRcth = getConsolePageSession()
431: .getConsoleConfig();
432: ConsoleConfig webPageConfig = ((ConsoleConfig) webPageConfigRcth
433: .getFirstChildConceptTag());
434:
435: //
436: for (int i = 0; i < webPageConfig.getLeftSectionPaneCount(); i++) {
437: String nextContext = webPageConfig
438: .getLeftSectionPaneContext(i);
439: if (availablePanes.contains(nextContext)) {
440: availablePanes.remove(nextContext);
441: }
442: }
443: //
444: for (int i = 0; i < webPageConfig.getCenterSectionPaneCount(); i++) {
445: String nextContext = webPageConfig
446: .getCenterSectionPaneContext(i);
447: if (availablePanes.contains(nextContext)) {
448: availablePanes.remove(nextContext);
449: }
450: }
451: //
452: for (int i = 0; i < webPageConfig.getRightSectionPaneCount(); i++) {
453: String nextContext = webPageConfig
454: .getRightSectionPaneContext(i);
455: if (availablePanes.contains(nextContext)) {
456: availablePanes.remove(nextContext);
457: }
458: }
459: //
460: //SubmitActionContext sacRefresh =
461: // SubmitActionContext.newInstance(this);
462: //sacRefresh.addAction(
463: // sacRefresh.FIRST_INPUT,
464: // singleQuotes(SubmitActionParameters.REFRESH));
465: //MenuLeaf refreshEditMenuMb = MenuLeaf.newInstance(
466: // "Refresh", sacRefresh.submitActionCall());
467: MenuBranch addToLeftMb = MenuBranch.newInstance("Add To Left");
468: addContextsToMenu(availablePanes, addToLeftMb,
469: BaseRcthStudioServlet.AREA__LEFT, 0);
470: //
471: MenuBranch addToCenterMb = MenuBranch
472: .newInstance("Add To Center");
473: addContextsToMenu(availablePanes, addToCenterMb,
474: BaseRcthStudioServlet.AREA__CENTER, webPageConfig
475: .getCenterSectionPaneCount());
476: //
477: MenuBranch addToRightMb = MenuBranch
478: .newInstance("Add To Right");
479: addContextsToMenu(availablePanes, addToRightMb,
480: BaseRcthStudioServlet.AREA__RIGHT, webPageConfig
481: .getRightSectionPaneCount());
482: //
483: outValue.add(addToLeftMb);
484: outValue.add(addToCenterMb);
485: outValue.add(addToRightMb);
486: //
487: //
488: //SubmitActionContext sacShowText =
489: // SubmitActionContext.newInstance(this);
490: //sacShowText.addAction(
491: // sacShowText.FIRST_INPUT,
492: // singleQuotes(SubmitActionParameters.SHOW_RCTH_TEXT));
493: //sacShowText.setTarget(sacShowText.TARGET_BLANK);
494: //MenuLeaf showTextMenuMb = MenuLeaf.newInstance(
495: // "Show Text", sacShowText.submitActionCall());
496: outValue.add(createShowMenuItem(
497: SubmitActionParameters.SHOW_RCTH_TEXT, "Show Text"));
498: //
499: //
500: //SubmitActionContext sacShowRollup =
501: // SubmitActionContext.newInstance(this);
502: //sacShowRollup.addAction(
503: // sacShowRollup.FIRST_INPUT,
504: // singleQuotes(SubmitActionParameters.SHOW_RCTH_ROLLUP));
505: //sacShowRollup.setTarget(sacShowRollup.TARGET_BLANK);
506: //MenuLeaf showRollupMenuMb = MenuLeaf.newInstance(
507: // "Show Rollup", sacShowRollup.submitActionCall());
508: //outValue.add(showRollupMenuMb);
509: outValue
510: .add(createShowMenuItem(
511: SubmitActionParameters.SHOW_RCTH_ROLLUP,
512: "Show Rollup"));
513:
514: outValue.add(createShowMenuItem(
515: SubmitActionParameters.SHOW_CONSOLE_CONFIG_RCTH_TEXT,
516: "Config Text"));
517: outValue.add(createShowMenuItem(
518: SubmitActionParameters.SHOW_CONSOLE_CONFIG_RCTH_ROLLUP,
519: "Config Rollup"));
520:
521: return outValue;
522: }
523:
524: private MenuLeaf createShowMenuItem(String inFirstAction,
525: String inLabel) {
526:
527: MenuLeaf outValue = null;
528:
529: //
530: SubmitActionContext sacShow = SubmitActionContext
531: .newInstance(this );
532: sacShow.addAction(ConsoleParameterContext.FIRST_INPUT,
533: singleQuotes(inFirstAction));
534: sacShow.setTarget(SubmitActionContext.TARGET_BLANK);
535: outValue = MenuLeaf.newInstance(inLabel,
536: submitActionCall(sacShow));
537: //
538:
539: return outValue;
540: }
541:
542: private void addContextsToMenu(ArrayList inList, MenuBranch inMb,
543: int inSection, int inIndex) {
544:
545: HashMap conToName = ConsoleConfigTagHelper
546: .getContextToNameConversion();
547:
548: for (int i = 0; i < inList.size(); i++) {
549: String nextContext = ((String) inList.get(i));
550: if (conToName.containsKey(nextContext)) {
551: String nextName = ((String) conToName.get(nextContext));
552: //
553: //
554: SubmitActionContext nextAddContextSac = createAddSac(
555: inSection, inIndex, nextContext);
556: MenuLeaf nextAddContextMb = MenuLeaf.newInstance(
557: nextName, submitActionCall(nextAddContextSac));
558: inMb.add(nextAddContextMb);
559: } else {
560: throw new UnexpectedSystemException("Context '"
561: + nextContext
562: + "' does not have a corresponding name");
563: }
564: }
565: }
566:
567: private SubmitActionContext createAddSac(int inSection,
568: int inIndex, String inContext) {
569: //
570:
571: //
572: //
573: SubmitActionContext outValue = SubmitActionContext
574: .newInstance(this );
575: //
576: outValue
577: .addAction(
578: ConsoleParameterContext.FIRST_INPUT,
579: singleQuotes(SubmitActionParameters.UPDATE_CONSOLE_CONFIG));
580: outValue.addAction(ConsoleParameterContext.SECOND_INPUT,
581: singleQuotes(SubmitActionParameters.CREATE_PANE));
582: //
583: outValue.addParameter(ConsoleParameterContext.FIRST_INPUT,
584: singleQuotes(inSection + ""));
585: outValue.addParameter(ConsoleParameterContext.SECOND_INPUT,
586: singleQuotes(inIndex + ""));
587: outValue.addParameter(ConsoleParameterContext.THIRD_INPUT,
588: singleQuotes(inContext));
589:
590: return outValue;
591: }
592:
593: //////////
594: private MenuBranch getToolsMenu(MenuBranch inMb) {
595:
596: MenuBranch outValue = null;
597:
598: //
599: if (inMb != null) {
600: outValue = inMb;
601: } else {
602: outValue = MenuBranch.newInstance("Root");
603: }
604: //
605: SubmitActionContext sacRefresh = SubmitActionContext
606: .newInstance(this );
607: sacRefresh
608: .addAction(
609: ConsoleParameterContext.FIRST_INPUT,
610: singleQuotes(SubmitActionParameters.DELETE_CONSOLE_CONFIG));
611: MenuLeaf refreshEditMenuMb = MenuLeaf.newInstance(
612: "Reset Config", submitActionCall(sacRefresh));
613: outValue.add(refreshEditMenuMb);
614:
615: return outValue;
616: }
617: }
|