1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.support;
14
15 import java.awt.event.ActionEvent;
16 import java.beans.PropertyChangeListener;
17 import java.beans.PropertyChangeSupport;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.Action;
21
22 import com.eviware.soapui.impl.EmptyPanelBuilder;
23 import com.eviware.soapui.model.ModelItem;
24 import com.eviware.soapui.model.PanelBuilder;
25 import com.eviware.soapui.support.UISupport;
26 import com.eviware.soapui.support.action.ActionList;
27 import com.eviware.soapui.support.action.DefaultActionList;
28
29 /***
30 * Base-class for ModelItem implementations
31 *
32 * @author Ole.Matzura
33 */
34
35 public abstract class AbstractModelItem implements ModelItem
36 {
37 private DefaultActionList actions;
38 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );
39
40 protected void addAction( Action action )
41 {
42 addAction( action, false );
43 }
44
45 protected void addAction( Action action, boolean isDefault )
46 {
47 if( actions == null )
48 initActions();
49
50 actions.addAction( action );
51 if( isDefault )
52 actions.setDefaultAction( action );
53
54 notifyPropertyChanged( ModelItem.ACTIONS_PROPERTY, null, getActions() );
55 }
56
57 private void initActions()
58 {
59 actions = new DefaultActionList( getName() );
60 actions.setDefaultAction( new ShowModelItemAction() );
61 }
62
63 public ActionList getActions()
64 {
65 if( actions == null )
66 initActions();
67
68 return actions;
69 }
70
71 public PanelBuilder getPanelBuilder()
72 {
73 return EmptyPanelBuilder.get();
74 }
75
76 public String getDescription()
77 {
78 return getName();
79 }
80
81 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
82 {
83 propertyChangeSupport.addPropertyChangeListener( propertyName, listener );
84 }
85
86 public void addPropertyChangeListener(PropertyChangeListener listener)
87 {
88 propertyChangeSupport.addPropertyChangeListener( listener );
89 }
90
91 public void removePropertyChangeListener(PropertyChangeListener listener)
92 {
93 propertyChangeSupport.removePropertyChangeListener( listener );
94 }
95
96 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
97 {
98 propertyChangeSupport.removePropertyChangeListener( propertyName, listener );
99 }
100
101 protected void notifyPropertyChanged( String name, Object oldValue, Object newValue )
102 {
103 propertyChangeSupport.firePropertyChange( name, oldValue, newValue );
104 }
105
106 protected void notifyPropertyChanged( String name, int oldValue, int newValue )
107 {
108 propertyChangeSupport.firePropertyChange( name, oldValue, newValue );
109 }
110
111 protected void notifyPropertyChanged( String name, boolean oldValue, boolean newValue )
112 {
113 propertyChangeSupport.firePropertyChange( name, oldValue, newValue );
114 }
115
116 public class ShowModelItemAction extends AbstractAction
117 {
118 public ShowModelItemAction()
119 {
120 super("Show Editor");
121 }
122
123 public void actionPerformed(ActionEvent e)
124 {
125 UISupport.selectAndShow( AbstractModelItem.this );
126 }
127 }
128 }