001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.core.admin.ui.dashboard;
023:
024: import org.jboss.portal.common.util.IteratorStatus;
025: import org.jboss.portal.core.admin.ui.actions.AddPageAction;
026: import org.jboss.portal.core.admin.ui.common.PageManagerBean;
027: import org.jboss.portal.core.admin.ui.portlet.PortletDefinitionInvoker;
028: import org.jboss.portal.core.model.instance.InstanceContainer;
029: import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
030: import org.jboss.portal.core.model.portal.Page;
031: import org.jboss.portal.core.model.portal.Portal;
032: import org.jboss.portal.core.model.portal.PortalObject;
033: import org.jboss.portal.core.model.portal.PortalObjectContainer;
034: import org.jboss.portal.core.model.portal.PortalObjectId;
035: import org.jboss.portal.core.model.portal.PortalObjectPath;
036: import org.jboss.portal.theme.LayoutService;
037: import org.jboss.portal.theme.ThemeConstants;
038: import org.jboss.portal.theme.ThemeService;
039:
040: import javax.faces.context.FacesContext;
041: import javax.faces.model.SelectItem;
042: import java.util.Collection;
043:
044: /**
045: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
046: * @version $Revision: 9130 $
047: */
048: public class DashboardBean implements AddPageAction.Listener {
049:
050: /** . */
051: private static final PortalObjectId dashboardId = PortalObjectId
052: .parse("dashboard" + PortalObjectId.NAMESPACE_SEPARATOR
053: + PortalObjectPath.CanonicalFormat.PATH_SEPARATOR,
054: PortalObjectPath.CANONICAL_FORMAT);
055:
056: // Wired services
057:
058: /** . */
059: public PortalObjectContainer portalObjectContainer;
060:
061: /** . */
062: public LayoutService layoutService;
063:
064: /** . */
065: public ThemeService themeService;
066:
067: /** . */
068: public InstanceContainer instanceContainer;
069:
070: // Navigational state
071:
072: /** . */
073: public String selectedPageName;
074:
075: // Runtime fields
076:
077: /** . */
078: public Portal userPortal;
079:
080: /** . */
081: public String selectedPageTheme;
082:
083: /** . */
084: public String selectedPageLayout;
085:
086: /** . */
087: public PageManagerBean pageManager;
088:
089: /** . */
090: public SelectItem[] pageItems;
091:
092: /** . */
093: public boolean selectePageIsDefault;
094:
095: //
096:
097: public void pageCreated(Page page) {
098: // Select page to show
099: selectedPageName = page.getName();
100: }
101:
102: public void actionRefresh() {
103: refresh();
104: }
105:
106: public Page getSelectedPage() {
107: return pageManager.page;
108: }
109:
110: private void refresh() {
111: // Create page manager if it does not exit
112: if (pageManager == null) {
113: pageManager = new PageManagerBean(layoutService,
114: new PortletDefinitionInvoker(instanceContainer));
115: }
116:
117: // Get user name
118: String userId = FacesContext.getCurrentInstance()
119: .getExternalContext().getRemoteUser();
120:
121: // Load portal
122: userPortal = (Portal) portalObjectContainer.getObject(
123: dashboardId).getChild(userId);
124:
125: if (userPortal == null) {
126: return;
127: }
128:
129: // Page for editing
130: if (selectedPageName != null) {
131: pageManager.page = userPortal.getPage(selectedPageName);
132: }
133: if (pageManager.page == null) {
134: pageManager.page = userPortal.getDefaultPage();
135: selectedPageName = pageManager.page.getName();
136: }
137:
138: //
139: String defaultPageName = pageManager.page
140: .getProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME);
141: if (defaultPageName == null) {
142: defaultPageName = PortalObject.DEFAULT_OBJECT_NAME;
143: }
144: selectePageIsDefault = selectedPageName.equals(defaultPageName);
145:
146: //
147: Collection pages = userPortal
148: .getChildren(PortalObject.PAGE_MASK);
149: pageItems = new SelectItem[pages.size()];
150: for (IteratorStatus i = new IteratorStatus(pages); i.hasNext();) {
151: PortalObject object = (PortalObject) i.next();
152: SelectItem item = new SelectItem();
153: item.setValue(object.getName());
154: item.setLabel(object.getName());
155: pageItems[i.getIndex()] = item;
156: }
157: }
158:
159: public void renderRefresh() {
160: refresh();
161:
162: if (userPortal != null) {
163: //
164: selectedPageTheme = userPortal
165: .getDeclaredProperty(ThemeConstants.PORTAL_PROP_THEME);
166: if (selectedPageTheme == null) {
167: selectedPageTheme = "";
168: }
169:
170: //
171: selectedPageLayout = userPortal
172: .getDeclaredProperty(ThemeConstants.PORTAL_PROP_LAYOUT);
173: if (selectedPageLayout == null) {
174: selectedPageLayout = "";
175: }
176: }
177: }
178:
179: public void updateTheme() {
180: userPortal.setDeclaredProperty(
181: ThemeConstants.PORTAL_PROP_THEME, ""
182: .equals(selectedPageTheme) ? null
183: : selectedPageTheme);
184: }
185:
186: public void updateLayout() {
187: userPortal.setDeclaredProperty(
188: ThemeConstants.PORTAL_PROP_LAYOUT, ""
189: .equals(selectedPageLayout) ? null
190: : selectedPageLayout);
191: }
192:
193: public void destroyPage() {
194: try {
195: userPortal.destroyChild(selectedPageName);
196:
197: // Fallback to default page
198: String defaultPageName = pageManager.page
199: .getProperty(PortalObject.PORTAL_PROP_DEFAULT_OBJECT_NAME);
200: if (defaultPageName == null) {
201: defaultPageName = PortalObject.DEFAULT_OBJECT_NAME;
202: }
203: selectedPageName = defaultPageName;
204: } catch (NoSuchPortalObjectException e) {
205: e.printStackTrace();
206: }
207: }
208:
209: public PortalObjectContainer getPortalObjectContainer() {
210: return portalObjectContainer;
211: }
212:
213: public void setPortalObjectContainer(
214: PortalObjectContainer portalObjectContainer) {
215: this .portalObjectContainer = portalObjectContainer;
216: }
217:
218: public LayoutService getLayoutService() {
219: return layoutService;
220: }
221:
222: public void setLayoutService(LayoutService layoutService) {
223: this .layoutService = layoutService;
224: }
225:
226: public ThemeService getThemeService() {
227: return themeService;
228: }
229:
230: public void setThemeService(ThemeService themeService) {
231: this .themeService = themeService;
232: }
233:
234: public InstanceContainer getInstanceContainer() {
235: return instanceContainer;
236: }
237:
238: public void setInstanceContainer(InstanceContainer instanceContainer) {
239: this.instanceContainer = instanceContainer;
240: }
241: }
|