protected String generateGetElementTreeNodeId(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("");
    buf.putLine4("");
    buf.putLine4("<!--");
    buf.putLine4("  ** get" + elementClassName + "TreeNodeId()");
    buf.putLine4("  ** Returns the node ID of the selected node.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function get" + elementClassName + "TreeNodeId() {");
    buf.putLine4("	if (" + elementNameUncapped + "TreeState != null)");
    buf.putLine4("		return " + elementNameUncapped + "TreeState.nodeId;");
    buf.putLine4("	return null;");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessEditElement(Element element) {
    // String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);
    // String targetNameUncapped = NameUtil.uncapName(targetName);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** processEditElement(event, type, action)");
    buf.putLine4("  ** Opens Element 'type' record for editing.");
    buf.putLine4("  ** Goes to Element 'type' Wizard page.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function processEditElement(event, type, action) {");
    buf.putLine4("	if (action == null)");
    buf.putLine4("		action = 'workspaceManager.editObject';");
    buf.putLine4("	try {");
    buf.putLine4("		setCursorWait(event.target);");
    buf.putLine4("		setCursorWait(event.currentTarget);");
    buf.putLine4("		setCursorWait(#{rich:element('" + elementNameUncapped + "Tree')});");
    buf.putLine4("		if (" + elementNameUncapped + "TreeState.nodeLabel != null) {");
    buf.putLine4("			var label = " + elementNameUncapped + "TreeState.nodeLabel;");
    buf.putLine4(
        "			showProgress('Nam', type+' Records', 'Preparing \\\"'+label+'\\\" '+type+' for editing...');");
    buf.putLine4(
        "		} else showProgress('Nam', type+' Records', 'Preparing '+type+' for editing...');");
    buf.putLine4("		executeActionForElement(type, action);");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessViewElement(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** processViewElement(event, type, action)");
    buf.putLine4("  ** Opens selected Element record.  ");
    buf.putLine4("  ** Goes to the Element summary page.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function processViewElement(event, type, action) {");
    buf.putLine4("	if (action == null)");
    buf.putLine4("		action = 'workspaceManager.viewObject';");
    buf.putLine4("	try {");
    buf.putLine4("		setCursorWait(event.target);");
    buf.putLine4("		setCursorWait(event.currentTarget);");
    buf.putLine4("		setCursorWait(#{rich:element('applicationTree')});");
    buf.putLine4("		showProgress('Nam', type+' Records', 'Opening '+type+' for viewing...');");
    buf.putLine4("		executeActionForElement(type, action);");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }
  // NOT_USED
  protected String generateProcessElementNodeDoubleClick(Element element, String targetName) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);
    String targetNameUncapped = NameUtil.uncapName(targetName);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** process" + targetName + "NodeDoubleClick(event, rowKey, nodeId)");
    buf.putLine4("  ** Handles double-click event on a " + targetName + " Node.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function process" + targetName + "NodeDoubleClick(event, rowKey, nodeId) {");
    buf.putLine4("	try {");
    buf.putLine4("		//show(event.currentTarget);");
    buf.putLine4("		setCursorWait(event.target);");
    buf.putLine4("		setCursorWait(event.currentTarget);");
    buf.putLine4("		setCursorWait(#{rich:element('" + elementNameUncapped + "Tree')});");
    // buf.putLine4("		//show"+elementClassName+"Page(source, 'Identification');");
    buf.putLine4(
        "		showProgress('Nam', '"
            + targetName
            + " #{"
            + targetNameUncapped
            + "InfoManager.selected"
            + targetName
            + ".name}', 'Preparing "
            + targetName
            + " \"summary\" view...');");
    // buf.putLine4("		//showPage(source,
    // '"+elementPath+"/application/application.seam?section='+section);");
    buf.putLine4("		view" + targetName + "('Overview', rowKey, nodeId);");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessElementTreeDoubleClick(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4(
        "  ** process"
            + elementClassName
            + "TreeDoubleClick(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel)");
    buf.putLine4("  ** Handles double-click event on the " + elementClassName + " Tree.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4(
        "function process"
            + elementClassName
            + "TreeDoubleClick(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel) {");
    buf.putLine4(
        "	update"
            + elementClassName
            + "TreeState(null, rowKey, nodeId, nodeArea, nodeType, nodeLabel);");
    buf.putLine4("	enable" + elementClassName + "TreeActions(nodeArea);");
    buf.putLine4("	");
    buf.putLine4("	try {");
    // buf.putLine4("		//show(event.currentTarget);");
    buf.putLine4("		setCursorWait(event.target);");
    buf.putLine4("		setCursorWait(event.currentTarget);");
    buf.putLine4("		setCursorWait(#{rich:element('applicationTree')});");
    buf.putLine4(
        "		showProgress('Nam', nodeType+' '+nodeLabel, 'Preparing '+nodeType+' summary view...');");
    buf.putLine4(
        "		executeActionForApplicationTreeViewer(rowKey, nodeId, nodeArea, nodeType, 'workspaceManager.viewObject');");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    // buf.putLine4("	if (nodeType == 'Project') {");
    // buf.putLine4("		processProjectNodeDoubleClick(event, rowKey, nodeId);");
    // buf.putLine4("	} else if (nodeType == 'Application') {");
    // buf.putLine4("		processApplicationNodeDoubleClick(event, rowKey, nodeId);");
    // buf.putLine4("	} else if (nodeType.endsWith('MODULE')) {");
    // buf.putLine4("		processModuleNodeDoubleClick(event, rowKey, nodeId);");
    // buf.putLine4("	} else {");
    // buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateShowElementNodeMenu(Element element, String targetName) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);
    String targetNameUncapped = NameUtil.uncapName(targetName);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** show" + targetName + "TreeNodeMenu(event, nodeType)");
    buf.putLine4("  ** Displays context-menu for " + targetName + " Tree node..");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function show" + targetName + "TreeNodeMenu(event, nodeType) {");
    buf.putLine4("	var typeUncapped = uncapitalize(nodeType);");
    buf.putLine4("	var menuName = mainFormId + ':' + typeUncapped + 'TreeMenu';");
    buf.putLine4("	var menu = RichFaces.component(menuName);");
    buf.putLine4("	if (menu != null) {");
    buf.putLine4("		menu.show(event, {});");
    buf.putLine4("	}");

    // buf.putLine4("	//alert("+elementNameUncapped+"TreeState.nodeLabel)");
    // buf.putLine4("	//TODO This currently has no effect, we are waiting for when it will work");
    // buf.putLine4("	var menu = #{rich:component('"+targetNameUncapped+"TreeMenu')};");
    // buf.putLine4("	menu.show(event, {});");
    // buf.putLine4("	menu.show(event, {");
    // buf.putLine4("		'projectName': 'project1',");
    // buf.putLine4("		'canAdd': 'false'");
    // buf.putLine4("	});");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessElementTreeMouseDown(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4(
        "  ** process"
            + elementClassName
            + "TreeMouseDown(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel)");
    buf.putLine4("  ** Handles mouseDown event on the " + elementClassName + " Tree.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4(
        "function process"
            + elementClassName
            + "TreeMouseDown(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel) {");
    buf.putLine4(
        "	update"
            + elementClassName
            + "TreeState(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel);");
    buf.putLine4("	enable" + elementClassName + "TreeActions(nodeArea);");
    buf.putLine4("	try {");
    buf.putLine4("		executeSelectFrom" + elementClassName + "Tree(rowKey, nodeId);");
    buf.putLine4("		if (event.which == 3) {");

    //		List<String> subTypes = element.getSubTypes();
    //		Iterator<String> iterator = subTypes.iterator();
    //		for (int i=0; iterator.hasNext(); i++) {
    //			String subType = iterator.next();
    //			if (i == 0) {
    //				buf.putLine4("			if (nodeType == '"+subType+"') {");
    //				buf.putLine4("			} else if (nodeType == '"+subType+"') {");
    //				buf.putLine4("				show"+subType+"NodeMenu(event);");
    //		}

    buf.putLine4("			show" + elementClassName + "TreeNodeMenu(event, nodeType);");
    buf.putLine4("		}");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateEnableElementTreeActions(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** enable" + elementClassName + "TreeActions(type)");
    buf.putLine4(
        "  ** Enables (or disables) "
            + elementClassName
            + " Tree actions based on current client-side state.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function enable" + elementClassName + "TreeActions(type) {");
    buf.putLine4("	enableButton(\'" + elementNameUncapped + "TreeViewButton\');");
    buf.putLine4("	enableButton(\'" + elementNameUncapped + "TreeNewButton\');");
    buf.putLine4("	enableButton(\'" + elementNameUncapped + "TreeEditButton\');");
    buf.putLine4("	enableButton(\'" + elementNameUncapped + "TreeMoveButton\');");
    buf.putLine4("	enableButton(\'" + elementNameUncapped + "TreeRemoveButton\');");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateUpdateElementTreeState(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4(
        "  ** update"
            + elementClassName
            + "TreeState(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel)");
    buf.putLine4("  ** Updates client-side state information for " + elementClassName + " Tree.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4(
        "function update"
            + elementClassName
            + "TreeState(event, rowKey, nodeId, nodeArea, nodeType, nodeLabel) {");
    buf.putLine4("	" + elementNameUncapped + "TreeState = new Object();");
    buf.putLine4("	" + elementNameUncapped + "TreeState.rowKey = rowKey;");
    buf.putLine4("	" + elementNameUncapped + "TreeState.nodeId = nodeId;");
    buf.putLine4("	" + elementNameUncapped + "TreeState.nodeArea = nodeArea;");
    buf.putLine4("	" + elementNameUncapped + "TreeState.nodeType = nodeType;");
    buf.putLine4("	" + elementNameUncapped + "TreeState.nodeLabel = nodeLabel;");
    buf.putLine4("	" + elementNameUncapped + "TreeState.nodeKey = nodeId;");
    buf.putLine4("	//show(" + elementNameUncapped + "TreeState);");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateInitializeElementTreeState(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** initialize" + elementClassName + "TreeState()");
    buf.putLine4("  ** Initializes and verifies " + elementClassName + " Tree state information.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function initialize" + elementClassName + "TreeState() {");
    buf.putLine4("	try {");
    buf.putLine4(
        "		var selectedNodeId = \'#{" + elementNameUncapped + "TreeManager.selectedNodeId}\';");
    buf.putLine4(
        "		var selectedRowKey = \'#{" + elementNameUncapped + "TreeManager.selectedRowKey}\';");
    buf.putLine4("		");
    buf.putLine4("		if (selectedNodeId != '') {");
    buf.putLine4("			" + elementNameUncapped + "TreeState = new Object();");
    buf.putLine4("			var nodeId = selectedNodeId;");
    buf.putLine4("			var rowKey = selectedRowKey;");
    buf.putLine4(
        "			var nodeArea = \'#{" + elementNameUncapped + "TreeManager.selectedNode.area}\';");
    buf.putLine4(
        "			var nodeType = \'#{" + elementNameUncapped + "TreeManager.selectedNode.type}\';");
    buf.putLine4(
        "			var nodeLabel = \'#{" + elementNameUncapped + "TreeManager.selectedNode.label}\';");
    buf.putLine4(
        "			update"
            + elementClassName
            + "TreeState(null, rowKey, nodeId, nodeArea, nodeType, nodeLabel);");
    buf.putLine4("		}");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessCancelElement(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** processCancel" + elementClassName + "(event)");
    buf.putLine4("  ** Cancels " + elementClassName + " editing.  Return to previous state.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function processRemove" + elementClassName + "() {");
    buf.putLine4("	setCursorWait(event.target);");
    buf.putLine4("	setCursorWait(event.currentTarget);");
    buf.putLine4("	var typeUncapped = type.toLowerCase();");
    buf.putLine4("	var nodeLabel = get" + elementClassName + "TreeNodeLabel();");
    buf.putLine4("	var warningTitle = 'Remove \"' + nodeLabel + '\" '+type+' from system';");
    buf.putLine4("	var removeEvent = typeUncapped + 'EventManager.remove' + type;");
    buf.putLine4("	//var removeEvent = typeUncapped+'EventManager.fireRemoveEvent';");
    buf.putLine4("	//var removeEvent = 'nam.model.'+typeUncapped+'.'+type+'RemoveEvent';");
    buf.putLine4(
        "	popupWarningPrompt('Nam', warningTitle, 'Do you wish to continue?', removeEvent, '"
            + elementNameUncapped
            + "Tree');");
    buf.putLine4("	setCursorDefault();");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessRemoveElement(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** processRemoveElement(event, type, action)");
    buf.putLine4("  ** Prompts user to remove selected Element 'type' record.");
    buf.putLine4("  ** Removes Element 'type' record from system.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function processRemoveElement(event, type, action) {");
    buf.putLine4("	var typeUncapped = uncapitalize(type);");
    buf.putLine4("	var label = type;");
    buf.putLine4("	if (" + elementNameUncapped + "TreeState != null)");
    buf.putLine4("		label = " + elementNameUncapped + "TreeState.nodeLabel + ' ' + type;");
    buf.putLine4("	var warningTitle = 'Remove \\\"'+label+'\\\" from system';");
    buf.putLine4("	if (action == null)");
    buf.putLine4("		action = typeUncapped + 'EventManager.remove' + type;");
    // buf.putLine4("	//var removeEvent = typeUncapped+'EventManager.fireRemoveEvent';");
    // buf.putLine4("	//var removeEvent = 'nam.model.'+typeUncapped+'.'+type+'RemoveEvent';");
    buf.putLine4(
        "	popupWarningPrompt('Nam', warningTitle, 'Do you wish to continue?', action, '"
            + elementNameUncapped
            + "Tree, "
            + elementNameUncapped
            + "TreeViewer');");
    buf.putLine4("	setCursorDefault();");
    buf.putLine4("}");
    return buf.get();
  }
  protected String generateProcessSaveElement(Element element) {
    String elementClassName = ModelLayerHelper.getElementClassName(element);
    String elementNameUncapped = ModelLayerHelper.getElementNameUncapped(element);

    Buf buf = new Buf();
    buf.putLine4("	");
    buf.putLine4("	");
    buf.putLine4("<!--");
    buf.putLine4("  ** processSaveElement(event, type, action)");
    buf.putLine4("  ** Saves selected Element 'type' record to server-side storage.");
    buf.putLine4("  -->");
    buf.putLine4("	");
    buf.putLine4("function processSaveElement(event, type, action) {");
    buf.putLine4("	try {");
    buf.putLine4("		setCursorWait(event.target);");
    buf.putLine4("		setCursorWait(event.currentTarget);");
    buf.putLine4("		setCursorWait(#{rich:element('" + elementNameUncapped + "Tree')});");
    buf.putLine4("		showProgress('Nam', type+' Records', 'Saving Element '+type+'...');");
    buf.putLine4("		saveElement(type, action);");
    buf.putLine4("	} catch(e) {");
    buf.putLine4("		alert(e);");
    buf.putLine4("	}");
    buf.putLine4("}");
    return buf.get();
  }