private static void createKey(CompositeEditor editor,
final Binding binding, final Field f) {
binding.setFactory(new IFactory() {
public Object getValue(Object context) {
GAEField d = (GAEField) f;
if (d.keyKind == null) {
final String[] kinds = new String[1];
kindCheck(kinds);
if (kinds[0] == null || kinds[0].length() == 0) {
return null;
}
d.keyKind = kinds[0];
}
final CompositeEditor rd = new CompositeEditor();
rd.setLayout(new GridLayout());
rd.setBinding(binding);
binding.setAutoCommit(false);
final TitledDialog titledDialog = new TitledDialog(rd) {
protected void okPressed() {
binding.commit();
super.okPressed();
}
};
binding.setDescription("Select entity to refer on");
UniversalUIElement<Composite> element = new UniversalUIElement<Composite>(
Composite.class, SWT.BORDER) {
protected Composite createControl(Composite conComposite) {
Composite c = new Composite(conComposite, SWT.NONE);
DataStoreTableUI ui = new DataStoreTableUI() {
public void open(Object selection) {
binding.commit();
titledDialog.close();
}
};
c.setLayout(new GridLayout(1, false));
ToolBarManager man = new ToolBarManager();
Action action = ui.createActions(man, false);
man.createControl(c);
GAEField d = (GAEField) f;
if (d.keyKind == null) {
final String[] kinds = new String[1];
Binding bnd = new Binding("");
final Binding kind = bnd.getBinding("Kind");
CompositeEditor bb = new CompositeEditor(bnd);
final InputElementDialog dlg = new InputElementDialog(
bb);
bb.setLayoutManager(new OneElementOnLineLayouter());
CompositeEditor pe = new CompositeEditor();
pe.setLayout(new FillLayout());
OneLineTextElement<String> keyKind = new OneLineTextElement<String>(
kind);
pe.add(keyKind);
bb.add(pe);
CompositeEditor buttons = new CompositeEditor();
buttons.setLayoutManager(new HorizontalLayouter());
ButtonSelector ok = new ButtonSelector();
ok.setText("submit");
ok.setValue(new Runnable() {
public void run() {
kinds[0] = (String) kind.getValue();
dlg.close();
}
});
buttons.add(ok);
bb.add(buttons);
DisposeBindingListener
.linkBindingLifeCycle(bnd, bb);
dlg.open();
d.keyKind = kinds[0];
}
BaseViewer bv = new BaseViewer(action, ui, d
.getProject(), d.keyKind) {
public void selectionChanged(
IStructuredSelection selection) {
if (!selection.isEmpty()) {
Entity firstElement = (Entity) selection
.getFirstElement();
rd.getBinding().setValue(
firstElement.getKey(), null);
}
}
};
bv.createControl(c);
BaseDataFacade createFacade = d.createFacade(d.keyKind,
bv.getRefreshCallback(), bv.getSingleCallback());
String namespace = d.getFacade().getNamespace();
createFacade.setNamespace(namespace);
ui.setFacade(createFacade);
bv.getControl().setLayoutData(
GridDataFactory.fillDefaults().grab(true, true)
.create());