1 23 24 package com.sun.enterprise.tools.guiframework.event.handlers; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.ViewBeanManager; 28 import com.iplanet.jato.view.DisplayField; 29 import com.iplanet.jato.view.ContainerView; 30 import com.iplanet.jato.view.View; 31 32 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 33 import com.sun.enterprise.tools.guiframework.view.DescriptorViewManager; 34 35 import java.util.Iterator ; 36 import java.util.List ; 37 import java.util.Map ; 38 39 40 43 public class DisplayFieldHandlers { 44 45 58 public void getDisplayFieldValue(RequestContext reqCtx, HandlerContext handlerCtx) { 59 DisplayField field = (DisplayField)handlerCtx.getInputValue(DISPLAY_FIELD); 60 if (field == null) { 61 getDisplayField(reqCtx, handlerCtx); 63 field = (DisplayField)handlerCtx.getOutputValue(VALUE); 64 } 65 66 Boolean multi = (Boolean )handlerCtx.getInputValue(MULTI_VALUE); 68 boolean getMulti = false; 69 if (multi != null) { 70 getMulti = multi.booleanValue(); 71 } 72 73 Object value = getMulti ? field.getValues() : field.getValue(); 75 handlerCtx.setOutputValue(VALUE, value); 76 } 77 78 79 82 public void getDisplayField(RequestContext reqCtx, HandlerContext handlerCtx) { 83 Object viewID = handlerCtx.getInputValue(VIEW_ID); 85 if (viewID == null) { 86 throw new IllegalArgumentException ( 87 "The parameter map did not contain "+VIEW_ID+"!"); 88 } 89 90 ViewBeanManager vm = reqCtx.getViewBeanManager(); 92 View view = null; 93 String topName = (viewID instanceof List ) ? 94 ((List )viewID).get(0).toString() : viewID.toString(); 95 try { 96 view = vm.getViewBean(topName); 97 } catch (ClassCastException ex) { 98 view = ((DescriptorViewManager)vm).getView(null, topName); 99 } catch (ClassNotFoundException ex) { 100 throw new RuntimeException (ex); 101 } 102 if (view == null) { 103 throw new RuntimeException ( 104 "Unable to obtain the view for mapping!"); 105 } 106 107 if (viewID instanceof List ) { 109 Iterator iter = ((List )viewID).iterator(); 110 iter.next(); while (iter.hasNext()) { 112 if (!(view instanceof ContainerView)) { 113 throw new RuntimeException ("View ("+ 114 view.getQualifiedName()+") is not a ContainerView!"); 115 } 116 view = ((ContainerView)view).getChild(""+iter.next()); 117 } 118 } 119 120 if (!(view instanceof ContainerView)) { 122 throw new RuntimeException ( 123 "View ("+view.getQualifiedName()+") is not a ContainerView!"); 124 } 125 126 Object fieldName = handlerCtx.getInputValue(FIELD_NAME); 128 if (fieldName == null) { 129 throw new IllegalArgumentException ( 130 "The parameter map did not contain "+FIELD_NAME+"!"); 131 } 132 133 DisplayField field = 135 ((ContainerView)view).getDisplayField(fieldName.toString()); 136 if (field == null) { 137 throw new RuntimeException ( 138 "Field ("+fieldName+") not found on View ("+viewID+")!"); 139 } 140 141 handlerCtx.setOutputValue(VALUE, field); 143 } 144 145 146 160 public void setDisplayFieldValue(RequestContext reqCtx, HandlerContext handlerCtx) { 161 DisplayField field = (DisplayField)handlerCtx.getInputValue(DISPLAY_FIELD); 162 if (field == null) { 163 getDisplayField(reqCtx, handlerCtx); 165 field = (DisplayField)handlerCtx.getOutputValue(VALUE); 166 } 167 168 Boolean multi = (Boolean )handlerCtx.getInputValue(MULTI_VALUE); 170 boolean getMulti = false; 171 if (multi != null) { 172 getMulti = multi.booleanValue(); 173 } 174 175 Object value = handlerCtx.getInputValue(VALUE); 177 if (getMulti) { 178 if ((value != null) && !value.getClass().isArray()) { 180 value = new Object [] {value}; 181 } 182 field.setValues((Object [])value); 183 } else { 184 field.setValue(value); 185 } 186 } 187 188 189 public static final String VALUE = "value"; 190 public static final String MULTI_VALUE = "multiple"; 191 public static final String VIEW_ID = "viewID"; 192 public static final String FIELD_NAME = "fieldName"; 193 public static final String DISPLAY_FIELD = "displayField"; 194 } 195 | Popular Tags |