## ============================================================================ ## Filename : WebShowSearchCmdTemplate.vm ## Note(s) : This template is used to generate a ShowSearchScreenCommand Java class. ## ## Note: The generated code is dependent on the ThinkUI framework. ## Please refer to the SQL Client documentation for details. ## ## Copyright (c) 2007 ThinkUI Software Inc. All rights reserved. ## ============================================================================ ## ## **************************************************************************** ## The following variables are available in this template. For more ## information on any of the following variable, please refer to the user guide. ## **************************************************************************** ## $projectName ## $authorName ## $headerText ## $objectName ## $objectVar ## $objectCaption ## $className ## $packageName ## $prjPkgName ## $prjClassPrefix ## $superClassName ## $date ## $fkRelationships ## $codeGen ## #if ($packageName) package $packageName; #end #parse( "ClassHeaderInclude.vm" ) import java.util.Iterator; import thinkui.command.Command; import thinkui.command.CommandContext; import thinkui.common.SearchResultsData; import thinkui.${prjPkgName}.criteria.${objectName}SearchData; import thinkui.${prjPkgName}.objects.${objectName}; import thinkui.${prjPkgName}.web.${prjClassPrefix}SessionManager; import thinkui.${prjPkgName}.web.handlers.${objectName}MultiSelectionHandler; import thinkui.${prjPkgName}.web.screens.Search${objectName}Screen; import thinkui.web.AbstractSearchCommand; import thinkui.web.${superClassName}; import thinkui.web.JSPAction; import thinkui.web.JSPScreen; import thinkui.web.WebCommandContext; /** * Implements a command to show the screen for searching ${objectName} objects. */ public class ${className} extends ${superClassName} { /** * ${className} constructor. */ public ${className}() { super(); } protected final void createActions( WebCommandContext ctx, JSPScreen screen, SearchResultsData results) throws Exception { // Get the previous command (if any) and determine what actions are // available based on it. String previousCmd = getPreviousCommand(); // Create the default actions. Search${objectName}Command searchCmd = new Search${objectName}Command(); searchCmd.setPreviousCommand(this.getName()); searchCmd.setClearSearchCriteria(false); New${objectName}Command addCmd = new New${objectName}Command(); addCmd.setPreviousCommand("search"); ${className} clearCmd = new ${className}(); clearCmd.setClearSearchCriteria(true); Command cancelCmd; /* TODO -- Uncomment if applicable, otherwise remove generated code. /*if ("".equals(previousCmd)) { cancelCmd = new SearchCommand(); } else { cancelCmd = new ShowHomeCommand(); } cancelCmd.copyFrom(this);*/ cancelCmd = new ShowHomeCommand(); screen.setDefaultCommand(searchCmd); screen.addAction(new JSPAction("search${objectName}", "Search", searchCmd)); screen.addAction( new JSPAction("resetForm", " Reset ", JSPAction.RESET)); screen.addAction(new JSPAction("clearCriteria", "Clear", clearCmd)); screen.addAction(new JSPAction("new${objectName}", "New ${objectCaption}", addCmd)); screen.addAction(new JSPAction("cancelSearch", "Cancel", cancelCmd)); // Create custom actions. if (results != null && results.hasObjects()) { int index = 0; for (Iterator iter = results.getObjects().iterator(); iter.hasNext(); index++) { ${objectName} ${objectVar} = (${objectName}) iter.next(); ShowView${objectName}Command viewCmd = new ShowView${objectName}Command(); Object ${objectVar}Id = ${objectVar}.getValue(${objectName}.ID); viewCmd.setValue(ShowView${objectName}Command.ID, ${objectVar}Id); viewCmd.setPreviousCommand("search"); JSPAction viewAction = new JSPAction( "view${objectName}" + index, String.valueOf(${objectVar}Id), viewCmd); screen.addCustomAction(viewAction); } Delete${objectName}Command deleteCmd = new Delete${objectName}Command(); deleteCmd.setSelectionHandler( ${objectName}MultiSelectionHandler.${objectName.toUpperCase()}_SELECTION); JSPAction deleteAction = new JSPAction("delete", "Delete", deleteCmd); deleteAction.setConfirmRequired(true); deleteAction.setDescription("delete the selected ${objectCaption.toLowerCase()}s"); screen.addCustomAction(deleteAction); // Create the previous/next navigation actions. createNavigationActions(ctx, screen, results); } } public final Object execute(CommandContext commandContext) throws Exception { WebCommandContext ctx = (WebCommandContext) commandContext; ${prjClassPrefix}SessionManager sessionMgr = new ${prjClassPrefix}SessionManager(ctx); Search${objectName}Command searchCmd = (Search${objectName}Command) getSearchCommand(ctx); ${objectName}SearchData criteria = null; if (!isClearSearchCriteria()) { criteria = sessionMgr.get${objectName}SearchData(); } if (criteria == null) { criteria = (${objectName}SearchData) searchCmd.createSearchDataCriteria(ctx); sessionMgr.set${objectName}SearchData(criteria); } // Register dynamic attribute types with the command context. /* TODO -- Uncomment if applicable, otherwise remove generated code. #foreach( $relationship in $fkRelationships ) ctx.overrideAttribute( criteria, ${objectName}SearchData.${codeGen.toString($relationship.getFromAttrNames(), null, null, "_")}, sessionMgr.create${codeGen.toClassName($relationship.getToDataClassName())}EnumType()); ctx.overrideAttribute( ${objectName}.DATA_CLASS, ${objectName}.${codeGen.toString($relationship.getFromAttrNames(), null, null, "_")}, sessionMgr.create${codeGen.toClassName($relationship.getToDataClassName())}EnumType()); #end */ // Display the search results (if any). SearchResultsData results = searchCmd.getSearchDataResults(ctx); JSPScreen screen = new Search${objectName}Screen(); screen.setObject("criteria", criteria); screen.setResults("results", results); // Create the actions available in this screen createActions(ctx, screen, results); return screen; } protected final AbstractSearchCommand getSearchCommand(WebCommandContext ctx) { return new Search${objectName}Command(); } }