Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EDT:Tutorial: RUI With DataBase Lesson 4 Code
Access a database with EGL Rich UI > Resources
Code for PaymentFileMaintenance.egl after lesson 4
The following code is the text of the PaymentFileMaintenance.egl file
at the end of lesson 4.
package handlers; import org.eclipse.edt.rui.mvc.Controller; import org.eclipse.edt.rui.mvc.FormField; import org.eclipse.edt.rui.mvc.FormManager; import org.eclipse.edt.rui.mvc.MVC; import org.eclipse.edt.rui.widgets.DataGrid; import org.eclipse.edt.rui.widgets.DataGridColumn; import org.eclipse.edt.rui.widgets.DataGridLib; import org.eclipse.edt.rui.widgets.Div; import org.eclipse.edt.rui.widgets.GridLayout; import org.eclipse.edt.rui.widgets.GridLayoutData; import org.eclipse.edt.rui.widgets.GridLayoutLib; import org.eclipse.edt.rui.widgets.TextLabel; import dojo.widgets.DojoButton; import dojo.widgets.DojoCheckBox; import dojo.widgets.DojoComboBox; import dojo.widgets.DojoCurrencyTextBox; import dojo.widgets.DojoDateTextBox; import dojo.widgets.DojoLib; import dojo.widgets.DojoTextField; import dojo.widgets.DojoTitlePane; import eglx.persistence.sql.column; import eglx.ui.rui.Event; import eglx.ui.rui.RUIHandler; import eglx.ui.rui.Widget; import eglx.ui.rui.view; import eglx.ui.rui.widget; import records.paymentRec; handler PaymentFileMaintenance type RUIhandler{ initialUI =[ui], onConstructionFunction = start, cssFile = "css/PaymentClient.css", title = "PaymentFileMaintenance"} ui GridLayout{columns = 2, rows = 2, cellPadding = 4, children = [detailButtonLayout, editPane, buttonLayout, allPayments_ui ] }; allPayments paymentRec[]; allPayments_ui DataGrid{ layoutData = new GridLayoutData{ row = 2, column = 1, verticalAlignment = GridLayoutLib.VALIGN_TOP}, columns =[ new DataGridColumn{name = "category", displayName = "Type", width = 90}, new DataGridColumn{name = "description", displayName = "Description", width = 120}, new DataGridColumn{name = "amount", displayName = "Amount due", width = 90} ], data = allPayments as any[], selectionMode = DataGridLib.SINGLE_SELECTION}; buttonLayout GridLayout{ layoutData = new GridLayoutData{ row = 1, column = 1 }, cellPadding = 4, rows = 1, columns = 3, children = [ sampleButton, deleteButton, addButton ] }; addButton DojoButton{ layoutData = new GridLayoutData{ row = 1, column = 1 }, text = "Add", onClick ::= addRow }; deleteButton DojoButton{ layoutData = new GridLayoutData{ row = 1, column = 2 }, text = "Delete", onClick ::= deleteRow }; sampleButton DojoButton{ layoutData = new GridLayoutData{ row = 1, column = 3 }, text = "Sample", onClick ::= sampleData }; selectedPayment paymentRec; editPane DojoTitlePane{ layoutData = new GridLayoutData{ row = 2, column = 2, verticalAlignment = GridLayoutLib.VALIGN_TOP }, title = "Payment record", isOpen=true, duration=1000, width = "350", children = [ new Div {children = [ selectedPayment_ui ]}] }; selectedPayment_ui GridLayout { rows = 9, columns = 2, cellPadding = 4, children = [ selectedPayment_paymentId_nameLabel, selectedPayment_paymentId_field, selectedPayment_category_nameLabel, selectedPayment_category_comboBox, selectedPayment_description_nameLabel, selectedPayment_description_field, selectedPayment_amount_nameLabel, selectedPayment_amount_textBox, selectedPayment_fixedPayment_nameLabel, selectedPayment_fixedPayment_checkBox, selectedPayment_dueDate_nameLabel, selectedPayment_dueDate_textBox, selectedPayment_payeeName_nameLabel, selectedPayment_payeeName_field, selectedPayment_payeeAddress1_nameLabel, selectedPayment_payeeAddress1_field, selectedPayment_payeeAddress2_nameLabel, selectedPayment_payeeAddress2_field ] }; selectedPayment_paymentId_nameLabel TextLabel { text="Key:" , layoutData = new GridLayoutData { row = 1, column = 1} }; selectedPayment_paymentId_field DojoTextField { layoutData = new GridLayoutData { row = 1, column = 2}, readOnly = true }; selectedPayment_paymentId_controller Controller { @MVC {model = selectedPayment.paymentId, view = selectedPayment_paymentId_field}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_paymentId_formField FormField { controller = selectedPayment_paymentId_controller, nameLabel = selectedPayment_paymentId_nameLabel}; selectedPayment_category_nameLabel TextLabel { text="Category:", layoutData = new GridLayoutData { row = 2, column = 1} }; selectedPayment_category_comboBox DojoComboBox { values = [], layoutData = new GridLayoutData { row = 2, column = 2} }; selectedPayment_category_controller Controller { @MVC {model = selectedPayment.category, view = selectedPayment_category_comboBox}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_category_formField FormField { controller = selectedPayment_category_controller, nameLabel = selectedPayment_category_nameLabel}; selectedPayment_description_nameLabel TextLabel { text="Description:" , layoutData = new GridLayoutData { row = 3, column = 1} }; selectedPayment_description_field DojoTextField { layoutData = new GridLayoutData { row = 3, column = 2} }; selectedPayment_description_controller Controller { @MVC {model = selectedPayment.description, view = selectedPayment_description_field}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_description_formField FormField { controller = selectedPayment_description_controller, nameLabel = selectedPayment_description_nameLabel}; selectedPayment_amount_nameLabel TextLabel { text="Amount:", layoutData = new GridLayoutData { row = 4, column = 1} }; selectedPayment_amount_textBox DojoCurrencyTextBox { currency = "USD", value = selectedPayment.amount, width = 166, errorMessage="Amount is not valid.", layoutData = new GridLayoutData { row = 4, column = 2} }; selectedPayment_amount_controller Controller { @MVC {model = selectedPayment.amount, view = selectedPayment_amount_textBox}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_amount_formField FormField { controller = selectedPayment_amount_controller, nameLabel = selectedPayment_amount_nameLabel}; selectedPayment_fixedPayment_nameLabel TextLabel { text="Fixed pmt:" , layoutData = new GridLayoutData { row = 5, column = 1} }; selectedPayment_fixedPayment_checkBox DojoCheckBox { layoutData = new GridLayoutData { row = 5, column = 2} }; selectedPayment_fixedPayment_controller Controller { @MVC {model = selectedPayment.fixedPayment, view = selectedPayment_fixedPayment_checkBox}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_fixedPayment_formField FormField { controller = selectedPayment_fixedPayment_controller, nameLabel = selectedPayment_fixedPayment_nameLabel}; selectedPayment_dueDate_nameLabel TextLabel { text="Due date:", layoutData = new GridLayoutData { row = 6, column = 1} }; selectedPayment_dueDate_textBox DojoDateTextBox { formatLength = DojoLib.DATEBOX_FORMAT_LONG, value = selectedPayment.dueDate, layoutData = new GridLayoutData { row = 6, column = 2} }; selectedPayment_dueDate_controller Controller { @MVC {model = selectedPayment.dueDate, view = selectedPayment_dueDate_textBox}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_dueDate_formField FormField { controller = selectedPayment_dueDate_controller, nameLabel = selectedPayment_dueDate_nameLabel}; selectedPayment_payeeName_nameLabel TextLabel { text="Payee:", layoutData = new GridLayoutData { row = 7, column = 1} }; selectedPayment_payeeName_field DojoTextField { layoutData = new GridLayoutData { row = 7, column = 2} }; selectedPayment_payeeName_controller Controller { @MVC {model = selectedPayment.payeeName, view = selectedPayment_payeeName_field}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_payeeName_formField FormField { controller = selectedPayment_payeeName_controller, nameLabel = selectedPayment_payeeName_nameLabel}; selectedPayment_payeeAddress1_nameLabel TextLabel { text="Address 1:" , layoutData = new GridLayoutData { row = 8, column = 1} }; selectedPayment_payeeAddress1_field DojoTextField { layoutData = new GridLayoutData { row = 8, column = 2} }; selectedPayment_payeeAddress1_controller Controller { @MVC {model = selectedPayment.payeeAddress1, view = selectedPayment_payeeAddress1_field}, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_payeeAddress1_formField FormField { controller = selectedPayment_payeeAddress1_controller, nameLabel = selectedPayment_payeeAddress1_nameLabel}; selectedPayment_payeeAddress2_nameLabel TextLabel { text="Address 2:" , layoutData = new GridLayoutData { row = 9, column = 1} }; selectedPayment_payeeAddress2_field DojoTextField { layoutData = new GridLayoutData { row = 9, column = 2} }; selectedPayment_payeeAddress2_controller Controller { @MVC {model = selectedPayment.payeeAddress2, view = selectedPayment_payeeAddress2_field }, validStateSetter = handleValidStateChange_selectedPayment}; selectedPayment_payeeAddress2_formField FormField { controller = selectedPayment_payeeAddress2_controller, nameLabel = selectedPayment_payeeAddress2_nameLabel}; selectedPayment_form FormManager { entries = [ selectedPayment_paymentId_formField, selectedPayment_category_formField, selectedPayment_description_formField, selectedPayment_amount_formField, selectedPayment_fixedPayment_formField, selectedPayment_dueDate_formField, selectedPayment_payeeName_formField, selectedPayment_payeeAddress1_formField, selectedPayment_payeeAddress2_formField ] }; detailButtonLayout GridLayout{ layoutData = new GridLayoutData{ row = 1, column = 2 }, cellPadding = 4, rows = 1, columns = 2, children = [ saveButton, clearButton ] }; clearButton DojoButton{ layoutData = new GridLayoutData{ row = 1, column = 1 }, text = "Clear", onClick ::= clearAllFields }; saveButton DojoButton{ layoutData = new GridLayoutData{ row = 1, column = 2 }, text = "Save", onClick ::= selectedPayment_form_Submit }; function start() allPayments_ui.data =[ new paymentRec{category = 1, description = "test01", amount = 100.00}, new paymentRec{category = 2, description = "test02", amount = 200.00}, new paymentRec{category = 3, description = "test03", amount = 300.00}]; end function addRow(event Event in) end function deleteRow(event Event in) end function sampleData(event Event in) end function selectedPayment_form_Submit(event Event in) if(selectedPayment_form.isValid()) selectedPayment_form.commit(); end end function selectedPayment_form_Publish(event Event in) selectedPayment_form.publish(); selectedPayment_form_Validate(); end function selectedPayment_form_Validate() selectedPayment_form.isValid(); end function handleValidStateChange_selectedPayment(view Widget in, valid boolean in) for (n int from selectedPayment_form.entries.getSize() to 1 decrement by 1) entry FormField = selectedPayment_form.entries[n]; if(entry.controller.view == view) if(valid) // TODO: handle valid value else msg String? = entry.controller.getErrorMessage(); // TODO: handle invalid value end end end end function clearAllFields(event Event in) end end
Related tasks