-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assignment to set shouldObserve and isDependent keys.
- Loading branch information
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...ModernDirectToWeb/Sources/er/modern/directtoweb/assignments/ERMDAjaxUpdateAssignment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package er.modern.directtoweb.assignments; | ||
|
||
import com.webobjects.directtoweb.D2WContext; | ||
import com.webobjects.eocontrol.EOKeyValueUnarchiver; | ||
import com.webobjects.foundation.NSArray; | ||
import com.webobjects.foundation.NSDictionary; | ||
|
||
import er.directtoweb.assignments.ERDAssignment; | ||
import er.directtoweb.pages.ERD2WPage; | ||
import er.extensions.foundation.ERXArrayUtilities; | ||
import er.modern.directtoweb.components.ERMDAjaxNotificationCenter; | ||
|
||
/** | ||
* Simple assignment that checks whether a property is to be observed for | ||
* changes or is dependent on another property. | ||
* | ||
* See {@link er.modern.directtoweb.components.ERMDAjaxNotificationCenter} | ||
* | ||
* @d2wKey propertyDependencies | ||
* @d2wKey propertyKey | ||
* | ||
* @author fpeters | ||
* | ||
*/ | ||
public class ERMDAjaxUpdateAssignment extends ERDAssignment { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Static constructor required by the EOKeyValueUnarchiver interface. If | ||
* this isn't implemented then the default behavior is to construct the | ||
* first super class that does implement this method. Very lame. | ||
* | ||
* @param eokeyvalueunarchiver | ||
* to be unarchived | ||
* @return decoded assignment of this class | ||
*/ | ||
public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver eokeyvalueunarchiver) { | ||
return new ERMDAjaxUpdateAssignment(eokeyvalueunarchiver); | ||
} | ||
|
||
/** | ||
* Public constructor | ||
* | ||
* @param u | ||
* key-value unarchiver used when unarchiving from rule files. | ||
*/ | ||
public ERMDAjaxUpdateAssignment(EOKeyValueUnarchiver u) { | ||
super(u); | ||
} | ||
|
||
/** | ||
* Public constructor | ||
* | ||
* @param key | ||
* context key | ||
* @param value | ||
* of the assignment | ||
*/ | ||
public ERMDAjaxUpdateAssignment(String key, Object value) { | ||
super(key, value); | ||
} | ||
|
||
/** | ||
* Implementation of the | ||
* {@link er.directtoweb.assignments.ERDComputingAssignmentInterface}. | ||
* | ||
* @return empty array. | ||
*/ | ||
@Override | ||
public NSArray<String> dependentKeys(String keyPath) { | ||
return new NSArray<String>(ERD2WPage.Keys.propertyKey, | ||
ERMDAjaxNotificationCenter.PROPERTY_DEPENDENCIES.key()); | ||
} | ||
|
||
/** | ||
* Checks whether the current property is declared as to be observed via the | ||
* propertyDependencies key. | ||
* | ||
* @return true if the current property key is to be observed | ||
*/ | ||
public Object shouldObserve(D2WContext context) { | ||
boolean shouldObserve = false; | ||
NSDictionary<String, NSArray<String>> propertyDependencies = ERMDAjaxNotificationCenter.PROPERTY_DEPENDENCIES | ||
.valueInObject(context); | ||
if (propertyDependencies != null | ||
&& propertyDependencies.containsKey(context.propertyKey())) { | ||
shouldObserve = true; | ||
} | ||
return shouldObserve; | ||
} | ||
|
||
/** | ||
* Checks whether the current property is declared dependent via the | ||
* propertyDependencies key. | ||
* | ||
* @return true if the current property is dependent | ||
*/ | ||
public Object isDependent(D2WContext context) { | ||
boolean isDependent = false; | ||
NSDictionary<String, NSArray<String>> propertyDependencies = ERMDAjaxNotificationCenter.PROPERTY_DEPENDENCIES | ||
.valueInObject(context); | ||
if (propertyDependencies != null) { | ||
if (ERXArrayUtilities.flatten(propertyDependencies.allValues()).contains( | ||
context.propertyKey())) { | ||
isDependent = true; | ||
} | ||
} | ||
return isDependent; | ||
} | ||
|
||
} |