KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > editor > ListDefinition


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.editor;
25
26 import org.riotfamily.common.i18n.MessageResolver;
27 import org.riotfamily.common.util.FormatUtils;
28 import org.riotfamily.riot.editor.ui.EditorReference;
29 import org.riotfamily.riot.list.ListConfig;
30 import org.springframework.util.Assert;
31
32 /**
33  *
34  */

35 public class ListDefinition extends AbstractEditorDefinition {
36
37     protected static final String JavaDoc TYPE_LIST = "list";
38
39     private EditorDefinition displayDefinition;
40
41     private String JavaDoc listId;
42
43     public ListDefinition(EditorRepository repository) {
44         setEditorRepository(repository);
45     }
46
47     public ListDefinition(ListDefinition prototype,
48             EditorRepository repository) {
49
50         this(repository);
51         displayDefinition = prototype.getDisplayDefinition();
52         listId = prototype.getListId();
53         setId(prototype.getId());
54     }
55     
56     public String JavaDoc getEditorType() {
57         return TYPE_LIST;
58     }
59
60     public String JavaDoc getListId() {
61         return listId;
62     }
63
64     protected String JavaDoc getDefaultName() {
65         return getListId();
66     }
67
68     public void setListId(String JavaDoc listId) {
69         this.listId = listId;
70         Assert.notNull(getListConfig(), "No such list: " + listId);
71     }
72
73     public Class JavaDoc getBeanClass() {
74         return getListConfig().getItemClass();
75     }
76
77     public EditorDefinition getDisplayDefinition() {
78         return displayDefinition;
79     }
80
81     public void setDisplayDefinition(EditorDefinition editorDef) {
82         this.displayDefinition = editorDef;
83     }
84
85     public EditorReference createEditorPath(String JavaDoc objectId, String JavaDoc parentId,
86             MessageResolver messageResolver) {
87
88         EditorReference parent = null;
89         if (getParentEditorDefinition() != null) {
90             // Delegate call to parent editor passing the parentId as objectId
91
parent = getParentEditorDefinition().createEditorPath(
92                     parentId, null, messageResolver);
93         }
94
95         EditorReference component = createReference(parentId, messageResolver);
96
97         component.setParent(parent);
98         return component;
99     }
100
101     public EditorReference createEditorPath(Object JavaDoc bean,
102             MessageResolver messageResolver) {
103
104         EditorReference component = null;
105         EditorReference parent = null;
106
107         if (getParentEditorDefinition() != null) {
108             parent = getParentEditorDefinition().createEditorPath(bean, messageResolver);
109             component = createReference(parent.getObjectId(), messageResolver);
110             component.setParent(parent);
111         }
112         else {
113             component = createReference(null, messageResolver);
114             if (getParentEditorDefinition() != null) {
115                 parent = getParentEditorDefinition().createEditorPath(
116                         null, null, messageResolver);
117
118                 component.setParent(parent);
119             }
120         }
121         return component;
122     }
123
124     /**
125      * Creates a reference to the list. The method is used by the {@link
126      * org.riotfamily.riot.form.ui.FormController FormController} to create
127      * links pointing to the child lists.
128      */

129     public EditorReference createReference(String JavaDoc parentId,
130             MessageResolver messageResolver) {
131
132         EditorReference ref = new EditorReference();
133         ref.setEditorType(getEditorType());
134         ref.setIcon(getIcon());
135
136         String JavaDoc defaultLabel = FormatUtils.camelToTitleCase(getListId());
137         ref.setLabel(messageResolver.getMessage(
138                 getMessageKey().toString(), null, defaultLabel));
139
140         ref.setDescription(messageResolver.getMessage(
141                 getMessageKey().append(".description").toString(), null, null));
142
143         ref.setEditorUrl(getEditorUrl(null, parentId));
144         return ref;
145     }
146
147     public ListConfig getListConfig() {
148         return getEditorRepository().getListRepository().getListConfig(listId);
149     }
150
151     public String JavaDoc getEditorUrl(String JavaDoc objectId, String JavaDoc parentId) {
152         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
153         sb.append(getEditorRepository().getRiotServletPrefix());
154         sb.append("/list/").append(getId());
155         if (parentId != null) {
156             sb.append('/').append(parentId);
157         }
158         return sb.toString();
159     }
160
161 }
162
Popular Tags