KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > resources > component > UISearchForm


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.resources.component;
6
7 import java.util.* ;
8 import org.exoplatform.faces.core.component.*;
9 import org.exoplatform.faces.core.component.model.*;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.container.PortalContainer;
13 import org.exoplatform.services.resources.LocaleConfigService;
14 import org.exoplatform.services.resources.LocaleConfig ;
15 /**
16  * Sat, Jan 03, 2004 @ 11:16
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $Id: UISearchForm.java,v 1.4 2004/06/24 13:35:32 tuan08 Exp $
20  */

21 public class UISearchForm extends UISimpleForm {
22   
23   private UIStringInput nameInput_ ;
24   private UISelectBox languageInput_ ;
25
26   public UISearchForm(boolean adminRole) {
27     super("searchForm", "post", null) ;
28     setId("UISearchForm");
29     LocaleConfigService service =
30       (LocaleConfigService) PortalContainer.getComponent(LocaleConfigService.class);
31     Iterator i = service.getLocalConfigs().iterator() ;
32     List options = new ArrayList() ;
33     options.add(new SelectItem("All", "")) ;
34     while (i.hasNext()) {
35       LocaleConfig config = (LocaleConfig) i.next() ;
36       options.add(new SelectItem(config.getLocaleName(), config.getLanguage())) ;
37     }
38     nameInput_ = new UIStringInput("name", "") ;
39     languageInput_ = new UISelectBox("language","" , options) ;
40     add(new Row().
41         add(new LabelCell("#{UISearchForm.label.name}")).
42         add(new ComponentCell(this, nameInput_))) ;
43     add(new Row().
44         add(new LabelCell("#{UISearchForm.label.language}")).
45         add(new ComponentCell(this, languageInput_))) ;
46     ListComponentCell buttonCell = new ListComponentCell() ;
47     buttonCell.addColspan("2").addAlign("center") ;
48     buttonCell.add(new FormButton("#{UISearchForm.button.search}", "searchResource")) ;
49     if(adminRole) {
50         buttonCell.add(new FormButton("#{UISearchForm.button.new-resource}", "newResource")) ;
51     }
52     add(new Row().add(buttonCell)) ;
53     addActionListener(SearchActionListener.class, "searchResource") ;
54     addActionListener(NewResourceActionListener.class, "newResource") ;
55   }
56  
57   static public class SearchActionListener extends ExoActionListener {
58     public void execute(ExoActionEvent event) throws Exception JavaDoc {
59         UISearchForm uiForm = (UISearchForm) event.getComponent() ;
60         UIListResources uiListResources = (UIListResources) uiForm.getParent() ;
61         String JavaDoc language = uiForm.languageInput_.getValue();
62         if ("all".equals(language)) language = null ;
63         uiListResources.update(uiForm.nameInput_.getValue(), language);
64     }
65   }
66   
67   static public class NewResourceActionListener extends ExoActionListener {
68     public void execute(ExoActionEvent event) throws Exception JavaDoc {
69         UISearchForm uiForm = (UISearchForm) event.getComponent() ;
70         UIResourcesPortlet uiPortlet = (UIResourcesPortlet) uiForm.getParent().getParent() ;
71         UIResource uiResource =
72             (UIResource)uiPortlet.getChildComponentOfType(UIResource.class) ;
73         uiResource.setResourceBundleData(null) ;
74       uiResource.setMode(UIResource.EDIT_MODE) ;
75         uiPortlet.setRenderedComponent(uiResource.getId()) ;
76     }
77   }
78 }
Popular Tags