1 5 package org.exoplatform.portal.faces.component; 6 7 import org.exoplatform.commons.exception.ExoPermissionException; 8 import org.exoplatform.container.SessionContainer; 9 import org.exoplatform.faces.application.ExoFacesMessage; 10 import org.exoplatform.faces.core.component.InformationProvider; 11 import org.exoplatform.faces.core.component.UIGrid; 12 import org.exoplatform.faces.core.component.UIPageListIterator; 13 import org.exoplatform.faces.core.component.UIToolbar; 14 import org.exoplatform.faces.core.component.model.*; 15 import org.exoplatform.faces.core.event.ExoActionEvent; 16 import org.exoplatform.faces.core.event.ExoActionListener; 17 import org.exoplatform.services.portal.PageDescription; 18 import org.exoplatform.services.portal.PortalACL; 19 import org.exoplatform.services.portal.PortalConfigService; 20 import org.exoplatform.services.portal.Query; 21 import org.exoplatform.services.portal.model.Page; 22 26 public class UIPageList extends UIGrid { 27 public static Parameter[] PREVIEW_PAGE = { new Parameter(ACTION , "preview") } ; 28 public static Parameter[] SELECT_PAGE = { new Parameter(ACTION , "select") } ; 29 public static Parameter[] DELETE_PAGE = { new Parameter(ACTION , DELETE_ACTION) } ; 30 public static Parameter NEW_PAGE = new Parameter(ACTION , "newPage") ; 31 public static Parameter RETURN_PAGE = new Parameter(ACTION , "return") ; 32 33 public static Parameter[] newParams = { NEW_PAGE} ; 34 public static Parameter[] returnParams = { RETURN_PAGE } ; 35 36 private UIPageListIterator uiPageIterator_ ; 37 private UISearchForm uiSearchForm_ ; 38 private Query query_ ; 39 40 public UIPageList() throws Exception { 41 setId("UIPageList") ; 42 UIToolbar uiToolbar = new UIToolbar(); 43 uiToolbar.addLeftButton(new Button("#{UIPageList.button.new-page}", newParams)); 44 uiToolbar.addRightButton(new Button("#{UIPageList.button.cancel}", returnParams)); 45 uiPageIterator_ = new UIPageListIterator(new PageDescriptionHandler()) ; 46 uiSearchForm_ = new UISearchForm() ; 47 add(new Row(). 48 add(new ComponentCell(this, uiToolbar). 49 addColspan("5"))); 50 add(new Rows(uiPageIterator_.getPageListDataHandler(), "even", "odd"). 51 add(new Column("#{UIPageList.header.owner}", "owner")). 52 add(new Column("#{UIPageList.header.name}", "name")). 53 add(new Column("#{UIPageList.header.view-permission}", "viewPermission")). 54 add(new Column("#{UIPageList.header.edit-permission}", "editPermission")). 55 add(new ActionColumn("#{UIPageList.header.action}", OBJECTID). 56 add(true, new Button("#{UIPageList.button.preview}", PREVIEW_PAGE )). 57 add(true, new Button("#{UIPageList.button.select}", SELECT_PAGE )). 58 add(true,new Button("#{UIPageList.button.delete}",DELETE_PAGE)). 59 setCellClass("action-column"))) ; 60 add(new Row(). 61 add(new ComponentCell(this, uiPageIterator_). 62 addColspan("5").addStyle("text-align: right"))); 63 add(new Row(). 64 add(new ComponentCell(this, uiSearchForm_). 65 addColspan("5"))); 66 67 68 addActionListener(DeleteActionListener.class, DELETE_ACTION) ; 69 addActionListener(SelectActionListener.class, "select") ; 70 addActionListener(PreviewActionListener.class, "preview") ; 71 addActionListener(NewPageActionListener.class, "newPage") ; 72 addActionListener(ReturnActionListener.class, "return") ; 73 } 74 75 76 public void queryDescriptions(String owner, String viewPerm, String editPerm) throws Exception { 77 uiSearchForm_.setOwner(owner) ; 78 uiSearchForm_.setViewPermission(viewPerm) ; 79 uiSearchForm_.setEditPermission(editPerm) ; 80 PortalConfigService service = ((UIPageBrowser) getParent()).getPortalConfigService() ; 81 query_= new Query(owner, viewPerm, editPerm) ; 82 uiPageIterator_.setPageList(service.findAllPageDescriptions(query_)) ; 83 } 84 85 public void update() throws Exception { 86 PortalConfigService service = ((UIPageBrowser) getParent()).getPortalConfigService() ; 87 uiPageIterator_.setPageList(service.findAllPageDescriptions(query_)) ; 88 } 89 90 static public class PageDescriptionHandler extends PageListDataHandler { 91 private PageDescription desc_ ; 92 93 public String getData(String fieldName) { 94 if(OBJECTID.equals(fieldName)) return desc_.getId() ; 95 if("owner".equals(fieldName)) return desc_.getOwner() ; 96 if("name".equals(fieldName)) return desc_.getName() ; 97 if("viewPermission".equals(fieldName)) return desc_.getViewPermission() ; 98 if("editPermission".equals(fieldName)) return desc_.getEditPermission() ; 99 return null ; 100 } 101 102 public void setCurrentObject(Object o) { desc_ = (PageDescription) o; } 103 } 104 105 static public class PreviewActionListener extends ExoActionListener { 106 public void execute(ExoActionEvent event) throws Exception { 107 UIPageList uiList = (UIPageList) event.getComponent() ; 108 UIPortal uiPortal = (UIPortal) uiList.getAncestorOfType(UIPortal.class) ; 109 UIPagePreview uiPagePreview = 110 (UIPagePreview)uiPortal.getPortalComponent(UIPagePreview.class) ; 111 String pageId = event.getParameter(OBJECTID) ; 112 if(uiPagePreview.setPage(uiPortal, pageId)) { 113 uiPortal.setBodyComponent(uiPagePreview) ; 114 } 115 } 116 } 117 118 static public class SelectActionListener extends ExoActionListener { 119 public void execute(ExoActionEvent event) throws Exception { 120 UIPageList uiList = (UIPageList) event.getComponent() ; 121 String pageId = event.getParameter(OBJECTID); 122 UIPageBrowser uiPageBrowser = (UIPageBrowser) uiList.getParent() ; 123 uiPageBrowser.setSelectNodeReferencePage(pageId); 124 } 125 } 126 127 static public class DeleteActionListener extends ExoActionListener { 128 public DeleteActionListener() { 129 130 } 131 132 public void execute(ExoActionEvent event) throws Exception { 133 UIPageList uiList = (UIPageList) event.getComponent() ; 134 UIPageBrowser uiPageBrowser = (UIPageBrowser) uiList.getParent(); 135 UIPortal uiPortal = (UIPortal) uiPageBrowser.getAncestorOfType(UIPortal.class) ; 136 PortalConfigService service = uiPageBrowser.getPortalConfigService(); 137 String pageId = event.getParameter(OBJECTID); 138 Page page = service.getPage(pageId) ; 139 PortalACL acl = service.getPortalACL() ; 140 if(!acl.hasEditPagePermission(page, uiPortal.getOwner())) { 141 throw new ExoPermissionException(getActionName(), "onwer") ; 142 } 143 service.removePage(pageId); 144 PortalComponentCache cache = 145 (PortalComponentCache) SessionContainer.getComponent(PortalComponentCache.class) ; 146 cache.removeUIPageFromCache(pageId) ; 147 uiList.queryDescriptions(uiList.uiSearchForm_.getOwner(), 148 uiList.uiSearchForm_.getViewPermission(), 149 uiList.uiSearchForm_.getEditPermission()); 150 InformationProvider ip = findInformationProvider(event.getComponent()); 151 ip.addMessage(new ExoFacesMessage("#{UIPageList.msg.delete-page-success}")); 152 } 153 } 154 155 static public class ReturnActionListener extends ExoActionListener { 156 public void execute(ExoActionEvent event) throws Exception { 157 UIPageList uiList = (UIPageList) event.getSource() ; 158 UIPageBrowser uiPageBrowser = (UIPageBrowser)uiList.getParent() ; 159 uiPageBrowser.goBack() ; 160 } 161 } 162 163 static public class NewPageActionListener extends ExoActionListener { 164 public void execute(ExoActionEvent event) throws Exception { 165 UIPageList uiList = (UIPageList) event.getSource() ; 166 UIPageBrowser uiPageBrowser = (UIPageBrowser)uiList.getParent() ; 167 uiPageBrowser.setRenderedComponent(UIPageModelForm.class) ; 168 } 169 } 170 171 } | Popular Tags |