001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsDependencyIconAction.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.8 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.accounts;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.main.CmsException;
036: import org.opencms.util.CmsUUID;
037: import org.opencms.workplace.CmsWorkplace;
038: import org.opencms.workplace.list.CmsListResourceIconAction;
039: import org.opencms.workplace.tools.A_CmsHtmlIconButton;
040:
041: /**
042: * Displays an icon action for dependency lists.<p>
043: *
044: * @author Michael Moossen
045: *
046: * @version $Revision: 1.8 $
047: *
048: * @since 6.0.0
049: */
050: public class CmsDependencyIconAction extends CmsListResourceIconAction {
051:
052: /** Path to the list buttons. */
053: public static final String PATH_BUTTONS = "tools/accounts/buttons/";
054:
055: /** the type of the icon. */
056: private final CmsDependencyIconActionType m_type;
057:
058: /**
059: * Default Constructor.<p>
060: *
061: * @param id the unique id
062: * @param type the type of the icon
063: * @param cms the cms context
064: */
065: public CmsDependencyIconAction(String id,
066: CmsDependencyIconActionType type, CmsObject cms) {
067:
068: super (id + type.getId(),
069: CmsGroupDependenciesList.LIST_COLUMN_TYPE, cms);
070: m_type = type;
071: }
072:
073: /**
074: * @see org.opencms.workplace.list.CmsListDirectAction#buttonHtml(org.opencms.workplace.CmsWorkplace)
075: */
076: public String buttonHtml(CmsWorkplace wp) {
077:
078: if (!isVisible()) {
079: return "";
080: }
081: if (m_type == CmsDependencyIconActionType.RESOURCE) {
082: return super .buttonHtml(wp);
083: } else {
084: return A_CmsHtmlIconButton.defaultButtonHtml(
085: resolveButtonStyle(), getId() + getItem().getId(),
086: getId(), resolveName(wp.getLocale()),
087: resolveHelpText(wp.getLocale()), isEnabled(),
088: getIconPath(), null, resolveOnClic(wp.getLocale()),
089: getColumnForTexts() == null, null);
090: }
091: }
092:
093: /**
094: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
095: */
096: public String getIconPath() {
097:
098: if (m_type == CmsDependencyIconActionType.USER) {
099: return PATH_BUTTONS + "user.png";
100: } else if (m_type == CmsDependencyIconActionType.GROUP) {
101: return PATH_BUTTONS + "group.png";
102: } else {
103: return super .getIconPath();
104: }
105: }
106:
107: /**
108: * Returns the type.<p>
109: *
110: * @return the type
111: */
112: public CmsDependencyIconActionType getType() {
113:
114: return m_type;
115: }
116:
117: /**
118: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
119: */
120: public boolean isVisible() {
121:
122: boolean visible = false;
123: if (getItem() != null) {
124: CmsUUID id = new CmsUUID(getItem().getId());
125: try {
126: if (m_type == CmsDependencyIconActionType.RESOURCE) {
127: try {
128: getCms().readUser(id);
129: } catch (CmsException e1) {
130: try {
131: getCms().readGroup(id);
132: } catch (CmsException e2) {
133: visible = true;
134: }
135: }
136: } else if (m_type == CmsDependencyIconActionType.USER) {
137: getCms().readUser(id);
138: visible = true;
139: } else if (m_type == CmsDependencyIconActionType.GROUP) {
140: getCms().readGroup(id);
141: visible = true;
142: }
143: } catch (CmsException e) {
144: // not visible
145: }
146: } else {
147: visible = super.isVisible();
148: }
149: return visible;
150: }
151: }
|