1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.ui.support;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.model.ModelItem;
17 import com.eviware.soapui.model.tree.SoapUITreeNode;
18 import com.eviware.soapui.model.tree.nodes.support.EmptyModelItem;
19 import com.eviware.soapui.support.UISupport;
20 import com.eviware.soapui.ui.desktop.DesktopPanel;
21
22 import javax.swing.*;
23 import javax.swing.tree.TreePath;
24 import java.awt.*;
25 import java.beans.PropertyChangeEvent;
26 import java.beans.PropertyChangeListener;
27
28 /***
29 * Base class for DesktopPanels..
30 */
31
32 public abstract class ModelItemDesktopPanel<T extends ModelItem> extends JPanel implements DesktopPanel, PropertyChangeListener
33 {
34 private final T modelItem;
35
36 public ModelItemDesktopPanel(T modelItem)
37 {
38 super(new BorderLayout());
39 this.modelItem = modelItem;
40
41 ((ModelItem) modelItem).addPropertyChangeListener(this);
42 }
43
44 protected boolean release()
45 {
46 modelItem.removePropertyChangeListener(this);
47 return true;
48 }
49
50 public JComponent getComponent()
51 {
52 return this;
53 }
54
55 final public T getModelItem()
56 {
57 return modelItem;
58 }
59
60 public Icon getIcon()
61 {
62 return modelItem.getIcon();
63 }
64
65 abstract public boolean dependsOn(ModelItem modelItem);
66
67 public String getTitle()
68 {
69 return modelItem.getName();
70 }
71
72 public final String getDescription()
73 {
74 TreePath treePath = SoapUI.getNavigator().getTreePath(modelItem);
75
76 if (treePath == null)
77 {
78 return modelItem.getDescription();
79 }
80 else
81 {
82 String str = modelItem.getName() + " [";
83
84 for (int c = 1; c < treePath.getPathCount(); c++)
85 {
86 SoapUITreeNode comp = (SoapUITreeNode) treePath.getPathComponent(c);
87 if (comp.getModelItem() instanceof EmptyModelItem)
88 continue;
89
90 if (c > 1)
91 str += "/";
92
93 str += comp.toString();
94 }
95
96 str += "]";
97
98 return str;
99 }
100 }
101
102 public static JButton createActionButton(Action action, boolean enabled)
103 {
104 JButton button = UISupport.createToolbarButton(action, enabled);
105 action.putValue(Action.NAME, null);
106 return button;
107 }
108
109 public void notifyPropertyChange(String propertyName, Object oldValue, Object newValue)
110 {
111 firePropertyChange(propertyName, oldValue, newValue);
112 }
113
114 public void propertyChange(PropertyChangeEvent evt)
115 {
116 if (evt.getPropertyName().equals(ModelItem.NAME_PROPERTY))
117 notifyPropertyChange(DesktopPanel.TITLE_PROPERTY, null, getTitle());
118
119 if (evt.getPropertyName().equals(ModelItem.ICON_PROPERTY))
120 notifyPropertyChange(DesktopPanel.ICON_PROPERTY, null, getIcon());
121 }
122 }