1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.support.action;
14
15 import java.awt.event.ActionEvent;
16 import java.beans.PropertyChangeEvent;
17 import java.beans.PropertyChangeListener;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.Action;
21 import javax.swing.Icon;
22
23 import com.eviware.soapui.support.UISupport;
24
25 public class SwingActionDelegate<T> extends AbstractAction implements PropertyChangeListener
26 {
27 private final SoapUIAction<T> action;
28 private final T target;
29
30 public SwingActionDelegate( SoapUIAction<T> action, T target )
31 {
32 this( action, target, null, null );
33 }
34
35 public SwingActionDelegate( SoapUIAction<T> action, T target, String keyStroke )
36 {
37 this( action, target, null, keyStroke );
38 }
39
40 public SwingActionDelegate( SoapUIAction<T> action, T target, Icon icon )
41 {
42 this( action, target, icon, null );
43 }
44
45 public SwingActionDelegate( SoapUIAction<T> action, T target, Icon icon, String keyStroke )
46 {
47 super( action.getName() );
48 this.action = action;
49 this.target = target;
50
51 if( action.getDescription() != null )
52 putValue( Action.SHORT_DESCRIPTION, action.getDescription() );
53
54 if( icon != null )
55 putValue( Action.SMALL_ICON, icon );
56
57 if( keyStroke != null )
58 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( keyStroke ));
59
60 setEnabled( action.isEnabled() );
61
62 action.addPropertyChangeListener( this );
63 }
64
65 public void actionPerformed(ActionEvent e)
66 {
67 action.perform( target );
68 }
69
70 public void propertyChange(PropertyChangeEvent evt)
71 {
72 if( evt.getPropertyName().equals( SoapUIAction.ENABLED_PROPERTY ))
73 setEnabled( ((Boolean)evt.getNewValue()).booleanValue() );
74 }
75
76 public SoapUIAction<T> getAction()
77 {
78 return action;
79 }
80
81 public T getTarget()
82 {
83 return target;
84 }
85
86
87 }