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