public static GenderType localInstanceIn(EOEditingContext editingContext, GenderType eo) { GenderType localInstance = (eo == null) ? null : ERXEOControlUtilities.localInstanceOfObject(editingContext, eo); if (localInstance == null && eo != null) { throw new IllegalStateException("You attempted to localInstance " + eo + ", which has not yet committed."); } return localInstance; } }
public static ERTag localInstanceIn(EOEditingContext editingContext, ERTag eo) { ERTag localInstance = (eo == null) ? null : ERXEOControlUtilities.localInstanceOfObject(editingContext, eo); if (localInstance == null && eo != null) { throw new IllegalStateException("You attempted to localInstance " + eo + ", which has not yet committed."); } return localInstance; } }
public static Person localInstanceIn(EOEditingContext editingContext, Person eo) { Person localInstance = (eo == null) ? null : ERXEOControlUtilities.localInstanceOfObject(editingContext, eo); if (localInstance == null && eo != null) { throw new IllegalStateException("You attempted to localInstance " + eo + ", which has not yet committed."); } return localInstance; } }
/** * Gets the actor as a local instance in the given context. * @param ec editing context to pull a local copy of the actor * into * @return actor instance in the given editing context */ public static EOEnterpriseObject actor(EOEditingContext ec) { EOEnterpriseObject actor = actor(); if (actor != null && actor.editingContext() != ec) { EOEditingContext actorEc = actor.editingContext(); actorEc.lock(); try { EOEnterpriseObject localActor = ERXEOControlUtilities.localInstanceOfObject(ec, actor); try { if(actor instanceof ERCoreUserInterface) { NSArray prefs = ((ERCoreUserInterface)actor).preferences(); prefs = ERXEOControlUtilities.localInstancesOfObjects(ec, prefs); ((ERCoreUserInterface)localActor).setPreferences(prefs); } } catch(RuntimeException ex) { log.error("Error while setting getting actor's preferences: ", actor, ex); } actor = localActor; } finally { actorEc.unlock(); } } return actor; }
public ERCStatic objectMatchingKey(EOEditingContext ec, String key, boolean noCache) { // If noCache is true we always go to the database Object result = noCache ? null : _staticsPerKey.objectForKey(key); if (result == null) { NSArray arr = staticsForKey(ec, key); if (arr.count() > 1) throw new IllegalStateException("Found " + arr.count() + " rows for key " + key); result = arr.count() == 1 ? arr.objectAtIndex(0) : NSKeyValueCoding.NullValue; if (result instanceof EOEnterpriseObject) { privateEditingContext().lock(); try { _staticsPerKey.setObjectForKey(ERXEOControlUtilities.localInstanceOfObject(privateEditingContext(), (ERCStatic) result), key); } finally { privateEditingContext().unlock(); } } result = result == NSKeyValueCoding.NullValue ? null : result; } else if (result instanceof EOEnterpriseObject) { privateEditingContext().lock(); try { result = ERXEOControlUtilities.localInstanceOfObject(ec, (ERCStatic) result); } finally { privateEditingContext().unlock(); } } else if (result.equals(NSKeyValueCoding.NullValue)) { result = null; } return (ERCStatic) result; }
/** * Action for inspect button */ public WOActionResults inspectObjectAction() { WOActionResults result = null; if (shouldAllowInlineEditing()) { EOEditingContext ec = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(ec, object()); SelectPageInterface parent = parentSelectPage(); if(parent != null) { d2wContext().takeValueForKey("inspect", Keys.inlineTask); parent.setSelectedObject(localObj); } else { throw new IllegalStateException("This page is not an instance of SelectPageInterface. I can't select here."); } } else { result = inspectObjectInPageAction(); } return result; }
/** * Action performed by the edit button */ public WOComponent editObjectAction() { WOComponent result = null; if (shouldAllowInlineEditing()) { EOEditingContext ec = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(ec, object()); SelectPageInterface parent = parentSelectPage(); if(parent != null) { d2wContext().takeValueForKey("edit", Keys.inlineTask); parent.setSelectedObject(localObj); } else { throw new IllegalStateException("This page is not an instance of SelectPageInterface. I can't select here."); } } else { result = editObjectInPageAction(); } return result; }
public void markAsRead() { EOEditingContext ec = ERXEC.newEditingContext(); ec.lock(); try { People people = (People) ERCoreBusinessLogic.actor(ec); Bug copy = ERXEOControlUtilities.localInstanceOfObject(ec, this); if(copy != null && !copy.isRead() && copy.owner().equals(people)) { copy.setIsRead(true); ec.saveChanges(); } } finally { ec.unlock(); } }
/** * Perform the edit action. Overridden to use ajax behaviour if useAjaxControlsWhenEmbedded is true */ @Override public WOComponent editAction() { boolean useAjax = ERXValueUtilities.booleanValue(d2wContext().valueForKey(Keys.useAjaxControlsWhenEmbedded)); if (useAjax) { EOEditingContext ec = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(ec, object()); d2wContext().takeValueForKey(localObj, Keys.objectBeingEdited); _previousPageConfig = (String)d2wContext().valueForKey(Keys.pageConfiguration); _previousTask = (String)d2wContext().valueForKey(Keys.task); d2wContext().takeValueForKey("edit", Keys.inlineTask); String newConfig = (String)d2wContext().valueForKey(Keys.inlinePageConfiguration); d2wContext().takeValueForKey(newConfig, Keys.pageConfiguration); d2wContext().takeValueForKey("edit", Keys.task); return null; } else { return super.editAction(); } }
/** * Action called when user clicks the Add button */ public WOActionResults addObject() { String currentPageConfiguration = stringValueForBinding(Keys.pageConfiguration); NSDictionary<String, String> extraValues = currentPageConfiguration != null ? new NSDictionary<String, String>(currentPageConfiguration, Keys.pageConfiguration) : null; String createPageConfigurationName = (String)ERDirectToWeb.d2wContextValueForKey(Keys.createConfigurationName, destinationEntityName(), extraValues); EditPageInterface epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed(createPageConfigurationName, session()); EOEditingContext newEc = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject relatedObject = EOUtilities.createAndInsertInstance(newEc, destinationEntityName()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(relatedObject.editingContext(), object()); if (localObj instanceof ERXGenericRecord) { ((ERXGenericRecord)localObj).setValidatedWhenNested(false); } localObj.addObjectToBothSidesOfRelationshipWithKey(relatedObject, propertyKey()); epi.setNextPage(context().page()); epi.setObject(relatedObject); // Null out the current searchValue so when we come back, it regenerates _searchValue = null; return (WOActionResults) epi; }
/** * Perform the edit action. * Overridden to support ajax behaviour. When useAjaxControlsWhenEmbedded is true, then * we will switch the behaviour of this page to edit and update ajax update the form. */ @Override public WOComponent editAction() { boolean useAjax = ERXValueUtilities.booleanValue(d2wContext().valueForKey(Keys.useAjaxControlsWhenEmbedded)); if (useAjax) { EOEditingContext ec = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(ec, object()); d2wContext().takeValueForKey(localObj, Keys.objectBeingEdited); _previousPageConfig = (String)d2wContext().valueForKey(Keys.pageConfiguration); _previousTask = (String)d2wContext().valueForKey(Keys.task); d2wContext().takeValueForKey("edit", Keys.inlineTask); String newConfig = (String)d2wContext().valueForKey(Keys.inlinePageConfiguration); d2wContext().takeValueForKey(newConfig, Keys.pageConfiguration); d2wContext().takeValueForKey("edit", Keys.task); return null; } else { return super.editAction(); } }
/** * Action called when the user makes a selection from the AjaxAutoComplete */ public WOActionResults selectObject() { // log.debug("selectobject called: " + item); EOQualifier qual = ERXQ.equals(keyWhenRelationship(), searchValue()); NSArray<EOEnterpriseObject> objs = destinationObjectsWithQualifier(qual); if (objs != null && objs.count() > 0) { EOEnterpriseObject localEO = ERXEOControlUtilities.localInstanceOfObject(object().editingContext(), objs.objectAtIndex(0)); object().addObjectToBothSidesOfRelationshipWithKey(localEO, propertyKey()); } else { EOEnterpriseObject existingObj = (EOEnterpriseObject)object().valueForKey(propertyKey()); if (existingObj != null) { object().removeObjectFromBothSidesOfRelationshipWithKey(existingObj, propertyKey()); } } // support for ERMDAjaxNotificationCenter if (ERXValueUtilities.booleanValueWithDefault(d2wContext().valueForKey("shouldObserve"), false)) { NSNotificationCenter.defaultCenter().postNotification( ERMDAjaxNotificationCenter.PropertyChangedNotification, parent().valueForKeyPath("d2wContext")); } // NSLog.out.appendln("Select Object Called: " + object().valueForKey(propertyKey()) + " " + searchValue()); return null; }
/** * Deletes the current object. Behaviour is dependent on the d2wContext useAjaxControls flag. * * if true: Display an in-line confirmation dialog and update the pages main update container. * if false: Take user to the confirmation page. * */ public WOActionResults buttonAction() { WOActionResults result = null; if (shouldUseAjax()) { EOEditingContext ec = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(ec, object()); d2wContext().takeValueForKey(localObj, Keys.objectPendingDeletion); } else { ConfirmPageInterface nextPage = (ConfirmPageInterface)D2W.factory().pageForConfigurationNamed((String)valueForBinding("confirmDeleteConfigurationName"), session()); nextPage.setConfirmDelegate(new ERDDeletionDelegate(object(), dataSource(), context().page())); nextPage.setCancelDelegate(new ERDPageDelegate(context().page())); D2WPage d2wPage = ((D2WPage)nextPage); String message = ERXLocalizer.currentLocalizer().localizedTemplateStringForKeyWithObject("ERDTrashcan.confirmDeletionMessage", d2wContext()); nextPage.setMessage(message); d2wPage.setObject(object()); result = (WOActionResults)nextPage; } return result; }