001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2006
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.riot.editor;
025:
026: import java.util.LinkedList;
027: import java.util.List;
028:
029: import org.riotfamily.common.i18n.MessageResolver;
030: import org.riotfamily.common.util.FormatUtils;
031: import org.riotfamily.riot.editor.ui.EditorReference;
032:
033: /**
034: *
035: */
036: public class GroupDefinition extends AbstractEditorDefinition {
037:
038: protected static final String TYPE_GROUP = "group";
039:
040: private List editorDefinitions;
041:
042: public GroupDefinition(EditorRepository editorRepository) {
043: setEditorRepository(editorRepository);
044: }
045:
046: public String getEditorType() {
047: return TYPE_GROUP;
048: }
049:
050: public List getEditorDefinitions() {
051: return editorDefinitions;
052: }
053:
054: public void setEditorDefinitions(List editorDefinitions) {
055: this .editorDefinitions = editorDefinitions;
056: }
057:
058: public void addEditorDefinition(EditorDefinition editorDefinition) {
059: if (editorDefinitions == null) {
060: editorDefinitions = new LinkedList();
061: }
062: editorDefinitions.add(editorDefinition);
063: editorDefinition.setParentEditorDefinition(this );
064: }
065:
066: public EditorReference createEditorPath(String objectId,
067: String parentId, MessageResolver messageResolver) {
068:
069: EditorReference parent = null;
070: if (getParentEditorDefinition() != null) {
071: parent = getParentEditorDefinition().createEditorPath(
072: parentId, null, messageResolver);
073: }
074: EditorReference component = createReference(messageResolver);
075:
076: component.setParent(parent);
077: return component;
078: }
079:
080: public EditorReference createEditorPath(Object bean,
081: MessageResolver messageResolver) {
082:
083: EditorReference component = null;
084: EditorReference parent = null;
085: if (getParentEditorDefinition() != null) {
086: parent = getParentEditorDefinition().createEditorPath(bean,
087: messageResolver);
088:
089: component = createReference(messageResolver);
090: component.setParent(parent);
091: } else {
092: component = createReference(messageResolver);
093: }
094: return component;
095: }
096:
097: public EditorReference createReference(String parentId,
098: MessageResolver messageResolver) {
099:
100: return createReference(messageResolver);
101: }
102:
103: private EditorReference createReference(
104: MessageResolver messageResolver) {
105: EditorReference ref = new EditorReference();
106: ref.setEditorType(TYPE_GROUP);
107: ref.setIcon(getIcon());
108:
109: String defaultLabel = FormatUtils.xmlToTitleCase(getId());
110: ref.setLabel(messageResolver.getMessage(getMessageKey()
111: .toString(), null, defaultLabel));
112:
113: ref.setDescription(messageResolver.getMessage(getMessageKey()
114: .append(".description").toString(), null, null));
115:
116: ref.setEditorUrl(getEditorUrl(null, null));
117: return ref;
118: }
119:
120: public String getEditorUrl(String objectId, String parentId) {
121: StringBuffer sb = new StringBuffer();
122: sb.append(getEditorRepository().getRiotServletPrefix());
123: sb.append("/group/").append(getId());
124: return sb.toString();
125: }
126: }
|