mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
@@ -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 = "<div class='wizardSectionHeading mainSubTitle' style='margin-top: 6px; margin-bottom: 6px;'> " +
|
||||
item.getDisplayLabel() + "</div>";
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
@@ -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 "<div style='margin-top: 6px; margin-bottom: 6px;'><hr/></div>";
|
||||
}
|
||||
}
|
@@ -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<String, ItemConfig> items = new LinkedHashMap<String, ItemConfig>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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<ClientValidation> validations = new ArrayList<ClientValidation>();
|
||||
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)
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -70,8 +70,6 @@ public class PropertySheetItemRenderer extends BaseRenderer
|
||||
UIComponent label = children.get(0);
|
||||
UIComponent control = children.get(1);
|
||||
|
||||
out.write("</td>");
|
||||
|
||||
// encode the mandatory marker component if present
|
||||
if (count == 3)
|
||||
{
|
||||
|
@@ -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 <td> generated by the property sheet's grid renderer
|
||||
context.getResponseWriter().write("</td>");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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("<td colspan='3'>");
|
||||
Utils.encodeRecursive(context, (UIComponent)component.getChildren().get(0));
|
||||
|
||||
// NOTE: we'll allow the property sheet's grid renderer close off the last <td>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user