} else {
Object firstElement = null;
Binding bnd = new Binding(firstElement);
bnd.setName("Edit");
CompositeEditor m = new CompositeEditor(bnd);
TitledDialog dlg = new TitledDialog(m);
GAEField singleField = fm.getSingleField();
ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(
e.getAppId()));
Entity c = new Entity("A");
if (fm instanceof CGAEField) {
c = new Entity(fm.getKeyKind(), parent);
// Entity example =
} else {
c.setProperty(f.name, firstElement);
}
createBindingsWithButton(c, m, bnd,
new Field[] { singleField }, facade, false);
int open = dlg.open();
if (open == Dialog.OK) {
Binding bb = bnd.getBinding(f.name);
Object value = bb.getValue();
if (value == null || bb.isReadOnly()) {
value = new NullValue();
}
v.addValue(value);
}
bnd.dispose();
}
}
});
manager.add(new Action("Edit selected") {
{
setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"/icons/text_edit.gif"));
}
public void run() {
if (f instanceof CGAEField) {
CGAEField cgf = (CGAEField) f;
Object[] selected = v.getSelection().toArray();
if (selected.length == 1) {
BaseDataFacade fac = new BaseDataFacade(
cgf.keyKind, facade.getProject(),
facade.isDebug());
fac.setNamespace(facade.getNamespace());
DataStoreTableUI dstui = new DataStoreTableUI();
Object selecttedd = selected[0];
if (selecttedd instanceof Entity) {
final Entity sel = (Entity) selecttedd;
ArrayList<Entity> select = new ArrayList();
select.add(sel);
fac.determineFields(select);
dstui.setFacade(fac);
dstui.open(sel, false, true,
new IUpdateList() {
public void update(Entity e) {
v.removeValue(sel);
v.addValue(e);
}
});
}
}
return;
} else {
Object firstElement = v.getSelection()
.getFirstElement();
Binding bnd = new Binding(firstElement);
bnd.setName("Edit");
CompositeEditor m = new CompositeEditor(bnd);
TitledDialog dlg = new TitledDialog(m);
GAEField singleField = fm.getSingleField();
ApiProxy.setEnvironmentForCurrentThread(new FakeEnvironment(
e.getAppId()));
Entity c = new Entity("A");
if (firstElement instanceof NullValue) {
c.setProperty(f.name, null);
} else {
c.setProperty(f.name, firstElement);
}
createBindingsWithButton(c, m, bnd,
new Field[] { singleField }, facade, false);
int open = dlg.open();
if (open == Dialog.OK) {
StructuredViewer viewer = v.getViewer();
if (viewer instanceof TableViewer) {
Binding bb = bnd.getBinding(f.name);
Object value = bb.getValue();
if (value == null || bb.isReadOnly()) {
value = new NullValue();
}
TableViewer tv = (TableViewer)viewer;
int index = tv.getTable().getSelectionIndex();
v.editValue(value, index);
//tv.get
} else {
v.removeValue(firstElement);
Binding bb = bnd.getBinding(f.name);
Object value = bb.getValue();
if (value == null || bb.isReadOnly()) {
value = new NullValue();
}
v.addValue(value);
}
}
bnd.dispose();
}
}
});
manager.add(new Action("Delete selected") {
{
setImageDescriptor(AbstractUIPlugin
.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"/icons/delete.gif"));
}
@SuppressWarnings("unchecked")
public void run() {
final List selected = v.getSelection().toList();
if (f instanceof CGAEField) {
final CGAEField cgf = (CGAEField) f;
BaseDataFacade fac = new BaseDataFacade(
cgf.keyKind, facade.getProject(), facade
.isDebug());
fac.setNamespace(facade.getNamespace());
fac.delete(selected.toArray(new Entity[selected
.size()]), new OperationCallback() {
public void passed(Object object) {
Collection coll = (Collection) ((HashMap) facade
.getChildren()
.get(cgf.getKeyKind())).get(e
.getKey());
coll.removeAll(selected);
facade.updateChildren(e);
v.removeValues(selected);
}
public void failed(Exception exception) {
return;
}
});
// facade.updateChildren(e);
} else {
v.removeValues(selected);
}
}
});
return manager.createControl(conComposite);
}
});
v.setValueAsSelection(false);
Binding binding = bnd.getBinding(f.name);
binding.setReadOnly(false);
Object property = null;
if (f instanceof CGAEField) {
HashMap hashMap = (HashMap) facade.getChildren().get(
((CGAEField) f).keyKind);
if (hashMap != null) {
Collection col = (Collection) (hashMap).get(e.getKey());
if (col != null) {
property = new ArrayList<Object>();
for (Iterator i = col.iterator(); i.hasNext();) {
Entity ent = (Entity) i.next();
((ArrayList<Object>) property).add(ent);
v.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
Entity e = (Entity) element;
String res = "";
String[] details = ((CGAEField) f)
.getKeyKindDetails();
if (details != null && details.length != 0) {
StringBuilder sb = new StringBuilder();
int ch = 0;
for (String det : details) {
Object prop = e.getProperty(det);
String toStr = ((CGAEField) f)
.getObjectText2(e, prop);
sb.append(toStr);
if (ch != details.length - 1) {
sb.append(":");
}
ch++;
}
res = sb.toString();
} else {
res = e.getKey().toString();
}
return res;
}
});
}
} else {
property = "";// <empty>
}
} else {
property = "";// <empty>
}
} else if (f instanceof PGAEField) {
property = e.getProperty(f.name);
} else {
property = e.getProperty(f.name);
}
if (property instanceof Collection<?>) {
Collection c = (Collection) property;
boolean remove = c.remove(null);
if (remove) {
c.add(new NullValue());
}
}
binding.setValue(property, null);
v.setBinding(binding);
v.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
.create());
m.add(v);
if (needIndexable) {
addNotIndexableButton(binding, m, fm);
}
text.add(m);
return binding;