diff --git a/config/alfresco/web-client-application-context.xml b/config/alfresco/web-client-application-context.xml index ba65077eb4..2655ec4bd5 100644 --- a/config/alfresco/web-client-application-context.xml +++ b/config/alfresco/web-client-application-context.xml @@ -5,10 +5,9 @@ - + classpath:alfresco/web-client-config.xml classpath:alfresco/web-client-config-properties.xml - classpath:alfresco/web-client-config-edit-properties.xml classpath:alfresco/web-client-config-navigation.xml classpath:alfresco/extension/web-client-config-custom.xml diff --git a/config/alfresco/web-client-config-edit-properties.xml b/config/alfresco/web-client-config-edit-properties.xml deleted file mode 100644 index 67edce3fc3..0000000000 --- a/config/alfresco/web-client-config-edit-properties.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/alfresco/web-client-config-properties.xml b/config/alfresco/web-client-config-properties.xml index 9d500c5a3d..ad1adaf4c3 100644 --- a/config/alfresco/web-client-config-properties.xml +++ b/config/alfresco/web-client-config-properties.xml @@ -2,11 +2,11 @@ - - - - - + + + + + @@ -78,8 +78,8 @@ - - + + @@ -97,16 +97,16 @@ - + - - - - + + + + diff --git a/source/java/org/alfresco/web/bean/DocumentPropertiesBean.java b/source/java/org/alfresco/web/bean/DocumentPropertiesBean.java index e80e94d680..2b7eca4197 100644 --- a/source/java/org/alfresco/web/bean/DocumentPropertiesBean.java +++ b/source/java/org/alfresco/web/bean/DocumentPropertiesBean.java @@ -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(); diff --git a/source/java/org/alfresco/web/config/PropertySheetConfigElement.java b/source/java/org/alfresco/web/config/PropertySheetConfigElement.java index 9895bb99e0..3ac1350637 100644 --- a/source/java/org/alfresco/web/config/PropertySheetConfigElement.java +++ b/source/java/org/alfresco/web/config/PropertySheetConfigElement.java @@ -37,8 +37,11 @@ public class PropertySheetConfigElement extends ConfigElementAdapter // in the future it will also deal with properties and associations to hide. private List items = new ArrayList(); + private List editableItems = new ArrayList(); private Map itemsMap = new HashMap(); + private Map editableItemsMap = new HashMap(); private List itemNames = new ArrayList(); + private List editableItemNames = new ArrayList(); 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 getEditableItemNamesToShow() + { + return this.editableItemNames; + } + + /** + * @return Returns the list of item config objects that represent those to display + */ + public List getEditableItemsToShow() + { + return this.editableItems; + } + + /** + * @return Returns a map of the item names to show + */ + public Map 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); } } } diff --git a/source/java/org/alfresco/web/config/PropertySheetElementReader.java b/source/java/org/alfresco/web/config/PropertySheetElementReader.java index 3832c5ed07..4ecd119612 100644 --- a/source/java/org/alfresco/web/config/PropertySheetElementReader.java +++ b/source/java/org/alfresco/web/config/PropertySheetElementReader.java @@ -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); } } } diff --git a/source/java/org/alfresco/web/config/WebClientConfigTest.java b/source/java/org/alfresco/web/config/WebClientConfigTest.java index 8fbc5df9b9..9443676fba 100644 --- a/source/java/org/alfresco/web/config/WebClientConfigTest.java +++ b/source/java/org/alfresco/web/config/WebClientConfigTest.java @@ -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 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 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 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 itemsToEdit = propSheet.getEditableItemsToShow(); + assertNotNull("itemsToEdit should not be null", itemsToEdit); + assertEquals("Number of properties", 3, itemsToEdit.size()); + } + /** * Tests the custom client configuration objects */ 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 4e70a0d156..4c6d62197b 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 @@ -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()) // { 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 d8612e5630..b4c92dfcb4 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 @@ -120,10 +120,22 @@ public class UIPropertySheet extends UIPanel implements NamingContainer if (itemsToDisplay != null) { - List itemsToRender = itemsToDisplay.getItemsToShow(); - - if (logger.isDebugEnabled()) - logger.debug("Items to render: " + itemsToDisplay.getItemNamesToShow()); + List 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); } diff --git a/source/test-resources/test-config.xml b/source/test-resources/test-config.xml index 26e3314798..b761650764 100644 --- a/source/test-resources/test-config.xml +++ b/source/test-resources/test-config.xml @@ -132,6 +132,7 @@ + @@ -165,7 +166,6 @@ - diff --git a/source/web/jsp/dialog/edit-document-properties.jsp b/source/web/jsp/dialog/edit-document-properties.jsp index 4119a3964a..0edd7a09b5 100644 --- a/source/web/jsp/dialog/edit-document-properties.jsp +++ b/source/web/jsp/dialog/edit-document-properties.jsp @@ -157,7 +157,7 @@ + externalConfig="true" />