1 16 package org.apache.cocoon.woody.formmodel; 17 18 import org.apache.avalon.framework.service.ServiceException; 19 import org.apache.avalon.framework.service.ServiceManager; 20 import org.apache.avalon.framework.service.Serviceable; 21 import org.apache.cocoon.woody.datatype.Datatype; 22 import org.apache.cocoon.woody.datatype.DynamicSelectionList; 23 import org.apache.cocoon.woody.datatype.FlowJXPathSelectionList; 24 import org.apache.cocoon.woody.datatype.SelectionList; 25 import org.apache.cocoon.woody.event.ValueChangedEvent; 26 import org.apache.cocoon.woody.event.ValueChangedListener; 27 import org.apache.cocoon.woody.event.WidgetEventMulticaster; 28 29 34 public abstract class AbstractDatatypeWidgetDefinition extends AbstractWidgetDefinition implements Serviceable { 35 private Datatype datatype; 36 private SelectionList selectionList; 37 private ValueChangedListener listener; 38 private ServiceManager manager; 39 40 public void service(ServiceManager manager) throws ServiceException { 41 this.manager = manager; 42 } 43 44 public Datatype getDatatype() { 45 return datatype; 46 } 47 48 public void setDatatype(Datatype datatype) { 49 this.datatype = datatype; 50 } 51 52 public void setSelectionList(SelectionList selectionList) { 53 if (selectionList.getDatatype() != getDatatype()) 54 throw new RuntimeException ("Tried to assign a SelectionList that is not associated with this widget's datatype."); 55 this.selectionList = selectionList; 56 } 57 58 public SelectionList getSelectionList() { 59 return selectionList; 60 } 61 62 68 public SelectionList buildSelectionList(String uri) { 69 return new DynamicSelectionList(datatype, uri, this.manager); 70 } 71 72 84 public SelectionList buildSelectionListFromModel(Object model, String valuePath, String labelPath) { 85 return new FlowJXPathSelectionList(model, valuePath, labelPath, datatype); 86 } 87 88 public void addValueChangedListener(ValueChangedListener listener) { 89 this.listener = WidgetEventMulticaster.add(this.listener, listener); 90 } 91 92 public void fireValueChangedEvent(ValueChangedEvent event) { 93 if (this.listener != null) { 94 this.listener.valueChanged(event); 95 } 96 } 97 98 public boolean hasValueChangedListeners() { 99 return this.listener != null; 100 } 101 102 } 103 | Popular Tags |