KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > command > core > StepIntoCommand


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.list.command.core;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
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 /**
41  *
42  */

43 public class StepIntoCommand extends AbstractCommand {
44
45     public static final String JavaDoc ACTION_STEP_INTO = "stepInto";
46
47     protected String JavaDoc getAction(CommandContext context) {
48         return ACTION_STEP_INTO;
49     }
50
51     protected boolean isEnabled(CommandContext context, String JavaDoc 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 JavaDoc 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 JavaDoc childRefs = displayDef.getChildEditorReferences(
72                     context.getBean(), context.getMessageResolver());
73
74             Iterator JavaDoc 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