KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > propertyEditors > PropertyEditor


1 package org.apache.ojb.tools.mapping.reversedb2.propertyEditors;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /**
19  * This class contains all the basic functionality for a property editor. It extends
20  * JPanel, so it could be added to a JScrollPane. The PropertyEditor always has
21  * an associated PropertyEditorTarget that acts as the "model" for the PropertyEditor
22  *
23  * To implement your PropertyEditor, you have to design a GUI with all the properties
24  * you want the user to see. You have to register the necessary listeners to get notified
25  * if a value is changed by the user in order to set the property in the model.
26  *
27  * Additionally you might want to register a PropertyChangeListener that gets notified
28  * if a property is changed in the model (for example by a second window based on the
29  * same model).
30  *
31  * In your implementation you should override setEditorTarget() to check, whether you get a correct
32  * object set as editorTarget and to retrieve the inital set of values from the editorTarget.
33  *
34  * If your Panel only contains components that implement PropertyEditorComponentInterface,
35  * you do not have to setup any listeners, you just should check that you get the correct
36  * object in setEditorTarget, everything else will be handled by this container. If you
37  * group components withing Panels and add those panels to this container, these panels
38  * have to implement PropertyEdtitorComponentInterface as well, the contained Components wouldn't
39  * get notified of a editorTarget change otherwise.
40  *
41  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
42  * @version $Id: PropertyEditor.java,v 1.1.2.1 2005/12/21 22:33:27 tomdz Exp $
43  */

44
45 abstract public class PropertyEditor extends javax.swing.JPanel JavaDoc
46 {
47     private PropertyEditorTarget propertyTarget = null;
48     private java.beans.PropertyChangeListener JavaDoc aPropertyChangeListener = null;
49     
50     /** Creates new form PropertyEditor */
51     public PropertyEditor ()
52     {
53         initComponents ();
54     }
55     
56     public void setEditorTarget(PropertyEditorTarget target)
57     {
58         if (propertyTarget != null && aPropertyChangeListener != null)
59         {
60             propertyTarget.removePropertyChangeListener(aPropertyChangeListener);
61         }
62         propertyTarget = target;
63         if (propertyTarget != null && aPropertyChangeListener != null)
64         {
65             propertyTarget.addPropertyChangeListener(aPropertyChangeListener);
66         }
67         
68         java.awt.Component JavaDoc c[] = this.getComponents();
69         for (int i = 0; i < c.length; i++)
70         {
71             if (c[i] instanceof PropertyEditorComponentInterface)
72                 ((PropertyEditorComponentInterface)c[i]).setEditorTarget(target);
73         }
74     }
75     
76     public PropertyEditorTarget getEditorTarget()
77     {
78         return propertyTarget;
79     }
80     
81     public void setPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pListener)
82     {
83         if (propertyTarget != null && aPropertyChangeListener != null)
84         {
85             propertyTarget.removePropertyChangeListener(aPropertyChangeListener);
86         }
87         aPropertyChangeListener = pListener;
88         if (propertyTarget != null && aPropertyChangeListener != null)
89         {
90             propertyTarget.addPropertyChangeListener(aPropertyChangeListener);
91         }
92     }
93     
94     /** This method is called from within the constructor to
95      * initialize the form.
96      * WARNING: Do NOT modify this code. The content of this method is
97      * always regenerated by the Form Editor.
98      */

99     private void initComponents ()
100     {//GEN-BEGIN:initComponents
101

102         setLayout (new java.awt.BorderLayout JavaDoc ());
103         
104     }//GEN-END:initComponents
105

106     
107     // Variables declaration - do not modify//GEN-BEGIN:variables
108
// End of variables declaration//GEN-END:variables
109

110 }
111
Popular Tags