From a4e8facbae651e085643bc54a6f4ecf6a0ce7714 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Thu, 3 Aug 2006 09:44:13 +0000 Subject: [PATCH] Added separator support into the property sheet git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3454 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../generator/BaseComponentGenerator.java | 7 ++ .../generator/HeaderSeparatorGenerator.java | 23 +++++ .../bean/generator/SeparatorGenerator.java | 49 ++++++++++ .../config/PropertySheetConfigElement.java | 40 ++++++++- .../config/PropertySheetElementReader.java | 5 ++ .../alfresco/web/ui/repo/RepoConstants.java | 3 + .../repo/component/property/UIProperty.java | 3 +- .../component/property/UIPropertySheet.java | 8 ++ .../repo/component/property/UISeparator.java | 80 +++++++++++++++++ .../property/PropertySheetItemRenderer.java | 2 - .../renderer/property/SeparatorRenderer.java | 90 +++++++++++++++++++ source/web/WEB-INF/faces-config-beans.xml | 18 ++++ source/web/WEB-INF/faces-config-repo.xml | 11 +++ 13 files changed, 333 insertions(+), 6 deletions(-) create mode 100644 source/java/org/alfresco/web/bean/generator/HeaderSeparatorGenerator.java create mode 100644 source/java/org/alfresco/web/bean/generator/SeparatorGenerator.java create mode 100644 source/java/org/alfresco/web/ui/repo/component/property/UISeparator.java create mode 100644 source/java/org/alfresco/web/ui/repo/renderer/property/SeparatorRenderer.java diff --git a/source/java/org/alfresco/web/bean/generator/BaseComponentGenerator.java b/source/java/org/alfresco/web/bean/generator/BaseComponentGenerator.java index 8137ec929b..3766266bea 100644 --- a/source/java/org/alfresco/web/bean/generator/BaseComponentGenerator.java +++ b/source/java/org/alfresco/web/bean/generator/BaseComponentGenerator.java @@ -32,6 +32,7 @@ import org.alfresco.web.ui.repo.component.property.BaseAssociationEditor; import org.alfresco.web.ui.repo.component.property.PropertySheetItem; import org.alfresco.web.ui.repo.component.property.UIProperty; import org.alfresco.web.ui.repo.component.property.UIPropertySheet; +import org.alfresco.web.ui.repo.component.property.UISeparator; import org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -83,6 +84,12 @@ public abstract class BaseComponentGenerator implements IComponentGenerator // setup any converter the property needs setupConverter(context, propertySheet, item, propertyDef, component); } + else if (item instanceof UISeparator) + { + // just create the component and add it + component = createComponent(context, propertySheet, item); + item.getChildren().add(component); + } else { // get the association definition diff --git a/source/java/org/alfresco/web/bean/generator/HeaderSeparatorGenerator.java b/source/java/org/alfresco/web/bean/generator/HeaderSeparatorGenerator.java new file mode 100644 index 0000000000..2cb6e31f9b --- /dev/null +++ b/source/java/org/alfresco/web/bean/generator/HeaderSeparatorGenerator.java @@ -0,0 +1,23 @@ +package org.alfresco.web.bean.generator; + +import javax.faces.component.UIComponent; + +import org.alfresco.web.ui.repo.component.property.PropertySheetItem; + +/** + * Generates a component to represent a separator that gets rendered + * as a header. + * + * @author gavinc + */ +public class HeaderSeparatorGenerator extends SeparatorGenerator +{ + @Override + protected String getHtml(UIComponent component, PropertySheetItem item) + { + String html = "
 " + + item.getDisplayLabel() + "
"; + + return html; + } +} diff --git a/source/java/org/alfresco/web/bean/generator/SeparatorGenerator.java b/source/java/org/alfresco/web/bean/generator/SeparatorGenerator.java new file mode 100644 index 0000000000..49076c1fa1 --- /dev/null +++ b/source/java/org/alfresco/web/bean/generator/SeparatorGenerator.java @@ -0,0 +1,49 @@ +package org.alfresco.web.bean.generator; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; + +import org.alfresco.web.ui.repo.component.property.PropertySheetItem; +import org.alfresco.web.ui.repo.component.property.UIPropertySheet; + +/** + * Generates a component to represent a separator. + * + * @author gavinc + */ +public class SeparatorGenerator extends BaseComponentGenerator +{ + @SuppressWarnings("unchecked") + public UIComponent generate(FacesContext context, String id) + { + UIComponent component = this.createOutputTextComponent(context, id); + component.getAttributes().put("escape", Boolean.FALSE); + + return component; + } + + @Override + @SuppressWarnings("unchecked") + protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, + PropertySheetItem item) + { + UIComponent component = this.generate(context, item.getName()); + + // set the HTML to use + component.getAttributes().put("value", getHtml(component, item)); + + return component; + } + + /** + * Returns the HTML to display for the separator + * + * @param component The JSF component representing the separator + * @param item The separator item + * @return The HTML + */ + protected String getHtml(UIComponent component, PropertySheetItem item) + { + return "

"; + } +} \ No newline at end of file diff --git a/source/java/org/alfresco/web/config/PropertySheetConfigElement.java b/source/java/org/alfresco/web/config/PropertySheetConfigElement.java index 5b556071fe..bd0fca32c9 100644 --- a/source/java/org/alfresco/web/config/PropertySheetConfigElement.java +++ b/source/java/org/alfresco/web/config/PropertySheetConfigElement.java @@ -32,9 +32,6 @@ import org.alfresco.config.element.ConfigElementAdapter; */ public class PropertySheetConfigElement extends ConfigElementAdapter { - // TODO: Currently this object just deals with properties and associations to show, - // in the future it will also deal with properties and associations to hide. - public static final String CONFIG_ELEMENT_ID = "property-sheet"; protected Map items = new LinkedHashMap(8, 10f); @@ -193,6 +190,24 @@ public class PropertySheetConfigElement extends ConfigElementAdapter converter, inView, inEdit, compGenerator)); } + /** + * Adds a separator + * + * @param name The name of the separator + * @param displayLabel Display label to use for the separator + * @param displayLabelId Display label message id to use for the separator + * @param inView Sets whether the separator should be shown when the property + * sheet is in view mode + * @param inEdit Sets whether the separator should be shown when the property + * sheet is in edit mode + * @param compGenerator The name of a bean that can be used as a component generator + */ + /*package*/ void addSeparator(String name, String displayLabel, String displayLabelId, + String inView, String inEdit, String compGenerator) + { + addItem(new SeparatorConfig(name, displayLabel, displayLabelId, inView, inEdit, compGenerator)); + } + /** * @return Returns a map of the all the items */ @@ -266,6 +281,12 @@ public class PropertySheetConfigElement extends ConfigElementAdapter boolean readOnly, String converter, String inView, String inEdit, String compGenerator, String ignoreIfMissing) { + // check we have a name + if (name == null || name.length() == 0) + { + throw new ConfigException("You must specify a name for a proprty sheet item"); + } + this.name = name; this.displayLabel = displayLabel; this.displayLabelId = displayLabelId; @@ -420,4 +441,17 @@ public class PropertySheetConfigElement extends ConfigElementAdapter inView, inEdit, compGenerator, null); } } + + /** + * Inner class to represent a configured separator + */ + public class SeparatorConfig extends ItemConfig + { + public SeparatorConfig(String name, String displayLabel, String displayLabelId, + String inView, String inEdit, String compGenerator) + { + super(name, displayLabel, displayLabelId, false, null, + inView, inEdit, compGenerator, null); + } + } } diff --git a/source/java/org/alfresco/web/config/PropertySheetElementReader.java b/source/java/org/alfresco/web/config/PropertySheetElementReader.java index bdbf413ded..e97bd6669c 100644 --- a/source/java/org/alfresco/web/config/PropertySheetElementReader.java +++ b/source/java/org/alfresco/web/config/PropertySheetElementReader.java @@ -34,6 +34,7 @@ public class PropertySheetElementReader implements ConfigElementReader public static final String ELEMENT_SHOW_PROPERTY = "show-property"; public static final String ELEMENT_SHOW_ASSOC = "show-association"; public static final String ELEMENT_SHOW_CHILD_ASSOC = "show-child-association"; + public static final String ELEMENT_SEPARATOR = "separator"; public static final String ATTR_NAME = "name"; public static final String ATTR_DISPLAY_LABEL = "display-label"; public static final String ATTR_DISPLAY_LABEL_ID = "display-label-id"; @@ -96,6 +97,10 @@ public class PropertySheetElementReader implements ConfigElementReader configElement.addChildAssociation(propName, label, labelId, readOnly, converter, inView, inEdit, compGenerator); } + else if (ELEMENT_SEPARATOR.equals(item.getName())) + { + configElement.addSeparator(propName, label, labelId, inView, inEdit, compGenerator); + } } } diff --git a/source/java/org/alfresco/web/ui/repo/RepoConstants.java b/source/java/org/alfresco/web/ui/repo/RepoConstants.java index 7382c89772..079c26176d 100644 --- a/source/java/org/alfresco/web/ui/repo/RepoConstants.java +++ b/source/java/org/alfresco/web/ui/repo/RepoConstants.java @@ -26,6 +26,7 @@ public final class RepoConstants public static final String ALFRESCO_FACES_ASSOCIATION = "org.alfresco.faces.Association"; public static final String ALFRESCO_FACES_CHILD_ASSOCIATION = "org.alfresco.faces.ChildAssociation"; public static final String ALFRESCO_FACES_PROPERTY = "org.alfresco.faces.Property"; + public static final String ALFRESCO_FACES_SEPARATOR = "org.alfresco.faces.Separator"; public static final String ALFRESCO_FACES_SPACE_SELECTOR = "org.alfresco.faces.SpaceSelector"; public static final String ALFRESCO_FACES_ASSOC_EDITOR = "org.alfresco.faces.AssociationEditor"; public static final String ALFRESCO_FACES_CHILD_ASSOC_EDITOR = "org.alfresco.faces.ChildAssociationEditor"; @@ -50,6 +51,8 @@ public final class RepoConstants public static final String GENERATOR_CATEGORY_SELECTOR = "CategorySelectorGenerator"; public static final String GENERATOR_ASSOCIATION = "AssociationGenerator"; public static final String GENERATOR_CHILD_ASSOCIATION = "ChildAssociationGenerator"; + public static final String GENERATOR_SEPARATOR = "SeparatorGenerator"; + public static final String GENERATOR_HEADER_SEPARATOR = "HeaderSeparatorGenerator"; /** * Private constructor diff --git a/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java b/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java index 9dea96b0af..d6b4b7c09c 100644 --- a/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java +++ b/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java @@ -178,7 +178,8 @@ public class UIProperty extends PropertySheetItem { // if we are trying to edit a NodeRef or Path property type set it to read-only as // these are internal properties that shouldn't be edited. - if (typeName.equals(DataTypeDefinition.NODE_REF) || typeName.equals(DataTypeDefinition.PATH)) + if (typeName.equals(DataTypeDefinition.NODE_REF) || typeName.equals(DataTypeDefinition.PATH) || + typeName.equals(DataTypeDefinition.CONTENT)) { logger.warn("Setting property " + propDef.getName().toString() + " to read-only as it can not be edited"); control.getAttributes().put("disabled", Boolean.TRUE); diff --git a/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java b/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java index d7d4b75bef..ea3acc89a5 100644 --- a/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java +++ b/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java @@ -43,6 +43,7 @@ import org.alfresco.web.config.PropertySheetConfigElement.AssociationConfig; import org.alfresco.web.config.PropertySheetConfigElement.ChildAssociationConfig; import org.alfresco.web.config.PropertySheetConfigElement.ItemConfig; import org.alfresco.web.config.PropertySheetConfigElement.PropertyConfig; +import org.alfresco.web.config.PropertySheetConfigElement.SeparatorConfig; import org.alfresco.web.ui.common.ComponentConstants; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.repo.RepoConstants; @@ -63,6 +64,7 @@ public class UIPropertySheet extends UIPanel implements NamingContainer private static String DEFAULT_VAR_NAME = "node"; private static String PROP_ID_PREFIX = "prop_"; private static String ASSOC_ID_PREFIX = "assoc_"; + private static String SEP_ID_PREFIX = "sep_"; private List validations = new ArrayList(); private String variable; @@ -737,6 +739,12 @@ public class UIPropertySheet extends UIPanel implements NamingContainer propSheetItem = (PropertySheetItem)context.getApplication(). createComponent(RepoConstants.ALFRESCO_FACES_CHILD_ASSOCIATION); } + else if (item instanceof SeparatorConfig) + { + id = SEP_ID_PREFIX + item.getName(); + propSheetItem = (PropertySheetItem)context.getApplication(). + createComponent(RepoConstants.ALFRESCO_FACES_SEPARATOR); + } // now setup the common stuff across all component types if (propSheetItem != null) diff --git a/source/java/org/alfresco/web/ui/repo/component/property/UISeparator.java b/source/java/org/alfresco/web/ui/repo/component/property/UISeparator.java new file mode 100644 index 0000000000..5059ae26c3 --- /dev/null +++ b/source/java/org/alfresco/web/ui/repo/component/property/UISeparator.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.ui.repo.component.property; + +import java.io.IOException; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; + +import org.alfresco.web.app.servlet.FacesHelper; +import org.alfresco.web.ui.repo.RepoConstants; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Component to represent a separator within a property sheet + * + * @author gavinc + */ +public class UISeparator extends PropertySheetItem +{ + public static final String COMPONENT_FAMILY = "org.alfresco.faces.Separator"; + + private static Log logger = LogFactory.getLog(UISeparator.class); + + /** + * Default constructor + */ + public UISeparator() + { + // set the default renderer + setRendererType("org.alfresco.faces.SeparatorRenderer"); + } + + /** + * @see javax.faces.component.UIComponent#getFamily() + */ + public String getFamily() + { + return COMPONENT_FAMILY; + } + + protected String getIncorrectParentMsg() + { + return "The separator component must be nested within a property sheet component"; + } + + protected void generateItem(FacesContext context, UIPropertySheet propSheet) throws IOException + { + String componentGeneratorName = this.getComponentGenerator(); + + if (componentGeneratorName == null) + { + componentGeneratorName = RepoConstants.GENERATOR_SEPARATOR; + } + + UIComponent separator = FacesHelper.getComponentGenerator(context, componentGeneratorName). + generateAndAdd(context, propSheet, this); + + if (logger.isDebugEnabled()) + logger.debug("Created separator " + separator + "(" + + separator.getClientId(context) + + ") for '" + this.getName() + + "' and added it to component " + this); + } +} diff --git a/source/java/org/alfresco/web/ui/repo/renderer/property/PropertySheetItemRenderer.java b/source/java/org/alfresco/web/ui/repo/renderer/property/PropertySheetItemRenderer.java index 82913887a7..bdc291f124 100644 --- a/source/java/org/alfresco/web/ui/repo/renderer/property/PropertySheetItemRenderer.java +++ b/source/java/org/alfresco/web/ui/repo/renderer/property/PropertySheetItemRenderer.java @@ -70,8 +70,6 @@ public class PropertySheetItemRenderer extends BaseRenderer UIComponent label = children.get(0); UIComponent control = children.get(1); - out.write(""); - // encode the mandatory marker component if present if (count == 3) { diff --git a/source/java/org/alfresco/web/ui/repo/renderer/property/SeparatorRenderer.java b/source/java/org/alfresco/web/ui/repo/renderer/property/SeparatorRenderer.java new file mode 100644 index 0000000000..24ab159804 --- /dev/null +++ b/source/java/org/alfresco/web/ui/repo/renderer/property/SeparatorRenderer.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.web.ui.repo.renderer.property; + +import java.io.IOException; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; + +import org.alfresco.web.ui.common.Utils; +import org.alfresco.web.ui.common.renderer.BaseRenderer; + +/** + * Renderer for a Separator component + * + * @author gavinc + */ +public class SeparatorRenderer extends BaseRenderer +{ + /** + * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent) + */ + public void encodeBegin(FacesContext context, UIComponent component) throws IOException + { + if (component.isRendered() == false) + { + return; + } + + // NOTE: we close off the first generated by the property sheet's grid renderer + context.getResponseWriter().write(""); + } + + /** + * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent) + */ + @SuppressWarnings("unchecked") + public void encodeChildren(FacesContext context, UIComponent component) throws IOException + { + if (component.isRendered() == false) + { + return; + } + + ResponseWriter out = context.getResponseWriter(); + + int count = component.getChildCount(); + + if (count == 1) + { + // there should be 3 columns so write out a td with colspan of 3 + // then render the child component + out.write(""); + Utils.encodeRecursive(context, (UIComponent)component.getChildren().get(0)); + + // NOTE: we'll allow the property sheet's grid renderer close off the last + } + } + + /** + * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent) + */ + public void encodeEnd(FacesContext context, UIComponent component) throws IOException + { + // we don't need to do anything in here + } + + /** + * @see javax.faces.render.Renderer#getRendersChildren() + */ + public boolean getRendersChildren() + { + return true; + } +} diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 4a5e2a1ac6..2e4aa100fa 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -1869,6 +1869,24 @@ ChildAssociationGenerator org.alfresco.web.bean.generator.ChildAssociationGenerator request + + + + + Bean that generates a separator component + + SeparatorGenerator + org.alfresco.web.bean.generator.SeparatorGenerator + request + + + + + Bean that generates a header separator component + + HeaderSeparatorGenerator + org.alfresco.web.bean.generator.HeaderSeparatorGenerator + request diff --git a/source/web/WEB-INF/faces-config-repo.xml b/source/web/WEB-INF/faces-config-repo.xml index c7869359a3..2bd25e9e89 100644 --- a/source/web/WEB-INF/faces-config-repo.xml +++ b/source/web/WEB-INF/faces-config-repo.xml @@ -12,6 +12,11 @@ org.alfresco.faces.Property org.alfresco.web.ui.repo.component.property.UIProperty + + + + org.alfresco.faces.Separator + org.alfresco.web.ui.repo.component.property.UISeparator @@ -170,6 +175,12 @@ org.alfresco.faces.Property org.alfresco.faces.PropertyRenderer org.alfresco.web.ui.repo.renderer.property.PropertyRenderer + + + + org.alfresco.faces.Separator + org.alfresco.faces.SeparatorRenderer + org.alfresco.web.ui.repo.renderer.property.SeparatorRenderer