001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.tools.accounts;
029
030import org.opencms.file.CmsGroup;
031import org.opencms.workplace.list.CmsListDefaultAction;
032
033import java.util.List;
034
035/**
036 * Shows direct/indirect assigned groups and enabled/disabled a remove action.<p>
037 *
038 * @since 6.0.0
039 */
040public class CmsGroupRemoveAction extends CmsListDefaultAction {
041
042    /** The direct group flag. */
043    private final boolean m_direct;
044
045    /**
046     * Default Constructor.<p>
047     *
048     * @param id the unique id
049     * @param direct the direct group flag
050     */
051    public CmsGroupRemoveAction(String id, boolean direct) {
052
053        super(id);
054        m_direct = direct;
055    }
056
057    /**
058     * Returns the direct group flag.<p>
059     *
060     * @return the direct group flag
061     */
062    public boolean isDirect() {
063
064        return m_direct;
065    }
066
067    /**
068     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#isVisible()
069     */
070    @Override
071    public boolean isVisible() {
072
073        if (getItem() != null) {
074            String groupName = (String)getItem().get(A_CmsUserGroupsList.LIST_COLUMN_NAME);
075            try {
076                List<CmsGroup> dGroups = getWp().getCms().getGroupsOfUser(
077                    ((A_CmsUserGroupsList)getWp()).getParamUsername(),
078                    true);
079                CmsGroup group = getWp().getCms().readGroup(groupName);
080                if (isDirect()) {
081                    return dGroups.contains(group);
082                } else {
083                    return !dGroups.contains(group);
084                }
085            } catch (Exception e) {
086                return false;
087            }
088        }
089        return super.isVisible();
090    }
091}