Created
April 25, 2014 15:41
-
-
Save hugithordarson/11293954 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ERPrototypes</title> | |
<style type="text/css"> | |
body, table, tr, td, th { | |
font-family: Helvetica, sans-serif; | |
font-size: 11px; | |
} | |
table { | |
border-top: 1px solid rgb( 200, 200, 200 ); | |
border-right: 1px solid rgb( 200, 200, 200 ); | |
} | |
td, th { | |
padding: 2px 10px; | |
text-align: left; | |
border-bottom: 1px solid rgb( 200, 200, 200 ); | |
border-left: 1px solid rgb( 200, 200, 200 ); | |
} | |
.difference { | |
background-color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<wo:form> | |
Method of EOAttribute: <wo:popUpButton id="method" list="$variables" selection="$selectedVariable" /> | |
<wo:AjaxObserveField observeFieldID="method" updateContainerID="container" /> | |
</wo:form> | |
<wo:AjaxUpdateContainer id="container"> | |
<table cellpadding="0" cellspacing="0"> | |
<tr> | |
<th></th> | |
<wo:repetition list="$model.entities" item="$currentEntity"> | |
<th><wo:str value="$currentEntityDisplayName" /></th> | |
</wo:repetition> | |
</tr> | |
<wo:repetition list="$attributeNames" item="$currentAttributeName"> | |
<tr> | |
<wo:container elementName="td" class="$currentRowClassName"><strong><wo:str value="$currentAttributeName" /></strong></wo:container> | |
<wo:repetition list="$model.entities" item="$currentEntity"> | |
<td><wo:str value="$currentValue" /></td> | |
</wo:repetition> | |
</tr> | |
</wo:repetition> | |
</table> | |
</wo:AjaxUpdateContainer> | |
</body> | |
</html> |
This file contains hidden or 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
package hugi.junk; | |
import is.rebbi.wo.util.USArrayUtilities; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Objects; | |
import com.webobjects.appserver.WOContext; | |
import com.webobjects.eoaccess.EOAttribute; | |
import com.webobjects.eoaccess.EOEntity; | |
import com.webobjects.eoaccess.ERXEntity; | |
import com.webobjects.eoaccess.ERXModel; | |
import com.webobjects.foundation.NSArray; | |
import com.webobjects.foundation.NSKeyValueCoding; | |
import com.webobjects.foundation.NSMutableArray; | |
import er.extensions.components.ERXComponent; | |
import er.extensions.eof.ERXModelGroup; | |
public class ERPrototypesPage extends ERXComponent { | |
public ERXModel model = (ERXModel)ERXModelGroup.defaultGroup().modelNamed( "erprototypes" ); | |
public ERXEntity currentEntity; | |
public String selectedVariable = "width"; | |
public String currentAttributeName; | |
public ERPrototypesPage( WOContext context ) { | |
super( context ); | |
} | |
public String currentEntityDisplayName() { | |
String name = currentEntity.name(); | |
if( name.equals( "EOJDBCPrototypes" ) ) { | |
return name; | |
} | |
if( name.startsWith( "EOJDBC" ) ) { | |
name = name.substring( 6, name.length() ); | |
} | |
if( name.endsWith( "Prototypes" ) ) { | |
name = name.substring( 0, name.length() - 10 ); | |
} | |
return name; | |
} | |
public boolean hasDifferences() { | |
List<Object> allValues = new ArrayList<>(); | |
for( EOEntity e : model.entities() ) { | |
Object value = valueInAttributeNamed( e, currentAttributeName, selectedVariable ); | |
allValues.add( value ); | |
} | |
Object first = allValues.get( 0 ); | |
for( Object current : allValues ) { | |
if( !Objects.equals( first, current ) ) { | |
return true; | |
} | |
} | |
return false; | |
} | |
public String currentRowClassName() { | |
return hasDifferences() ? "difference" : null; | |
} | |
public NSArray<String> variables() { | |
NSMutableArray<String> variables = new NSMutableArray<>(); | |
try { | |
for( java.lang.reflect.Method m : EOAttribute.class.getMethods() ) { | |
if( m.getParameterTypes().length == 0 && !m.getReturnType().getName().equals( "void" ) ) { | |
variables.addObject( m.getName() ); | |
} | |
} | |
} | |
catch( Exception e ) { | |
throw new RuntimeException( "FAIL", e ); | |
} | |
return USArrayUtilities.sortedArrayUsingIcelandicComparator( variables ); | |
} | |
public NSArray<String> attributeNames() { | |
NSMutableArray<String> attributeNames = new NSMutableArray<>(); | |
for( EOEntity entity : model.entities() ) { | |
for( EOAttribute attribute : entity.attributes() ) { | |
attributeNames.addObject( attribute.name() ); | |
} | |
} | |
NSArray<String> a = USArrayUtilities.arrayWithoutDuplicates( attributeNames ); | |
return USArrayUtilities.sortedArrayUsingIcelandicComparator( a ); | |
} | |
public Object currentValue() { | |
return valueInAttributeNamed( currentEntity, currentAttributeName, selectedVariable ); | |
} | |
private static Object valueInAttributeNamed( EOEntity entity, String attributeName, String key ) { | |
EOAttribute a = entity.attributeNamed( attributeName ); | |
if( a != null ) { | |
return NSKeyValueCoding.Utility.valueForKey( a, key ); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment