1 5 package org.exoplatform.faces.core.component; 6 7 import org.exoplatform.commons.utils.HtmlUtil; 8 import org.exoplatform.faces.core.component.UISimpleForm; 9 import org.exoplatform.faces.core.component.UITextArea; 10 import org.exoplatform.faces.core.component.model.ComponentCell; 11 import org.exoplatform.faces.core.component.model.FormButton; 12 import org.exoplatform.faces.core.component.model.ListComponentCell; 13 import org.exoplatform.faces.core.component.model.Row; 14 import org.exoplatform.faces.core.event.ExoActionEvent; 15 import org.exoplatform.faces.core.event.ExoActionListener; 16 22 public class UIText extends UISimpleForm { 23 final static public String PREVIEW_MODE_ACTION = "previewMode" ; 24 final static public String EDIT_MODE_ACTION = "editMode" ; 25 26 private UITextArea textInput_ ; 27 private ListComponentCell actions_ ; 28 29 public UIText() { 30 super("textForm", "post", null) ; 31 setId("UIText"); 32 textInput_ = new UITextArea("text" , "") ; 33 add(new Row(). 34 add(new ComponentCell(this, textInput_))) ; 35 actions_ = new ListComponentCell() ; 36 add(new Row(). 37 add(actions_.addColspan("2").addAlign("center"))) ; 38 } 39 40 public void addEditButton(String label, String action, Class listener) { 41 actions_.add(new FormButton(label, action, EDIT_MODE)) ; 42 addActionListener(listener, action) ; 43 } 44 45 public void addViewButton(String label, String action, Class listener) { 46 actions_.add(new FormButton(label, action, VIEW_MODE)) ; 47 addActionListener(listener, action) ; 48 } 49 50 public String getText() { return textInput_.getValue(); } 51 public void setText(String page) { 52 if (page != null) textInput_.setValue(page) ; 53 else textInput_.setValue("") ; 54 } 55 56 public void setXMLText(String text) { 57 if (text != null) { 58 text = HtmlUtil.showXmlTags(text) ; 59 textInput_.setValue(text) ; 60 } else { 61 textInput_.setValue("") ; 62 } 63 } 64 65 public class PreviewModeActionListener extends ExoActionListener { 66 public void execute(ExoActionEvent event) throws Exception { 67 UIText uiText = (UIText) event.getSource(); 68 uiText.setMode(VIEW_MODE) ; 69 } 70 } 71 72 public class EditModeActionListener extends ExoActionListener { 73 public void execute(ExoActionEvent event) throws Exception { 74 UIText uiText = (UIText) event.getSource(); 75 uiText.setMode(VIEW_MODE) ; 76 } 77 } 78 } | Popular Tags |