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.support.editor.inspectors.attachments;
14  
15  import com.eviware.soapui.impl.wsdl.AttachmentContainer;
16  import com.eviware.soapui.support.editor.EditorView;
17  import com.eviware.soapui.support.editor.inspectors.AbstractXmlInspector;
18  import com.eviware.soapui.support.editor.views.xml.raw.RawXmlEditorFactory;
19  import com.eviware.soapui.support.editor.xml.XmlDocument;
20  
21  import javax.swing.*;
22  import java.beans.PropertyChangeEvent;
23  import java.beans.PropertyChangeListener;
24  
25  public class AttachmentsInspector extends AbstractXmlInspector implements PropertyChangeListener
26  {
27  	private AttachmentContainer container;
28  	private AttachmentsPanel attachmentsPanel;
29  
30  	public AttachmentsInspector( AttachmentContainer container)
31  	{
32  		super( "Attachments (" + container.getAttachmentCount() + ")", "Files attached to this message",
33  					true, AttachmentsInspectorFactory.INSPECTOR_ID );
34  		this.container = container;
35  		
36  		container.addAttachmentsChangeListener( this );
37  	}
38  
39  	public JComponent getComponent()
40  	{
41  		if( attachmentsPanel == null )
42        {
43  			attachmentsPanel = new AttachmentsPanel( container );
44        }
45  		
46  		return attachmentsPanel;
47  	}
48  
49  	@Override
50  	public void release()
51  	{
52  		super.release();
53  		attachmentsPanel.release();
54  		container.removeAttachmentsChangeListener( this );
55  	}
56  
57  	public void propertyChange( PropertyChangeEvent evt )
58  	{
59  		setTitle( "Attachments (" + container.getAttachmentCount() + ")");
60  	}
61  
62  	@Override
63  	public boolean isEnabledFor( EditorView<XmlDocument> view )
64  	{
65  		return !view.getViewId().equals( RawXmlEditorFactory.VIEW_ID );
66  	}
67  }