View Javadoc
1   /*
2    * Copyright 2010 Daniel Kurka
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package com.googlecode.mgwt.dom.client.event.mouse;
17  
18  import java.util.LinkedList;
19  
20  import com.google.gwt.event.shared.HandlerRegistration;
21  
22  /**
23   * A collection of HandlerRegistrations which behaves like a single
24   * registration: On remove all collected Handlers are removed.
25   *
26   * @author Daniel Kurka
27   * @version $Id: $
28   */
29  public class HandlerRegistrationCollection implements HandlerRegistration, com.google.web.bindery.event.shared.HandlerRegistration {
30  
31  	private LinkedList<com.google.web.bindery.event.shared.HandlerRegistration> collectedHandlers = new LinkedList<com.google.web.bindery.event.shared.HandlerRegistration>();
32  
33  	/**
34  	 * Construct an empty HandlerRegistrationCollection
35  	 */
36  	public HandlerRegistrationCollection() {
37  
38  	}
39  
40  	/**
41  	 * Add a {@link HandlerRegistration} to the collection
42  	 *
43  	 * @param handlerRegistration the handlerregistration to add
44  	 */
45  	public void addHandlerRegistration(HandlerRegistration handlerRegistration) {
46  		collectedHandlers.add(handlerRegistration);
47  	}
48  
49  	public void addHandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration handlerRegistration) {
50  		collectedHandlers.add(handlerRegistration);
51  	}
52  
53  	/**
54  	 * {@inheritDoc}
55  	 *
56  	 * Remove all handlers: Call remove on each Handler
57  	 */
58  	@Override
59  	public void removeHandler() {
60  		for (com.google.web.bindery.event.shared.HandlerRegistration handlerRegistration : collectedHandlers) {
61  			handlerRegistration.removeHandler();
62  		}
63  		collectedHandlers.clear();
64  
65  	}
66  
67  }