final com.google.appengine.api.datastore.Entity e,
final CompositeEditor editor, final Binding bnd,
final BaseDataFacade facade, Container text, final Field f,
final boolean needIndexable) {
final GAEField fm = (GAEField) f;
final CompositeEditor ed = new CompositeEditor();
ed.setLayout(new GridLayout());
ed.setLayoutManager(new HorizontalLayouter());
if (fm.multiplicity) {
if (text == null) {
text = new CTabFolderElement();
text.setBordered(true);
ed.setData("text", text);
ed.add(text);
}
IBinding bb = createSpecialMultiEdit(e, bnd, facade, text, f, fm,
needIndexable);
// addButtonSelector(bb, ed,null);
ed.setId(bnd.getId());
editor.add(ed);
return text;
}
if (f.isKey()) {
return text;
} else {
final Class<?> type = f.getType();
if (type != null) {
final Binding binding = bnd.getBinding(f.name);
binding.setValue(e.getProperty(f.name), null);
Object adapter = new ClassAdapterFactory().getAdapter(type,
IValidator.class);
if (adapter != null) {
binding.setAdapter(IValidator.class, (IValidator) adapter);
}
adapter = new ClassAdapterFactory().getAdapter(type,
ILabelLookup.class);
if (adapter != null) {
binding.setAdapter(ILabelLookup.class,
(ILabelLookup) adapter);
}
adapter = new ClassAdapterFactory().getAdapter(type,
IRealmProvider.class);
if (adapter != null) {
binding.setAdapter(IRealmProvider.class,
(IRealmProvider) adapter);
} else {
IRealm<?> c = facade.getRealm(f);
if (c != null) {
binding.setRealm(c);
}
}
binding.setReadOnly(false);
binding.setName(f.getTitle());
if (type == String.class) {
OneLineTextElement<String> t = new OneLineTextElement<String>();
t.setBinding(binding);
ed.add(t);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (Number.class.isAssignableFrom(type)
|| type.isPrimitive()) {
binding.setSubjectClass(type);
OneLineTextElement<Number> t = new OneLineTextElement<Number>();
binding.addValidator(new ValidatorAdapter() {
public CodeAndMessage isValid(IBinding context,
Object object) {
if (object == null) {
return CodeAndMessage.OK_MESSAGE;
}
try {
if (object instanceof String) {
if (type == Double.class) {
Double.parseDouble((String) object);
} else if (type == Long.class) {
Long.parseLong((String) object);
} else if (type == Float.class) {
Float.parseFloat((String) object);
} else if (type == Integer.class) {
Integer.parseInt((String) object);
}
} else {
if (!Number.class.isAssignableFrom(object
.getClass())) {
return CodeAndMessage
.errorMessage("The number should be in this place");
}
}
return CodeAndMessage.OK_MESSAGE;
} catch (NumberFormatException e) {
return CodeAndMessage
.errorMessage("The number should be in this place");
}
// return super.isValid(context, object);
}
});
t.setBinding(binding);
ed.add(t);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Boolean.class) {
binding.setSubjectClass(type);
ComboEnumeratedValueSelector<Boolean> t = new ComboEnumeratedValueSelector<Boolean>();
t.setBinding(binding);
ed.add(t);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Text.class) {
if (text == null) {
text = new CTabFolderElement();
text.setBordered(true);
ed.setData("text", text);
ed.add(text);
}
createText(ed, text, binding, true);
// addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Link.class) {
createLink(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Category.class) {
createCategory(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Email.class) {
createEmail(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == PostalAddress.class) {
createPostalAddress(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == PhoneNumber.class) {
createPhoneNumber(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Date.class) {
createDate(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == IMHandle.class) {
createIMHandle(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == GeoPt.class) {
createGeoPt(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == User.class) {
createUser(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Blob.class || type == ShortBlob.class) {
createBlob(ed, type, binding, facade.getProject());
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Rating.class) {
createRating(ed, binding);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Key.class) {
createKey(ed, binding, f);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
}
// editor.setId(binding.getId());
} else {
final Binding binding = bnd.getBinding(f.name);
final Container txt = text;
binding.setReadOnly(false);
binding.setName(f.getTitle());
final LinkElement bs = new LinkElement();
bs.setId(binding.getId());
ed.setId(binding.getId());
bs.getLayoutHints().setGrabVertical(false);
bs.setText("Specify type");
bs.setCaption(f.getTitle());
bs.addHyperLinkListener(new IHyperlinkListener() {
public void linkExited(HyperlinkEvent e) {
// TODO Auto-generated method stub
}
public void linkEntered(HyperlinkEvent e) {
return;
}
public void linkActivated(HyperlinkEvent event) {
final Binding tmpBinding = new Binding("");
tmpBinding.setName("Specify type for property");
final Binding type = tmpBinding.getBinding("type");
type.setReadOnly(false);
type.setRequired(true);
type.setName("Select type");
type.setAdapter(ITextLabelProvider.class,
new TextProviderAdapter() {
public String getText(Object object) {
Class<?> c = (Class<?>) object;
return c.getSimpleName();
}
});
type.setValue(String.class, null);
type.setRealm(new Realm<Class<?>>(
EditorUtility.SUPPORTED_TYPES));
final ComboEnumeratedValueSelector ce = new ComboEnumeratedValueSelector(
type);
final CompositeEditor c1 = new CompositeEditor();
c1.setLayoutManager(new OneElementOnLineLayouter());
c1.add(ce);
final Binding multi = tmpBinding.getBinding("multi");
multi.setReadOnly(false);
multi.setName("Multivalue");
multi.setValue(false, null);
ButtonSelector multiB = new ButtonSelector(multi,
SWT.CHECK);
c1.add(multiB);
final Binding kk = tmpBinding.getBinding("KeyKind");
kk.setName("Kind");
kk.setValue(e.getKind(), null);
kk.setReadOnly(false);
kk.setRequired(false);
final OneLineTextElement<String> keyKind = new OneLineTextElement<String>(
kk);
type.addValueListener(new IValueListener<Class<?>>() {
public void valueChanged(Class<?> oldValue,
Class<?> newValue) {
if (newValue == Key.class) {
c1.add(1, keyKind);
c1.getControl().getShell().pack(true);
} else if (oldValue == Key.class) {
c1.remove(keyKind);
c1.getControl().getShell().pack(true);
}
}
});
CompositeEditor c2 = new CompositeEditor();
c2.setLayoutManager(new HorizontalLayouter());
ButtonSelector ok = new ButtonSelector();
ok.setText("submit");
ButtonSelector canc = new ButtonSelector();
canc.setText("cancel");
c2.add(ok);
c2.add(canc);
CompositeEditor finall = new CompositeEditor(tmpBinding);
finall.setLayoutManager(new OneElementOnLineLayouter());
finall.add(c1);
finall.add(c2);
final InputElementDialog ied = new InputElementDialog(
finall);
ok.setValue(new Runnable() {