1 5 package org.exoplatform.portlets.content.display.component; 6 7 import org.exoplatform.container.SessionContainer; 8 import org.exoplatform.faces.core.component.UIHtmlTextArea; 9 import org.exoplatform.faces.core.component.UISimpleForm; 10 import org.exoplatform.faces.core.component.UIStringInput; 11 import org.exoplatform.faces.core.component.model.*; 12 import org.exoplatform.faces.core.event.ExoActionEvent; 13 import org.exoplatform.faces.core.event.ExoActionListener; 14 import org.exoplatform.faces.core.validator.EmptyFieldValidator; 15 import org.exoplatform.portal.session.ExoPortal; 16 import org.exoplatform.portlets.content.ContentUtil; 17 import org.exoplatform.portlets.content.display.component.model.ContentConfig; 18 import org.exoplatform.services.portal.model.Node; 19 28 public class UIContentEditor extends UISimpleForm { 29 30 private UIStringInput nameInput_; 31 private UIStringInput titleInput_; 32 private UIHtmlTextArea editorInput_; 33 private ContentConfig config_; 34 35 public UIContentEditor() { 36 super("editorForm", "post", null); 37 setId("UIContentEditor"); 38 setClazz("UIContentEditor"); 39 nameInput_ = new UIStringInput("name", ""). 40 addValidator(EmptyFieldValidator.class) ; 41 titleInput_ = new UIStringInput("title", ""). 42 addValidator(EmptyFieldValidator.class) ; 43 editorInput_ = new UIHtmlTextArea("htmlEditor", "", "100%", "500px") ; 44 add(new HeaderRow(). 45 add(new Cell("#{UIContentEditor.header.content-html-editor-form}"). 46 addColspan("2"))); 47 add(new Row(). 48 add(new LabelCell("#{UIContentEditor.label.name}")). 49 add(new ComponentCell(this, nameInput_))); 50 add(new Row(). 51 add(new LabelCell("#{UIContentEditor.label.title}")). 52 add(new ComponentCell(this, titleInput_))); 53 add(new Row(). 54 add(new ComponentCell(this, editorInput_).addColspan("2"))); 55 add(new Row(). 56 add(new ListComponentCell(). 57 add(new FormButton("#{UIContentEditor.button.save}", SAVE_ACTION)). 58 add(new FormButton("#{UIContentEditor.button.cancel}", CANCEL_ACTION)). 59 addColspan("2").addAlign("center"))); 60 addActionListener(CancelActionListener.class, CANCEL_ACTION) ; 61 addActionListener(SaveActionListener.class, SAVE_ACTION) ; 62 } 63 64 public ContentConfig getContentConfig() { return config_; } 65 66 public void setContentConfig(ContentConfig config) { 67 config_ = config; 68 if (config == null) { 69 nameInput_.setText(""); 70 titleInput_.setText(""); 71 editorInput_.setValue(""); 72 } else { 73 nameInput_.setText(config.getName()); 74 titleInput_.setText(config.getTitle()); 75 ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ; 76 Node selectedNode = portal.getSelectedNode(); 77 String content = ContentUtil.resolveContent(config, selectedNode); 78 if(content == null){ 79 content = "No content found"; 80 } 81 content = content.replaceAll("<", "<"); 82 content = content.replaceAll(">", ">"); 83 editorInput_.setValue(content); 84 } 85 } 86 87 88 static public class CancelActionListener extends ExoActionListener { 89 public void execute(ExoActionEvent event) throws Exception { 90 UIContentEditor uiEditor = (UIContentEditor) event.getSource() ; 91 uiEditor.setRenderedSibling(UIContentConfig.class) ; 92 } 93 } 94 95 static public class SaveActionListener extends ExoActionListener { 96 public void execute(ExoActionEvent event) throws Exception { 97 UIContentEditor uiEditor = (UIContentEditor) event.getSource() ; 98 if (uiEditor.config_ == null) { 99 uiEditor.config_ = new ContentConfig(); 100 } 101 uiEditor.config_.setName(uiEditor.nameInput_.getValue()); 102 uiEditor.config_.setTitle(uiEditor.titleInput_.getValue()); 103 104 uiEditor.config_.setContent(uiEditor.editorInput_.getValue()); 105 UIContentConfig uiConfig = 106 (UIContentConfig)uiEditor.getSibling(UIContentConfig.class); 107 uiConfig.saveContentConfig(ContentUtil.MODIFY_STATE, uiEditor.config_); 108 uiEditor.setRenderedSibling(UIContentConfig.class) ; 109 } 110 } 111 } | Popular Tags |