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.share.ShowLastBodyComponentActionListener; 13 import org.exoplatform.services.portal.model.Portlet; 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 import org.exoplatform.services.portletcontainer.pci.ExoWindowID; 18 24 public class UIPortletForm extends UISimpleForm { 25 final static String UPDATE_RENDERER_ACTION = "updateRenderer"; 26 27 private UIPortlet uiEditingPortlet_ ; 28 private SkinConfigService skinService_ ; 29 30 private UIStringInput idInput_ ; 31 private UIStringInput titleInput_ ; 32 private UISelectBox portletStyleInput_ ; 33 private UISelectBox decoratorInput_ ; 34 private UISelectBox rendererInput_ ; 35 private UIStringInput widthInput_ ; 36 private UIStringInput heightInput_ ; 37 private UICheckBox showInfoBarInput_ ; 38 private UICheckBox showWindowStateInput_ ; 39 private UICheckBox showPortletModeInput_ ; 40 private List decoratorOptions_ ; 41 private List portletStyleOptions_ ; 42 private List rendererOptions_ ; 43 44 public UIPortletForm(SkinConfigService configService) { 45 super("portletForm", "post", null) ; 46 setId("UIPortletForm"); 47 skinService_ = configService ; 48 idInput_ = new UIStringInput("id", "") ; 49 idInput_.setEditable(false) ; 50 titleInput_ = new UIStringInput("title", "") ; 51 portletStyleInput_ = new UISelectBox("style", "", null) ; 52 decoratorInput_ = new UISelectBox("decorator", "", null) ; 53 rendererInput_ = new UISelectBox("renderer","" , null) ; 54 rendererInput_.setUpdateOnChangeAction(UPDATE_RENDERER_ACTION) ; 55 heightInput_ = new UIStringInput("height", "") ; 56 widthInput_ = new UIStringInput("width", "") ; 57 showInfoBarInput_ = new UICheckBox("showInfoBar", "true") ; 58 showWindowStateInput_ = new UICheckBox("showWindowState", "true") ; 59 showPortletModeInput_ = new UICheckBox("showPortletMode", "true") ; 60 String saveButton = "#{UIPortletForm.link.save}" ; 61 String cancelButton = "#{UIPortletForm.link.cancel}" ; 62 rendererOptions_ = new ArrayList(5) ; 63 portletStyleOptions_ = new ArrayList(5) ; 64 decoratorOptions_ = new ArrayList(5) ; 65 66 add(new HeaderRow(). 67 add(new Cell("#{UIPortletForm.header.edit-portlet}"). 68 addColspan("2"))); 69 add(new Row(). 70 add(new LabelCell("#{UIPortletForm.label.portlet-id}")). 71 add(new ComponentCell(this, idInput_))); 72 add(new Row(). 73 add(new LabelCell("#{UIPortletForm.label.portlet-title}")). 74 add(new ComponentCell(this, titleInput_))); 75 add(new Row(). 76 add(new LabelCell("#{UIPortletForm.label.renderer}")). 77 add(new ComponentCell(this, rendererInput_))); 78 add(new Row(). 79 add(new LabelCell("#{UIPortletForm.label.style}")). 80 add(new ComponentCell(this, portletStyleInput_))); 81 add(new Row(). 82 add(new LabelCell("#{UIPortletForm.label.decorator}")). 83 add(new ComponentCell(this, decoratorInput_))); 84 add(new Row(). 85 add(new LabelCell("#{UIPortletForm.label.width}")). 86 add(new ComponentCell(this, widthInput_))); 87 add(new Row(). 88 add(new LabelCell("#{UIPortletForm.label.height}")). 89 add(new ComponentCell(this, heightInput_))); 90 add(new Row(). 91 add(new LabelCell("#{UIPortletForm.label.show-info-bar}")). 92 add(new ComponentCell(this, showInfoBarInput_))); 93 add(new Row(). 94 add(new LabelCell("#{UIPortletForm.label.show-portlet-mode}")). 95 add(new ComponentCell(this, showPortletModeInput_))); 96 add(new Row(). 97 add(new LabelCell("#{UIPortletForm.label.show-window-state}")). 98 add(new ComponentCell(this, showWindowStateInput_))); 99 add(new Row(). 100 add(new ListComponentCell(). 101 add(new FormButton(saveButton, SAVE_ACTION)). 102 add(new FormButton(cancelButton, CANCEL_ACTION)). 103 addColspan("2").addAlign("center"))) ; 104 105 addActionListener(ShowLastBodyComponentActionListener.class, CANCEL_ACTION) ; 106 addActionListener(SaveActionListener.class, SAVE_ACTION) ; 107 addActionListener(UpdateRendererActionListener.class, UPDATE_RENDERER_ACTION) ; 108 } 109 110 public void setEditingPortlet(UIPortlet uiPortlet) { 111 uiEditingPortlet_ = uiPortlet ; 112 rendererOptions_.clear() ; 113 portletStyleOptions_.clear() ; 114 decoratorOptions_.clear() ; 115 ExoWindowID windowID = uiEditingPortlet_.getWindowId() ; 116 String portletId = windowID.getPortletApplicationName() + "/" + windowID.getPortletName() ; 117 Portlet model = uiPortlet.getPortletModel() ; 118 Iterator decoratorIterator = skinService_.getPortletDecorators().iterator() ; 119 String currentRenderer = uiPortlet.getRendererType() ; 120 Decorator selectDecorator = null ; 121 while(decoratorIterator.hasNext()) { 122 Decorator decorator = (Decorator) decoratorIterator.next() ; 123 String rendererType = decorator.getRendererType() ; 124 rendererOptions_.add(new SelectItem(rendererType, rendererType)) ; 125 if (selectDecorator == null) { 126 selectDecorator = decorator ; 127 }else if(currentRenderer.equals(rendererType)) { 128 selectDecorator = decorator ; 129 } 130 } 131 132 List styles = selectDecorator.getStyles() ; 133 for (int i = 0; i < styles.size(); i++) { 134 Style style = (Style) styles.get(i) ; 135 String name = style.getName() ; 136 decoratorOptions_.add(new SelectItem(name, name)) ; 137 } 138 139 List portletStyles = skinService_.getPortletStyles(portletId) ; 140 if(portletStyles == null) { 141 portletStyles = skinService_.getPortletStyles("default") ; 142 } 143 for (int i = 0; i < portletStyles.size(); i++) { 144 Style style = (Style) portletStyles.get(i) ; 145 String name = style.getName() ; 146 portletStyleOptions_.add(new SelectItem(name, name)) ; 147 } 148 149 idInput_.setValue(uiPortlet.getId()) ; 150 titleInput_.setValue(model.getTitle()) ; 151 rendererInput_.setOptions(rendererOptions_); 152 rendererInput_.setValue(currentRenderer); 153 decoratorInput_.setOptions(decoratorOptions_); 154 decoratorInput_.setValue(model.getDecorator()); 155 portletStyleInput_.setOptions(portletStyleOptions_); 156 portletStyleInput_.setValue(model.getPortletStyle()); 157 widthInput_.setValue(model.getWidth()) ; 158 heightInput_.setValue(model.getHeight()) ; 159 showInfoBarInput_.setSelect(model.getShowInfoBar()) ; 160 showWindowStateInput_.setSelect(model.getShowWindowState()) ; 161 showPortletModeInput_.setSelect(model.getShowPortletMode()) ; 162 } 163 164 static public class UpdateRendererActionListener extends ExoActionListener { 165 public void execute(ExoActionEvent event) throws Exception { 166 UIPortletForm uiForm = (UIPortletForm) event.getSource() ; 167 String selectRenderer = uiForm.rendererInput_.getValue() ; 168 Decorator selectDecorator = uiForm.skinService_.getPortletDecorator(selectRenderer) ; 169 uiForm.decoratorOptions_.clear() ; 170 List styles = selectDecorator.getStyles() ; 171 String decoratorDefaultStyle = "default" ; 172 for (int i = 0; i < styles.size(); i++) { 173 Style style = (Style) styles.get(i) ; 174 String name = style.getName() ; 175 uiForm.decoratorOptions_.add(new SelectItem(name, name)) ; 176 if(i == 0) decoratorDefaultStyle = name ; 177 } 178 uiForm.rendererInput_.setValue(selectRenderer); 179 uiForm.decoratorInput_.setOptions(uiForm.decoratorOptions_); 180 uiForm.decoratorInput_.setValue(decoratorDefaultStyle); 181 } 182 } 183 184 static public class SaveActionListener extends ExoActionListener { 185 public void execute(ExoActionEvent event) throws Exception { 186 UIPortletForm uiForm = (UIPortletForm) event.getSource() ; 187 UIPortal uiPortal = (UIPortal) uiForm.getAncestorOfType(UIPortal.class); 188 Portlet model = uiForm.uiEditingPortlet_.getEditablePortletModel() ; 189 String portletTitle = uiForm.titleInput_.getValue() ; 190 if(portletTitle == null || portletTitle.length() == 0) portletTitle = null ; 191 model.setTitle(portletTitle) ; 192 model.setDecorator(uiForm.decoratorInput_.getValue()) ; 193 model.setPortletStyle(uiForm.portletStyleInput_.getValue()) ; 194 model.setRenderer(uiForm.rendererInput_.getValue()) ; 195 model.setWidth(uiForm.widthInput_.getValue()) ; 196 model.setHeight(uiForm.heightInput_.getValue()) ; 197 model.setShowInfoBar(uiForm.showInfoBarInput_.getSelect()) ; 198 model.setShowWindowState(uiForm.showWindowStateInput_.getSelect()) ; 199 model.setShowPortletMode(uiForm.showPortletModeInput_.getSelect()) ; 200 String id = uiForm.idInput_.getValue() ; 201 ExoWindowID windowId = uiForm.uiEditingPortlet_.getWindowId() ; 202 if(id == null || id.length() == 0) id = windowId.getPortletName() ; 203 windowId.setUniqueID(id) ; 204 model.setWindowId(windowId.generatePersistenceId()) ; 205 uiForm.uiEditingPortlet_.setId(id); 206 uiForm.uiEditingPortlet_.setDisplayTitle(portletTitle); 207 uiForm.uiEditingPortlet_.updateChange() ; 208 uiForm.uiEditingPortlet_.setComponentModified(true) ; 209 uiPortal.setLastBodyComponent() ; 210 } 211 } 212 } | Popular Tags |