/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.bean;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.IContextListener;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.groups.GroupsProperties;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.IBreadcrumbHandler;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.alfresco.web.ui.common.component.UIBreadcrumb;
import org.alfresco.web.ui.common.component.UIModeList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Backing Bean for the Groups Management pages.
*
* @author Kevin Roast
*/
public class GroupsDialog extends BaseDialogBean implements IContextListener
{
protected GroupsProperties properties;
private static final String FILTER_CHILDREN = "children";
private static final String MSG_GROUPS = "root_groups";
private static Log logger = LogFactory.getLog(GroupsDialog.class);
// ------------------------------------------------------------------------------
// Construction
/**
* Default Constructor
*/
public GroupsDialog()
{
UIContextService.getInstance(FacesContext.getCurrentInstance()).registerBean(this);
}
// ------------------------------------------------------------------------------
// Bean property getters and setters
public void setProperties(GroupsProperties properties)
{
this.properties = properties;
}
/**
* @param filterMode The filterMode to set.
*/
public void setFilterMode(String filterMode)
{
properties.setFilterMode(filterMode);
// clear datalist cache ready to change results based on filter setting
contextUpdated();
}
/**
* @param group Set the Group to be used for the current action screen.
*/
public void setActionGroup(String group)
{
properties.setActionGroup(group);
if (group != null)
{
// calculate action group metadata
properties.setActionGroupName(properties.getAuthService().getShortName(group));
int count = properties.getAuthService().getContainedAuthorities(AuthorityType.GROUP, group, false).size();
count += properties.getAuthService().getContainedAuthorities(AuthorityType.USER, group, false).size();
properties.setActionGroupItems(count);
}
else
{
properties.setActionGroupName(null);
properties.setActionGroupItems(0);
}
// clear value used by Create Group form
properties.setName(null);
}
/**
* Set the current Group Authority.
*
* Setting this value causes the UI to update and display the specified node as current.
*
* @param group The current group authority.
*/
public void setCurrentGroup(String group, String groupName)
{
if (logger.isDebugEnabled())
logger.debug("Setting current group: " + group);
// set the current Group Authority for our UI context operations
properties.setGroup(group);
properties.setGroupName(groupName);
// inform that the UI needs updating after this change
contextUpdated();
}
/**
* @return Breadcrumb location list
*/
public List getLocation()
{
if (properties.getLocation() == null)
{
List loc = new ArrayList(8);
loc.add(new GroupBreadcrumbHandler(null,
Application.getMessage(FacesContext.getCurrentInstance(), MSG_GROUPS)));
properties.setLocation(loc);
}
return properties.getLocation();
}
/**
* @return The list of group objects to display. Returns the list of root groups or the
* list of sub-groups for the current group if set.
*/
public List