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  
37     public RestResourceDesktopPanel( RestResource modelItem )
38     {
39        super( modelItem );
40  
41        add( buildToolbar(), BorderLayout.NORTH );
42        add( buildContent(), BorderLayout.CENTER );
43     }
44  
45     private Component buildContent()
46     {
47        JTabbedPane tabs = new JTabbedPane();
48        tabs.addTab( "Resource Parameters", new RestParamsTable( getModelItem().getParams(), true ) );
49        return UISupport.createTabPanel( tabs, false );
50     }
51  
52     @Override
53     public String getTitle()
54     {
55        return getName( getModelItem() );
56     }
57  
58     private String getName( RestResource modelItem )
59     {
60        if( modelItem.getParentResource() != null )
61           return getName( modelItem.getParentResource() ) + "/" + modelItem.getName();
62        else
63           return modelItem.getName();
64     }
65  
66     private Component buildToolbar()
67     {
68        JXToolBar toolbar = UISupport.createToolbar();
69  
70        toolbar.addFixed( createActionButton( SwingActionDelegate.createDelegate(
71                NewRestRequestAction.SOAPUI_ACTION_ID, getModelItem(), null, "/create_empty_request.gif" ), true ) );
72  
73        toolbar.addSeparator();
74  
75        pathTextField = new JUndoableTextField( getModelItem().getPath(), 20 );
76        pathTextField.getDocument().addDocumentListener( new DocumentListenerAdapter(){
77           public void update( Document document )
78           {
79              if( !updating)
80              {
81                 updating = true;
82                 getModelItem().setPath( getText( document ));
83                 updating = false;
84              }
85           }
86        } );
87        toolbar.addLabeledFixed( "Resource Path", pathTextField );
88  
89        toolbar.addGlue();
90        toolbar.add( UISupport.createToolbarButton( new ShowOnlineHelpAction( HelpUrls.RESTRESOURCEEDITOR_HELPURL ) ) );
91  
92        return toolbar;
93     }
94  
95     @Override
96     public boolean dependsOn( ModelItem modelItem )
97     {
98        return getModelItem().dependsOn( modelItem );
99     }
100 
101    public boolean onClose( boolean canCancel )
102    {
103       return true;
104    }
105 
106    @Override
107    public void propertyChange( PropertyChangeEvent evt )
108    {
109       if( evt.getPropertyName().equals( "path" ))
110       {
111          if( !updating )
112          {
113             updating = true;
114             pathTextField.setText( String.valueOf( evt.getNewValue() ) );
115             updating = false;
116          }
117       }
118 
119       super.propertyChange( evt );
120    }
121 }