Source code: jac/aspects/gui/web/AbstractFieldView.java
1 /*
2 Copyright (C) 2001-2002 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 jac.aspects.gui.web;
19
20 import jac.aspects.gui.FieldUpdate;
21 import jac.aspects.gui.FieldView;
22 import jac.aspects.gui.GuiAC;
23 import jac.aspects.gui.Utils;
24 import jac.core.rtti.ClassItem;
25 import jac.core.rtti.FieldItem;
26 import jac.util.Log;
27 import jac.util.Stack;
28
29 public abstract class AbstractFieldView extends AbstractView
30 implements FieldUpdate, FieldView
31 {
32 // substance and field are required so that we can register and
33 // unregister ourself from fieldUpdated events on close()
34 Object substance;
35 FieldItem field;
36
37 public AbstractFieldView(Object substance, FieldItem field) {
38 this.substance = substance;
39 this.field = field;
40
41 Utils.registerField(substance,field,this);
42
43 if (GuiAC.getGraphicContext()!=null)
44 contexts.addAll(GuiAC.getGraphicContext());
45 if (field!=null)
46 contexts.push(field);
47 }
48
49 Stack contexts = new Stack();
50
51 public AbstractFieldView() {
52 if (GuiAC.getGraphicContext()!=null)
53 contexts.addAll(GuiAC.getGraphicContext());
54 }
55
56 public abstract void setValue(Object value);
57
58 public void setSubstance(Object substance) {
59 Utils.unregisterField(this.substance,field,this);
60 this.substance = substance;
61 Utils.registerField(substance,field,this);
62 }
63
64 public void setField(FieldItem field) {
65 Utils.unregisterField(substance,this.field,this);
66 this.field = field;
67 Utils.registerField(substance,field,this);
68 if (field!=null)
69 contexts.push(field);
70 }
71
72 public FieldItem getField() {
73 return field;
74 }
75
76 public void close() {
77 Utils.unregisterField(substance,field,this);
78 }
79
80 // FieldUpdate interface
81 public void fieldUpdated(Object substance, FieldItem field, Object value, Object param) {
82 setValue(value);
83 }
84
85 }