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.List;
027:
028: import org.riotfamily.common.i18n.MessageResolver;
029:
030: /**
031: * Abstract base class for {@link EditorDefinition EditorDefinitions}.
032: * @author Felix Gnass [fgnass at neteye dot de]
033: */
034: public abstract class AbstractEditorDefinition implements
035: EditorDefinition {
036:
037: private String id;
038:
039: private String name;
040:
041: private EditorRepository editorRepository;
042:
043: private EditorDefinition parentEditorDefinition;
044:
045: private String icon;
046:
047: private boolean hidden;
048:
049: private EditorCondition condition;
050:
051: public void setEditorRepository(EditorRepository editorRepository) {
052: this .editorRepository = editorRepository;
053: }
054:
055: public String getId() {
056: return id;
057: }
058:
059: public void setId(String id) {
060: this .id = id;
061: if (name == null) {
062: name = id;
063: }
064: }
065:
066: public final void setName(String name) {
067: this .name = name;
068: }
069:
070: public final String getName() {
071: return name != null ? name : getDefaultName();
072: }
073:
074: protected String getDefaultName() {
075: return null;
076: }
077:
078: public Class getBeanClass() {
079: return null;
080: }
081:
082: public EditorDefinition getParentEditorDefinition() {
083: return this .parentEditorDefinition;
084: }
085:
086: public void setParentEditorDefinition(
087: EditorDefinition parentEditorDefinition) {
088: this .parentEditorDefinition = parentEditorDefinition;
089: }
090:
091: public void addReference(List refs, EditorDefinition parentDef,
092: Object parent, MessageResolver messageResolver) {
093:
094: if (show(parent)) {
095: String parentId = EditorDefinitionUtils.getObjectId(
096: parentDef, parent);
097: refs.add(createReference(parentId, messageResolver));
098: }
099: }
100:
101: public boolean show(Object parent) {
102: return !hidden && parent != null
103: && (condition == null || condition.showEditor(parent));
104: }
105:
106: protected EditorRepository getEditorRepository() {
107: return editorRepository;
108: }
109:
110: public String getIcon() {
111: return this .icon;
112: }
113:
114: public void setIcon(String icon) {
115: this .icon = icon;
116: }
117:
118: public boolean isHidden() {
119: return this .hidden;
120: }
121:
122: public void setHidden(boolean hidden) {
123: this .hidden = hidden;
124: }
125:
126: public void setCondition(EditorCondition condition) {
127: this .condition = condition;
128: }
129:
130: protected EditorCondition getCondition() {
131: return this .condition;
132: }
133:
134: protected StringBuffer getMessageKey() {
135: StringBuffer key = new StringBuffer();
136: key.append(getEditorType());
137: key.append('.');
138: key.append(getName());
139: return key;
140: }
141:
142: public String getLabel(Object object) {
143: return null;
144: }
145:
146: }
|