KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > forum > component > UIToolbarPanel


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.communication.forum.component;
6
7 import org.exoplatform.faces.core.component.UIGrid;
8 import org.exoplatform.faces.core.component.UIToolbar;
9 import org.exoplatform.faces.core.component.model.Button;
10 import org.exoplatform.faces.core.component.model.ComponentCell;
11 import org.exoplatform.faces.core.component.model.Parameter;
12 import org.exoplatform.faces.core.component.model.Row;
13 import org.exoplatform.faces.core.event.ExoActionEvent;
14 import org.exoplatform.faces.core.event.ExoActionListener;
15 /**
16  * @author Benjamin Mestrallet
17  * benjamin.mestrallet@exoplatform.com
18  */

19 public class UIToolbarPanel extends UIGrid {
20   
21   private static final String JavaDoc SEARCH = "search";
22   private static final String JavaDoc VIEW_FORUMS = "viewForums";
23   private static final String JavaDoc BACK = "back";
24   
25   public static Parameter[] backParams = { new Parameter(ACTION , BACK)} ;
26   public static Parameter[] searchParams = { new Parameter(ACTION , SEARCH)} ;
27   public static Parameter[] viewForumsParams = { new Parameter(ACTION , VIEW_FORUMS)} ;
28   
29   public UIToolbarPanel() {
30     setId("UIToolbarPanel");
31     setClazz("UIToolbarPanel");
32     UIToolbar toolbar = new UIToolbar() ;
33     toolbar.setRendered(true) ;
34     toolbar.addLeftButton(new Button("#{UIForumPortlet.button.home}", viewForumsParams));
35     toolbar.addLeftButton(new Button("#{UIForumPortlet.button.search}", searchParams));
36     toolbar.addRightButton(new Button("#{UIForumPortlet.button.back}", backParams));
37     getChildren().add(toolbar) ;
38     
39     add(new Row().add(new ComponentCell(this, toolbar))) ;
40     
41     addActionListener(ViewForumsActionListener.class, VIEW_FORUMS) ;
42     addActionListener(SearchActionListener.class, SEARCH) ;
43     addActionListener(BackActionListener.class, BACK) ;
44     
45   }
46
47   
48   static public class ViewForumsActionListener extends ExoActionListener {
49     public void execute(ExoActionEvent event) throws Exception JavaDoc {
50       UIToolbarPanel panel = (UIToolbarPanel) event.getComponent() ;
51       UIForumPortlet forumPortlet = (UIForumPortlet)panel.getAncestorOfType(UIForumPortlet.class);
52       forumPortlet.addHistoryElement(forumPortlet.getRenderedComponent());
53       forumPortlet.setRenderedComponent(UIViewCategories.class);
54       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
55     }
56   }
57   
58   static public class SearchActionListener extends ExoActionListener {
59     public void execute(ExoActionEvent event) throws Exception JavaDoc {
60       UIToolbarPanel panel = (UIToolbarPanel) event.getSource() ;
61       UIForumPortlet forumPortlet = (UIForumPortlet)panel.getAncestorOfType(UIForumPortlet.class);
62       forumPortlet.addHistoryElement(forumPortlet.getRenderedComponent());
63       forumPortlet.setRenderedComponent(UIForumSearcher.class);
64       ((UIToolbarPanel)forumPortlet.getChildComponentOfType(UIToolbarPanel.class)).setRendered(true);
65     }
66   }
67   
68   static public class BackActionListener extends ExoActionListener {
69     public void execute(ExoActionEvent event) throws Exception JavaDoc {
70       UIToolbarPanel panel = (UIToolbarPanel) event.getSource() ;
71       ((UIForumPortlet)panel.getAncestorOfType(UIForumPortlet.class)).undo();
72       panel.setRendered(true);
73     }
74   }
75   
76 }
77
Popular Tags