1. Even though I set all the atomic fields to read only, none of
them
are when I invoke New on the type from the class bar.
2. When I select a type from the Choice dropdown the readonly state
does not work immediately, but after a few choices are made it starts
to work.
I have provided the test class file below that I is exhibiting this
problem and the corresponding Choice file to go with it.
import javax.persistence.Entity;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.u2d.model.AbstractComplexEObject;
import com.u2d.model.Title;
import com.u2d.type.atom.DateEO;
import com.u2d.type.atom.StringEO;
@Entity
public class TestReadOnly extends AbstractComplexEObject {
private static final long serialVersionUID =
-3677447989144234747L;
private final TestReadOnlyType type = new TestReadOnlyType();
private final StringEO fieldOne = new StringEO();
private final DateEO fieldTwo = new DateEO();
private final StringEO fieldThree = new StringEO();
private final StringEO fieldFour = new StringEO();
private final StringEO fieldFive = new StringEO();
private final StringEO fieldSix = new StringEO();
private final StringEO fieldSeven = new StringEO();
public static String fieldOrder[] = {"type", "fieldOne",
"fieldTwo", "fieldThree", "fieldFour",
"fieldFive", "fieldSix", "fieldSeven"};
@Override
public void initialize() {
super.initialize();
fieldOne.setReadOnly(true);
fieldTwo.setReadOnly(true);
fieldThree.setReadOnly(true);
fieldFour.setReadOnly(true);
fieldFive.setReadOnly(true);
fieldSix.setReadOnly(true);
fieldSeven.setReadOnly(true);
type.getCode().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if(type.getCode().stringValue().equalsIgnoreCase
("T3")) {
System.out.println("Type 3 selected");
fieldOne.setReadOnly(false);
fieldTwo.setReadOnly(false);
fieldThree.setReadOnly(true);
fieldFour.setReadOnly(true);
fieldFive.setReadOnly(true);
fieldSix.setReadOnly(true);
fieldSeven.setReadOnly(true);
}
else if(type.getCode().stringValue().equalsIgnoreCase
("T4")) {
System.out.println("Type 4 selected");
fieldOne.setReadOnly(true);
fieldTwo.setReadOnly(true);
fieldThree.setReadOnly(false);
fieldFour.setReadOnly(false);
fieldFive.setReadOnly(false);
fieldSix.setReadOnly(false);
fieldSeven.setReadOnly(false);
}
else {
System.out.println("Type 1 or 2 selected");
fieldOne.setReadOnly(true);
fieldTwo.setReadOnly(true);
fieldThree.setReadOnly(true);
fieldFour.setReadOnly(true);
fieldFive.setReadOnly(true);
fieldSix.setReadOnly(true);
fieldSeven.setReadOnly(true);
}
}
});
}
public TestReadOnlyType getType() {
return type;
}
public StringEO getFieldOne() {
return fieldOne;
}
public DateEO getFieldTwo() {
return fieldTwo;
}
public StringEO getFieldThree() {
return fieldThree;
}
public StringEO getFieldFour() {
return fieldFour;
}
public StringEO getFieldFive() {
return fieldFive;
}
public StringEO getFieldSix() {
return fieldSix;
}
public StringEO getFieldSeven() {
return fieldSeven;
}
@Override
public Title title() {
return type.getCaption().title();
}
}
import javax.persistence.Entity;
import com.u2d.type.AbstractChoiceEO;
import com.u2d.type.atom.StringEO;
@Entity
public class TestReadOnlyType extends AbstractChoiceEO {
private static final long serialVersionUID =
-704884297831145501L;
private final StringEO code = new StringEO();
private final StringEO caption = new StringEO();
public static String[] identities = { "code" };
public TestReadOnlyType(){}
public TestReadOnlyType(String code, String caption) {
this.code.setValue(code);
this.caption.setValue(caption);
}
public StringEO getCode() {
return code;
}
public StringEO getCaption() {
return caption;
}
@Override
public void setSelectedItem(Object anItem) {
super.setSelectedItem(anItem);
}
}
Here is the code I use to set up the types I used.
String testReadOnlyTypes[] = {"Type1", "Type2", "Type3", "Type4"};
String testReadOnlyTypeCodes[] = {"T1", "T2", "T3", "T4"};
for(int i=0;i<testReadOnlyTypes.length;i++) {
TestReadOnlyType testReadOnlyType = new TestReadOnlyType();
testReadOnlyType.getCaption().setValue(testReadOnlyTypes[i]);
testReadOnlyType.getCode().setValue(testReadOnlyTypeCodes[i]);
testReadOnlyType.save();