KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormPropertyContext


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form;
21
22 import java.beans.*;
23
24 /**
25  * An interface for working with "context" of properties
26  * (of FormProperty type). The interface has three methods.
27  * First:
28  * boolean useMultipleEditors();
29  * describes whether the FormPropertyEditor can be used for editing properties.
30  * This property editor encapsulates multiple property editors which can be used
31  * for given property - this feature is not suitable e.g. for event properties,
32  * and sometimes not possible beacuase of restrictions in XML storage format
33  * (which must stay compatible with previous versions).
34  *
35  * Second:
36  * void initPropertyEditor(PropertyEditor prEd);
37  * initializes property editor for a property - property editors are usually
38  * constructed with no parameters, but often needs some context
39  * (e.g. FormAwareEditor needs FormModel).
40  *
41  * Third:
42  * FormModel getFormModel();
43  * provides the form the property belongs to. The context is needed for loading
44  * classes of property editors (from the right classpath).
45  *
46  * @author Tomas Pavek
47  */

48
49 public interface FormPropertyContext {
50
51     public boolean useMultipleEditors();
52
53     public void initPropertyEditor(PropertyEditor prEd);
54
55     public FormModel getFormModel();
56
57     /**
58      * Support for default implementation of FormPropertyContext interface.
59      * A FormModel must be supplied in addition to use this support.
60      */

61     public static abstract class DefaultSupport implements FormPropertyContext {
62
63         public boolean useMultipleEditors() {
64             FormModel formModel = getFormModel();
65             return formModel != null;
66         }
67
68         public void initPropertyEditor(PropertyEditor prEd) {
69             FormModel formModel = getFormModel();
70
71             if (formModel != null && prEd instanceof FormAwareEditor)
72                 ((FormAwareEditor)prEd).setFormModel(formModel);
73         }
74     }
75
76     /** Defualt implementation of FormPropertyContext interface. */
77     public static class DefaultImpl extends DefaultSupport {
78
79         FormModel formModel;
80
81         public DefaultImpl(FormModel form) {
82             formModel = form;
83         }
84
85         public FormModel getFormModel() {
86             return formModel;
87         }
88     }
89
90     /** "Empty" implementation of FormPropertyContext. */
91     public static class EmptyImpl implements FormPropertyContext {
92
93         public boolean useMultipleEditors() {
94             return false;
95         }
96
97         public void initPropertyEditor(PropertyEditor prEd) {
98         }
99
100         public FormModel getFormModel() {
101             return null;
102         }
103
104         // ------
105

106         public static EmptyImpl getInstance() {
107             if (theInstance == null)
108                 theInstance = new EmptyImpl();
109             return theInstance;
110         }
111
112         static private EmptyImpl theInstance = null;
113     }
114 }
115
Popular Tags