001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.ui.support;
014:
015: import java.awt.BorderLayout;
016: import java.beans.PropertyChangeEvent;
017: import java.beans.PropertyChangeListener;
018: import java.beans.PropertyChangeSupport;
019:
020: import javax.swing.Action;
021: import javax.swing.Icon;
022: import javax.swing.JButton;
023: import javax.swing.JComponent;
024: import javax.swing.JPanel;
025:
026: import com.eviware.soapui.model.ModelItem;
027: import com.eviware.soapui.support.UISupport;
028: import com.eviware.soapui.ui.desktop.DesktopPanel;
029:
030: /**
031: * Base class for DesktopPanels..
032: */
033:
034: public abstract class ModelItemDesktopPanel<T extends ModelItem>
035: extends JPanel implements DesktopPanel {
036: private PropertyChangeSupport propertyChangeSupport;
037: private final T modelItem;
038: private InternalPropertyChangeListener propertyChangeListener;
039:
040: public ModelItemDesktopPanel(T modelItem) {
041: super (new BorderLayout());
042: this .modelItem = modelItem;
043: propertyChangeSupport = new PropertyChangeSupport(this );
044:
045: propertyChangeListener = new InternalPropertyChangeListener();
046: ((ModelItem) modelItem)
047: .addPropertyChangeListener(propertyChangeListener);
048: }
049:
050: protected boolean release() {
051: modelItem.removePropertyChangeListener(propertyChangeListener);
052: return true;
053: }
054:
055: public JComponent getComponent() {
056: return this ;
057: }
058:
059: final public T getModelItem() {
060: return modelItem;
061: }
062:
063: public Icon getIcon() {
064: return modelItem.getIcon();
065: }
066:
067: abstract public boolean dependsOn(ModelItem modelItem);
068:
069: public String getTitle() {
070: return modelItem.getName();
071: }
072:
073: public String getDescription() {
074: return modelItem.getDescription();
075: }
076:
077: protected JButton createActionButton(Action action, boolean enabled) {
078: JButton button = UISupport.createToolbarButton(action, enabled);
079: action.putValue(Action.NAME, null);
080: return button;
081: }
082:
083: public void addPropertyChangeListener(String propertyName,
084: PropertyChangeListener listener) {
085: propertyChangeSupport.addPropertyChangeListener(propertyName,
086: listener);
087: }
088:
089: public void addPropertyChangeListener(
090: PropertyChangeListener listener) {
091: propertyChangeSupport.addPropertyChangeListener(listener);
092: }
093:
094: public void removePropertyChangeListener(
095: PropertyChangeListener listener) {
096: propertyChangeSupport.removePropertyChangeListener(listener);
097: }
098:
099: public void removePropertyChangeListener(String propertyName,
100: PropertyChangeListener listener) {
101: propertyChangeSupport.removePropertyChangeListener(
102: propertyName, listener);
103: }
104:
105: public void notifyPropertyChange(String propertyName,
106: Object oldValue, Object newValue) {
107: propertyChangeSupport.firePropertyChange(propertyName,
108: oldValue, newValue);
109: }
110:
111: private class InternalPropertyChangeListener implements
112: PropertyChangeListener {
113: public void propertyChange(PropertyChangeEvent evt) {
114: if (evt.getPropertyName().equals(ModelItem.NAME_PROPERTY))
115: notifyPropertyChange(DesktopPanel.TITLE_PROPERTY, null,
116: getTitle());
117:
118: if (evt.getPropertyName().equals(ModelItem.ICON_PROPERTY))
119: notifyPropertyChange(DesktopPanel.ICON_PROPERTY, null,
120: getIcon());
121: }
122: }
123: }
|