id);
// OneLineTextElement<String>nl=new
// OneLineTextElement<String>(name);
CompositeEditor ed = new CompositeEditor(b);
ed.setLayoutManager(new OneElementOnLineLayouter());
ed.add(idel);
// ed.add(nl);
Container buttons = new Container();
buttons.setLayoutManager(new HorizontalLayouter());
ButtonSelector ba = new ButtonSelector();
ba.setText("Ok");
final InputElementDialog dlg = new InputElementDialog(
ed);
ba.setValue(new Runnable() {
public void run() {
String value = (String) id.getValue();
Key k = null;
Entity value2 = (Entity) editor.getBinding()
.getValue();
Key c = (Key) value2.getKey();
if (c != null && c.isComplete()) {
if (!value2.hasProperty("$$OLD_KEY_SET")) {
value2.setProperty("$$OLD_KEY_SET",
Boolean.TRUE);
value2.setProperty("$$OLD_KEY"
+ Entity.KEY_RESERVED_PROPERTY,
c);
}
}
if (value != null && value.trim().length() != 0) {
String vl = value.trim();
try {
long l = Long.parseLong(vl);
k = KeyFactory.createKey(
value2.getKind(), l);
} catch (Exception e) {
k = KeyFactory.createKey(
((Entity) editor.getBinding()
.getValue()).getKind(),
vl);
}
} else {
return;
}
// value2.setProperty(Entity.KEY_RESERVED_PROPERTY,
// k);
try {
java.lang.reflect.Field f = value2
.getClass().getDeclaredField("key");
f.setAccessible(true);
f.set(value2, k);
} catch (Exception e) {
Activator.log(e);
}
if (k != null) {
String string = "" + k.toString();
((Binding) editor.getBinding())
.setName(string);
EditDialog.this.setTitle(string);
;
dlg.close();
}
}
});
ButtonSelector ba1 = new ButtonSelector();
ba1.setValue(new Runnable() {
public void run() {
dlg.close();
}
});
ba1.setText("Cancel");
buttons.add(ba);
buttons.add(ba1);
ed.add(buttons);
DisposeBindingListener.linkBindingLifeCycle(b, ed);
dlg.open();
super.widgetSelected(e);
}
});
}
Link l1 = new Link(cm, SWT.NONE);
l1.setText("<a>Add new property</a>");
l1.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
Binding b = new Binding("");
b.setName("Configure new Property");
final Binding binding = b.getBinding("name");
binding.setName("Name");
binding.setReadOnly(false);
binding.addValidator(new ValidatorAdapter<String>() {
public CodeAndMessage isValid(IBinding context,
String object) {
if (object == null || object.length() == 0) {
return CodeAndMessage
.errorMessage("please define property name");
}
Binding b = (Binding) editor.getBinding();
if (b.getKnownChilds().contains(object)) {
return CodeAndMessage
.errorMessage("property with this name already exits");
}
return super.isValid(context, object);
}
});
final Binding type = b.getBinding("type");
final Binding kc = b.getBinding("keyKind");
kc.setName("Kind:");
kc.setValue(
((Entity) editor.getBinding().getValue()).getKind(),
null);
kc.setReadOnly(false);
kc.setRequired(false);
type.setName("Type");
type.setReadOnly(false);
type.setRequired(true);
final OneLineTextElement<String> keyKind = new OneLineTextElement<String>(
kc);
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 Binding multi = b.getBinding("multi");
multi.setReadOnly(false);
multi.setName("Multivalue");
type.setName("Type");
multi.setValue(false, null);
CompositeEditor z = new CompositeEditor(b);
final Container m = new Container();
m.setLayoutManager(new OneElementOnLineLayouter());
OneLineTextElement<String> t = new OneLineTextElement<String>(
binding);
// t.setCaption("Name:");
m.add(t);
ComboEnumeratedValueSelector<Class<?>> element2 = new ComboEnumeratedValueSelector<Class<?>>(
type);
type.addValueListener(new IValueListener<Class<?>>() {
public void valueChanged(Class<?> oldValue,
Class<?> newValue) {
if (newValue == Key.class) {
m.add(2, keyKind);
m.getControl().getShell().pack(true);
} else if (oldValue == Key.class) {
m.remove(keyKind);
m.getControl().getShell().pack(true);
}
}
});
ButtonSelector sl = new ButtonSelector(SWT.CHECK);
sl.setBinding(multi);
m.add(element2);
m.add(sl);
z.setLayoutManager(new OneElementOnLineLayouter());
z.add(m);
Container m1 = new Container();
m1.setLayoutManager(new HorizontalLayouter());
final InputElementDialog dl = new InputElementDialog(z);
final ButtonSelector ok = new ButtonSelector();
ok.setText("Ok");
ok.setValue(new Runnable() {
public void run() {
String value = (String) binding.getValue();
BaseDataFacade.GAEField gaeField = facade
.createField(value,
(Class<?>) type.getValue(),
(Boolean) (multi.getValue()),
(String) kc.getValue());
EditingBinding binding2 = (EditingBinding) editor
.getBinding();
binding2.removedElements.remove(value);
binding2.fieldsChanged = true;
binding2.getBinding(value).setValue(null, null);
EditorUtility.createBindingsWithButton(
(Entity) binding2.getValue(), editor,
(Binding) binding2,
new Field[] { gaeField }, facade, true);
dl.close();
editor.getControl().getShell().layout(true, true);
editor.getControl().getShell().pack(true);
}
});
ok.setEnabled(false);
b.addStatusChangeListener(new IStatusChangeListener() {
public void statusChanged(IBinding bnd,
CodeAndMessage cm) {
ok.setEnabled(cm.getCode() == 0);
}
});
ButtonSelector cancel = new ButtonSelector();
cancel.setText("Cancel");
m1.add(ok);
m1.add(cancel);
cancel.setValue(new Runnable() {
public void run() {
dl.close();
}
});
m1.getLayoutHints().setGrabHorizontal(true);
m1.getLayoutHints().setAlignmentHorizontal(SWT.RIGHT);
z.add(m1);
DisposeBindingListener.linkBindingLifeCycle(b, z);
dl.open();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
Link l2 = new Link(cm, SWT.NONE);
l2.setText("<a>Remove property</a>");
l2.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
Binding bnd2 = new Binding("");
bnd2.setName("Select property to remove");
CompositeEditor ed = new CompositeEditor(bnd2);
ed.setLayoutManager(new OneElementOnLineLayouter());
final ListEnumeratedValueSelector<String> element2 = new ListEnumeratedValueSelector<String>();
ed.add(element2);
final Binding bnd = (Binding) editor.getBinding();
Collection<String> str = bnd.getKnownChilds();
element2.setRealm(new Realm<String>(str));