View Javadoc
1   /**
2    * This file Copyright (c) 2013-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.vaadin.gwt.client.editor.event;
35  
36  import info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlComponent;
37  
38  import com.google.gwt.event.shared.EventHandler;
39  import com.google.gwt.event.shared.GwtEvent;
40  
41  /**
42   * Event to notify the system that the move has been stopped.
43   * Event holds contextual information about the stop:
44   * <pre>
45   *  <ul>
46   *      <li>Whether it was a server or client side action causing it.</li>
47   *      <li>Whether the move was cancelled (by dropping it outside the drop zone, hitting ESC, "Cancel move" by action bar
48   *      or stop the drag of the component).</li>
49   *  </ul>
50  
51   *  fired by:
52   *  <ul>
53   *      <li>{@link info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlComponent#onMoveStop} to notify about a sort</li>
54   *      <li>{@link info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlComponent#onMoveCancel()} when cancelled from clientside</li>
55   *      <li>{@link info.magnolia.ui.vaadin.gwt.client.rpc.PageEditorClientRpc#cancelMoveComponent} when cancelled from serverside</li>
56   *  </ul>
57   *  handler registered in:
58   *  <ul>
59   *      <li>info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlComponent#doStartMove(boolean) for notifying the source component</li>
60   *      <li>{@link info.magnolia.ui.vaadin.gwt.client.editor.dom.MgnlComponent#registerMoveTarget(boolean)} by all move target components.</li>
61   *      <li>{@link info.magnolia.ui.vaadin.gwt.client.connector.PageEditorConnector} to reset the {@link info.magnolia.ui.vaadin.gwt.client.editor.model.Model}
62   *      and notify the server when client side action.</li>
63   *  </ul>
64   * </pre>
65   */
66  public class ComponentStopMoveEvent extends GwtEvent<ComponentStopMoveEvent.ComponentStopMoveEventHandler> {
67  
68      public static Type<ComponentStopMoveEventHandler> TYPE = new Type<ComponentStopMoveEventHandler>();
69  
70      private MgnlComponent component;
71  
72      private boolean serverSide;
73  
74      public ComponentStopMoveEvent(MgnlComponent component, boolean serverSide) {
75          this.component = component;
76          this.serverSide = serverSide;
77      }
78  
79      @Override
80      public Type<ComponentStopMoveEventHandler> getAssociatedType() {
81          return TYPE;
82      }
83  
84      @Override
85      protected void dispatch(ComponentStopMoveEventHandler handler) {
86          handler.onStop(this);
87      }
88  
89      public MgnlComponent getTargetComponent() {
90          return component;
91      }
92  
93      public boolean isServerSide() {
94          return serverSide;
95      }
96  
97      /**
98       * Handler for {@link ComponentStopMoveEvent}.
99       */
100     public static interface ComponentStopMoveEventHandler extends EventHandler {
101         void onStop(ComponentStopMoveEvent componentMoveEvent);
102     }
103 }