View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of 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,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-widget Project
18  //
19  // TabDropController.java
20  // Since: May 1, 2008
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.widget.client.impl;
26  
27  import java.util.Iterator;
28  
29  import org.utgenome.gwt.widget.client.TrackFrame;
30  import org.utgenome.gwt.widget.client.TrackPanel;
31  
32  import com.allen_sauer.gwt.dnd.client.DragContext;
33  import com.allen_sauer.gwt.dnd.client.drop.AbstractDropController;
34  import com.google.gwt.user.client.ui.TabPanel;
35  import com.google.gwt.user.client.ui.Widget;
36  
37  /**
38   * Tab drop
39   * 
40   * @author leo
41   * 
42   */
43  public class TabDropController extends AbstractDropController {
44  
45  	private final TabPanel tabPanel;
46  	private int tabIndex;
47  
48  	public TabDropController(Widget dropTarget, TabPanel tabPanel, int tabIndex) {
49  		super(dropTarget);
50  		this.tabPanel = tabPanel;
51  		this.tabIndex = tabIndex;
52  	}
53  
54  	@SuppressWarnings("unchecked")
55  	@Override
56  	public void onDrop(DragContext context) {
57  
58  		TrackPanel tab = (TrackPanel) tabPanel.getWidget(tabIndex);
59  
60  		for (Iterator it = context.selectedWidgets.iterator(); it.hasNext();) {
61  			TrackFrame widget = (TrackFrame) it.next();
62  			tab.add(widget);
63  		}
64  		super.onDrop(context);
65  	}
66  
67  	@Override
68  	public void onEnter(DragContext context) {
69  		super.onEnter(context);
70  		tabPanel.selectTab(tabIndex);
71  		context.dragController.resetCache();
72  	}
73  
74  }