Skip to content

Commit

Permalink
Merge pull request #652 from paulhoadley/fix-erxdisplaygroup-serializ…
Browse files Browse the repository at this point in the history
…ation

Make ERXDisplayGroup serializable
  • Loading branch information
darkv committed May 21, 2015
2 parents f868911 + f777b14 commit daa2bf9
Showing 1 changed file with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
* @param <T> data type of the displaygroup's objects
*/
public class ERXDisplayGroup<T> extends WODisplayGroup {
private Field displayedObjectsField;
/**
* {@code _displayedObjects} field in parent object
*/
private transient Field displayedObjectsField;

/**
* Do I need to update serialVersionUID?
Expand All @@ -52,16 +55,29 @@ public class ERXDisplayGroup<T> extends WODisplayGroup {

public ERXDisplayGroup() {
super();
try {
displayedObjectsField = WODisplayGroup.class.getDeclaredField("_displayedObjects");
displayedObjectsField.setAccessible(true);
}
catch (SecurityException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
catch (NoSuchFieldException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}

/**
* Fetches the {@code _displayedObjects} field from the parent
* {@link WODisplayGroup}. This is used in the overriden
* {@link #setSelectedObjects(NSArray)} method.
*
* @return {@code _displayedObjects} field from parent object
*/
private Field displayedObjectsField() {
if (displayedObjectsField == null) {
try {
displayedObjectsField = WODisplayGroup.class.getDeclaredField("_displayedObjects");
displayedObjectsField.setAccessible(true);
}
catch (SecurityException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
catch (NoSuchFieldException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
}
}
return displayedObjectsField;
}

/**
Expand Down Expand Up @@ -222,7 +238,7 @@ public void setSelectedObjects(NSArray objects) {
// wrong indexes when calling displayedObjects()
NSMutableArray displayedObjects;
try {
displayedObjects = (NSMutableArray) displayedObjectsField.get(this);
displayedObjects = (NSMutableArray) displayedObjectsField().get(this);
}
catch (IllegalArgumentException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
Expand Down

0 comments on commit daa2bf9

Please sign in to comment.