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