1 5 package org.exoplatform.portlets.jmx.component; 6 7 import javax.management.MBeanServer ; 8 import javax.management.ObjectName ; 9 10 import org.exoplatform.faces.core.component.UIGrid; 11 import org.exoplatform.faces.core.component.model.ActionColumn; 12 import org.exoplatform.faces.core.component.model.Button; 13 import org.exoplatform.faces.core.component.model.CollectionDataHandler; 14 import org.exoplatform.faces.core.component.model.Column; 15 import org.exoplatform.faces.core.component.model.Parameter; 16 import org.exoplatform.faces.core.component.model.Rows; 17 import org.exoplatform.faces.core.event.ExoActionEvent; 18 import org.exoplatform.faces.core.event.ExoActionListener; 19 import org.exoplatform.portlets.jmx.component.model.MBeanDomain; 20 21 25 public class UIListMBean extends UIGrid { 26 private static Parameter[] VIEW_ACTION = {new Parameter(ACTION , "view") } ; 27 private MBeanServer mserver_ ; 28 private MBeanDomain mdomain_; 29 private ObjectNameDataHandler dataHandler_ ; 30 31 public UIListMBean() { 32 setId("UIListMbean") ; 33 setClazz("UIListMBean") ; 34 dataHandler_ = new ObjectNameDataHandler() ; 35 add(new Rows(dataHandler_, "even", "odd"). 36 add(new Column("#{UIListMBean.header.object-name}", "name")). 37 add(new ActionColumn("#{UIListMBean.header.action}", "id"). 38 add(true ,new Button("#{UIListMBean.button.view}", VIEW_ACTION)))) ; 39 addActionListener(SelectMBeanActionListener.class, "view") ; 40 } 41 42 public void setMBeanServerDomain(MBeanServer mserver, MBeanDomain mdomain) { 43 mserver_ = mserver ; 44 mdomain_ = mdomain ; 45 dataHandler_.setDatas(mdomain.getMBeanNames()) ; 46 } 47 48 49 static public class ObjectNameDataHandler extends CollectionDataHandler { 50 private MBeanDomain.MBeanDescription desc_ ; 51 52 public String getData(String fieldName) { 53 if("name".equals(fieldName)) return desc_.getObjectName().getCanonicalName(); 54 if("id".equals(fieldName)) return desc_.getId(); 55 return null ; 56 } 57 58 public void setCurrentObject(Object o) { desc_ = (MBeanDomain.MBeanDescription) o; } 59 } 60 61 static public class SelectMBeanActionListener extends ExoActionListener { 62 public void execute(ExoActionEvent event) throws Exception { 63 UIListMBean uiList = (UIListMBean)event.getComponent() ; 64 String mbean = event.getParameter("objectId") ; 65 ObjectName name = uiList.mdomain_.findMBeanObjectname(mbean) ; 66 UIJMXPortlet uiPortlet = (UIJMXPortlet) uiList.getAncestorOfType(UIJMXPortlet.class) ; 67 UIMBean uiMBean = (UIMBean) uiPortlet.getChildComponentOfType(UIMBean.class) ; 68 uiMBean.setUIMBeanData(uiList.mserver_, name) ; 69 uiPortlet.setRenderedComponent(uiMBean.getId()) ; 70 } 71 } 72 } | Popular Tags |