1 24 package org.riotfamily.riot.list.command.core; 25 26 import org.riotfamily.riot.dao.ListParams; 27 import org.riotfamily.riot.dao.RiotDao; 28 import org.riotfamily.riot.editor.EditorDefinition; 29 import org.riotfamily.riot.editor.ListDefinition; 30 import org.riotfamily.riot.list.command.CommandContext; 31 import org.riotfamily.riot.list.command.CommandResult; 32 import org.riotfamily.riot.list.command.result.GotoUrlResult; 33 import org.riotfamily.riot.list.support.ListParamsImpl; 34 35 38 public class DescendCommand extends AbstractCommand { 39 40 public static final String ID = "descend"; 41 42 private ListDefinition nextListDefinition; 43 44 private EditorDefinition targetDefinition; 45 46 private static ListParams params = new ListParamsImpl(); 47 48 public DescendCommand(ListDefinition listDefinition, 49 EditorDefinition targetDefinition) { 50 51 this.nextListDefinition = listDefinition; 52 this.targetDefinition = targetDefinition; 53 } 54 55 public String getId() { 56 return ID; 57 } 58 59 protected boolean isEnabled(CommandContext context, String action) { 60 RiotDao dao = nextListDefinition.getListConfig().getDao(); 61 int size = dao.getListSize(context.getBean(), params); 62 if (size == -1) { 63 size = dao.list(context.getBean(), params).size(); 64 } 65 return size > 0; 66 } 67 68 public CommandResult execute(CommandContext context) { 69 return new GotoUrlResult(context, nextListDefinition.getEditorUrl( 70 null, context.getObjectId()) + "?choose=" 71 + targetDefinition.getId()); 72 } 73 } 74 | Popular Tags |