public static java.util.Vector makePrototypeStructure( final ElementPrototype elementPrototype, final PopupItemFactory factory, final edu.cmu.cs.stage3.alice.core.Element context, edu.cmu.cs.stage3.alice.authoringtool.SceneManager sceneManager){
//System.out.println("make prototype structure");
java.util.Vector structure = new java.util.Vector();
final String[] desiredProperties = elementPrototype.getDesiredProperties();
if( (desiredProperties == null) || (desiredProperties.length == 0) ) {
structure.add( new StringObjectPair( "no properties to set on " + elementPrototype.getElementClass().getName() + "; please report this bug", factory.createItem( elementPrototype ) ) ); // this should not be reached
} else if( desiredProperties.length > 0 ) {
String preRepr = elementPrototype.getElementClass().getName() + "." + desiredProperties[0];
String propertyRepr = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( preRepr );
if( propertyRepr.equals( preRepr ) ) {
propertyRepr = desiredProperties[0];
}
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( propertyRepr, null ) );
// structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
Class preValueClass = null;
java.util.Vector preDefaultStructure = null;
if( edu.cmu.cs.stage3.alice.core.response.PropertyAnimation.class.isAssignableFrom( elementPrototype.getElementClass() ) ) {
preDefaultStructure = getDefaultValueStructureForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
preValueClass = getValueClassForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
} else if( edu.cmu.cs.stage3.alice.core.question.userdefined.PropertyAssignment.class.isAssignableFrom( elementPrototype.getElementClass() ) ) {
preDefaultStructure = getDefaultValueStructureForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
preValueClass = getValueClassForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
} else if( edu.cmu.cs.stage3.alice.core.question.list.ListBooleanQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
edu.cmu.cs.stage3.alice.core.question.list.ListNumberQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
edu.cmu.cs.stage3.alice.core.question.list.ListObjectQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
edu.cmu.cs.stage3.alice.core.response.list.ListResponse.class.isAssignableFrom( elementPrototype.getElementClass() ) )
{
if( desiredProperties[0].equals( "item" ) ) {
preValueClass = getValueClassForList( elementPrototype.getKnownPropertyValues() );
preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
} else if( desiredProperties[0].equals( "index" ) ) { // a bit hackish.
preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
preDefaultStructure = getDefaultValueStructureForCollectionIndexProperty( elementPrototype.getKnownPropertyValues() );
} else {
preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
preDefaultStructure = getDefaultValueStructureForProperty( elementPrototype.getElementClass(), desiredProperties[0] );
}
} else if( edu.cmu.cs.stage3.alice.core.question.array.ArrayNumberQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
edu.cmu.cs.stage3.alice.core.question.array.ArrayObjectQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
edu.cmu.cs.stage3.alice.core.response.array.ArrayResponse.class.isAssignableFrom( elementPrototype.getElementClass() ) )
{
if( desiredProperties[0].equals( "item" ) ) {
preValueClass = getValueClassForArray( elementPrototype.getKnownPropertyValues() );
preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
} else if( desiredProperties[0].equals( "index" ) ) {
preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
preDefaultStructure = getDefaultValueStructureForCollectionIndexProperty( elementPrototype.getKnownPropertyValues() );
} else {
preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
preDefaultStructure = getDefaultValueStructureForProperty( elementPrototype.getElementClass(), desiredProperties[0] );
}
} else if( elementPrototype instanceof CallToUserDefinedResponsePrototype ) {
edu.cmu.cs.stage3.alice.core.response.UserDefinedResponse actualResponse = ((CallToUserDefinedResponsePrototype)elementPrototype).getActualResponse();
Object[] params = actualResponse.requiredFormalParameters.getArrayValue();
for( int i = 0; i < params.length; i++ ) {
if( ((edu.cmu.cs.stage3.alice.core.Variable)params[i]).name.getStringValue().equals( desiredProperties[0] ) ) {
preValueClass = (Class)((edu.cmu.cs.stage3.alice.core.Variable)params[i]).valueClass.getValue();
break;
}
}
preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
} else if( elementPrototype instanceof CallToUserDefinedQuestionPrototype ) {
edu.cmu.cs.stage3.alice.core.question.userdefined.UserDefinedQuestion actualQuestion = ((CallToUserDefinedQuestionPrototype)elementPrototype).getActualQuestion();
Object[] params = actualQuestion.requiredFormalParameters.getArrayValue();
for( int i = 0; i < params.length; i++ ) {
if( ((edu.cmu.cs.stage3.alice.core.Variable)params[i]).name.getStringValue().equals( desiredProperties[0] ) ) {
preValueClass = (Class)((edu.cmu.cs.stage3.alice.core.Variable)params[i]).valueClass.getValue();
break;
}
}
preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
} else if (edu.cmu.cs.stage3.alice.core.question.IsEqualTo.class.isAssignableFrom( elementPrototype.getElementClass()) ||
edu.cmu.cs.stage3.alice.core.question.IsNotEqualTo.class.isAssignableFrom( elementPrototype.getElementClass())){
preValueClass = getValueClassForComparator(elementPrototype.knownPropertyValues);
preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
}else {
preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
preDefaultStructure = getDefaultValueStructureForProperty( elementPrototype.getElementClass(), desiredProperties[0] );
}
// hack so we can use these in an inner class
final Class valueClass = preValueClass;
PopupItemFactory recursiveFactory = new PopupItemFactory() {
public Object createItem( Object o ) {
if (!valueClass.isInstance(o)){ //Add the question here?
if (valueClass.isAssignableFrom(javax.vecmath.Vector3d.class) && o instanceof edu.cmu.cs.stage3.alice.core.Transformable){
edu.cmu.cs.stage3.alice.core.question.Position positionQuestion = new edu.cmu.cs.stage3.alice.core.question.Position();
positionQuestion.subject.set(o);
o = positionQuestion;
} else if (valueClass.isAssignableFrom(javax.vecmath.Matrix4d.class) && o instanceof edu.cmu.cs.stage3.alice.core.Transformable){
edu.cmu.cs.stage3.alice.core.question.PointOfView POVQuestion = new edu.cmu.cs.stage3.alice.core.question.PointOfView();
POVQuestion.subject.set(o);
o = POVQuestion;
}else if (valueClass.isAssignableFrom(edu.cmu.cs.stage3.math.Quaternion.class) && o instanceof edu.cmu.cs.stage3.alice.core.Transformable){
edu.cmu.cs.stage3.alice.core.question.Quaternion quaternionQuestion = new edu.cmu.cs.stage3.alice.core.question.Quaternion();
quaternionQuestion.subject.set(o);
o = quaternionQuestion;
}
}
if( desiredProperties.length == 1 ) { // end of the line
//DEBUG System.out.println( "end of the line: " + desiredProperties[0] + ", " + o );
return factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ) );
} else { // recurse
//DEBUG System.out.println( "recursive: " + desiredProperties[0] + ", " + o );
return makePrototypeStructure( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ), factory, context );
}
}
};
// hack so we can use these in an inner class
final java.util.Vector defaultStructure = processStructure( preDefaultStructure, recursiveFactory, NO_CURRENT_VALUE );
//System.out.println("defStructure: " + defaultStructure.size());
// compute recent values
java.util.Vector recentlyUsedStructure = new java.util.Vector();
if( recentlyUsedValues.containsKey( preValueClass ) ) {
java.util.List recentList = (java.util.List)recentlyUsedValues.get( preValueClass );
int count = 0;
for( java.util.Iterator iter = recentList.iterator(); iter.hasNext(); ) {
if( count > Integer.parseInt( authoringToolConfig.getValue( "maxRecentlyUsedValues" ) ) ) {
break;
}
Object value = iter.next();
if( ! structureContains( preDefaultStructure, value ) ) {
recentlyUsedStructure.add( value );
count++;
}
}
}
if( ! defaultStructure.isEmpty() ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.addAll( defaultStructure );
}
// add recent values if there are any
if( ! recentlyUsedStructure.isEmpty() ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
addLabelsToValueStructure( recentlyUsedStructure, elementPrototype.getElementClass(), desiredProperties[0] );
structure.addAll( processStructure( recentlyUsedStructure, recursiveFactory, NO_CURRENT_VALUE ) );
}
// elements
// create criterion; handle exceptions
// HERE
edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion instanceOf = new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( valueClass );
edu.cmu.cs.stage3.util.Criterion elementIsNamed = new edu.cmu.cs.stage3.util.Criterion() { //HACK; shouldn't have to cull unnamed elements
public boolean accept( Object o ) {
if( o instanceof edu.cmu.cs.stage3.alice.core.Element ) {
if( ((edu.cmu.cs.stage3.alice.core.Element)o).name.get() != null ) {
return true;
}
}
return false;
}
};
InAppropriateObjectArrayPropertyCriterion inAppropriateOAPCriterion = new InAppropriateObjectArrayPropertyCriterion();
edu.cmu.cs.stage3.util.Criterion criterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { instanceOf, elementIsNamed, inAppropriateOAPCriterion } );
Class elementClass = elementPrototype.getElementClass();
edu.cmu.cs.stage3.util.StringObjectPair[] knownPropertyValues = elementPrototype.getKnownPropertyValues();
//Don't get self criterion stuff!
if( (edu.cmu.cs.stage3.alice.core.response.AbstractPointAtAnimation.class.isAssignableFrom( elementClass ) && desiredProperties[0].equals( "target" )) ||
(edu.cmu.cs.stage3.alice.core.response.VehiclePropertyAnimation.class.isAssignableFrom(elementPrototype.elementClass) && desiredProperties[0].equals( "value" )) ){
for( int i = 0; i < knownPropertyValues.length; i++ ) {
String propertyName = knownPropertyValues[i].getString();
if( propertyName.equals( "subject" ) || propertyName.equals( "element" ) ) {
final Object transformableValue = knownPropertyValues[i].getObject();
edu.cmu.cs.stage3.util.Criterion notSelf = new edu.cmu.cs.stage3.util.Criterion() {
public boolean accept( Object o ) {
if( o == transformableValue ) {
return false;
}
return true;
}
};
//criterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { instanceOf, elementIsNamed, inAppropriateOAPCriterion, notSelf } );
break;
}
}
}
// make structure
edu.cmu.cs.stage3.alice.core.Group currentGroup = null;
if (sceneManager != null) currentGroup = sceneManager.getCurrentGroup();
if( edu.cmu.cs.stage3.alice.core.Element.class.isAssignableFrom( valueClass ) || valueClass.isAssignableFrom( edu.cmu.cs.stage3.alice.core.Element.class ) ) {
edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( criterion );
if( elements.length > 0 ) {
//CLK begin
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
if (sceneManager != null) {
//System.out.println("group: " + sceneManager.getCurrentGroup());
structure.addAll( makeSceneElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE, sceneManager.getCurrentGroup() ) );
} else {
//System.out.println("no scenemanager");
structure.addAll( makeSceneElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE, null ) );
}
/*if( elements.length < 10 ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.addAll( makeFlatElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
} else {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.addAll( makeElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
}*/
//CLK end
}
}
//if (!Object.class.isAssignableFrom(valueClass)) {
if (Object.class.isAssignableFrom(valueClass)) {
//Okay, this needs to build a structure to find models, get their position and pass them to the vector3d property
if( javax.vecmath.Vector3d.class.isAssignableFrom( valueClass ) || valueClass.isAssignableFrom(javax.vecmath.Vector3d.class)) {
edu.cmu.cs.stage3.util.Criterion modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion } );
edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( modelCriterion );
if( elements.length > 0 ) {
//if( elements.length < 10 ) {
// if( structure.size() > 0 ) {
// structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
// }
// structure.addAll( makeFlatElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
//} else {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.addAll( makeSceneElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE, currentGroup ) );
//}
}
}
if( valueClass.isAssignableFrom(javax.vecmath.Matrix4d.class)) {
edu.cmu.cs.stage3.util.Criterion modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion } );
//BEGIN CLK - filter out everything but dummy objects in set point of view
if (edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.isExperimentalSceneSupportEnabled()) {
if( (edu.cmu.cs.stage3.alice.core.response.PointOfViewAnimation.class.isAssignableFrom( elementClass )) && desiredProperties[0].equals( "pointOfView" ) ) {
edu.cmu.cs.stage3.util.Criterion onlyDummies = new edu.cmu.cs.stage3.util.Criterion() {
public boolean accept( Object o ) {
if (o instanceof edu.cmu.cs.stage3.alice.core.Dummy)
return true;
else return false;
}
};
modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion, onlyDummies } );
}
}
// END CLK
edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( modelCriterion );
if( elements.length > 0 ) {
//if( elements.length < 10 ) {
//if( structure.size() > 0 ) {
// structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
//}
//structure.addAll( makeFlatElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
//} else {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.addAll( makeSceneElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE, currentGroup ) );
//}
}
}
if( valueClass.isAssignableFrom(edu.cmu.cs.stage3.math.Quaternion.class)) {
edu.cmu.cs.stage3.util.Criterion modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion } );
edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( modelCriterion );
if( elements.length > 0 ) {
//if( elements.length < 10 ) {
// if( structure.size() > 0 ) {
// structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
// }
// structure.addAll( makeFlatElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
//} else {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.addAll( makeSceneElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE, currentGroup ) );
//}
}
}
}
//else {
// System.out.println("bleh");
//}
// import or record sound if necessary
final PopupItemFactory metaFactory = new PopupItemFactory() {
public Object createItem( final Object o ) {
return new Runnable() {
public void run() {
((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ) )).run();
}
};
}
};
if( valueClass.isAssignableFrom( edu.cmu.cs.stage3.alice.core.Sound.class ) && (valueClass != Object.class) ) {
java.io.File soundDir = new java.io.File( edu.cmu.cs.stage3.alice.authoringtool.JAlice.getAliceHomeDirectory(), "sounds" ).getAbsoluteFile();
if( soundDir.exists() && soundDir.isDirectory() ) {
java.util.ArrayList sounds = new java.util.ArrayList();
java.io.File[] fileList = soundDir.listFiles();
for( int i = 0; i < fileList.length; i++ ) {
if( fileList[i].isFile() && fileList[i].canRead() ) {
sounds.add( fileList[i] );
}
}
if( sounds.size() > 0 ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
for( java.util.Iterator iter = sounds.iterator(); iter.hasNext(); ) {
final java.io.File soundFile = (java.io.File)iter.next();
String name = soundFile.getName();
name = name.substring( 0, name.lastIndexOf( '.' ) );
Runnable importSoundRunnable = new Runnable() {
public void run() {
edu.cmu.cs.stage3.alice.core.Sound sound = (edu.cmu.cs.stage3.alice.core.Sound)edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().importElement( soundFile, context.getSandbox() );
if( sound != null ) {
((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], sound ) ) )).run();
}
// edu.cmu.cs.stage3.alice.authoringtool.util.SwingWorker worker = edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().importElement( soundFile, context.getSandbox() );
// ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], worker.get() ) ) )).run();
}
};
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( name, importSoundRunnable ) );
}
}
}
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
Runnable importRunnable = new Runnable() {
public void run() {
// PropertyPopupPostWorker postWorker = new PropertyPopupPostWorker( metaFactory );
PropertyPopupPostImportRunnable propertyPopupPostImportRunnable = new PropertyPopupPostImportRunnable( metaFactory );
edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().setImportFileFilter( "Sound Files" );
edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().importElement( null, context.getSandbox(), propertyPopupPostImportRunnable );
}
};
Runnable recordRunnable = new Runnable() {
public void run() {
edu.cmu.cs.stage3.alice.core.Sound sound = edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().promptUserForRecordedSound( context.getSandbox() );
if( sound != null ) {
((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], sound ) ) )).run();
}
}
};
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "import sound file...", importRunnable ) );
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "record new sound...", recordRunnable ) );
}
// expressions
java.util.Vector expressionStructure = makeFlatExpressionStructure( valueClass, recursiveFactory, context, NO_CURRENT_VALUE );
if( (expressionStructure != null) && (expressionStructure.size() > 0) ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "expressions", expressionStructure ) );
}
// Null
boolean nullValid;
if( elementPrototype instanceof edu.cmu.cs.stage3.alice.authoringtool.util.CallToUserDefinedResponsePrototype ) {
nullValid = true;
} else if( elementPrototype instanceof edu.cmu.cs.stage3.alice.authoringtool.util.CallToUserDefinedQuestionPrototype ) {
nullValid = true;
} else {
nullValid = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.shouldGUIIncludeNone( elementPrototype.getElementClass(), desiredProperties[0] );
// nullValid = edu.cmu.cs.stage3.alice.core.Element.isNullValidForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
}
if( nullValid ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
String nullRepr = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( null, elementClass, desiredProperties[0], "menuContext" );
if( desiredProperties.length == 1 ) { // end of the line
structure.add( new StringObjectPair( nullRepr, factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], null ) ) ) ) );
} else { // recurse
structure.add( new StringObjectPair( nullRepr, makePrototypeStructure( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], null ) ), factory, context ) ) );
}
}
// Other...
final PopupItemFactory otherFactory = new PopupItemFactory() {
public Object createItem( final Object o ) {
return new Runnable() {
public void run() {
((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ) )).run();
}
};
}
};
if( (desiredProperties.length == 1) && edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.isOtherDialogSupportedForClass( valueClass ) ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
Runnable runnable = new Runnable() {
public void run() {
//TODO: context doesn't really want to be passed here... it wants to be the response that will be made...
edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.showOtherDialog( valueClass, null, otherFactory, context );
}
};
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "other...", runnable ) );
}
// allow user to create new list
if( edu.cmu.cs.stage3.alice.core.List.class.isAssignableFrom( valueClass ) && (desiredProperties.length == 1) ) {
if( structure.size() > 0 ) {
structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
}
Runnable createNewListRunnable = new Runnable() {
public void run() {
edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool authoringTool = edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack();
edu.cmu.cs.stage3.alice.core.property.ObjectArrayProperty variables = context.getSandbox().variables;
edu.cmu.cs.stage3.alice.core.Variable variable = authoringTool.showNewVariableDialog( "Create new list", context.getRoot(), true, true );
if( variable != null ) {
if( variables != null ) {
authoringTool.getUndoRedoStack().startCompound();
try {
variables.getOwner().addChild( variable );
variables.add( variable );
} finally {
authoringTool.getUndoRedoStack().stopCompound();
}
}
((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], variable ) ) )).run();
}
}
};
structure.add( new StringObjectPair( "create new list...", createNewListRunnable ) );
}
}
return structure;