1 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.page.ShowCurrentPageActionListener; 13 import org.exoplatform.services.portal.model.PortalConfig; 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 23 public class UIPortalForm extends UISimpleForm { 24 25 private UIStringInput localeInput_ ; 26 private UIStringInput viewPermissionInput_ ; 27 private UIStringInput editPermissionInput_ ; 28 private UISelectBox rendererInput_ ; 29 private List styleOptions_; 31 private List rendererOptions_; 32 33 public UIPortalForm(SkinConfigService service) { 34 super("portalForm", "post", null) ; 35 setId("UIPortalForm") ; 36 localeInput_ = new UIStringInput("defaultLocale", "") ; 37 viewPermissionInput_ = new UIStringInput("viewPermission", "") ; 38 editPermissionInput_ = new UIStringInput("editPermission", "") ; 39 40 rendererOptions_ = new ArrayList(); 41 styleOptions_ = new ArrayList(); 42 Iterator i = service.getPortalDecorators().iterator(); 43 while(i.hasNext()) { 44 Decorator decorator = (Decorator) i.next(); 45 String rendererType = decorator.getRendererType(); 46 rendererOptions_.add(new SelectItem(rendererType, rendererType)); 47 } 48 49 50 Decorator currentDecorator = service.getPortalDecorator("default"); 51 List styles = currentDecorator.getStyles(); 52 for(int j= 0; j < styles.size(); j++) { 53 Style style = (Style)styles.get(j); 54 String name = style.getName(); 55 styleOptions_.add(new SelectItem(name, name)); 56 } 57 58 rendererInput_ = new UISelectBox("renderer", "", rendererOptions_); 59 rendererInput_.setUpdateOnChangeAction("updateStyles"); 60 rendererInput_.setValue(""); 61 62 String saveButton = "#{UIPortalForm.link.save}"; 63 String cancelButton = "#{UIPortalForm.link.cancel}"; 64 add(new HeaderRow(). 65 add(new Cell("#{UIPortalForm.header.edit-portal-config}"). 66 addColspan("2"))); 67 add(new Row(). 68 add(new LabelCell("#{UIPortalForm.label.default-locale}")). 69 add(new ComponentCell(this, localeInput_))); 70 add(new Row(). 71 add(new LabelCell("#{UIPortalForm.label.view-permission}")). 72 add(new ComponentCell(this, viewPermissionInput_))); 73 add(new Row(). 74 add(new LabelCell("#{UIPortalForm.label.edit-permission}")). 75 add(new ComponentCell(this, editPermissionInput_))); 76 add(new Row(). 77 add(new LabelCell("#{UIPortalForm.label.renderer}")). 78 add(new ComponentCell(this, rendererInput_))); 79 add(new Row(). 80 add(new ListComponentCell(). 81 add(new FormButton(saveButton, SAVE_ACTION)). 82 add(new FormButton(cancelButton, CANCEL_ACTION)). 83 addColspan("2").addAlign("center"))) ; 84 85 addActionListener(SaveActionListener.class, SAVE_ACTION) ; 86 addActionListener(ShowCurrentPageActionListener.class, CANCEL_ACTION) ; 87 } 88 89 public void setUIPortal(UIPortal uiPortal) { 90 PortalConfig model = uiPortal.getPortalConfigModel() ; 91 localeInput_.setValue(model.getLocale()) ; 92 viewPermissionInput_.setValue(model.getViewPermission()) ; 93 editPermissionInput_.setValue(model.getEditPermission()) ; 94 rendererInput_.setValue(model.getRenderer()) ; 95 } 96 97 98 static public class SaveActionListener extends ExoActionListener { 99 public void execute(ExoActionEvent event) throws Exception { 100 UIPortalForm uiForm = (UIPortalForm) event.getSource() ; 101 UIPortal uiPortal = (UIPortal) uiForm.getAncestorOfType(UIPortal.class) ; 102 PortalConfig config = uiPortal.getEditablePortalConfigModel() ; 103 config.setLocale(uiForm.localeInput_.getValue()) ; 104 config.setViewPermission(uiForm.viewPermissionInput_.getValue()) ; 105 config.setEditPermission(uiForm.editPermissionInput_.getValue()) ; 106 config.setRenderer(uiForm.rendererInput_.getValue()) ; 107 uiPortal.setBodyComponent(uiPortal.getCurrentUIPage()) ; 108 uiPortal.setComponentModified(true) ; 109 } 110 } 111 } | Popular Tags |