1 5 6 package org.exoplatform.portlets.portletregistery.component; 7 8 import org.exoplatform.faces.application.ExoFacesMessage; 9 import org.exoplatform.faces.core.component.InformationProvider; 10 import org.exoplatform.faces.core.component.UISimpleForm; 11 import org.exoplatform.faces.core.component.UIStringInput; 12 import org.exoplatform.faces.core.component.UITextArea; 13 import org.exoplatform.faces.core.component.model.*; 14 import org.exoplatform.faces.core.event.CheckRoleInterceptor; 15 import org.exoplatform.faces.core.event.ExoActionEvent; 16 import org.exoplatform.faces.core.event.ExoActionListener; 17 import org.exoplatform.portal.faces.component.model.PortletCategoryData; 18 import org.exoplatform.services.portletregistery.PortletCategory; 19 import org.exoplatform.services.portletregistery.PortletRegisteryService; 20 25 public class UIPortletCategoryForm extends UISimpleForm { 26 private PortletCategoryData categoryData_ ; 27 protected UIStringInput name_; 28 protected UITextArea description_; 29 private PortletRegisteryService service_; 30 31 public UIPortletCategoryForm(PortletRegisteryService service) { 32 super("portletCategoryForm", "post", null); 33 service_ = service ; 34 name_ = new UIStringInput("name", ""); 35 description_ = new UITextArea("description", ""); 36 setClazz("UIPortletCategoryForm"); 37 add(new HeaderRow(). 38 add(new Cell("#{UIPortletCategoryForm.header.create-category}"). 39 addColspan("2"))); 40 add(new Row(). 41 add(new LabelCell("#{UIPortletCategoryForm.label.portlet-category-name}")). 42 add(new ComponentCell(this, name_))); 43 add(new Row(). 44 add(new LabelCell("#{UIPortletCategoryForm.label.description}")). 45 add(new ComponentCell(this, description_))); 46 add(new Row(). 47 add(new ListComponentCell(). 48 add(new FormButton("#{UIPortletCategoryForm.button.save}", SAVE_ACTION)). 49 add(new FormButton("#{UIPortletCategoryForm.button.cancel}", CANCEL_ACTION)). 50 addColspan("2").addAlign("center"))); 51 addFacesListener(new SaveActionListener().setActionToListen(SAVE_ACTION)); 52 addFacesListener(new CancelActionListener().setActionToListen(CANCEL_ACTION)); 53 } 54 55 public void setPortletCategoryData(PortletCategoryData category) { 56 categoryData_ = category ; 57 if(category == null) { 58 description_.setValue("") ; 59 name_.setValue("") ; 60 } else { 61 name_.setValue(category.getPortletCategoryName()) ; 62 description_.setValue(category.getPortletCategory().getDescription()) ; 63 } 64 } 65 66 public class SaveActionListener extends ExoActionListener { 67 public SaveActionListener() { 68 addInterceptor(new CheckRoleInterceptor("admin")) ; 69 } 70 71 public void execute(ExoActionEvent event) throws Exception { 72 UIPortletCategoryForm uiForm = (UIPortletCategoryForm) event.getComponent() ; 73 InformationProvider iprovider = findInformationProvider(event.getComponent()) ; 74 String categoryName = name_.getValue() ; 75 if (categoryName == null || "".equals(categoryName)) { 76 iprovider.addMessage(new ExoFacesMessage("#{UIPortletCategoryForm.msg.category-name-null}")); 77 return; 78 } 79 if(categoryData_ == null) { 80 PortletCategory category = service_.createPortletCategoryInstance(); 81 category.setPortletCategoryName(categoryName); 82 category.setDescription(description_.getValue()); 83 service_.addPortletCategory(category); 84 } else { 85 PortletCategory category = categoryData_.getPortletCategory() ; 86 category.setPortletCategoryName(categoryName); 87 category.setDescription(description_.getValue()); 88 service_.updatePortletCategory(category); 89 } 90 UIPortletCategories uiCategories = 91 (UIPortletCategories) uiForm.getSibling(UIPortletCategories.class) ; 92 uiCategories.reset() ; 93 uiForm.setRenderedSibling(UIPortletCategories.class) ; 94 } 95 } 96 97 public class CancelActionListener extends ExoActionListener { 98 public void execute(ExoActionEvent event) throws Exception { 99 UIPortletCategoryForm uiForm = (UIPortletCategoryForm) event.getComponent() ; 100 uiForm.setRenderedSibling(UIPortletCategories.class) ; 101 } 102 } 103 } | Popular Tags |