KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > faces > component > UIPageForm


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portal.faces.component;
6
7 import java.util.*;
8 import org.exoplatform.faces.core.component.*;
9 import org.exoplatform.faces.core.component.model.*;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.portal.faces.listener.share.ShowLastBodyComponentActionListener;
13 import org.exoplatform.services.portal.model.Page;
14 import org.exoplatform.services.portal.skin.SkinConfigService;
15 import org.exoplatform.services.portal.skin.model.Decorator;
16 import org.exoplatform.services.portal.skin.model.Style;
17 /**
18  * Sat, Jan 03, 2004 @ 11:16
19  * @author: Tuan Nguyen
20  * @email: tuan08@users.sourceforge.net
21  * @version: $Id: UIPageForm.java,v 1.8 2004/09/29 17:44:51 benjmestrallet Exp $
22  */

23 public class UIPageForm extends UISimpleForm {
24   static private List PERMISSIONS = new ArrayList() ;
25   static {
26     PERMISSIONS.add(new SelectItem("owner", "owner"));
27     PERMISSIONS.add(new SelectItem("any", "any"));
28   }
29   
30   private UIPage uiEditingPage_;
31   private SkinConfigService skinService_;
32   private UIStringInput titleInput_;
33   private UIStringInput iconInput_;
34   private UISelectBox viewPermissionInput_;
35   private UISelectBox editPermissionInput_;
36   private UISelectBox decoratorInput_;
37   private UISelectBox rendererInput_;
38   private UIStringInput widthInput_;
39   private UIStringInput heightInput_;
40   private UIStringInput stateInput_;
41   private List styleOptions_;
42   private List rendererOptions_;
43
44   public UIPageForm(SkinConfigService skinService) {
45     super("pageForm", "post", null);
46     setId("UIPageForm");
47     skinService_ = skinService ;
48     titleInput_ = new UIStringInput("title", "");
49     iconInput_ = new UIStringInput("icon", "");
50     viewPermissionInput_ = new UISelectBox("viewPermission", "", PERMISSIONS);
51     editPermissionInput_ = new UISelectBox("editPermission", "", PERMISSIONS);
52     decoratorInput_ = new UISelectBox("decorator", "", null);
53     rendererInput_ = new UISelectBox("renderer", "", null);
54     rendererInput_.setUpdateOnChangeAction("updateStyles");
55     widthInput_ = new UIStringInput("width", "");
56     heightInput_ = new UIStringInput("height", "");
57     stateInput_ = new UIStringInput("state", "");
58     
59     String JavaDoc saveButton = "#{UIPageForm.link.save}";
60     String JavaDoc cancelButton = "#{UIPageForm.link.cancel}";
61     rendererOptions_ = new ArrayList();
62     styleOptions_ = new ArrayList();
63     Iterator i = skinService_.getPageDecorators().iterator() ;
64     while(i.hasNext()) {
65       Decorator decorator = (Decorator) i.next() ;
66       String JavaDoc rendererType = decorator.getRendererType();
67       rendererOptions_.add(new SelectItem(rendererType, rendererType));
68     }
69
70     add((new HeaderRow()).
71          add((new Cell("#{UIPageForm.header.add-edit-page}")).
72               addColspan("2")));
73     add((new Row()).
74          add(new LabelCell("#{UIPageForm.label.page-title}")).
75              add(new ComponentCell(this, titleInput_)));
76     add((new Row()).
77          add(new LabelCell("#{UIPageForm.label.icon}")).
78              add(new ComponentCell(this, iconInput_)));
79     add((new Row()).
80          add(new LabelCell("#{UIPageForm.label.view-permission}")).
81              add(new ComponentCell(this, viewPermissionInput_)));
82     add((new Row()).
83          add(new LabelCell("#{UIPageForm.label.edit-permission}")).
84              add(new ComponentCell(this, editPermissionInput_)));
85     add((new Row()).
86         add(new LabelCell("#{UIPageForm.label.renderer}")).
87             add(new ComponentCell(this, rendererInput_)));
88     add((new Row()).
89          add(new LabelCell("#{UIPageForm.label.decorator}")).
90              add(new ComponentCell(this, decoratorInput_)));
91     add((new Row()).
92          add(new LabelCell("#{UIPageForm.label.width}")).
93              add(new ComponentCell(this, widthInput_)));
94     add((new Row()).
95          add(new LabelCell("#{UIPageForm.label.height}")).
96              add(new ComponentCell(this, heightInput_)));
97     add((new Row()).
98          add(new LabelCell("#{UIPageForm.label.page-state}")).
99              add(new ComponentCell(this, stateInput_)));
100     add((new Row()).
101          add((new ListComponentCell()).
102               add(new FormButton(saveButton, SAVE_ACTION)).
103               add(new FormButton(cancelButton, CANCEL_ACTION)).
104               addColspan("2").addAlign("center")));
105     
106     addActionListener(ShowLastBodyComponentActionListener.class, CANCEL_ACTION) ;
107     addActionListener(SaveActionListener.class, SAVE_ACTION) ;
108   }
109
110   public void setEditingPage(UIPage uiPage) {
111     uiEditingPage_ = uiPage;
112     styleOptions_.clear();
113     Page model = uiPage.getPageModel() ;
114     String JavaDoc currentRenderer = uiPage.getRendererType();
115     String JavaDoc currentDecorator = uiPage.getDecorator();
116     if(currentDecorator == null || currentDecorator.length() == 0)
117       currentDecorator = "default";
118     Decorator decorator = skinService_.getPageDecorator(currentRenderer);
119     List styles = decorator.getStyles();
120     for(int i = 0; i < styles.size(); i++) {
121       Style style = (Style)styles.get(i);
122       String JavaDoc name = style.getName();
123       styleOptions_.add(new SelectItem(name, name));
124     }
125
126     titleInput_.setValue(model.getTitle());
127     iconInput_.setValue(model.getIcon());
128     editPermissionInput_.setValue(uiPage.getEditPermission());
129     viewPermissionInput_.setValue(uiPage.getViewPermission());
130     rendererInput_.setOptions(rendererOptions_);
131     rendererInput_.setValue(currentRenderer);
132     decoratorInput_.setOptions(styleOptions_);
133     decoratorInput_.setValue(currentDecorator);
134     widthInput_.setValue(model.getWidth());
135     heightInput_.setValue(model.getHeight());
136     stateInput_.setValue(model.getState());
137   }
138
139   public void addNewPage() {
140     titleInput_.setValue("");
141     iconInput_.setValue("");
142     rendererInput_.setOptions(rendererOptions_);
143     rendererInput_.setValue("default");
144     decoratorInput_.setOptions(styleOptions_);
145     decoratorInput_.setValue("default");
146     editPermissionInput_.setValue("owner");
147     viewPermissionInput_.setValue("any");
148     widthInput_.setValue("");
149     heightInput_.setValue("");
150     stateInput_.setValue("");
151   }
152   
153   static public class SaveActionListener extends ExoActionListener {
154     public void execute(ExoActionEvent event) throws Exception JavaDoc {
155       UIPageForm uiForm = (UIPageForm) event.getComponent();
156       UIPortal uiPortal = (UIPortal) uiForm.getAncestorOfType(UIPortal.class) ;
157       Page model = uiForm.uiEditingPage_.getEditablePageModel() ;
158       model.setTitle(uiForm.titleInput_.getValue());
159       model.setIcon(uiForm.iconInput_.getValue());
160       model.setViewPermission(uiForm.viewPermissionInput_.getValue());
161       model.setEditPermission(uiForm.editPermissionInput_.getValue());
162       model.setDecorator(uiForm.decoratorInput_.getValue());
163       model.setRenderer(uiForm.rendererInput_.getValue());
164       model.setWidth(uiForm.widthInput_.getValue());
165       model.setHeight(uiForm.heightInput_.getValue());
166       model.setState(uiForm.stateInput_.getValue());
167       uiForm.uiEditingPage_.updateChange() ;
168       uiForm.uiEditingPage_.setComponentModified(true) ;
169       uiPortal.setLastBodyComponent() ;
170     }
171   }
172 }
Popular Tags