I am using gwt editor framework to bind form in gwt. I was able to bind form successfully, but my problem is I need to write too many code. I think using generic will shorten my code but I couldn't do it.
The code for EditVendorWorkflow
is almost same, the only difference is this two line
interface Driver extends SimpleBeanEditorDriver<Vendor, VendorEditor>{}
private VendorEditor editor;
Example, If I write a PersonEditor
the corresponding EditPersonWorkflow
code will have
interface Driver extends SimpleBeanEditorDriver<Person, PersonEditor>{}
private PersonEditor editor;
So basically there is a repetition.
Any Help is appreciable.
public class EditVendorWorkflow{
interface Driver extends SimpleBeanEditorDriver<Vendor, VendorEditor>{}
Driver driver = GWT.create(Driver.class);
private VendorEditor editor;
void edit(Vendor p) {
driver.initialize(editor);
driver.edit(p);
}
void save() {
Vendor edited = driver.flush();
//doSomethingWithEditedVendor(edited);
}
public void initialize(VendorEditor editor) {
this.editor = editor;
}
}
public class VendorEditor extends Composite implements Editor<Vendor> {
private static VendorEditorUiBinder uiBinder = GWT
.create(VendorEditorUiBinder.class);
@UiField Button save;
@UiField TextBox address;
@UiField TextBox contactName;
@UiField ValueBoxEditorDecorator<String> contactMobileNo;
@Path("department.name")
@UiField TextBox deptName;
interface VendorEditorUiBinder extends UiBinder<Widget, VendorEditor> {
}
private final EditVendorWorkflow vendorDriver;
public VendorEditor(Vendor p) {
initWidget(uiBinder.createAndBindUi(this));
vendorDriver = GWT.create(EditVendorWorkflow.class);
vendorDriver.initialize(this);
vendorDriver.edit(p);
}
@UiHandler("save")
void onSaveClick(ClickEvent event) {
vendorDriver.save();
}
}