KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > portletregistery > component > UIPortletForm


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.portletregistery.component;
6
7 import org.exoplatform.faces.application.ExoFacesMessage;
8 import org.exoplatform.faces.core.component.InformationProvider;
9 import org.exoplatform.faces.core.component.UISimpleForm;
10 import org.exoplatform.faces.core.component.UIStringInput;
11 import org.exoplatform.faces.core.component.UITextArea;
12 import org.exoplatform.faces.core.component.model.*;
13 import org.exoplatform.faces.core.event.CheckRoleInterceptor;
14 import org.exoplatform.faces.core.event.ExoActionEvent;
15 import org.exoplatform.faces.core.event.ExoActionListener;
16 import org.exoplatform.services.portletregistery.Portlet;
17 import org.exoplatform.services.portletregistery.PortletRegisteryService;
18 /**
19  * Created y the eXo platform team
20  * User: Benjamin Mestrallet
21  * Date: 19 juin 2004
22  */

23 public class UIPortletForm extends UISimpleForm {
24   protected UIStringInput portletDisplayName;
25   protected UITextArea description;
26   private Portlet portlet_ ;
27   private PortletRegisteryService portletRegisteryService;
28
29   public UIPortletForm(PortletRegisteryService portletRegisteryService) {
30     super("portletForm", "post", null);
31     this.portletRegisteryService = portletRegisteryService;
32     portletDisplayName = new UIStringInput("name", "");
33     description = new UITextArea("description", "");
34
35     setClazz("UIPortletCategoryForm");
36     add(new HeaderRow().
37         add(new Cell("#{UIPortletForm.header.edit-portlet}").
38         addColspan("2")));
39     add(new Row().
40         add(new LabelCell("#{UIPortletForm.label.portlet-display-name}")).
41         add(new ComponentCell(this, portletDisplayName)));
42     add(new Row().
43         add(new LabelCell("#{UIPortletForm.label.description}")).
44         add(new ComponentCell(this, description)));
45     add(new Row().
46         add(new ListComponentCell().
47         add(new FormButton("#{UIPortletForm.button.save}", SAVE_ACTION)).
48         add(new FormButton("#{UIPortletForm.button.cancel}", CANCEL_ACTION)).
49         addColspan("2").addAlign("center")));
50
51     addActionListener(new UpdateActionListener().setActionToListen(SAVE_ACTION));
52     addActionListener(new CancelActionListener().setActionToListen(CANCEL_ACTION));
53   }
54   
55   public void setPortletData(Portlet portlet) {
56     portlet_ = portlet ;
57     portletDisplayName.setValue(portlet.getDisplayName());
58     description.setValue(portlet.getDescription());
59   }
60
61   private class UpdateActionListener extends ExoActionListener {
62     public UpdateActionListener() {
63       addInterceptor(new CheckRoleInterceptor("admin")) ;
64     }
65     
66     public void execute(ExoActionEvent event) throws Exception JavaDoc {
67       InformationProvider iprovider = findInformationProvider(event.getComponent()) ;
68       String JavaDoc displayName = portletDisplayName.getValue();
69       if (displayName == null || "".equals(displayName)) {
70         iprovider.addMessage(new ExoFacesMessage("#{UIPortletForm.msg.portlet-name-null}")) ;
71         return;
72       }
73       portlet_.setDisplayName(displayName);
74       portlet_.setDescription(description.getValue());
75       portletRegisteryService.updatePortlet(portlet_);
76       UIPortletRegistry uiPortlet = (UIPortletRegistry) getParent();
77       uiPortlet.setRenderedComponent(UIPortletCategories.class);
78     }
79   }
80
81   private class CancelActionListener extends ExoActionListener {
82     public void execute(ExoActionEvent event) throws Exception JavaDoc {
83       UIPortletRegistry uiPortlet = (UIPortletRegistry) getParent();
84       uiPortlet.setRenderedComponent(UIPortletCategories.class);
85     }
86   }
87 }
Popular Tags