View Javadoc
1   /*
2    * Copyright (C) 2003-2010 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.wcm.webui.administration;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.exoplatform.portal.application.PortalRequestContext;
23  import org.exoplatform.portal.webui.util.Util;
24  import org.exoplatform.wcm.webui.Utils;
25  import org.exoplatform.webui.application.portlet.PortletRequestContext;
26  import org.exoplatform.webui.config.annotation.ComponentConfig;
27  import org.exoplatform.webui.config.annotation.EventConfig;
28  import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
29  import org.exoplatform.webui.core.model.SelectItemOption;
30  import org.exoplatform.webui.event.Event;
31  import org.exoplatform.webui.event.EventListener;
32  import org.exoplatform.webui.form.UIForm;
33  import org.exoplatform.webui.form.UIFormSelectBox;
34  
35  /**
36   * Created by The eXo Platform SAS
37   * Author : eXoPlatform
38   *          exo@exoplatform.com
39   * Feb 2, 2010
40   */
41  @ComponentConfig(
42                   lifecycle = UIFormLifecycle.class,
43                   template = "app:/groovy/Editing/UIEditingToolBar.gtmpl",
44                   events = {
45                     @EventConfig(listeners = UIEditingForm.ChangeEditingActionListener.class)
46  })
47  public class UIEditingForm extends UIForm {
48  
49    /** The Constant PUBLISHED. */
50    public static final String PUBLISHED = "Published";
51  
52    /** The Constant DRAFT. */
53    public static final String DRAFT = "Draft";
54  
55    /** The Constant EDITING_OPTIONS. */
56    public static final String EDITING_OPTIONS = "EditingOptions";
57  
58    public UIEditingForm() {
59      List<SelectItemOption<String>> editingOptions = new ArrayList<SelectItemOption<String>>();
60      editingOptions.add(new SelectItemOption<String>(PUBLISHED, PUBLISHED));
61      editingOptions.add(new SelectItemOption<String>(DRAFT, DRAFT));
62  
63      UIFormSelectBox orderBySelectBox = new UIFormSelectBox(EDITING_OPTIONS, EDITING_OPTIONS, editingOptions);
64      orderBySelectBox.setOnChange("ChangeEditing");
65      addChild(orderBySelectBox);
66    }
67  
68    /**
69     * The listener interface for receiving changeRepositoryAction events.
70     * The class that is interested in processing a changeRepositoryAction
71     * event implements this interface, and the object created
72     * with that class is registered with a component using the
73     * component's <code>addChangeRepositoryActionListener</code> method. When
74     * the changeRepositoryAction event occurs, that object's appropriate
75     * method is invoked.
76     */
77    public static class ChangeEditingActionListener extends EventListener<UIEditingForm> {
78  
79      /* (non-Javadoc)
80       * @see org.exoplatform.webui.event.EventListener#execute(org.exoplatform.webui.event.Event)
81       */
82      public void execute(Event<UIEditingForm> event) throws Exception {
83        UIEditingForm editingForm = event.getSource();
84        PortalRequestContext context = Util.getPortalRequestContext();
85        UIFormSelectBox options = editingForm.getChildById(UIEditingForm.EDITING_OPTIONS);
86        String option = options.getValue() ;
87        if(option.equals(UIEditingForm.PUBLISHED)) {
88          context.getRequest().getSession().setAttribute(Utils.TURN_ON_QUICK_EDIT, false);
89          Utils.updatePortal((PortletRequestContext) event.getRequestContext());
90        } else {
91          context.getRequest().getSession().setAttribute(Utils.TURN_ON_QUICK_EDIT, true);
92          Utils.updatePortal((PortletRequestContext) event.getRequestContext());
93        }
94      }
95    }
96  }