View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.event;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.UIViewRoot;
26  
27  import javax.faces.event.FacesEvent;
28  import javax.faces.event.FacesListener;
29  import javax.faces.event.PhaseId;
30  
31  import org.apache.myfaces.trinidad.context.RequestContext;
32  
33  
34  /**
35   * Event delivered to indicate that a dialog is about to be
36   * launched.  A {@link LaunchListener} can serve to add parameters that
37   * should be passed to the dialog by using the {@link #getDialogParameters}
38   * map, or add UI hints for any dialog that is being raised by
39   * using the {@link #getWindowProperties} map.
40   * <p>
41   * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/event/LaunchEvent.java#0 $) $Date: 10-nov-2005.19:09:02 $
42   */
43  public class LaunchEvent extends FacesEvent
44  {
45    /**
46     * Create a LaunchEvent.
47     * @param source the component responsible for launching the dialog
48     * @param viewRoot the UIViewRoot to be displayed at the start of
49     *   the dialog
50     */
51    public LaunchEvent(UIComponent source,
52                       UIViewRoot viewRoot)
53    {
54      super(source);
55      _viewRoot = viewRoot;
56      _dialogParameters = new HashMap<String, Object>();
57      _windowProperties  = new HashMap<String, Object>();
58  
59      // LaunchEvents should always be queued for the current phase
60      setPhaseId(PhaseId.ANY_PHASE);
61    }
62  
63    /**
64     *
65     */
66    public void launchDialog(boolean useWindow)
67    {
68      RequestContext afContext = RequestContext.getCurrentInstance();
69      afContext.launchDialog(getViewRoot(),
70                             getDialogParameters(),
71                             getComponent(),
72                             useWindow,
73                             getWindowProperties());
74    }
75  
76    /**
77     * The UIViewRoot that will be displayed at the start of the dialog.
78     */
79    public UIViewRoot getViewRoot()
80    {
81      return _viewRoot;
82    }
83  
84    /**
85     * A map of parameters to pass to the dialog.  All entries
86     * in the map will be added to the pageFlowScope.
87     */
88    public Map<String, Object> getDialogParameters()
89    {
90      return _dialogParameters;
91    }
92  
93    /**
94     * A map of user interface hints used to configure a dialog.
95     * The set of property keys will depend on the current RenderKit.
96     * However, "width" and "height" are common examples.
97     * The map will be ignored if a dialog is not used.
98     * =-=AEW getWindowProperties or getDialogProperties or ??
99     */
100   public Map<String, Object> getWindowProperties()
101   {
102     return _windowProperties;
103   }
104 
105   @Override
106   public void processListener(FacesListener listener)
107   {
108     ((LaunchListener) listener).processLaunch(this);
109   }
110 
111   @Override
112   public boolean isAppropriateListener(FacesListener listener)
113   {
114     return (listener instanceof LaunchListener);
115   }
116 
117   @Override
118   public int hashCode()
119   {
120     int result = (getComponent() == null) ? 0 : getComponent().hashCode();
121     result = 37 * result + ((_viewRoot == null) ? 0 : _viewRoot.hashCode());
122     result = 37 * result + _windowProperties.hashCode();
123     result = 37 * result + _dialogParameters.hashCode();
124     return result;
125   }
126 
127   @Override
128   public boolean equals(Object o)
129   {
130     if (o == this)
131       return true;
132 
133     if (o instanceof LaunchEvent)
134     {
135       LaunchEvent that = (LaunchEvent)o;
136       if (!this.getComponent().equals(that.getComponent()))
137         return false;
138 
139       if (_viewRoot == null)
140       {
141         if (that._viewRoot != null)
142           return false;
143       }
144       else
145       {
146         if (!_viewRoot.equals(that._viewRoot))
147           return false;
148       }
149 
150       if (!_dialogParameters.equals(that._dialogParameters))
151         return false;
152 
153       if (!_windowProperties.equals(that._windowProperties))
154         return false;
155 
156       return true;
157     }
158 
159     return false;
160   }
161 
162   @Override
163   public String toString()
164   {
165     StringBuffer sb = new StringBuffer();
166     sb.append(getClass().getName());
167     sb.append("[component=");
168     sb.append(getComponent());
169     sb.append(", viewRoot=");
170     sb.append(getViewRoot());
171     sb.append(", dialogParameters=");
172     sb.append(getDialogParameters());
173     sb.append(", windowProperties=");
174     sb.append(getWindowProperties());
175     sb.append(']');
176     return sb.toString();
177   }
178 
179   // UIViewRoot is not serializable, so must be transient
180   transient private UIViewRoot          _viewRoot;
181 
182   private Map<String, Object> _dialogParameters;
183   private Map<String, Object> _windowProperties;
184   private static final long serialVersionUID = 1L;
185 }