KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > accounts > CmsDependencyIconAction


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsDependencyIconAction.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
4  * Version: $Revision: 1.5 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.accounts;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsException;
36 import org.opencms.util.CmsUUID;
37 import org.opencms.workplace.CmsWorkplace;
38 import org.opencms.workplace.list.CmsListResourceIconAction;
39 import org.opencms.workplace.tools.A_CmsHtmlIconButton;
40
41 /**
42  * Displays an icon action for dependency lists.<p>
43  *
44  * @author Michael Moossen
45  *
46  * @version $Revision: 1.5 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsDependencyIconAction extends CmsListResourceIconAction {
51
52     /** Path to the list buttons. */
53     public static final String JavaDoc PATH_BUTTONS = "tools/accounts/buttons/";
54
55     /** the type of the icon. */
56     private final CmsDependencyIconActionType m_type;
57
58     /**
59      * Default Constructor.<p>
60      *
61      * @param id the unique id
62      * @param type the type of the icon
63      * @param cms the cms context
64      */

65     public CmsDependencyIconAction(String JavaDoc id, CmsDependencyIconActionType type, CmsObject cms) {
66
67         super(id + type.getId(), CmsGroupDependenciesList.LIST_COLUMN_TYPE, cms);
68         m_type = type;
69     }
70
71     /**
72      * @see org.opencms.workplace.list.CmsListDirectAction#buttonHtml(org.opencms.workplace.CmsWorkplace)
73      */

74     public String JavaDoc buttonHtml(CmsWorkplace wp) {
75
76         if (!isVisible()) {
77             return "";
78         }
79         if (m_type == CmsDependencyIconActionType.RESOURCE) {
80             return super.buttonHtml(wp);
81         } else {
82             return A_CmsHtmlIconButton.defaultButtonHtml(
83                 wp.getJsp(),
84                 resolveButtonStyle(),
85                 getId() + getItem().getId(),
86                 getId(),
87                 resolveName(wp.getLocale()),
88                 resolveHelpText(wp.getLocale()),
89                 isEnabled(),
90                 getIconPath(),
91                 null,
92                 resolveOnClic(wp.getLocale()),
93                 getColumnForTexts() == null);
94         }
95     }
96
97     /**
98      * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
99      */

100     public String JavaDoc getIconPath() {
101
102         if (m_type == CmsDependencyIconActionType.USER) {
103             return PATH_BUTTONS + "user.png";
104         } else if (m_type == CmsDependencyIconActionType.GROUP) {
105             return PATH_BUTTONS + "group.png";
106         } else {
107             return super.getIconPath();
108         }
109     }
110
111     /**
112      * Returns the type.<p>
113      *
114      * @return the type
115      */

116     public CmsDependencyIconActionType getType() {
117
118         return m_type;
119     }
120
121     /**
122      * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
123      */

124     public boolean isVisible() {
125
126         boolean visible = false;
127         if (getItem() != null) {
128             CmsUUID id = new CmsUUID(getItem().getId());
129             try {
130                 if (m_type == CmsDependencyIconActionType.RESOURCE) {
131                     try {
132                         getCms().readUser(id);
133                     } catch (CmsException e1) {
134                         try {
135                             getCms().readGroup(id);
136                         } catch (CmsException e2) {
137                             visible = true;
138                         }
139                     }
140                 } else if (m_type == CmsDependencyIconActionType.USER) {
141                     getCms().readUser(id);
142                     visible = true;
143                 } else if (m_type == CmsDependencyIconActionType.GROUP) {
144                     getCms().readGroup(id);
145                     visible = true;
146                 }
147             } catch (CmsException e) {
148                 // not visible
149
}
150         } else {
151             visible = super.isVisible();
152         }
153         return visible;
154     }
155 }
Popular Tags