View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.wsdl.actions.iface;
14  
15  import java.awt.event.ActionEvent;
16  
17  import javax.swing.AbstractAction;
18  import javax.swing.Action;
19  
20  import com.eviware.soapui.model.ModelItem;
21  import com.eviware.soapui.support.UISupport;
22  
23  /***
24   * Utility class for creating Swing Actions for ModelItems
25   * 
26   * @author ole.matzura
27   */
28  
29  public abstract class AbstractSwingAction<T extends ModelItem> extends AbstractAction
30  {
31  	private T modelItem;
32  	private final String name;
33  	
34  	public AbstractSwingAction( String name, String description )
35  	{
36  		super( name );
37  		this.name= name;
38  		this.modelItem = null;
39  		
40  		putValue( Action.SHORT_DESCRIPTION, description );
41  	}
42  	
43  	public AbstractSwingAction( String name, String description, T modelItem )
44  	{
45  		super( name );
46  		this.name= name;
47  		this.modelItem = modelItem;
48  		
49  		putValue( Action.SHORT_DESCRIPTION, description );
50  	}
51  
52  	public AbstractSwingAction( String name, String description, String iconUrl )
53  	{
54  		super( name );
55  		this.name= name;
56  		this.modelItem = null;
57  		
58  		putValue( Action.SHORT_DESCRIPTION, description );
59  		putValue( Action.SMALL_ICON, UISupport.createImageIcon( iconUrl ));
60  	}
61  	
62  	public AbstractSwingAction( String name, String description, String iconUrl, T modelItem )
63  	{
64  		super( name );
65  		this.name= name;
66  		this.modelItem = modelItem;
67  		
68  		putValue( Action.SHORT_DESCRIPTION, description );
69  		putValue( Action.SMALL_ICON, UISupport.createImageIcon( iconUrl ));
70  	}
71  	
72  	public void actionPerformed( ActionEvent arg0 )
73  	{
74  		actionPerformed( arg0, modelItem );
75  	}
76  	
77  	public String getName()
78  	{
79  		return name;
80  	}
81  
82  	public abstract void actionPerformed( ActionEvent arg0, T modelItem2 );
83  	
84  	public T getModelItem()
85  	{
86  		return modelItem;
87  	}
88  }