1 5 6 7 package com.raptus.owxv3.api.components; 8 9 import java.util.Enumeration ; 10 11 import javax.servlet.http.*; 12 13 import com.raptus.owxv3.api.*; 14 import com.raptus.owxv3.modules.base.*; 15 16 38 public class ComponentContainerAction extends Object 39 { 40 43 public boolean initialize(ComponentContainer cc, HttpServletRequest request) 44 { 45 HttpSession session = request.getSession(); 46 47 49 if(cc.getComponents()!=null) 50 { 51 Enumeration enuCmps = cc.getComponents().elements(); 52 while(enuCmps.hasMoreElements()) 53 { 54 ComponentBean cb = (ComponentBean) enuCmps.nextElement(); 55 56 cb.setVModule(cc.getVModule()); session.setAttribute(cb.getData().getID(), cb); } } 61 62 cc.setURI(request.getServletPath()); return true; 64 } 65 66 71 public int process(ComponentContainer cc, HttpServletRequest request, BusinessObject bo) 72 { 73 processOpenClose(cc, request); 75 76 int ID = OmniaWebAction.convertToInteger(ComponentConstants.COMPONENT_NULL_DATAID, 78 request.getParameter(ComponentConstants.HTTPGET_PARAM_DATAID)); 79 String action = request.getParameter(ComponentConstants.HTTPGET_PARAM_ACTION); 80 81 if( action!=null && action.equalsIgnoreCase(ComponentConstants.COMPONENT_ACTION_NEW)) 82 { 83 cc.closeAllComponents(); 85 if(! ((BaseObject) bo).isNewEntryAllowed() ) 86 { 87 cc.setDataID( ComponentConstants.COMPONENT_NULL_DATAID ); 88 return 0; 89 } 90 91 if( ((ComponentBusinessObject) bo).loadComponentDefaultData(cc) ) return 1; 92 else return -1; 93 } 94 else if( (cc.getDataID() == ComponentConstants.COMPONENT_NULL_DATAID) && 95 (ID == ComponentConstants.COMPONENT_NULL_DATAID) ) 96 { 97 98 if(! ((BaseObject) bo).isNewEntryAllowed() ){ 99 cc.closeAllComponents(); 100 return 0; 101 } 102 } 103 else if( ID >= 0 ) 105 { 106 cc.setDataID(ID); 107 cc.closeAllComponents(); 108 109 if( ((ComponentBusinessObject) bo).loadComponentData(cc) ) 110 return 1; 111 else 112 return -1; 113 } 114 115 118 if(action != null && action.equalsIgnoreCase(ComponentConstants.COMPONENT_ACTION_SAVE)) 119 { 120 cc.closeAllComponents(); 121 122 if( ((ComponentBusinessObject) bo).saveComponentData(cc) ) return 2; 123 else return -1; 124 } 125 126 String openComponent = request.getParameter(ComponentConstants.HTTPGET_PARAM_OPEN); 127 128 if( openComponent!=null && openComponent.equalsIgnoreCase(BaseConstants.COMPONENT_PREVIEW_ID) ){ 129 fillDataForPreview(cc,bo); 130 } 131 String leftComponentOpen = request.getParameter(ComponentConstants.HTTPGET_PARAM_LEFTOPEN); 132 if(leftComponentOpen!=null) 133 { 134 cc.setLeftComponentOpen( !cc.getLeftComponentOpen() ); 135 } 136 return 1; 137 } 138 139 140 143 protected void processOpenClose(ComponentContainer cc, HttpServletRequest request) 144 { 145 String openComponent = request.getParameter(ComponentConstants.HTTPGET_PARAM_OPEN); 146 String closeComponent = request.getParameter(ComponentConstants.HTTPGET_PARAM_CLOSE); 147 148 boolean wantOpen = false; 150 ComponentBean cb = null; 151 if(openComponent != null) 152 { 153 cb = cc.getComponent(openComponent); 154 wantOpen = true; 155 } 156 else if(closeComponent != null) 157 cb = cc.getComponent(closeComponent); 158 159 if(cb != null) 160 { 161 if(cc.getOpenMultiple() == false) 164 cc.closeAllComponents(); 165 166 cb.setOpen(wantOpen); 167 } 168 } 169 170 173 174 protected void fillDataForPreview(ComponentContainer cc,BusinessObject bo){ 175 Enumeration enuCmps = cc.getComponents().elements(); 176 while(enuCmps.hasMoreElements()) 177 { 178 ComponentBean cb = (ComponentBean) enuCmps.nextElement(); 179 String cmpID = cb.getData().getID(); 180 if( cmpID.equals(BaseConstants.COMPONENT_PREVIEW_ID) ) 181 { 182 ((BaseObject)bo).loadPreviewData(cc, (CmpPreviewBean)cb); 183 break; 184 } 185 } 187 188 } 189 190 191 } 192 193 | Popular Tags |