001: package org.apache.ojb.tools.mapping.reversedb2.propertyEditors;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * This class contains all the basic functionality for a property editor. It extends
020: * JPanel, so it could be added to a JScrollPane. The PropertyEditor always has
021: * an associated PropertyEditorTarget that acts as the "model" for the PropertyEditor
022: *
023: * To implement your PropertyEditor, you have to design a GUI with all the properties
024: * you want the user to see. You have to register the necessary listeners to get notified
025: * if a value is changed by the user in order to set the property in the model.
026: *
027: * Additionally you might want to register a PropertyChangeListener that gets notified
028: * if a property is changed in the model (for example by a second window based on the
029: * same model).
030: *
031: * In your implementation you should override setEditorTarget() to check, whether you get a correct
032: * object set as editorTarget and to retrieve the inital set of values from the editorTarget.
033: *
034: * If your Panel only contains components that implement PropertyEditorComponentInterface,
035: * you do not have to setup any listeners, you just should check that you get the correct
036: * object in setEditorTarget, everything else will be handled by this container. If you
037: * group components withing Panels and add those panels to this container, these panels
038: * have to implement PropertyEdtitorComponentInterface as well, the contained Components wouldn't
039: * get notified of a editorTarget change otherwise.
040: *
041: * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
042: * @version $Id: PropertyEditor.java,v 1.1.2.1 2005/12/21 22:33:27 tomdz Exp $
043: */
044:
045: abstract public class PropertyEditor extends javax.swing.JPanel {
046: private PropertyEditorTarget propertyTarget = null;
047: private java.beans.PropertyChangeListener aPropertyChangeListener = null;
048:
049: /** Creates new form PropertyEditor */
050: public PropertyEditor() {
051: initComponents();
052: }
053:
054: public void setEditorTarget(PropertyEditorTarget target) {
055: if (propertyTarget != null && aPropertyChangeListener != null) {
056: propertyTarget
057: .removePropertyChangeListener(aPropertyChangeListener);
058: }
059: propertyTarget = target;
060: if (propertyTarget != null && aPropertyChangeListener != null) {
061: propertyTarget
062: .addPropertyChangeListener(aPropertyChangeListener);
063: }
064:
065: java.awt.Component c[] = this .getComponents();
066: for (int i = 0; i < c.length; i++) {
067: if (c[i] instanceof PropertyEditorComponentInterface)
068: ((PropertyEditorComponentInterface) c[i])
069: .setEditorTarget(target);
070: }
071: }
072:
073: public PropertyEditorTarget getEditorTarget() {
074: return propertyTarget;
075: }
076:
077: public void setPropertyChangeListener(
078: java.beans.PropertyChangeListener pListener) {
079: if (propertyTarget != null && aPropertyChangeListener != null) {
080: propertyTarget
081: .removePropertyChangeListener(aPropertyChangeListener);
082: }
083: aPropertyChangeListener = pListener;
084: if (propertyTarget != null && aPropertyChangeListener != null) {
085: propertyTarget
086: .addPropertyChangeListener(aPropertyChangeListener);
087: }
088: }
089:
090: /** This method is called from within the constructor to
091: * initialize the form.
092: * WARNING: Do NOT modify this code. The content of this method is
093: * always regenerated by the Form Editor.
094: */
095: private void initComponents() {//GEN-BEGIN:initComponents
096:
097: setLayout(new java.awt.BorderLayout());
098:
099: }//GEN-END:initComponents
100:
101: // Variables declaration - do not modify//GEN-BEGIN:variables
102: // End of variables declaration//GEN-END:variables
103:
104: }
|