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.impl.rest.panels.resource;
14  
15  import java.awt.BorderLayout;
16  import java.awt.Component;
17  import java.beans.PropertyChangeEvent;
18  
19  import javax.swing.JTabbedPane;
20  import javax.swing.text.Document;
21  
22  import com.eviware.soapui.impl.rest.RestResource;
23  import com.eviware.soapui.impl.rest.actions.resource.NewRestMethodAction;
24  import com.eviware.soapui.impl.support.actions.ShowOnlineHelpAction;
25  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
26  import com.eviware.soapui.model.ModelItem;
27  import com.eviware.soapui.support.DocumentListenerAdapter;
28  import com.eviware.soapui.support.UISupport;
29  import com.eviware.soapui.support.action.swing.SwingActionDelegate;
30  import com.eviware.soapui.support.components.JUndoableTextField;
31  import com.eviware.soapui.support.components.JXToolBar;
32  import com.eviware.soapui.ui.support.ModelItemDesktopPanel;
33  
34  public class RestResourceDesktopPanel extends ModelItemDesktopPanel<RestResource>
35  {
36  	private JUndoableTextField pathTextField;
37  	private boolean updating;
38  	private RestParamsTable paramsTable;
39  
40  	public RestResourceDesktopPanel( RestResource modelItem )
41  	{
42  		super( modelItem );
43  
44  		add( buildToolbar(), BorderLayout.NORTH );
45  		add( buildContent(), BorderLayout.CENTER );
46  	}
47  
48  	private Component buildContent()
49  	{
50  		JTabbedPane tabs = new JTabbedPane();
51  		paramsTable = new RestParamsTable( getModelItem().getParams(), true );
52  		tabs.addTab( "Resource Parameters", paramsTable );
53  		return UISupport.createTabPanel( tabs, false );
54  	}
55  
56  	@Override
57  	public String getTitle()
58  	{
59  		return getName( getModelItem() );
60  	}
61  
62  	public RestParamsTable getParamsTable()
63  	{
64  		return paramsTable;
65  	}
66  
67  	@Override
68  	protected boolean release()
69  	{
70  		paramsTable.release();
71  		return super.release();
72  	}
73  
74  	private String getName( RestResource modelItem )
75  	{
76  		if( modelItem.getParentResource() != null )
77  			return getName( modelItem.getParentResource() ) + "/" + modelItem.getName();
78  		else
79  			return modelItem.getName();
80  	}
81  
82  	private Component buildToolbar()
83  	{
84  		JXToolBar toolbar = UISupport.createToolbar();
85  
86  		toolbar.addFixed( createActionButton( SwingActionDelegate.createDelegate( NewRestMethodAction.SOAPUI_ACTION_ID,
87  				getModelItem(), null, "/create_empty_method.gif" ), true ) );
88  
89  		toolbar.addSeparator();
90  
91  		pathTextField = new JUndoableTextField( getModelItem().getPath(), 20 );
92  		pathTextField.getDocument().addDocumentListener( new DocumentListenerAdapter()
93  		{
94  			public void update( Document document )
95  			{
96  				if( !updating )
97  				{
98  					updating = true;
99  					getModelItem().setPath( getText( document ) );
100 					updating = false;
101 				}
102 			}
103 		} );
104 		toolbar.addLabeledFixed( "Resource Path", pathTextField );
105 
106 		toolbar.addGlue();
107 		toolbar.add( UISupport.createToolbarButton( new ShowOnlineHelpAction( HelpUrls.RESTRESOURCEEDITOR_HELPURL ) ) );
108 
109 		return toolbar;
110 	}
111 
112 	@Override
113 	public boolean dependsOn( ModelItem modelItem )
114 	{
115 		return getModelItem().dependsOn( modelItem );
116 	}
117 
118 	public boolean onClose( boolean canCancel )
119 	{
120 		return true;
121 	}
122 
123 	@Override
124 	public void propertyChange( PropertyChangeEvent evt )
125 	{
126 		if( evt.getPropertyName().equals( "path" ) )
127 		{
128 			if( !updating )
129 			{
130 				updating = true;
131 				pathTextField.setText( String.valueOf( evt.getNewValue() ) );
132 				updating = false;
133 			}
134 		}
135 
136 		super.propertyChange( evt );
137 	}
138 }