From bac4f6f892763b16a63c65373ccac5a30e4f34a5 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Fri, 12 May 2006 09:34:43 +0000 Subject: [PATCH] - Added ability to hide actions git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2862 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/config/ActionsConfigElement.java | 67 ++++++++++++++----- .../web/config/ActionsElementReader.java | 15 ++++- .../web/config/WebClientConfigTest.java | 7 +- .../test-resources/test-config-override.xml | 3 +- source/test-resources/test-config.xml | 7 ++ 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/source/java/org/alfresco/web/config/ActionsConfigElement.java b/source/java/org/alfresco/web/config/ActionsConfigElement.java index 6f2b56a1f4..4331d6b85a 100644 --- a/source/java/org/alfresco/web/config/ActionsConfigElement.java +++ b/source/java/org/alfresco/web/config/ActionsConfigElement.java @@ -18,6 +18,7 @@ package org.alfresco.web.config; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -28,6 +29,7 @@ import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigException; import org.alfresco.config.element.ConfigElementAdapter; import org.alfresco.web.action.ActionEvaluator; +import org.alfresco.web.bean.repository.Repository; /** * Action config element. @@ -89,24 +91,30 @@ public class ActionsConfigElement extends ConfigElementAdapter { // there is already a group with this id, combine it // with the new one - ActionGroup existingGroup = combinedElement.actionGroups.get(newGroup.getId()); - if (newGroup.ShowLink != existingGroup.ShowLink) + ActionGroup combinedGroup = combinedElement.actionGroups.get(newGroup.getId()); + if (newGroup.ShowLink != combinedGroup.ShowLink) { - existingGroup.ShowLink = newGroup.ShowLink; + combinedGroup.ShowLink = newGroup.ShowLink; } if (newGroup.Style != null) { - existingGroup.Style = newGroup.Style; + combinedGroup.Style = newGroup.Style; } if (newGroup.StyleClass != null) { - existingGroup.StyleClass = newGroup.StyleClass; + combinedGroup.StyleClass = newGroup.StyleClass; } - // add the new groups to the existing set - for (String actionRef : newGroup.actions) + // add all the actions from the new group to the combined one + for (String actionRef : newGroup.getAllActions()) { - existingGroup.actions.add(actionRef); + combinedGroup.addAction(actionRef); + } + + // add all the hidden actions from the new group to the combined one + for (String actionRef : newGroup.getHiddenActions()) + { + combinedGroup.hideAction(actionRef); } } else @@ -115,7 +123,7 @@ public class ActionsConfigElement extends ConfigElementAdapter combinedElement.actionGroups.put(newGroup.getId(), newGroup); } } - + return combinedElement; } @@ -246,17 +254,43 @@ public class ActionsConfigElement extends ConfigElementAdapter return id; } - public void addAction(String actionId) + /** + * @return Iterator over the visible ActionDefinition IDs referenced by this group + */ + public Iterator iterator() + { + // create a list of the visible actions and return it's iterator + ArrayList visibleActions = new ArrayList( + this.actions.size() - this.hiddenActions.size()); + for (String actionId : this.actions) + { + if (this.hiddenActions.contains(actionId) == false) + { + visibleActions.add(actionId); + } + } + + return visibleActions.iterator(); + } + + /*package*/ void addAction(String actionId) { actions.add(actionId); } - /** - * @return Iterator over the ActionDefinition IDs referenced by this group - */ - public Iterator iterator() + /*package*/ void hideAction(String actionId) { - return actions.iterator(); + this.hiddenActions.add(actionId); + } + + /*package*/ Set getAllActions() + { + return this.actions; + } + + /*pacakge*/ Set getHiddenActions() + { + return this.hiddenActions; } private String id; @@ -265,6 +299,9 @@ public class ActionsConfigElement extends ConfigElementAdapter than one action with the same Id and that the insertion order is preserved */ private Set actions = new LinkedHashSet(16, 1.0f); + /** the actions that have been hidden */ + private Set hiddenActions = new HashSet(4, 1.0f); + public boolean ShowLink; public String Style; public String StyleClass; diff --git a/source/java/org/alfresco/web/config/ActionsElementReader.java b/source/java/org/alfresco/web/config/ActionsElementReader.java index 8533270d36..6c1fce52d1 100644 --- a/source/java/org/alfresco/web/config/ActionsElementReader.java +++ b/source/java/org/alfresco/web/config/ActionsElementReader.java @@ -56,7 +56,7 @@ public class ActionsElementReader implements ConfigElementReader public static final String ATTRIBUTE_IDREF = "idref"; public static final String ATTRIBUTE_NAME = "name"; public static final String ATTRIBUTE_ALLOW = "allow"; - + public static final String ATTRIBUTE_HIDE = "hide"; /** * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) @@ -123,8 +123,17 @@ public class ActionsElementReader implements ConfigElementReader } else { - // add the action definition ID to the group - actionGroup.addAction(idRef); + // look for the hide attribute + String hide = actionRefElement.attributeValue(ATTRIBUTE_HIDE); + if (hide != null && Boolean.parseBoolean(hide)) + { + actionGroup.hideAction(idRef); + } + else + { + // add the action definition ID to the group + actionGroup.addAction(idRef); + } } } diff --git a/source/java/org/alfresco/web/config/WebClientConfigTest.java b/source/java/org/alfresco/web/config/WebClientConfigTest.java index df48bd3cc2..dd92340e31 100644 --- a/source/java/org/alfresco/web/config/WebClientConfigTest.java +++ b/source/java/org/alfresco/web/config/WebClientConfigTest.java @@ -896,19 +896,18 @@ public class WebClientConfigTest extends BaseTest assertEquals("document_browse group style class", "inlineAction", group.StyleClass); assertNull("Style for document_browse group should be null", group.Style); - // make sure there are 3 items + // make sure there are 2 items (as one was hidden in the override) ArrayList actions = new ArrayList(3); for (String actionId : group) { actions.add(actionId); } - assertEquals("number of items in document_browse group", 3, actions.size()); + assertEquals("number of items in document_browse group", 2, actions.size()); // make sure they are in the correct order assertEquals("first action", "details_doc", actions.get(0)); - assertEquals("second action", "details_space", actions.get(1)); - assertEquals("third action", "custom_action", actions.get(2)); + assertEquals("second action", "custom_action", actions.get(1)); // get the new_group action group ActionGroup newGroup = actionsConfig.getActionGroup("new_group"); diff --git a/source/test-resources/test-config-override.xml b/source/test-resources/test-config-override.xml index 75159a43f0..33c7c1ad71 100644 --- a/source/test-resources/test-config-override.xml +++ b/source/test-resources/test-config-override.xml @@ -117,7 +117,8 @@ true - + + diff --git a/source/test-resources/test-config.xml b/source/test-resources/test-config.xml index 4855aea2bc..1b655ce234 100644 --- a/source/test-resources/test-config.xml +++ b/source/test-resources/test-config.xml @@ -62,11 +62,18 @@ dialog:showSpaceDetails + + view_details + /images/icons/View_details.gif + dialog:showSpaceDetails + + false inlineAction +