1 24 package org.riotfamily.riot.list.command.core; 25 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.riotfamily.riot.editor.AbstractObjectEditorDefinition; 30 import org.riotfamily.riot.editor.EditorDefinition; 31 import org.riotfamily.riot.editor.IntermediateDefinition; 32 import org.riotfamily.riot.editor.ListDefinition; 33 import org.riotfamily.riot.editor.ui.EditorReference; 34 import org.riotfamily.riot.list.command.CommandContext; 35 import org.riotfamily.riot.list.command.CommandResult; 36 import org.riotfamily.riot.list.command.result.GotoUrlResult; 37 import org.springframework.util.Assert; 38 39 40 43 public class StepIntoCommand extends AbstractCommand { 44 45 public static final String ACTION_STEP_INTO = "stepInto"; 46 47 protected String getAction(CommandContext context) { 48 return ACTION_STEP_INTO; 49 } 50 51 protected boolean isEnabled(CommandContext context, String action) { 52 return getTargetUrl(context) != null; 53 } 54 55 public CommandResult execute(CommandContext context) { 56 return new GotoUrlResult(context, getTargetUrl(context)); 57 } 58 59 private static String getTargetUrl(CommandContext context) { 60 EditorDefinition def = context.getListDefinition().getDisplayDefinition(); 61 Assert.notNull(def, "A DisplayDefinition must be set"); 62 63 if (def instanceof IntermediateDefinition) { 64 ListDefinition listDef = ((IntermediateDefinition) def).getNestedListDefinition(); 65 return listDef.getEditorUrl(null, context.getObjectId()); 66 } 67 else { 68 Assert.isInstanceOf(AbstractObjectEditorDefinition.class, def); 69 AbstractObjectEditorDefinition displayDef = (AbstractObjectEditorDefinition) def; 70 71 List childRefs = displayDef.getChildEditorReferences( 72 context.getBean(), context.getMessageResolver()); 73 74 Iterator it = childRefs.iterator(); 75 while (it.hasNext()) { 76 EditorReference ref = (EditorReference) it.next(); 77 return ref.getEditorUrl(); 78 } 79 return null; 80 } 81 } 82 83 } 84 | Popular Tags |