1 24 package org.riotfamily.riot.editor; 25 26 import java.util.List ; 27 import java.util.regex.Matcher ; 28 import java.util.regex.Pattern ; 29 30 import org.riotfamily.common.beans.PropertyUtils; 31 import org.riotfamily.common.i18n.MessageResolver; 32 import org.riotfamily.riot.editor.ui.EditorReference; 33 34 38 public abstract class AbstractEditorDefinition implements EditorDefinition { 39 40 private String id; 41 42 private String name; 43 44 private EditorRepository editorRepository; 45 46 private EditorDefinition parentEditorDefinition; 47 48 private String icon; 49 50 private boolean hidden; 51 52 public void setEditorRepository(EditorRepository editorRepository) { 53 this.editorRepository = editorRepository; 54 } 55 56 public String getId() { 57 return id; 58 } 59 60 public void setId(String id) { 61 this.id = id; 62 } 63 64 public final void setName(String name) { 65 this.name = name; 66 if (id == null) { 67 id = name; 68 } 69 } 70 71 public final String getName() { 72 return name != null ? name : getDefaultName(); 73 } 74 75 protected String getDefaultName() { 76 return null; 77 } 78 79 public Class getBeanClass() { 80 return null; 81 } 82 83 public EditorDefinition getParentEditorDefinition() { 84 return this.parentEditorDefinition; 85 } 86 87 public void setParentEditorDefinition(EditorDefinition parentEditorDefinition) { 88 this.parentEditorDefinition = parentEditorDefinition; 89 } 90 91 public void addReference(List refs, EditorDefinition parentDef, 92 Object parent, MessageResolver messageResolver) { 93 94 String parentId = null; 95 if (parent != null) { 96 parentId = EditorDefinitionUtils.getObjectId(parentDef, parent); 97 } 98 EditorReference ref = createReference(parentId, messageResolver); 99 ref.setEnabled(parent != null); 100 refs.add(ref); 101 } 102 103 protected EditorRepository getEditorRepository() { 104 return editorRepository; 105 } 106 107 public String getIcon() { 108 return this.icon; 109 } 110 111 public void setIcon(String icon) { 112 this.icon = icon; 113 } 114 115 public boolean isHidden() { 116 return this.hidden; 117 } 118 119 public void setHidden(boolean hidden) { 120 this.hidden = hidden; 121 } 122 123 protected StringBuffer getMessageKey() { 124 StringBuffer key = new StringBuffer (); 125 key.append(getEditorType()); 126 key.append('.'); 127 key.append(getName()); 128 return key; 129 } 130 131 public String getLabelProperty() { 132 return null; 133 } 134 135 public String getLabel(Object object) { 136 if (object == null) { 137 return "New"; } 139 if (getLabelProperty() != null) { 140 StringBuffer label = new StringBuffer (); 141 Pattern p = Pattern.compile("(\\w+)(\\W*)"); 142 Matcher m = p.matcher(getLabelProperty()); 143 while (m.find()) { 144 String property = m.group(1); 145 Object value = PropertyUtils.getProperty(object, property); 146 if (value != null) { 147 label.append(value); 148 label.append(m.group(2)); 149 } 150 } 151 if (label.length() > 0) { 152 return label.toString(); 153 } 154 } 155 return object.toString(); 156 } 157 158 } 159 | Popular Tags |