-
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.
adding facet filter (like solr, ebay etc) first cut. Contribution com…
…ing from SourceForge
- Loading branch information
Pascal Robert
committed
Jul 7, 2012
1 parent
18ecfe8
commit 03d956d
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<wodefinitions> | ||
<wo wocomponentcontent="false" class="ERDFacetFilter.java"> | ||
|
||
</wo> | ||
</wodefinitions> |
18 changes: 18 additions & 0 deletions
18
...ks/Core/ERDirectToWeb/Components/Nonlocalized.lproj/ERDFacetFilter.wo/ERDFacetFilter.html
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,18 @@ | ||
<webobject name = "HasKeyList"> | ||
<ul class = "keyList"> | ||
<webobject name = "KeyList"> | ||
<webobject name = "HasValueList"> | ||
<li class = "key"> | ||
<webobject name = "Key" /> | ||
<ul> | ||
<webobject name = "ValueList"> | ||
<li> | ||
<webobject name = "IsSelectedValue">[X]</webobject> <webobject name = "ValueLink"><webobject name = "Value" /></webobject> (<webobject name = "ValueCount" />)</li> | ||
</webobject> | ||
<webobject name = "HasSelectedValues"><li><webobject name = "ClearSelectionLink">[Clear]</webobject></li></webobject> | ||
</ul> | ||
</li> | ||
</webobject> | ||
</webobject> | ||
</ul> | ||
</webobject> |
45 changes: 45 additions & 0 deletions
45
...rks/Core/ERDirectToWeb/Components/Nonlocalized.lproj/ERDFacetFilter.wo/ERDFacetFilter.wod
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,45 @@ | ||
HasKeyList: WOConditional { | ||
condition = keyList.@count; | ||
} | ||
|
||
KeyList: WORepetition { | ||
list = keyList; | ||
item = currentKey; | ||
} | ||
|
||
Key: WOString { | ||
value = currentKey; | ||
} | ||
|
||
HasValueList: WOConditional { | ||
condition = valueList.@count; | ||
} | ||
|
||
ValueList: WORepetition { | ||
list = valueList; | ||
item = currentValue; | ||
} | ||
|
||
IsSelectedValue: WOConditional { | ||
condition = isCurrentValueSelected; | ||
} | ||
|
||
HasSelectedValues: WOConditional { | ||
condition = hasSelectedValues; | ||
} | ||
|
||
ClearSelectionLink: WOHyperlink { | ||
action = clearSelectedValues; | ||
} | ||
|
||
Value: WOString { | ||
value = currentValue; | ||
} | ||
|
||
ValueCount: WOString { | ||
value = currentValueCount; | ||
} | ||
|
||
ValueLink: WOHyperlink { | ||
action = selectCurrentValue; | ||
} |
4 changes: 4 additions & 0 deletions
4
...rks/Core/ERDirectToWeb/Components/Nonlocalized.lproj/ERDFacetFilter.wo/ERDFacetFilter.woo
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,4 @@ | ||
{ | ||
"WebObjects Release" = "WebObjects 5.0"; | ||
encoding = "UTF-8"; | ||
} |
109 changes: 109 additions & 0 deletions
109
Frameworks/Core/ERDirectToWeb/Sources/er/directtoweb/components/ERDFacetFilter.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,109 @@ | ||
package er.directtoweb.components; | ||
|
||
import com.webobjects.appserver.WOActionResults; | ||
import com.webobjects.appserver.WOContext; | ||
import com.webobjects.eocontrol.EOEnterpriseObject; | ||
import com.webobjects.foundation.NSArray; | ||
import com.webobjects.foundation.NSDictionary; | ||
import com.webobjects.foundation.NSMutableArray; | ||
import com.webobjects.foundation.NSMutableDictionary; | ||
import com.webobjects.foundation.NSMutableSet; | ||
|
||
import er.extensions.eof.ERXS; | ||
import er.extensions.foundation.ERXArrayUtilities; | ||
|
||
public class ERDFacetFilter extends ERDCustomQueryComponent { | ||
|
||
public Object currentValue; | ||
public String currentKey; | ||
private NSArray<EOEnterpriseObject> _allObjects; | ||
|
||
private NSMutableDictionary<String, NSDictionary<Object, NSArray<EOEnterpriseObject>>> values = new NSMutableDictionary(); | ||
private NSMutableDictionary<String, NSMutableArray<Object>> selectedValues = new NSMutableDictionary(); | ||
|
||
public ERDFacetFilter(WOContext context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public boolean synchronizesVariablesWithBindings() { | ||
return false; | ||
} | ||
|
||
public NSArray<EOEnterpriseObject> allObjects() { | ||
if(_allObjects == null && allKeys() != null) { | ||
_allObjects = (NSArray<EOEnterpriseObject>) displayGroup().allObjects(); | ||
values.removeAllObjects(); | ||
selectedValues.removeAllObjects(); | ||
for (String keyPath : allKeys()) { | ||
NSDictionary<Object, NSArray<EOEnterpriseObject>> groupedObjects = ERXArrayUtilities.arrayGroupedByKeyPath(_allObjects, keyPath); | ||
values.setObjectForKey(groupedObjects, keyPath); | ||
selectedValues.setObjectForKey(new NSMutableArray(), keyPath); | ||
} | ||
} | ||
return _allObjects; | ||
} | ||
|
||
public NSArray<String> allKeys() { | ||
return (NSArray<String>) valueForBinding("groupingKeys"); | ||
} | ||
|
||
public NSArray valueList() { | ||
return ERXS.asc("toString").sorted(values.objectForKey(currentKey).allKeys()); | ||
} | ||
|
||
public int currentValueCount() { | ||
return values.objectForKey(currentKey).objectForKey(currentValue).count(); | ||
} | ||
|
||
public NSArray keyList() { | ||
allObjects(); | ||
return values.allKeys(); | ||
} | ||
|
||
public boolean isCurrentValueSelected() { | ||
NSMutableArray<Object> selected = selectedValues.objectForKey(currentKey); | ||
return selected.containsObject(currentValue); | ||
} | ||
|
||
public WOActionResults selectCurrentValue() { | ||
NSMutableArray<Object> selected = selectedValues.objectForKey(currentKey); | ||
if(selected.containsObject(currentValue)) { | ||
selected.removeObject(currentValue); | ||
} else { | ||
selected.addObject(currentValue); | ||
} | ||
updateSelectedValues(); | ||
return null; | ||
} | ||
|
||
public void updateSelectedValues() { | ||
if (selectedValues.count() > 0) { | ||
NSMutableSet eos = new NSMutableSet(allObjects()); | ||
for (String key : selectedValues.allKeys()) { | ||
NSMutableArray<Object> selection = selectedValues.objectForKey(key); | ||
if (selection.count() > 0) { | ||
NSMutableSet currentEos = new NSMutableSet(); | ||
for (Object value : selection) { | ||
currentEos.addObjectsFromArray(values.objectForKey(key).objectForKey(value)); | ||
} | ||
eos.intersectSet(currentEos); | ||
} | ||
} | ||
displayGroup().setObjectArray(eos.allObjects()); | ||
displayGroup().setSortOrderings(displayGroup().sortOrderings()); | ||
} else { | ||
displayGroup().setObjectArray(null); | ||
} | ||
} | ||
|
||
public boolean hasSelectedValues() { | ||
return selectedValues.objectForKey(currentKey).count() > 0; | ||
} | ||
|
||
public WOActionResults clearSelectedValues() { | ||
selectedValues.objectForKey(currentKey).removeAllObjects(); | ||
updateSelectedValues(); | ||
return null; | ||
} | ||
} |