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.propertyexpansion;
14  
15  import java.awt.Point;
16  
17  import com.eviware.soapui.model.ModelItem;
18  import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
19  import com.eviware.soapui.support.xml.JXEditTextArea;
20  
21  public class JXEditTextAreaPropertyExpansionTarget extends AbstractPropertyExpansionTarget
22  {
23  	private final JXEditTextArea textField;
24  
25  	public JXEditTextAreaPropertyExpansionTarget( JXEditTextArea textField, ModelItem modelItem )
26  	{
27  		super( modelItem );
28  		this.textField = textField;
29  	}
30  
31  	public void insertPropertyExpansion( PropertyExpansion expansion, Point pt )
32  	{
33  		int pos = pt == null ? -1 : textField.pointToOffset( pt );
34  		if( pos == -1 )
35  			pos = textField.getCaretPosition();
36  
37  		textField.setSelectedText( expansion.toString() );
38  
39  		if( pos >= 0 )
40  		{
41  			textField.setCaretPosition( pos );
42  			textField.requestFocusInWindow();
43  		}
44  	}
45  
46  	public String getValueForCreation()
47  	{
48  		return textField.getSelectedText();
49  	}
50  
51  	public String getNameForCreation()
52  	{
53  		return textField.getName();
54  	}
55  }