KickJava   Java API By Example, From Geeks To Geeks.

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


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.Container;
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: UIContainerForm.java,v 1.11 2004/11/03 01:19:45 tuan08 Exp $
22  */

23 public class UIContainerForm extends UISimpleForm {
24   
25   private UIContainer uiEditingContainer_ ;
26   private UIBasicComponent uiParent_ ;
27   private SkinConfigService configService_ ;
28
29   private UIStringInput idInput_ ;
30   private UIStringInput titleInput_ ;
31   private UISelectBox styleInput_ ;
32   private UISelectBox rendererInput_ ;
33   private UIStringInput widthInput_ ;
34   private UIStringInput heightInput_ ;
35   private List styleOptions_ ;
36   private List rendererOptions_ ;
37
38   public UIContainerForm(SkinConfigService configService) {
39     super("containerForm", "post", null) ;
40     setId("UIContainerForm");
41     configService_ = configService ;
42     idInput_ = new UIStringInput("id", "") ;
43     idInput_.setEditable(false) ;
44     titleInput_ = new UIStringInput("title", "") ;
45     styleInput_ = new UISelectBox("style", "", null) ;
46     rendererInput_ = new UISelectBox("renderer","" , null) ;
47     widthInput_ = new UIStringInput("width", "") ;
48     heightInput_ = new UIStringInput("height", "") ;
49     String JavaDoc saveButton = "#{UIContainerForm.link.save}";
50     String JavaDoc cancelButton = "#{UIContainerForm.link.cancel}";
51     rendererOptions_ = new ArrayList() ;
52     styleOptions_ = new ArrayList() ;
53     Iterator i = configService_.getContainerDecorators().iterator() ;
54     while(i.hasNext()) {
55       Decorator decorator = (Decorator) i.next() ;
56       String JavaDoc rendererType = decorator.getRendererType() ;
57       rendererOptions_.add(new SelectItem(rendererType, rendererType)) ;
58     }
59
60     add(new HeaderRow().
61         add(new Cell("#{UIContainerForm.header.add-edit-container}").
62             addColspan("2")));
63     add(new Row().
64         add(new LabelCell("#{UIContainerForm.label.container-id}")).
65         add(new ComponentCell(this, idInput_)));
66     add((new Row()).
67         add(new LabelCell("#{UIContainerForm.label.container-title}")).
68             add(new ComponentCell(this, titleInput_)));
69     add(new Row().
70         add(new LabelCell("#{UIContainerForm.label.renderer}")).
71         add(new ComponentCell(this, rendererInput_)));
72     add(new Row().
73         add(new LabelCell("#{UIContainerForm.label.style}")).
74         add(new ComponentCell(this, styleInput_)));
75     add(new Row().
76         add(new LabelCell("#{UIContainerForm.label.width}")).
77         add(new ComponentCell(this, widthInput_)));
78     add(new Row().
79         add(new LabelCell("#{UIContainerForm.label.height}")).
80         add(new ComponentCell(this, heightInput_)));
81     add(new Row().
82         add(new ListComponentCell().
83             add(new FormButton(saveButton, SAVE_ACTION)).
84             add(new FormButton(cancelButton, CANCEL_ACTION)).
85             addColspan("2").addAlign("center"))) ;
86     
87     addActionListener(SaveActionListener.class, SAVE_ACTION) ;
88     addActionListener(ShowLastBodyComponentActionListener.class, CANCEL_ACTION) ;
89   }
90   
91   public void setEditingContainer(UIContainer uiContainer) {
92     uiEditingContainer_ = uiContainer ;
93     styleOptions_.clear() ;
94     Container model = uiContainer.getContainerModel() ;
95     String JavaDoc currentRenderer = uiContainer.getRendererType() ;
96
97     String JavaDoc currentStyle = uiContainer.getDecorator() ;
98     if(currentStyle == null || currentStyle.length() == 0) {
99       currentStyle = "default" ;
100     }
101
102     Decorator decorator = configService_.getContainerDecorator(currentRenderer) ;
103     List styles = decorator.getStyles() ;
104     for (int i = 0; i < styles.size(); i++) {
105       Style style = (Style) styles.get(i) ;
106       String JavaDoc name = style.getName() ;
107       styleOptions_.add(new SelectItem(name, name)) ;
108     }
109     
110     idInput_.setValue(uiContainer.getId());
111     rendererInput_.setOptions(rendererOptions_);
112     rendererInput_.setValue(currentRenderer);
113     styleInput_.setOptions(styleOptions_);
114     styleInput_.setValue(currentStyle);
115     widthInput_.setValue(model.getWidth()) ;
116     heightInput_.setValue(model.getHeight()) ;
117   }
118   
119   public void addNewContainer(UIBasicComponent uiParent) {
120     uiEditingContainer_ = null ;
121     uiParent_ = uiParent ;
122     styleOptions_.clear() ;
123     Decorator decorator = configService_.getContainerDecorator("default") ;
124     List styles = decorator.getStyles() ;
125     for (int i = 0; i < styles.size(); i++) {
126       Style style = (Style) styles.get(i) ;
127       String JavaDoc name = style.getName() ;
128       styleOptions_.add(new SelectItem(name, name)) ;
129     }
130     
131     idInput_.setValue("");
132     rendererInput_.setOptions(rendererOptions_);
133     rendererInput_.setValue("default");
134     styleInput_.setOptions(styleOptions_);
135     styleInput_.setValue("default");
136     widthInput_.setValue("") ;
137     heightInput_.setValue("") ;
138   }
139   
140   static public class SaveActionListener extends ExoActionListener {
141         public void execute(ExoActionEvent event) throws Exception JavaDoc {
142       UIContainerForm uiForm = (UIContainerForm) event.getSource() ;
143             UIPortal uiPortal = (UIPortal) uiForm.getAncestorOfType(UIPortal.class) ;
144           if(uiForm.uiEditingContainer_ == null) {
145         List children = uiForm.uiParent_.getChildren() ;
146         uiForm.uiEditingContainer_ = new UIContainer(new Container()) ;
147         children.add(uiForm.uiEditingContainer_) ;
148       }
149           Container model = uiForm.uiEditingContainer_.getEditableContainerModel() ;
150       model.setDecorator(uiForm.styleInput_.getValue()) ;
151       model.setRenderer(uiForm.rendererInput_.getValue()) ;
152       model.setWidth(uiForm.widthInput_.getValue()) ;
153       model.setHeight(uiForm.heightInput_.getValue()) ;
154       model.setId(uiForm.idInput_.getValue()) ;
155       model.setTitle(uiForm.titleInput_.getValue()) ;
156       uiForm.uiEditingContainer_.updateChange() ;
157       uiForm.uiEditingContainer_.setId(uiForm.idInput_.getValue()) ;
158       uiForm.uiEditingContainer_.setComponentModified(true) ;
159       uiPortal.setLastBodyComponent() ;
160         }
161     }
162 }
Popular Tags