1 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 31 public abstract class AbstractFieldView extends AbstractView 32 implements FieldUpdate, FieldView 33 { 34 static Logger logger = Logger.getLogger("gui.autoupdate"); 35 36 protected Object substance; 39 protected FieldItem field; 40 protected boolean autoUpdate = true; 41 42 public AbstractFieldView(Object 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 value); 63 64 public void setSubstance(Object 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 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 public void fieldUpdated(Object substance, FieldItem field, Object value, Object param) { 110 setValue(value); 111 } 112 113 } 114 | Popular Tags |