View Javadoc

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