1 18 19 package org.objectweb.jac.aspects.gui.web; 20 21 import org.objectweb.jac.aspects.gui.*; 22 import org.objectweb.jac.core.rtti.FieldItem; 23 import java.io.PrintWriter ; 24 25 37 38 public class ReferenceView extends AbstractFieldView 39 implements FieldView, FieldUpdate, ObjectUpdate, 40 HTMLViewer, SelectionListener, LinkGenerator 41 { 42 protected Object object; 43 protected String text; 44 protected String eventURL; 45 46 50 51 public ReferenceView(Object value, Object substance, FieldItem reference) { 52 super(substance,reference); 53 this.object = value; 54 55 if (autoUpdate) 56 Utils.registerField(substance,reference,this); 57 58 refreshView(); 59 } 60 61 public ReferenceView() { 62 } 63 64 boolean enableLinks = true; 65 public void setEnableLinks(boolean enable) { 66 this.enableLinks = enable; 67 } 68 public boolean areLinksEnabled() { 69 return enableLinks; 70 } 71 72 public void refreshView() { 73 if (autoUpdate) 74 Utils.registerObject(object,this); 75 if (object!=null) { 76 text = GuiAC.toString(object,contexts); 77 } else { 78 text = ""; 79 } 80 } 81 82 85 public void setEventURL(String eventURL) { 86 this.eventURL = eventURL; 87 } 88 89 91 public void setValue(Object value) { 92 if (autoUpdate) 93 Utils.unregisterObject(object,this); 94 this.object = value; 95 refreshView(); 96 } 97 98 public void close(boolean validate) { 99 super.close(validate); 100 if (autoUpdate) 101 Utils.unregisterObject(object,this); 102 } 103 104 106 public void fieldUpdated(Object substance, FieldItem field, Object value, Object param) { 107 setValue(value); 108 } 109 110 112 public void objectUpdated(Object object, Object param) { 113 refreshView(); 114 } 115 116 public void genHTML(PrintWriter out) { 118 if (enableLinks) 119 out.print("<a HREF=\""+ 120 (eventURL!=null?eventURL:eventURL("onSelection"))+"\">"+text+"</a>"); 121 else 122 out.print(text); 123 } 124 125 127 public void onSelection() { 128 EventHandler.get().onSelection(context,field,object,null,null,true); 129 } 130 131 } 132 | Popular Tags |