KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > projects > A_CmsProjectDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/A_CmsProjectDialog.java,v $
3  * Date : $Date: 2005/06/25 11:19:03 $
4  * Version: $Revision: 1.7 $
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.projects;
33
34 import org.opencms.db.CmsUserProjectSettings;
35 import org.opencms.db.CmsUserSettings;
36 import org.opencms.file.CmsGroup;
37 import org.opencms.jsp.CmsJspActionElement;
38 import org.opencms.main.CmsException;
39 import org.opencms.main.CmsIllegalArgumentException;
40 import org.opencms.util.CmsUUID;
41 import org.opencms.widgets.CmsSelectWidgetOption;
42 import org.opencms.workplace.CmsWidgetDialog;
43
44 import java.util.ArrayList JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47
48 /**
49  * Base Dialog for project related dialogs.<p>
50  *
51  * @author Michael Moossen
52  *
53  * @version $Revision: 1.7 $
54  *
55  * @since 6.0.0
56  */

57 public abstract class A_CmsProjectDialog extends CmsWidgetDialog {
58
59     /** Defines which pages are valid for this dialog. */
60     public static final String JavaDoc[] PAGES = {"page1"};
61
62     /** Auxiliary Property for better representation of the bean managerGroupId property. */
63     private String JavaDoc m_managerGroup;
64
65     /** Auxiliary Property for better representation of the bean groupId property. */
66     private String JavaDoc m_userGroup;
67
68     /**
69      * Public constructor with JSP action element.<p>
70      *
71      * @param jsp an initialized JSP action element
72      */

73     public A_CmsProjectDialog(CmsJspActionElement jsp) {
74
75         super(jsp);
76     }
77
78     /**
79      * Returns the manager Group name.<p>
80      *
81      * @return the manager Group name
82      */

83     public String JavaDoc getManagerGroup() {
84
85         return m_managerGroup;
86     }
87
88     /**
89      * Returns the user Group name.<p>
90      *
91      * @return the user Group name
92      */

93     public String JavaDoc getUserGroup() {
94
95         return m_userGroup;
96     }
97
98     /**
99      * Sets the manager Group name.<p>
100      *
101      * @param managerGroup the manager Group name to set
102      */

103     public void setManagerGroup(String JavaDoc managerGroup) {
104
105         checkGroup(managerGroup);
106         m_managerGroup = managerGroup;
107     }
108
109     /**
110      * Sets the user Group name.<p>
111      *
112      * @param userGroup the user Group name to set
113      */

114     public void setUserGroup(String JavaDoc userGroup) {
115
116         checkGroup(userGroup);
117         m_userGroup = userGroup;
118     }
119
120     /**
121      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
122      */

123     protected String JavaDoc[] getPageArray() {
124
125         return PAGES;
126     }
127
128     /**
129      * Returns the groups names to show in the select box.<p>
130      *
131      * @param pManager project manager group selection flag
132      *
133      * @return the groups names to show in the select box
134      */

135     protected List JavaDoc getSelectGroups(boolean pManager) {
136
137         List JavaDoc retVal = new ArrayList JavaDoc();
138         CmsUUID defaultGroup = null;
139         CmsUserProjectSettings settings = new CmsUserSettings(getCms()).getProjectSettings();
140         if (settings != null) {
141             if (pManager) {
142                 defaultGroup = settings.getManagerGroup();
143             } else {
144                 defaultGroup = settings.getUserGroup();
145             }
146         }
147         try {
148             Iterator JavaDoc itGroups = getCms().getGroups().iterator();
149             while (itGroups.hasNext()) {
150                 CmsGroup group = (CmsGroup)itGroups.next();
151                 if (!pManager || group.getProjectManager()) {
152                     if (group.getId().equals(defaultGroup)) {
153                         retVal.add(new CmsSelectWidgetOption(group.getName(), true));
154                     } else {
155                         retVal.add(new CmsSelectWidgetOption(group.getName()));
156                     }
157                 }
158             }
159         } catch (Exception JavaDoc e) {
160             // noop
161
}
162         return retVal;
163     }
164
165     /**
166      * @see org.opencms.workplace.CmsWorkplace#initMessages()
167      */

168     protected void initMessages() {
169
170         // add specific dialog resource bundle
171
addMessages(Messages.get().getBundleName());
172         // add default resource bundles
173
super.initMessages();
174     }
175
176     /**
177      * Checks if the given group name is a valid opencms user group.<p>
178      *
179      * @param groupName the group name to chek
180      */

181     private void checkGroup(String JavaDoc groupName) {
182
183         try {
184             getCms().readGroup(groupName);
185         } catch (CmsException e) {
186             throw new CmsIllegalArgumentException(e.getMessageContainer());
187         }
188     }
189 }
Popular Tags