1 5 package org.exoplatform.portlets.content.display.component; 6 7 import org.exoplatform.faces.application.ExoFacesMessage; 8 import org.exoplatform.faces.core.component.InformationProvider; 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.portlets.content.ContentUtil; 15 import org.exoplatform.portlets.content.display.component.model.ContentConfig; 16 17 18 24 public class UIContentConfigForm extends UISimpleForm { 25 26 private UIStringInput nameInput_ ; 27 private UIStringInput titleInput_ ; 28 private UIStringInput uriInput_ ; 29 private UIStringInput encodingInput_ ; 30 private ContentConfig config_ ; 31 32 public UIContentConfigForm() { 33 super("configForm", "post", null) ; 34 setId("UIContentConfigForm") ; 35 setClazz("UIContentConfigForm") ; 36 nameInput_ = new UIStringInput("name", "") ; 37 titleInput_ = new UIStringInput("title", "") ; 38 uriInput_ = new UIStringInput("uri", "") ; 39 encodingInput_ = new UIStringInput("encoding", "") ; 40 41 add(new HeaderRow(). 42 add(new Cell("#{UIContentConfigForm.header.content-config-form}"). 43 addColspan("2"))); 44 add(new Row(). 45 add(new LabelCell("#{UIContentConfigForm.label.name}")). 46 add(new ComponentCell(this, nameInput_))); 47 add(new Row(). 48 add(new LabelCell("#{UIContentConfigForm.label.title}")). 49 add(new ComponentCell(this, titleInput_))); 50 add(new Row(). 51 add(new LabelCell("#{UIContentConfigForm.label.uri}")). 52 add(new ComponentCell(this, uriInput_))); 53 add(new Row(). 54 add(new LabelCell("#{UIContentConfigForm.label.encoding}")). 55 add(new ComponentCell(this, encodingInput_))); 56 add(new Row(). 57 add(new ListComponentCell(). 58 add(new FormButton("#{UIContentConfigForm.button.save}", SAVE_ACTION)). 59 add(new FormButton("#{UIContentConfigForm.button.cancel}", CANCEL_ACTION)). 60 addColspan("2").addAlign("center"))) ; 61 addActionListener(SaveActionListener.class, SAVE_ACTION) ; 62 addActionListener(CancelActionListener.class, CANCEL_ACTION) ; 63 } 64 65 public void setContentConfig(ContentConfig config) { 66 config_ = config ; 67 if (config == null) { 68 nameInput_.setText("") ; 69 nameInput_.setEditable(true) ; 70 titleInput_.setText("") ; 71 uriInput_.setText("") ; 72 encodingInput_.setText("") ; 73 } else { 74 nameInput_.setText(config.getName()) ; 75 nameInput_.setEditable(false) ; 76 titleInput_.setText(config.getTitle()) ; 77 uriInput_.setText(config.getUri()) ; 78 encodingInput_.setText(config.getEncoding()) ; 79 } 80 } 81 82 83 static public class CancelActionListener extends ExoActionListener { 84 public void execute(ExoActionEvent event) throws Exception { 85 UIContentConfigForm uiForm = (UIContentConfigForm) event.getComponent() ; 86 uiForm.setRenderedSibling(UIContentConfig.class) ; 87 } 88 } 89 90 static public class SaveActionListener extends ExoActionListener { 91 public void execute(ExoActionEvent event) throws Exception { 92 UIContentConfigForm uiForm = (UIContentConfigForm) event.getComponent() ; 93 if(uiForm.config_ == null) { 94 uiForm.config_ = new ContentConfig() ; 95 } 96 String name = uiForm.nameInput_.getValue() ; 97 if(name == null || name.length() == 0) { 98 InformationProvider iprovider = findInformationProvider(uiForm) ; 99 iprovider.addMessage(new ExoFacesMessage("#{UIContentConfigForm.msg.name-is-null}")) ; 100 return ; 101 } 102 uiForm.config_.setName(name); 103 uiForm.config_.setTitle( uiForm.titleInput_.getValue()); 104 uiForm.config_.setUri( uiForm.uriInput_.getValue()); 105 String encoding = uiForm.encodingInput_.getValue(); 106 if(encoding == null || "".equals(encoding)){ 107 encoding = "UTF-8"; 108 } 109 uiForm.config_.setEncoding(encoding); 110 UIContentConfig uiConfig = (UIContentConfig)uiForm.getSibling(UIContentConfig.class) ; 111 uiConfig.saveContentConfig(ContentUtil.EDIT_STATE, uiForm.config_) ; 112 uiForm.setRenderedSibling(UIContentConfig.class) ; 113 } 114 } 115 } | Popular Tags |