KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > AbstractFieldView


1 /*
2   Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui.web;
19
20 import org.apache.log4j.Logger;
21 import org.objectweb.jac.aspects.gui.FieldUpdate;
22 import org.objectweb.jac.aspects.gui.FieldView;
23 import org.objectweb.jac.aspects.gui.GuiAC;
24 import org.objectweb.jac.aspects.gui.Utils;
25 import org.objectweb.jac.core.rtti.FieldItem;
26 import org.objectweb.jac.util.Stack;
27
28 /**
29  * Base class for field views
30  */

31 public abstract class AbstractFieldView extends AbstractView
32    implements FieldUpdate, FieldView
33 {
34     static Logger logger = Logger.getLogger("gui.autoupdate");
35
36     // substance and field are required so that we can register and
37
// unregister ourself from fieldUpdated events on close()
38
protected Object JavaDoc substance;
39     protected FieldItem field;
40     protected boolean autoUpdate = true;
41
42     public AbstractFieldView(Object JavaDoc substance, FieldItem field) {
43         this.substance = substance;
44         this.field = field;
45
46         if (autoUpdate)
47             Utils.registerField(substance,field,this);
48
49         if (GuiAC.getGraphicContext()!=null)
50             contexts.addAll(GuiAC.getGraphicContext());
51         if (field!=null)
52             contexts.push(field);
53     }
54
55     Stack contexts = new Stack();
56
57     public AbstractFieldView() {
58         if (GuiAC.getGraphicContext()!=null)
59             contexts.addAll(GuiAC.getGraphicContext());
60     }
61
62     public abstract void setValue(Object JavaDoc value);
63
64     public void setSubstance(Object JavaDoc substance) {
65         logger.debug(this+".setSubstance, autoUpdate="+autoUpdate);
66         if (autoUpdate)
67             Utils.unregisterField(this.substance,field,this);
68         this.substance = substance;
69         if (autoUpdate)
70             Utils.registerField(substance,field,this);
71     }
72
73     public Object JavaDoc getSubstance() {
74         return substance;
75     }
76
77     public void setField(FieldItem field) {
78         logger.debug(this+".setField, autoUpdate="+autoUpdate);
79         if (autoUpdate)
80             Utils.unregisterField(substance,this.field,this);
81         this.field = field;
82         if (autoUpdate)
83             Utils.registerField(substance,field,this);
84         if (field!=null)
85             contexts.push(field);
86     }
87
88     public FieldItem getField() {
89         return field;
90     }
91
92     public void setAutoUpdate(boolean autoUpdate) {
93         logger.debug(this+".setAutoUpdate "+autoUpdate);
94         if (this.autoUpdate!=autoUpdate) {
95             if (this.autoUpdate)
96                 Utils.unregisterField(substance,field,this);
97             this.autoUpdate = autoUpdate;
98             if (autoUpdate)
99                 Utils.registerField(substance,field,this);
100         }
101     }
102
103     public void close(boolean validate) {
104         if (autoUpdate)
105             Utils.unregisterField(substance,field,this);
106     }
107    
108     // FieldUpdate interface
109
public void fieldUpdated(Object JavaDoc substance, FieldItem field, Object JavaDoc value, Object JavaDoc param) {
110         setValue(value);
111     }
112
113 }
114
Popular Tags