00001 00066 package com.arcle.rmt.superwaba.vc; 00067 00068 import waba.ui.ListBox; 00069 import waba.ui.Event; 00070 import waba.ui.ControlEvent; 00071 00072 import com.arcle.rmt.superwaba.ui.ListForm; 00073 import com.arcle.rmt.superwaba.framework.View; 00074 import com.arcle.rmt.superwaba.framework.Model; 00075 import com.arcle.rmt.superwaba.model.Document; 00076 import com.arcle.rmt.superwaba.vc.ElementListController; 00077 import com.arcle.rmt.rqml.RQMLFirstClass; 00078 00086 public abstract class ElementList extends ListForm implements View { 00087 00092 public ElementList(ElementListController ctrl, String caption) { 00093 _controller = ctrl; 00094 this.caption = caption; 00095 } 00096 00097 //----------------------------------------------------------------------- 00098 // Abstract Methods 00099 00100 protected abstract int getElementCount(); 00101 00102 protected abstract RQMLFirstClass getElementAt(int i); 00103 00104 //----------------------------------------------------------------------- 00105 // View implementations 00106 00111 public void modelUpdated() { 00112 ListBox lb = getListBox(); 00113 lb.removeAll(); 00114 lb.add(getElements()); 00115 } 00116 00117 //----------------------------------------------------------------------- 00118 // Overridden Methods 00119 00120 protected void initChildren() { } 00121 00122 protected void initCompleted() { 00123 getController().viewInitialized(this); 00124 } 00125 00126 00127 public void onEvent(Event event) { 00128 ListBox lb = getListBox(); 00129 switch (event.type) { 00130 case ControlEvent.PRESSED: 00131 if (event.target == lb) { 00132 int selected = lb.getSelectedIndex(); 00133 RQMLFirstClass elem = getElementAt(selected); 00134 getController().cmdEditElement(elem); 00135 event.consumed = true; 00136 } 00137 } 00138 if (!event.consumed) { 00139 super.onEvent(event); 00140 } 00141 } 00142 00143 //----------------------------------------------------------------------- 00144 // Accessor Methods 00145 00146 00147 protected Document getDocument() { 00148 return getController().getDocument(); 00149 } 00150 00151 public ElementListController getController() { 00152 return _controller; 00153 } 00154 00155 00156 protected String[] getElements() { 00157 String[] titles = new String[getElementCount()]; 00158 00159 for (int i=0; i<titles.length; i++) { 00160 RQMLFirstClass elem = getElementAt(i); 00161 String id = elem.getID(); 00162 String name = elem.getName().getString(); 00163 titles[i] = id + " " + name; 00164 } 00165 00166 return titles; 00167 } 00168 00169 //----------------------------------------------------------------------- 00170 // Own Public methods 00171 00175 public String getCaption() { 00176 return caption; 00177 } 00178 00179 //----------------------------------------------------------------------- 00180 // Member Variables 00181 00182 00183 private String caption; 00184 00185 private Document _document; 00186 00187 private ElementListController _controller; 00188 }