View Javadoc

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