From: Anjo K. <an...@us...> - 2003-08-30 20:57:37
|
Update of /cvsroot/wonder/Wonder/Common/Frameworks/ERDirectToWeb/Sources/er/directtoweb In directory sc8-pr-cvs1:/tmp/cvs-serv12044 Modified Files: ERD2WListPage.java Log Message: changed inheritance to descend from ERD2WPage instead of D2WListPage, re-implemented missing functions Index: ERD2WListPage.java =================================================================== RCS file: /cvsroot/wonder/Wonder/Common/Frameworks/ERDirectToWeb/Sources/er/directtoweb/ERD2WListPage.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ERD2WListPage.java 29 Aug 2003 17:29:38 -0000 1.22 --- ERD2WListPage.java 30 Aug 2003 20:57:33 -0000 1.23 *************** *** 15,19 **** import org.apache.log4j.NDC; ! public abstract class ERD2WListPage extends D2WListPage implements ERXComponentActionRedirector.Restorable { /** logging support */ --- 15,19 ---- import org.apache.log4j.NDC; ! public abstract class ERD2WListPage extends ERD2WPage implements ListPageInterface, SelectPageInterface, ERXComponentActionRedirector.Restorable { /** logging support */ *************** *** 26,34 **** public ERD2WListPage(WOContext c) { super(c); ! if (ERD2WFactory.erFactory().defaultListPageDisplayGroupDelegate() != null) { ! displayGroup().setDelegate(ERD2WFactory.erFactory().defaultListPageDisplayGroupDelegate()); } } public String urlForCurrentState() { return context().directActionURLForActionNamed(d2wContext().dynamicPage(), null); --- 26,117 ---- public ERD2WListPage(WOContext c) { super(c); ! NSNotificationCenter.defaultCenter().addObserver(this, new NSSelector("savedChanges", ERXConstant.NotificationClassArray), EOEditingContext.EditingContextDidSaveChangesNotification, null); ! } ! ! public void finalize() throws Throwable { ! NSNotificationCenter.defaultCenter().removeObserver(this); ! super.finalize(); ! } ! ! /** reimplementation of D2WList stuff */ ! ! protected WODisplayGroup _displayGroup; ! public boolean _hasToUpdate = false; ! protected boolean _rowFlip = false; ! ! public WODisplayGroup displayGroup() { ! if(_displayGroup == null) { ! _displayGroup = new WODisplayGroup(); ! if (ERD2WFactory.erFactory().defaultListPageDisplayGroupDelegate() != null) { ! _displayGroup.setDelegate(ERD2WFactory.erFactory().defaultListPageDisplayGroupDelegate()); ! } } + return _displayGroup; + } + + public void savedChanges(NSNotification nsnotification) { + _hasToUpdate = true; + } + + public boolean isEntityReadOnly() { + boolean isEntityReadOnly = super.isEntityReadOnly(); + boolean isEditable = ERXValueUtilities.booleanValueWithDefault(d2wContext().valueForKey("isEntityEditable"), true); + boolean readOnly = ERXValueUtilities.booleanValueWithDefault(d2wContext().valueForKey("readOnly"), false); + return isEntityReadOnly && !isEditable && readOnly; + } + + public boolean isSelecting() { + return d2wContext().task().equals("select"); + } + + public boolean isListEmpty() { + return listSize() == 0; + } + + public int listSize() { + return displayGroup().allObjects().count(); + } + + public String alternatingColorForRow() { + _rowFlip = !_rowFlip; + if(_rowFlip || !alternateRowColor()) + return backgroundColorForTable(); + else + return backgroundColorForTableDark(); + } + + public String backgroundColorForRow() { + return !isSelecting() || object() != displayGroup().selectedObject() ? alternatingColorForRow() : "#FFFF00"; } + public void setBackgroundColorForRow(String value) { + // just for KVC reasons + } + + public EOEnterpriseObject selectedObject() { + return (EOEnterpriseObject)displayGroup().selectedObject(); + } + + public void setSelectedObject(EOEnterpriseObject eo) { + if(eo != null) + displayGroup().selectObject(eo); + else + displayGroup().clearSelection(); + } + + public WOComponent selectObjectAction() { + setSelectedObject(object()); + if(nextPageDelegate() != null) + return nextPageDelegate().nextPage(this); + else + return null; + } + + public WOComponent backAction() { + return nextPageDelegate() == null ? nextPage() == null ? (WOComponent)D2W.factory().queryPageForEntityNamed(entity().name(), session()) : nextPage() : nextPageDelegate().nextPage(this); + } + + /*** end of reimplementation */ + public String urlForCurrentState() { return context().directActionURLForActionNamed(d2wContext().dynamicPage(), null); *************** *** 72,82 **** } - public boolean isEntityReadOnly() { - return !ERXValueUtilities.booleanValueWithDefault(d2wContext().valueForKey("isEntityEditable"), !super.isEntityReadOnly()); - } - private boolean _hasBeenInitialized=false; private Integer _batchSize = null; public int numberOfObjectsPerBatch() { if (_batchSize == null) { --- 155,162 ---- } private boolean _hasBeenInitialized=false; private Integer _batchSize = null; + public int numberOfObjectsPerBatch() { if (_batchSize == null) { *************** *** 143,218 **** return null; } - - public D2WContext d2wContext() { - if(hasBinding("localContext") && super.d2wContext()==null) { - setLocalContext((D2WContext)valueForBinding("localContext")); - } - return super.d2wContext(); - } - - // make kvc happy - public void setD2wContext(D2WContext newValue) { - log.info("Hu? this should never be called."); - } - - public void setLocalContext(D2WContext newValue) { - if (ERXExtensions.safeDifferent(newValue,super.d2wContext())) { - _hasBeenInitialized=false; - _batchSize=null; - // HACK ALERT: this next line is made necessary by the brain-damageness of - // D2WComponent.setLocalContext, which holds on to the first non null value it gets. - // I swear if I could get my hands on the person who did that.. :-) - _localContext=newValue; - if (log.isDebugEnabled()) log.debug("SetLocalContext "+newValue); - } - super.setLocalContext(newValue); - } - public void takeValuesFromRequest(WORequest r, WOContext c) { setupPhase(); ! NDC.push("Page: " + getClass().getName()+ (d2wContext()!= null ? (" - Configuration: "+d2wContext().valueForKey("pageConfiguration")) : "")); ! try { ! super.takeValuesFromRequest(r, c); ! } finally { ! NDC.pop(); ! } } public WOActionResults invokeAction(WORequest r, WOContext c) { setupPhase(); ! WOActionResults result=null; ! NDC.push("Page: " + getClass().getName()+ (d2wContext()!= null ? (" - Configuration: "+d2wContext().valueForKey("pageConfiguration")) : "")); ! try { ! result= super.invokeAction(r, c); ! } finally { ! NDC.pop(); ! } ! return result; } public void appendToResponse(WOResponse r, WOContext c) { setupPhase(); ! NDC.push("Page: " + getClass().getName()+ (d2wContext()!= null ? (" - Configuration: "+d2wContext().valueForKey("pageConfiguration")) : "")); ! try { ! super.appendToResponse(r,c); ! } catch(Exception ex) { ! ERDirectToWeb.reportException(ex, d2wContext()); ! } finally { ! NDC.pop(); } } ! public void setDataSource(EODataSource eodatasource) { ! try{ ! super.setDataSource(eodatasource); ! } catch (Exception ex) { ! log.warn("Exception when setting datasource", ex); ! NSArray sortOrderings=sortOrderings(); ! displayGroup().setDataSource(eodatasource); ! displayGroup().setSortOrderings(sortOrderings!=null ? sortOrderings : NSArray.EmptyArray); ! displayGroup().fetch(); ! } } protected void setupPhase() { WODisplayGroup dg=displayGroup(); --- 223,254 ---- return null; } public void takeValuesFromRequest(WORequest r, WOContext c) { setupPhase(); ! super.takeValuesFromRequest(r, c); } public WOActionResults invokeAction(WORequest r, WOContext c) { setupPhase(); ! return super.invokeAction(r, c); } public void appendToResponse(WOResponse r, WOContext c) { setupPhase(); ! _rowFlip = true; ! if(_hasToUpdate) { ! displayGroup().fetch(); ! _hasToUpdate = false; } + super.appendToResponse(r,c); } ! public void setDataSource(EODataSource eodatasource) { ! NSArray sortOrderings=sortOrderings(); ! displayGroup().setDataSource(eodatasource); ! displayGroup().setSortOrderings(sortOrderings!=null ? sortOrderings : NSArray.EmptyArray); ! displayGroup().fetch(); } + protected void setupPhase() { WODisplayGroup dg=displayGroup(); *************** *** 227,234 **** } NSArray sortOrderings=sortOrderings(); ! displayGroup().setSortOrderings(sortOrderings!=null ? sortOrderings : NSArray.EmptyArray); ! displayGroup().setNumberOfObjectsPerBatch(numberOfObjectsPerBatch()); ! displayGroup().fetch(); ! displayGroup().updateDisplayedObjects(); _hasBeenInitialized=true; } --- 263,270 ---- } NSArray sortOrderings=sortOrderings(); ! dg.setSortOrderings(sortOrderings!=null ? sortOrderings : NSArray.EmptyArray); ! dg.setNumberOfObjectsPerBatch(numberOfObjectsPerBatch()); ! dg.fetch(); ! dg.updateDisplayedObjects(); _hasBeenInitialized=true; } *************** *** 267,306 **** public WOComponent editObjectAction() { ! WOComponent result = null; String editConfigurationName=(String)d2wContext().valueForKey("editConfigurationName"); ! if(editConfigurationName != null) { ! log.debug("editConfigurationName = "+editConfigurationName); ! Object page = D2W.factory().pageForConfigurationNamed(editConfigurationName,session()); ! log.debug("page = "+page); ! EditPageInterface epi = (EditPageInterface)page; ! ! epi.setObject(localInstanceOfObject()); ! epi.setNextPage(context().page()); ! result = (WOComponent)epi; } else { ! EditPageInterface editpageinterface = D2W.factory().editPageForEntityNamed(object().entityName(), session()); ! editpageinterface.setObject(localInstanceOfObject()); ! editpageinterface.setNextPage(context().page()); ! result = (WOComponent)editpageinterface; } ! return result; } public WOComponent inspectObjectAction() { ! WOComponent result = null; String inspectConfigurationName=(String)d2wContext().valueForKey("inspectConfigurationName"); ! if(inspectConfigurationName!=null) { ! InspectPageInterface ipi=(InspectPageInterface)D2W.factory().pageForConfigurationNamed(inspectConfigurationName,session()); ! ipi.setObject(object()); ! ipi.setNextPage(context().page()); ! return (WOComponent)ipi; } else { ! InspectPageInterface inspectpageinterface = D2W.factory().inspectPageForEntityNamed(object().entityName(), session()); ! inspectpageinterface.setObject(object()); ! inspectpageinterface.setNextPage(context().page()); ! return (WOComponent)inspectpageinterface; } } --- 303,331 ---- public WOComponent editObjectAction() { ! EditPageInterface epi; String editConfigurationName=(String)d2wContext().valueForKey("editConfigurationName"); ! log.debug("editConfigurationName: " + editConfigurationName); if(editConfigurationName != null) { ! epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed(editConfigurationName,session()); } else { ! epi = D2W.factory().editPageForEntityNamed(object().entityName(), session()); } ! epi.setObject(localInstanceOfObject()); ! epi.setNextPage(context().page()); ! return (WOComponent)epi; } public WOComponent inspectObjectAction() { ! InspectPageInterface ipi; String inspectConfigurationName=(String)d2wContext().valueForKey("inspectConfigurationName"); ! log.debug("inspectConfigurationName: " + inspectConfigurationName); if(inspectConfigurationName!=null) { ! ipi=(InspectPageInterface)D2W.factory().pageForConfigurationNamed(inspectConfigurationName,session()); } else { ! ipi = D2W.factory().inspectPageForEntityNamed(object().entityName(), session()); } + ipi.setObject(object()); + ipi.setNextPage(context().page()); + return (WOComponent)ipi; } |