1 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 35 public class ListDefinition extends AbstractEditorDefinition { 36 37 protected static final String TYPE_LIST = "list"; 38 39 private EditorDefinition displayDefinition; 40 41 private String 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 getEditorType() { 57 return TYPE_LIST; 58 } 59 60 public String getListId() { 61 return listId; 62 } 63 64 protected String getDefaultName() { 65 return getListId(); 66 } 67 68 public void setListId(String listId) { 69 this.listId = listId; 70 Assert.notNull(getListConfig(), "No such list: " + listId); 71 } 72 73 public Class 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 objectId, String parentId, 86 MessageResolver messageResolver) { 87 88 EditorReference parent = null; 89 if (getParentEditorDefinition() != null) { 90 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 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 129 public EditorReference createReference(String parentId, 130 MessageResolver messageResolver) { 131 132 EditorReference ref = new EditorReference(); 133 ref.setEditorType(getEditorType()); 134 ref.setIcon(getIcon()); 135 136 String 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 getEditorUrl(String objectId, String parentId) { 152 StringBuffer sb = new StringBuffer (); 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 |