UIViewPrivateMessage.java

  1. /***************************************************************************
  2.  * Copyright (C) 2003-2008 eXo Platform SAS.
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Affero General Public License
  6.  * as published by the Free Software Foundation; either version 3
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, see<http://www.gnu.org/licenses/>.
  16.  ***************************************************************************/
  17. package org.exoplatform.forum.webui.popup;

  18. import org.exoplatform.forum.common.webui.WebUIUtils;
  19. import org.exoplatform.forum.rendering.RenderHelper;
  20. import org.exoplatform.forum.rendering.RenderingException;
  21. import org.exoplatform.forum.service.ForumPrivateMessage;
  22. import org.exoplatform.forum.service.Post;
  23. import org.exoplatform.forum.service.UserProfile;
  24. import org.exoplatform.forum.service.Utils;
  25. import org.exoplatform.webui.config.annotation.ComponentConfig;
  26. import org.exoplatform.webui.config.annotation.EventConfig;
  27. import org.exoplatform.webui.core.UIContainer;
  28. import org.exoplatform.webui.event.Event;
  29. import org.exoplatform.webui.event.EventListener;

  30. @ComponentConfig(
  31.     template = "app:/templates/forum/webui/popup/UIViewPrivateMessage.gtmpl",
  32.     events = {
  33.       @EventConfig(listeners = UIViewPrivateMessage.CloseActionListener.class)
  34.     }
  35. )
  36. public class UIViewPrivateMessage extends UIContainer {
  37.   private ForumPrivateMessage privateMessage;

  38.   private UserProfile         userProfile;

  39.   RenderHelper                renderHelper = new RenderHelper();

  40.   public UIViewPrivateMessage() {
  41.   }

  42.   public ForumPrivateMessage getPrivateMessage() {
  43.     return privateMessage;
  44.   }

  45.   public void setPrivateMessage(ForumPrivateMessage privateMessage) {
  46.     this.privateMessage = privateMessage;
  47.   }

  48.   public String renderMessage(String str) throws RenderingException {
  49.     Post post = new Post();
  50.     post.setMessage(str);
  51.     return renderHelper.renderPost(post);
  52.   }

  53.   public UserProfile getUserProfile() {
  54.     return userProfile;
  55.   }

  56.   public void setUserProfile(UserProfile userProfile) {
  57.     this.userProfile = userProfile;
  58.   }

  59.   public void activate() {
  60.   }

  61.   public void deActivate() {
  62.   }
  63.  
  64.   public void reset() {
  65.     setRendered(false);
  66.     privateMessage = null;
  67.   }
  68.  
  69.   protected boolean isListSendPrivateMessage() {
  70.     return ((UIListPrivateMessage) getParent()).getMessageType().equals(Utils.SEND_MESSAGE) ? true : false;
  71.   }

  72.   protected String eventParent(String action, String id) throws Exception {
  73.     return getParent().event(action, id);
  74.   }
  75.  
  76.   static public class CloseActionListener extends EventListener<UIViewPrivateMessage> {
  77.     public void execute(Event<UIViewPrivateMessage> event) throws Exception {
  78.       UIViewPrivateMessage uiViewPrivateMessage = event.getSource();
  79.       uiViewPrivateMessage.reset();
  80.       UIListPrivateMessage container = uiViewPrivateMessage.getParent();
  81.       WebUIUtils.addScripts("ForumUtils", "forumUtils", "forumUtils.initTooltip('" + container.getId() + "');");
  82.       WebUIUtils.addScripts("UIForumPortlet", "forumPortlet", "forumPortlet.initConfirm('" + container.getId() + "');");
  83.       event.getRequestContext().addUIComponentToUpdateByAjax(container);
  84.     }
  85.   }
  86. }