1 24 package org.riotfamily.riot.editor; 25 26 import java.util.LinkedList ; 27 import java.util.List ; 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 36 public class GroupDefinition extends AbstractEditorDefinition { 37 38 protected static final String TYPE_GROUP = "group"; 39 40 private List editorDefinitions; 41 42 43 public GroupDefinition(EditorRepository editorRepository) { 44 setEditorRepository(editorRepository); 45 } 46 47 public String getEditorType() { 48 return TYPE_GROUP; 49 } 50 51 public List getEditorDefinitions() { 52 return editorDefinitions; 53 } 54 55 public void setEditorDefinitions(List editorDefinitions) { 56 this.editorDefinitions = editorDefinitions; 57 } 58 59 public void addEditorDefinition(EditorDefinition editorDefinition) { 60 if (editorDefinitions == null) { 61 editorDefinitions = new LinkedList (); 62 } 63 editorDefinitions.add(editorDefinition); 64 editorDefinition.setParentEditorDefinition(this); 65 } 66 67 public EditorReference createEditorPath(String objectId, String 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 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 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 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 getEditorUrl(String objectId, String parentId) { 122 StringBuffer sb = new StringBuffer (); 123 sb.append(getEditorRepository().getRiotServletPrefix()); 124 sb.append("/group/").append(getId()); 125 return sb.toString(); 126 } 127 } 128 | Popular Tags |