T
- original sub-property type, referred to as the model type by the ConverterU
- type editable by E, referred to as the field type by the ConverterE
- editor type used to display, modify Upublic class ConverterEditorAdapter<T,U,E extends Editor<U>> extends Object implements CompositeEditor<T,U,E>, LeafValueEditor<T>
Converter
-modified instance of the data.
As an example, consider an Order
object that has a property vendorId
, which holds
the id
property of a Vendor
object. But to draw the field, the full
Vendor
must be used in a ComboBox<Vendor>
:
public class Order {
public String getVendorId() { ... }
}
public class Vendor {
public String getName() { ... }
public String getId() { ... }
}
interface VendorProperties extends ValueProvider<Vendor> {
ModelKeyProvider<Vendor> id();
LabelProvider<Vendor> name();
}
public class OrderEditor implements Editor<Order> {
// Won't work as a subeditor, since we can't refer to the String vendorId as a Vendor
//ComboBox<Vendor> vendorId;
// Instead, we create a way to map from String -> Vendor
public static class VendorIdConverter implements Converter<String, Vendor> {
private final Store<Vendor> store;
public VendorIdConverter(Store<Vendor> store) {
this.store = store;
}
public String convertFieldValue(Vendor object) {
return object.getId();
}
public Vendor convertModelValue(String object) {
return store.findModelWithKey(object);
}
}
// We create a ComboBox to display, but tell the editor to ignore it
@Ignore
ComboBox<Vendor> vendor;
// And we wire the vendorId property to the vendor ComboBox, using the Converter
// This is an editor, so it must be public, protected, or default
ConverterEditorAdapter<String, Vendor, ComboBox<Vendor>> vendorId;
public OrderEditor() {
VendorProperties props = GWT.create(VendorProperties.class);
ListStore<Vendor> vendorList = new ListStore<Vendor>(props.id());
//possible vendors should be added to this list, might be an RPC call?
vendorList.add(...);
//this will make the combo box draw the vendor name - easier to read than the id
vendor = new ComboBox<Vendor>(props.name());
//and finally, actually wire them together
vendorId = new ConverterEditorAdapter<String, Vendor, ComboBox<Vendor>>
(vendor, new VendorIdConverter(vendorList));
}
}
CompositeEditor.EditorChain<C,E extends Editor<? super C>>
Editor.Ignore, Editor.Path
Constructor and Description |
---|
ConverterEditorAdapter(E editor,
Converter<T,U> converter)
Creates a new editor adapter using the given converter to translate values to and from what
can be used by the given editor.
|
Modifier and Type | Method and Description |
---|---|
E |
createEditorForTraversal() |
void |
flush() |
Converter<T,U> |
getConverter() |
String |
getPathElement(E subEditor) |
T |
getValue() |
void |
onPropertyChange(String... paths) |
void |
setDelegate(EditorDelegate<T> delegate) |
void |
setEditorChain(CompositeEditor.EditorChain<U,E> chain) |
void |
setValue(T value) |
public void flush()
flush
in interface ValueAwareEditor<T>
public void onPropertyChange(String... paths)
onPropertyChange
in interface ValueAwareEditor<T>
public void setDelegate(EditorDelegate<T> delegate)
setDelegate
in interface HasEditorDelegate<T>
public void setValue(T value)
setValue
in interface ValueAwareEditor<T>
setValue
in interface TakesValue<T>
public T getValue()
getValue
in interface TakesValue<T>
public E createEditorForTraversal()
createEditorForTraversal
in interface CompositeEditor<T,U,E extends Editor<U>>
public String getPathElement(E subEditor)
getPathElement
in interface CompositeEditor<T,U,E extends Editor<U>>
public void setEditorChain(CompositeEditor.EditorChain<U,E> chain)
setEditorChain
in interface CompositeEditor<T,U,E extends Editor<U>>
Copyright © 2015. All rights reserved.