KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > wsrp > component > UIProducerMenu


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5 package org.exoplatform.portlets.wsrp.component;
6
7
8 import javax.faces.context.FacesContext;
9 import javax.faces.component.UIComponent;
10 import org.exoplatform.faces.FacesConstants;
11 import org.exoplatform.faces.core.component.UINode;
12 import org.exoplatform.portlets.wsrp.component.model.ProducerData;
13 import org.exoplatform.services.wsrp.consumer.ConsumerEnvironment;
14 import org.exoplatform.services.wsrp.consumer.Producer;
15 import org.exoplatform.services.wsrp.consumer.ProducerRegistry;
16 import org.exoplatform.services.wsrp.type.PortletDescription;
17 import java.util.*;
18
19 /**
20  * Created y the eXo platform team
21  * User: Benjamin Mestrallet
22  * Date: 6 juin 2004
23  */

24 public class UIProducerMenu extends UINode{
25   private ConsumerEnvironment consumerEnvironment_;
26   private HashMap producers;
27   private long lastAccessTime_;
28
29   public UIProducerMenu(ConsumerEnvironment consumerEnvironment) throws Exception JavaDoc {
30     setRendererType("ProducerMenuRenderer") ;
31     consumerEnvironment_ = consumerEnvironment ;
32     producers = new HashMap() ;
33     init();
34   }
35
36   public String JavaDoc getFamily() {
37     return "org.exoplatform.portlets.wsrp.component.UIProducerMenu" ;
38   }
39
40   private void init() throws Exception JavaDoc {
41     producers.clear();
42     ProducerRegistry pregistry = consumerEnvironment_.getProducerRegistry() ;
43     Iterator i = pregistry.getAllProducers() ;
44     while (i.hasNext()) {
45       Producer producer = (Producer) i.next() ;
46       ProducerData producerData = new ProducerData(producer);
47       producers.put(producer.getName(), producerData);
48     }
49     lastAccessTime_ = consumerEnvironment_.getProducerRegistry().getLastModifiedTime() ;
50   }
51
52   public Collection getProducers() {
53     if(lastAccessTime_ != consumerEnvironment_.getProducerRegistry().getLastModifiedTime()){
54       try {
55         init();
56       } catch (Exception JavaDoc e) {
57         e.printStackTrace();
58       }
59     }
60     return producers.values() ;
61   }
62
63   public void decode(FacesContext context) {
64     Map paramMap = context.getExternalContext().getRequestParameterMap() ;
65     String JavaDoc action = (String JavaDoc) paramMap.get(FacesConstants.ACTION) ;
66     if("selectProducer".equals(action)) {
67         String JavaDoc producerName = (String JavaDoc) paramMap.get("producerName") ;
68         ProducerData producerData = (ProducerData) producers.get(producerName) ;
69         producerData.setSelect(!producerData.isSelect()) ;
70         context.renderResponse() ;
71     } else if("showProducer".equals(action)) {
72         String JavaDoc producerName = (String JavaDoc) paramMap.get("producerName") ;
73         ProducerData producerData = (ProducerData) producers.get(producerName) ;
74         producerData.setSelect(true) ;
75         UIProducerNode uiParent = (UIProducerNode) getParent() ;
76         UIProducerInfo uiProducerInfo = (UIProducerInfo) uiParent.getChildComponentOfType(UIProducerInfo.class) ;
77         uiProducerInfo.setProducerData(producerData) ;
78         uiProducerInfo.setRendered(true);
79       ((UIComponent)uiParent.getChildComponentOfType(UIOfferedPortlet.class)).setRendered(false); ;
80         context.renderResponse() ;
81     } else if("showPortlet".equals(action)) {
82         String JavaDoc producerName = (String JavaDoc) paramMap.get("producerName") ;
83       String JavaDoc portletName = (String JavaDoc) paramMap.get("portletName") ;
84         ProducerData producerData = (ProducerData) producers.get(producerName) ;
85       PortletDescription portletDescription = producerData.getOfferedPortlet(portletName) ;
86       UIProducerNode uiParent = (UIProducerNode) getParent() ;
87       UIOfferedPortlet uiOfferedPortlet = (UIOfferedPortlet) uiParent.
88           getChildComponentOfType(UIOfferedPortlet.class) ;
89       uiOfferedPortlet.populate(portletDescription) ;
90       uiOfferedPortlet.setRendered(true);
91       ((UIComponent)uiParent.getChildComponentOfType(UIProducerInfo.class)).setRendered(false); ;
92       context.renderResponse() ;
93     }
94   }
95 }
96
Popular Tags