1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: BeansEditorManager.java,v 1.7 2002/09/12 10:51:03 ludovicc Exp $
37 */
38 package org.scopemvc.model.beans;
39
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43 import org.scopemvc.core.EditorManager;
44 import org.scopemvc.core.PropertyManager;
45 import org.scopemvc.core.Selector;
46 import org.scopemvc.core.View;
47 import org.scopemvc.view.util.PropertyEditorFactory;
48
49 /***
50 * <P>
51 *
52 * BeansEditorManager is a {@link org.scopemvc.core.EditorManager} that handles
53 * creation of editors and viewer for properties of JavaBean model objects. </P>
54 * <P>
55 *
56 * Currently this ignores BeanInfo and uses the defaults in {@link
57 * org.scopemvc.view.util.PropertyEditorFactory} since the BeanInfo API has no
58 * way to distinguish different View implementations and doesn't have a getter
59 * for a viewer, just an editor. We could handle this a little better by
60 * type-checking the BeanInfo property editor for instanceof JComponent (and
61 * View) to see if it has a Swing impl, however that doesn't really work for
62 * arbitrary view types. </P>
63 *
64 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A>
65 * @created 05 September 2002
66 * @version $Revision: 1.7 $ $Date: 2002/09/12 10:51:03 $
67 */
68 public class BeansEditorManager extends EditorManager {
69
70 private static final Log LOG = LogFactory.getLog(BeansEditorManager.class);
71
72
73 /***
74 * Get the editor for the view type and the property in the model.
75 *
76 * @param inViewType type of view this editor is needed for. Defaults are
77 * provided for "swing" in DefaultScopeConfig that the
78 * BeansEditorManager uses.
79 * @param inModel model for whose property the editor is required.
80 * @param inSelector identify the property that the editor is needed for.
81 * @return a View used to edit the passed model's property for the passed
82 * view type.
83 */
84 public View getEditor(String inViewType, Object inModel, Selector inSelector) {
85 try {
86 Class propertyClass = PropertyManager.getInstance(inModel).getPropertyClass(inModel, inSelector);
87 return PropertyEditorFactory.getPropertyEditor(inViewType, propertyClass);
88 } catch (Exception e) {
89 LOG.warn("getEditor", e);
90 }
91 return null;
92 // PropertyDescriptor propertyDescriptor = BeansPropertyManager.getPropertyDescriptor(model, propertyName);
93 // Class editorClass = propertyDescriptor.getPropertyEditorClass();
94 // Object editor;
95 // if (editorClass == null) {
96 // editor = PropertyEditorManager.findEditor();
97 // } else {
98 // try {
99 // editor = editorClass.newInstance();
100 // } catch(Exception e) {
101 // LOG.fatal("Can't create: " + editorClass, e);
102 // editor = null;
103 // }
104 // }
105 // if (Debug.ON) Debug.assert(editor instanceof View, "editor not a View: " + editor);
106 // return (View)editor;
107 }
108
109
110 /***
111 * Get the viewer for the view type and the property in the model.
112 *
113 * @param inViewType type of view this viewer is needed for. Defaults are
114 * provided for "swing" in DefaultScopeConfig that the
115 * BeansEditorManager uses.
116 * @param inModel model for whose property the viewer is required.
117 * @param inSelector identify the property that the viewer is needed for.
118 * @return a View used to view the passed model's property for the passed
119 * view type.
120 */
121 public View getViewer(String inViewType, Object inModel, Selector inSelector) {
122 try {
123 Class propertyClass = PropertyManager.getInstance(inModel).getPropertyClass(inModel, inSelector);
124 return PropertyEditorFactory.getPropertyViewer(inViewType, propertyClass);
125 } catch (Exception e) {
126 LOG.warn("getViewer", e);
127 }
128 return null;
129 }
130 }
131
This page was automatically generated by Maven