KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.LinkedList JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.riotfamily.common.i18n.MessageResolver;
30 import org.riotfamily.common.util.FormatUtils;
31 import org.riotfamily.riot.editor.ui.EditorReference;
32
33 /**
34  *
35  */

36 public class GroupDefinition extends AbstractEditorDefinition {
37
38     protected static final String JavaDoc TYPE_GROUP = "group";
39
40     private List JavaDoc editorDefinitions;
41
42     
43     public GroupDefinition(EditorRepository editorRepository) {
44         setEditorRepository(editorRepository);
45     }
46     
47     public String JavaDoc getEditorType() {
48         return TYPE_GROUP;
49     }
50     
51     public List JavaDoc getEditorDefinitions() {
52         return editorDefinitions;
53     }
54
55     public void setEditorDefinitions(List JavaDoc editorDefinitions) {
56         this.editorDefinitions = editorDefinitions;
57     }
58
59     public void addEditorDefinition(EditorDefinition editorDefinition) {
60         if (editorDefinitions == null) {
61             editorDefinitions = new LinkedList JavaDoc();
62         }
63         editorDefinitions.add(editorDefinition);
64         editorDefinition.setParentEditorDefinition(this);
65     }
66
67     public EditorReference createEditorPath(String JavaDoc objectId, String JavaDoc parentId,
68             MessageResolver messageResolver) {
69
70         EditorReference parent = null;
71         if (getParentEditorDefinition() != null) {
72             parent = getParentEditorDefinition().createEditorPath(
73                     parentId, null, messageResolver);
74         }
75         EditorReference component = createReference(messageResolver);
76
77         component.setParent(parent);
78         return component;
79     }
80
81     public EditorReference createEditorPath(Object JavaDoc bean,
82             MessageResolver messageResolver) {
83
84         EditorReference component = null;
85         EditorReference parent = null;
86         if (getParentEditorDefinition() != null) {
87             parent = getParentEditorDefinition().createEditorPath(
88                     bean, messageResolver);
89
90             component = createReference(messageResolver);
91             component.setParent(parent);
92         }
93         else {
94             component = createReference(messageResolver);
95         }
96         return component;
97     }
98
99     public EditorReference createReference(String JavaDoc parentId,
100             MessageResolver messageResolver) {
101
102         return createReference(messageResolver);
103     }
104
105     private EditorReference createReference(MessageResolver messageResolver) {
106         EditorReference ref = new EditorReference();
107         ref.setEditorType(TYPE_GROUP);
108         ref.setIcon(getIcon());
109
110         String JavaDoc defaultLabel = FormatUtils.camelToTitleCase(getId());
111         ref.setLabel(messageResolver.getMessage(getMessageKey().toString(),
112                 null, defaultLabel));
113
114         ref.setDescription(messageResolver.getMessage(
115                 getMessageKey().append(".description").toString(), null, null));
116
117         ref.setEditorUrl(getEditorUrl(null, null));
118         return ref;
119     }
120
121     public String JavaDoc getEditorUrl(String JavaDoc objectId, String JavaDoc parentId) {
122         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
123         sb.append(getEditorRepository().getRiotServletPrefix());
124         sb.append("/group/").append(getId());
125         return sb.toString();
126     }
127 }
128
Popular Tags