View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.support.dnd;
14  
15  import java.awt.datatransfer.DataFlavor;
16  import java.awt.datatransfer.Transferable;
17  import java.awt.datatransfer.UnsupportedFlavorException;
18  
19  import com.eviware.soapui.model.ModelItem;
20  
21  public class ModelItemTransferable implements Transferable
22  {
23  	public static final DataFlavor MODELITEM_DATAFLAVOR = new DataFlavor( DataFlavor.javaJVMLocalObjectMimeType,
24  			"SoapUIModelItem" );
25  
26  	private ModelItem modelItem;
27  
28  	private DataFlavor[] _flavors = { MODELITEM_DATAFLAVOR };
29  
30  	/***
31  	 * Constructs a transferrable tree path object for the specified path.
32  	 */
33  	public ModelItemTransferable( ModelItem path )
34  	{
35  		modelItem = path;
36  	}
37  
38  	// Transferable interface methods...
39  	public DataFlavor[] getTransferDataFlavors()
40  	{
41  		return _flavors;
42  	}
43  
44  	public ModelItem getModelItem()
45  	{
46  		return modelItem;
47  	}
48  
49  	public boolean isDataFlavorSupported( DataFlavor flavor )
50  	{
51  		return java.util.Arrays.asList( _flavors ).contains( flavor );
52  	}
53  
54  	public synchronized Object getTransferData( DataFlavor flavor ) throws UnsupportedFlavorException
55  	{
56  		if( flavor.isMimeTypeEqual( MODELITEM_DATAFLAVOR.getMimeType() ) ) // DataFlavor.javaJVMLocalObjectMimeType))
57  			return modelItem;
58  		else
59  			throw new UnsupportedFlavorException( flavor );
60  	}
61  }