1 23 24 package com.sun.enterprise.tools.admingui.descriptors; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.RequestManager; 28 import com.iplanet.jato.model.DefaultModel; 29 import com.iplanet.jato.view.BasicCommandField; 30 import com.iplanet.jato.view.ContainerView; 31 import com.iplanet.jato.view.ContainerViewBase; 32 import com.iplanet.jato.view.View; 33 34 import com.sun.web.ui.model.CCBreadCrumbsModel; 35 import com.sun.web.ui.model.CCBreadCrumbsModelInterface; 36 import com.sun.web.ui.view.breadcrumb.CCBreadCrumbs; 37 38 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode; 39 import com.sun.enterprise.tools.admingui.util.Util; 40 import com.sun.enterprise.tools.admingui.ConfigProperties; 41 import com.sun.enterprise.tools.guiframework.event.descriptors.EventDescriptor; 42 import com.sun.enterprise.tools.guiframework.event.descriptors.HandlerDescriptor; 43 import com.sun.enterprise.tools.guiframework.event.descriptors.UseHandlerDescriptor; 44 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 45 import com.sun.enterprise.tools.guiframework.view.descriptors.BasicCommandFieldDescriptor; 46 import com.sun.enterprise.tools.guiframework.view.descriptors.FakeContainerDescriptor; 47 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 48 49 import java.util.ArrayList ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Stack ; 53 54 55 60 public class CCBreadCrumbsDescriptor extends ViewDescriptor implements FakeContainerDescriptor { 61 62 65 public CCBreadCrumbsDescriptor() { 66 this(BREADCRUMB); 67 } 68 69 70 73 public CCBreadCrumbsDescriptor(String name) { 74 super(name); 75 } 76 77 78 84 public View getInstance(RequestContext ctx, ContainerView container, String name) { 85 return new CCBreadCrumbs(container, getModel(), name); 86 } 87 88 89 92 public void registerChildren(ContainerViewBase instance) { 93 super.registerChildren(instance); 96 97 int numberOfCrumbs = getNumberOfBreadCrumbs( 99 instance.getParentViewBean().getRequestContext()); 100 for (int i=0; i<numberOfCrumbs; i++) { 101 instance.registerChild(CHILD_BREADCRUMB_LINK+i, BasicCommandField.class); 102 } 103 } 104 105 106 109 public int getNumberOfBreadCrumbs(RequestContext ctx) { 110 CCBreadCrumbsModelInterface model = getModel(ctx); 111 if (model == null) { 112 return 0; 113 } 114 115 return ((DefaultModel)model).getNumRows(); 117 } 118 119 120 128 public CCBreadCrumbsModelInterface getModel() { 129 RequestContext rc = RequestManager.getRequestContext(); 130 return getModel(rc); 131 } 132 133 134 144 protected CCBreadCrumbsModelInterface getModel(RequestContext rc) { 145 IndexTreeNode node = Util.getSelectedNode(); 147 148 CCBreadCrumbsModelInterface model = (CCBreadCrumbsModelInterface) 151 rc.getModelManager().getModel(CCBreadCrumbsModelInterface.class, 152 node.getPath(), false, false); 153 154 if (model.getCurrentPageLabel() != null) { 158 return model; 160 } 161 162 model.setCurrentPageLabel(node.getDisplayName()); 164 165 Stack stack = getNodeStack(node); 167 168 DefaultModel defModel = (DefaultModel)model; 170 171 int crumbCount = 0; 172 while (!stack.empty()) { 173 node = (IndexTreeNode)stack.pop(); 174 defModel.appendRow(); 175 defModel.setValue( 176 CCBreadCrumbsModel.COMMANDFIELD, 177 CHILD_BREADCRUMB_LINK+crumbCount++); 178 defModel.setValue(CCBreadCrumbsModel.LABEL, node.getDisplayName()); 179 defModel.setValue(CCBreadCrumbsModel.MOUSEOVER, node.getDisplayName()); 180 } 181 182 return model; 184 } 185 186 187 191 public List getChildDescriptors() { 192 List descs = new ArrayList (super.getChildDescriptors()); 194 195 Stack stack = getNodeStack(Util.getSelectedNode()); 197 for (int count=0; !stack.empty(); count++) { 198 descs.add(createChildBreadCrumbDescriptor( 199 CHILD_BREADCRUMB_LINK+count, (IndexTreeNode)stack.pop())); 200 } 201 202 return descs; 203 } 204 205 206 215 protected Stack getNodeStack(IndexTreeNode node) { 216 Stack stack = new Stack (); 218 for (node=node.getParent(); (node != null); node=node.getParent()) { 219 String include = (String )node.getAttribute("includeInBreadCrumb", false); 220 if (include != null && include.equals("false")) 221 continue; 222 stack.push(node); 223 } 224 225 return stack; 226 } 227 228 229 233 public ViewDescriptor getChildDescriptor(String name) { 234 238 if (name.startsWith(CHILD_BREADCRUMB_LINK)) { 240 int linkNum = 0; 242 try { 243 linkNum = Integer.parseInt(name.substring(CHILD_BREADCRUMB_LINK.length())); 244 } catch (NumberFormatException ex) { 245 throw new FrameworkException( 246 "Could not determine link number of: "+name, 247 ex, this, null); 248 } 249 250 Stack stack = getNodeStack(Util.getSelectedNode()); 252 253 IndexTreeNode node = (IndexTreeNode) 257 stack.get(stack.size()-linkNum-1); 258 259 return createChildBreadCrumbDescriptor(name, node); 262 } 263 264 ViewDescriptor desc = null; 269 Iterator iter = super.getChildDescriptors().iterator(); 270 while (iter.hasNext()) { 271 desc = (ViewDescriptor)iter.next(); 272 if (desc.getName().equals(name)) { 273 return desc; 274 } 275 } 276 277 return null; 279 } 280 281 282 286 protected ViewDescriptor createChildBreadCrumbDescriptor(String name, IndexTreeNode node) { 287 ViewDescriptor desc = new BasicCommandFieldDescriptor(name); 288 289 desc.addParameter("treeNode", node.getPath()); 291 292 EventDescriptor event = new EventDescriptor(desc, EventDescriptor.TYPES.COMMAND); 294 event.addEventHandler(new UseHandlerDescriptor(desc, CLICK_HANDLER)); 295 desc.setEventDescriptor(event); 296 desc.setParent(this); 297 298 return desc; 300 } 301 302 303 public static final String BREADCRUMB = "BreadCrumb"; 305 public static final String CHILD_BREADCRUMB_LINK = "BreadCrumbLink"; 306 307 public static HandlerDescriptor CLICK_HANDLER; 308 static { 309 CLICK_HANDLER = new HandlerDescriptor("BreadCrumbHandler"); 310 CLICK_HANDLER.setHandlerMethod( 311 "com.sun.enterprise.tools.admingui.handlers.BreadCrumbHandler", 312 "handleClick"); 313 } 314 315 private CCBreadCrumbsModel _model = null; 316 } 317 | Popular Tags |