1 23 24 package com.sun.enterprise.tools.guiframework.view.descriptors; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.RequestManager; 28 import com.iplanet.jato.view.ContainerView; 29 import com.iplanet.jato.view.ContainerViewBase; 30 import com.iplanet.jato.view.View; 31 32 import com.sun.web.ui.model.CCTabsModelInterface; 33 import com.sun.web.ui.model.CCNavNode; 34 import com.sun.web.ui.model.CCNavNodeInterface; 35 36 import com.sun.enterprise.tools.guiframework.view.DescriptorCCTabs; 37 38 import java.util.HashMap ; 39 import java.util.List ; 40 import java.util.Map ; 41 42 import javax.servlet.ServletRequest ; 43 44 45 51 public class CCTabsDescriptor extends ViewDescriptor { 52 53 56 public CCTabsDescriptor(String name) { 57 super(name); 58 } 59 60 61 64 public void registerChildren(ContainerViewBase instance) { 65 getNodeTabsModel(); 66 super.registerChildren(instance); 67 } 68 69 70 77 public View getInstance(RequestContext ctx, ContainerView container, String name) { 78 return new DescriptorCCTabs(ctx, container, name, this, getNodeTabsModel(ctx)); 79 } 80 81 82 85 public CCTabsModelInterface getNodeTabsModel() { 86 return getNodeTabsModel(RequestManager.getRequestContext()); 87 } 88 89 90 93 public CCTabsModelInterface getNodeTabsModel(RequestContext ctx) { 94 String pageName = getParent().getName(); 96 CCTabsModelInterface model = (CCTabsModelInterface) 97 ctx.getModelManager().getModel( 98 CCTabsModelInterface.class, pageName+'.'+getName(), false, false); 99 if (model.getNodes().size() > 0) { 100 return model; 102 } 103 model.setIsLocal(true); 105 ServletRequest request = ctx.getRequest(); 106 107 Map viewBeanMap = ((Map )request.getAttribute(VIEW_BEAN_MAP)); 112 int startCount = 1; 113 if (viewBeanMap == null || 114 pageName.equals((String )viewBeanMap.get("pageName")) == false) { 115 viewBeanMap = new HashMap (); 116 viewBeanMap.put("pageName", pageName); 117 request.setAttribute(VIEW_BEAN_MAP, viewBeanMap); 118 } else { 119 startCount += viewBeanMap.size(); 120 } 121 buildTabs(ctx, model, getChildDescriptors(), null, startCount); 122 model.setSelectedNode( 123 ((Integer )request.getAttribute(CURR_TAB_ID)).intValue()); 124 return model; 125 } 126 127 128 131 protected int buildTabs(RequestContext ctx, CCTabsModelInterface model, List tabs, CCNavNodeInterface parent, int id) { 132 if ((tabs == null) || (tabs.size() == 0)) { 133 return id; 134 } 135 136 String currViewName = getParent().getName(); 137 138 for (int index=0; index<tabs.size(); index++) { 140 ViewDescriptor tab = (ViewDescriptor)tabs.get(index); 141 if (tab.getName().equals("TabHref")) { 142 continue; 148 } 149 String label = (String )tab.getParameter("label"); 150 String tooltip = (String )tab.getParameter("tooltip"); 151 String status = (String )tab.getParameter("status"); 152 String tabPage = (String )tab.getParameter("nextPage"); 153 String target = (String )tab.getParameter("target"); 154 if (label == null || tabPage == null) { 155 throw new RuntimeException ("Missing required parameters (label, nextPage) in tab declaration: "+ 156 tab.getName()+", in view: "+currViewName, null); 157 } 158 CCNavNode node = new CCNavNode(id, parent, label, tooltip, status); 159 if ((target != null) && !(target.trim().equals(""))) { 160 node.setTarget(target); 161 } 162 if (parent == null) { 163 model.addNode(node); 164 } 165 if ((tabPage != null) && !(tabPage.equals(""))) { 166 ServletRequest request = ctx.getRequest(); 167 ((Map )request.getAttribute(VIEW_BEAN_MAP)).put(""+id, tabPage); 168 if (tabPage.equals(currViewName)) { 169 request.setAttribute(CURR_TAB_ID, new Integer (id)); 170 } 171 } 172 id++; 173 id = buildTabs(ctx, model, tab.getChildDescriptors(), node, id); 174 } 175 return id; 176 } 177 178 179 182 public String getViewBean(RequestContext ctx, int id) { 183 Map vbMap = (Map )ctx.getRequest().getAttribute(VIEW_BEAN_MAP); 184 if (vbMap == null) { 185 getNodeTabsModel(ctx); 186 vbMap = (Map )ctx.getRequest().getAttribute(VIEW_BEAN_MAP); 187 } 188 ctx.getRequest().setAttribute(VIEW_BEAN_MAP, null); 192 return vbMap.get(""+id).toString(); 193 } 194 195 196 protected static final String VIEW_BEAN_MAP = "__CCTabsDesc_VBs"; 197 protected static final String CURR_TAB_ID = "__CCTabsDesc_parentID"; 198 } 199 | Popular Tags |