- Added ability to hide actions

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2862 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-05-12 09:34:43 +00:00
parent 38f88da91b
commit bac4f6f892
5 changed files with 76 additions and 23 deletions

View File

@@ -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<String> iterator()
{
// create a list of the visible actions and return it's iterator
ArrayList<String> visibleActions = new ArrayList<String>(
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<String> iterator()
/*package*/ void hideAction(String actionId)
{
return actions.iterator();
this.hiddenActions.add(actionId);
}
/*package*/ Set<String> getAllActions()
{
return this.actions;
}
/*pacakge*/ Set<String> 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<String> actions = new LinkedHashSet<String>(16, 1.0f);
/** the actions that have been hidden */
private Set<String> hiddenActions = new HashSet<String>(4, 1.0f);
public boolean ShowLink;
public String Style;
public String StyleClass;

View File

@@ -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);
}
}
}

View File

@@ -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<String> actions = new ArrayList<String>(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");

View File

@@ -117,7 +117,8 @@
<!-- Add the custom action to the existing document_browse group -->
<action-group id="document_browse">
<show-link>true</show-link>
<action idref="custom_action" />
<action idref="custom_action" hide="false" />
<action idref="details_space" hide="true" />
</action-group>
<action-group id="new_group">

View File

@@ -62,11 +62,18 @@
<action>dialog:showSpaceDetails</action>
</action>
<action id="always_hidden">
<label-id>view_details</label-id>
<image>/images/icons/View_details.gif</image>
<action>dialog:showSpaceDetails</action>
</action>
<action-group id="document_browse">
<show-link>false</show-link>
<style-class>inlineAction</style-class>
<action idref="details_doc" />
<action idref="details_space" />
<action idref="always_hidden" hide="true" />
</action-group>
</actions>
</config>