Eliminated web-client-config-edit-properties.xml

Fixed AWC-474 and AWC-475

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2312 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-02-07 15:09:27 +00:00
parent ce283a2f01
commit 9a50b7d471
11 changed files with 178 additions and 111 deletions

View File

@@ -30,7 +30,6 @@ import javax.faces.model.SelectItem;
import javax.transaction.UserTransaction;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigLookupContext;
import org.alfresco.config.ConfigService;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
@@ -312,10 +311,18 @@ public class DocumentPropertiesBean
// we need to use the config service to see whether there are any
// editable properties configured for this document.
ConfigService configSvc = Application.getConfigService(FacesContext.getCurrentInstance());
Config configProps = configSvc.getConfig(this.editableNode, new ConfigLookupContext("edit-properties"));
Config configProps = configSvc.getConfig(this.editableNode);
PropertySheetConfigElement propsToDisplay = (PropertySheetConfigElement)configProps.
getConfigElement("property-sheet");
this.hasOtherProperties = Boolean.valueOf(propsToDisplay != null);
if (propsToDisplay != null && propsToDisplay.getEditableItemNamesToShow().size() > 0)
{
this.hasOtherProperties = Boolean.TRUE;
}
else
{
this.hasOtherProperties = Boolean.FALSE;
}
}
return this.hasOtherProperties.booleanValue();

View File

@@ -37,8 +37,11 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
// in the future it will also deal with properties and associations to hide.
private List<ItemConfig> items = new ArrayList<ItemConfig>();
private List<ItemConfig> editableItems = new ArrayList<ItemConfig>();
private Map<String, ItemConfig> itemsMap = new HashMap<String, ItemConfig>();
private Map<String, ItemConfig> editableItemsMap = new HashMap<String, ItemConfig>();
private List<String> itemNames = new ArrayList<String>();
private List<String> editableItemNames = new ArrayList<String>();
private boolean kidsPopulated = false;
/**
@@ -96,6 +99,7 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
ce.addAttribute(PropertySheetElementReader.ATTR_DISPLAY_LABEL_ID, pc.getDisplayLabelId());
ce.addAttribute(PropertySheetElementReader.ATTR_READ_ONLY, Boolean.toString(pc.isReadOnly()));
ce.addAttribute(PropertySheetElementReader.ATTR_CONVERTER, pc.getConverter());
ce.addAttribute(PropertySheetElementReader.ATTR_SHOW_IN_EDIT_MODE, Boolean.toString(pc.isShownInEditMode()));
this.children.add(ce);
}
@@ -144,6 +148,14 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
this.items.add(itemConfig);
this.itemsMap.put(itemConfig.getName(), itemConfig);
this.itemNames.add(itemConfig.getName());
// also add to the edit items collections if necessary
if (itemConfig.isShownInEditMode())
{
this.editableItems.add(itemConfig);
this.editableItemsMap.put(itemConfig.getName(), itemConfig);
this.editableItemNames.add(itemConfig.getName());
}
}
}
@@ -155,10 +167,14 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
* @param displayLabelId Display label message id to use for the property
* @param readOnly Sets whether the property should be rendered as read only
* @param converter The name of a converter to apply to the property control
* @param inEdit Sets whether the property should be shown when the property
* sheet is in edit mode
*/
/*package*/ void addProperty(String name, String displayLabel, String displayLabelId, String readOnly, String converter)
/*package*/ void addProperty(String name, String displayLabel, String displayLabelId, String readOnly,
String converter, String inEdit)
{
addItem(new PropertyConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), converter));
addItem(new PropertyConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly),
converter, inEdit));
}
/**
@@ -169,10 +185,14 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
* @param displayLabelId Display label message id to use for the property
* @param readOnly Sets whether the association should be rendered as read only
* @param converter The name of a converter to apply to the association control
* @param inEdit Sets whether the property should be shown when the property
* sheet is in edit mode
*/
/*package*/ void addAssociation(String name, String displayLabel, String displayLabelId, String readOnly, String converter)
/*package*/ void addAssociation(String name, String displayLabel, String displayLabelId, String readOnly,
String converter, String inEdit)
{
addItem(new AssociationConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), converter));
addItem(new AssociationConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly),
converter, inEdit));
}
/**
@@ -184,9 +204,11 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
* @param readOnly Sets whether the association should be rendered as read only
* @param converter The name of a converter to apply to the association control
*/
/*package*/ void addChildAssociation(String name, String displayLabel, String displayLabelId, String readOnly, String converter)
/*package*/ void addChildAssociation(String name, String displayLabel, String displayLabelId, String readOnly,
String converter, String inEdit)
{
addItem(new ChildAssociationConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), converter));
addItem(new ChildAssociationConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly),
converter, inEdit));
}
/**
@@ -213,6 +235,30 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
return this.itemsMap;
}
/**
* @return Returns a list of item names to display
*/
public List<String> getEditableItemNamesToShow()
{
return this.editableItemNames;
}
/**
* @return Returns the list of item config objects that represent those to display
*/
public List<ItemConfig> getEditableItemsToShow()
{
return this.editableItems;
}
/**
* @return Returns a map of the item names to show
*/
public Map<String, ItemConfig> getEditableItemsMapToShow()
{
return this.editableItemsMap;
}
/**
* Inner class to represent a configured property sheet item
*/
@@ -223,15 +269,21 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
private String displayLabelId;
private String converter;
private boolean readOnly;
private boolean showInEditMode = true;
public ItemConfig(String name, String displayLabel, String displayLabelId,
boolean readOnly, String converter)
boolean readOnly, String converter, String inEdit)
{
this.name = name;
this.displayLabel = displayLabel;
this.displayLabelId = displayLabelId;
this.readOnly = readOnly;
this.converter = converter;
if (inEdit != null)
{
this.showInEditMode = Boolean.parseBoolean(inEdit);
}
}
/**
@@ -271,6 +323,11 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
return this.converter;
}
public boolean isShownInEditMode()
{
return this.showInEditMode;
}
/**
* @see java.lang.Object#toString()
*/
@@ -281,7 +338,8 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
buffer.append(" displaylabel=").append(this.displayLabel);
buffer.append(" displaylabelId=").append(this.displayLabelId);
buffer.append(" converter=").append(this.converter);
buffer.append(" readonly=").append(this.readOnly).append(")");
buffer.append(" readonly=").append(this.readOnly);
buffer.append(" showInEditMode=").append(this.showInEditMode).append(")");
return buffer.toString();
}
}
@@ -292,9 +350,9 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
public class PropertyConfig extends ItemConfig
{
public PropertyConfig(String name, String displayLabel, String displayLabelId,
boolean readOnly, String converter)
boolean readOnly, String converter, String inEdit)
{
super(name, displayLabel, displayLabelId, readOnly, converter);
super(name, displayLabel, displayLabelId, readOnly, converter, inEdit);
}
}
@@ -304,9 +362,9 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
public class AssociationConfig extends ItemConfig
{
public AssociationConfig(String name, String displayLabel, String displayLabelId,
boolean readOnly, String converter)
boolean readOnly, String converter, String inEdit)
{
super(name, displayLabel, displayLabelId, readOnly, converter);
super(name, displayLabel, displayLabelId, readOnly, converter, inEdit);
}
}
@@ -316,9 +374,9 @@ public class PropertySheetConfigElement extends ConfigElementAdapter
public class ChildAssociationConfig extends ItemConfig
{
public ChildAssociationConfig(String name, String displayLabel, String displayLabelId,
boolean readOnly, String converter)
boolean readOnly, String converter, String inEdit)
{
super(name, displayLabel, displayLabelId, readOnly, converter);
super(name, displayLabel, displayLabelId, readOnly, converter, inEdit);
}
}
}

View File

@@ -39,6 +39,7 @@ public class PropertySheetElementReader implements ConfigElementReader
public static final String ATTR_DISPLAY_LABEL_ID = "displayLabelId";
public static final String ATTR_READ_ONLY = "readOnly";
public static final String ATTR_CONVERTER = "converter";
public static final String ATTR_SHOW_IN_EDIT_MODE = "showInEditMode";
/**
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
@@ -69,19 +70,20 @@ public class PropertySheetElementReader implements ConfigElementReader
String labelId = item.attributeValue(ATTR_DISPLAY_LABEL_ID);
String readOnly = item.attributeValue(ATTR_READ_ONLY);
String converter = item.attributeValue(ATTR_CONVERTER);
String inEdit = item.attributeValue(ATTR_SHOW_IN_EDIT_MODE);
if (ELEMENT_SHOW_PROPERTY.equals(item.getName()))
{
// add the property to show to the custom config element
configElement.addProperty(propName, label, labelId, readOnly, converter);
configElement.addProperty(propName, label, labelId, readOnly, converter, inEdit);
}
else if (ELEMENT_SHOW_ASSOC.equals(item.getName()))
{
configElement.addAssociation(propName, label, labelId, readOnly, converter);
configElement.addAssociation(propName, label, labelId, readOnly, converter, inEdit);
}
else if (ELEMENT_SHOW_CHILD_ASSOC.equals(item.getName()))
{
configElement.addChildAssociation(propName, label, labelId, readOnly, converter);
configElement.addChildAssociation(propName, label, labelId, readOnly, converter, inEdit);
}
}
}

View File

@@ -28,8 +28,6 @@ import org.alfresco.config.xml.XMLConfigService;
import org.alfresco.util.BaseTest;
import org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty;
import org.alfresco.web.config.PropertySheetConfigElement.ItemConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* JUnit tests to exercise the capabilities added to the web client config
@@ -78,7 +76,7 @@ public class WebClientConfigTest extends BaseTest
.getConfigElement("property-sheet");
assertNotNull("Space aspect property config should not be null", spacePropConfig);
propNames = spacePropConfig.getItemNamesToShow();
assertTrue("There should be 5 properties in the list", propNames.size() == 5);
assertTrue("There should be 6 properties in the list", propNames.size() == 6);
// make sure the property sheet config has come back with the correct data
Map<String, ItemConfig> props = spacePropConfig.getItemsMapToShow();
@@ -98,7 +96,7 @@ public class WebClientConfigTest extends BaseTest
assertEquals("display label for icon should be null", null, iconProp.getDisplayLabel());
assertFalse("read only for icon should be 'false'", iconProp.isReadOnly());
}
/**
* Tests the config service by retrieving property sheet configuration using
* the generic interfaces
@@ -126,8 +124,12 @@ public class WebClientConfigTest extends BaseTest
propNames.add(propName);
}
assertTrue("There should be 5 properties", propNames.size() == 5);
assertTrue("There should be 6 properties", propNames.size() == 6);
assertFalse("The id attribute should not be present", propsToDisplay.hasAttribute("id"));
// make sure the inEditMode and readOnly flags are set correctly on the last property
assertEquals("showInEditMode", "false", kids.get(5).getAttribute("showInEditMode"));
assertEquals("readOnly", "true", kids.get(5).getAttribute("readOnly"));
}
/**
@@ -155,10 +157,54 @@ public class WebClientConfigTest extends BaseTest
assertNotNull("kids should not be null", kids);
assertTrue("There should be more than one child", kids.size() > 1);
assertEquals("There should be 5 properties", propNames.size() == 5, true);
assertEquals("There should be 6 properties", propNames.size() == 6, true);
assertFalse("The id attribute should not be present", propsToDisplay.hasAttribute("id"));
}
public void testPropertyEditing()
{
// setup the config service
String configFiles = getResourcesDir() + "test-config.xml";
XMLConfigService svc = new XMLConfigService(new FileConfigSource(configFiles));
svc.init();
Config propEditConfig = svc.getConfig("Property Editing");
assertNotNull("Property Editing section should not be null", propEditConfig);
PropertySheetConfigElement propSheet = (PropertySheetConfigElement)propEditConfig.
getConfigElement("property-sheet");
assertNotNull("property-sheet config should not be null", propSheet);
// make sure the list of names method works correctly
List<String> itemNamesToEdit = propSheet.getEditableItemNamesToShow();
assertNotNull("itemNamesToEdit should not be null", itemNamesToEdit);
assertEquals("Number of properties", 3, itemNamesToEdit.size());
// make sure the property names are correct
assertEquals("first property name", "name", itemNamesToEdit.get(0));
assertEquals("second property name", "description", itemNamesToEdit.get(1));
assertEquals("third property name", "icon", itemNamesToEdit.get(2));
// make sure the map has the correct number of items
Map<String, ItemConfig> itemsToEditMap = propSheet.getEditableItemsMapToShow();
assertNotNull("itemsToEditMap should not be null", itemsToEditMap);
assertEquals("Number of properties", 3, itemsToEditMap.size());
// make sure the icon property is set as read only
ItemConfig item = itemsToEditMap.get("icon");
assertNotNull("icon should not be null", item);
assertTrue("icon property readOnly status should be true", item.isReadOnly());
// make the size property is unavailable
item = itemsToEditMap.get("size");
assertNull("size should be null", item);
// make sure the list has the correct numbe of items
List<ItemConfig> itemsToEdit = propSheet.getEditableItemsToShow();
assertNotNull("itemsToEdit should not be null", itemsToEdit);
assertEquals("Number of properties", 3, itemsToEdit.size());
}
/**
* Tests the custom client configuration objects
*/

View File

@@ -253,6 +253,14 @@ public class UIProperty extends PropertySheetItem
control.getAttributes().put("disabled", Boolean.TRUE);
}
// for now we can not handle multi valued properties in the client so if the property
// is defined as such make sure it is rendered as disabled
if (propDef.isMultiValued())
{
logger.warn("Setting property " + propDef.getName().toString() + " to read-only, it can not be edited as it is defined as multi-valued");
control.getAttributes().put("disabled", Boolean.TRUE);
}
// add a validator if the field is required
// if (propDef.isMandatory())
// {

View File

@@ -120,10 +120,22 @@ public class UIPropertySheet extends UIPanel implements NamingContainer
if (itemsToDisplay != null)
{
List<ItemConfig> itemsToRender = itemsToDisplay.getItemsToShow();
if (logger.isDebugEnabled())
logger.debug("Items to render: " + itemsToDisplay.getItemNamesToShow());
List<ItemConfig> itemsToRender = null;
if (this.getMode().equalsIgnoreCase(EDIT_MODE))
{
itemsToRender = itemsToDisplay.getEditableItemsToShow();
if (logger.isDebugEnabled())
logger.debug("Items to render: " + itemsToDisplay.getEditableItemNamesToShow());
}
else
{
itemsToRender = itemsToDisplay.getItemsToShow();
if (logger.isDebugEnabled())
logger.debug("Items to render: " + itemsToDisplay.getItemNamesToShow());
}
createComponentsFromConfig(context, itemsToRender);
}

View File

@@ -132,6 +132,7 @@
<show-property name="modifieddate" readOnly="true" />
<show-property name="description" displayLabel="Description" readOnly="false" />
<show-property name="icon" />
<show-property name="size" readOnly="true" showInEditMode="false" />
</property-sheet>
</config>
@@ -165,7 +166,6 @@
<config evaluator="string-compare" condition="Property Editing">
<property-sheet>
<show-property name="name" showInEditMode="false" />
<show-property name="description" showInEditMode="true" />
<show-property name="icon" readOnly="true" />
<show-property name="size" readOnly="true" showInEditMode="false" />

View File

@@ -157,7 +157,7 @@
<r:propertySheetGrid id="document-props" value="#{EditDocPropsDialog.editableNode}"
var="editDocProps" columns="1"
rendered="#{EditDocPropsDialog.otherPropertiesPresent}"
externalConfig="true" configArea="edit-properties" />
externalConfig="true" />
<h:outputText value="#{msg.no_other_properties}"
rendered="#{EditDocPropsDialog.otherPropertiesPresent == false}" />
</td>