T
timasmith
Hi,
I have an architecture question for designing a suite of rich client
applications. The synatx is Java although there is little specific to
the language - I consider this a software engineering dilema.
What do you think of my solution as follows?
My general requirement is to avoid hand crafting each gui application.
Many are similar with a subset of controls others are using but
following a simple form data entry layout. There will be more complex
interactions between controls to be scripted.
I have a data/business layer which ultimately creates objects, here is
a simplified one as example - there are getter/setters per field
public class PatientObject {
private String patientName;
private Date birthDate;
private int genderId;
private int locationId;
}
I have a table which lists the gui controls in use for each app:
control_id addAction width height Text
1 addLabel 200 20 Patient Name
2 addPatientName 200 20
3 addLabel 200 20 Birth Date
4 addBirthDate 100 20
5 addLabel 200 20 Sex
6 addGenderId 100 20
7 addLabel 200 20 Location
8 addLocationId 100 20
I have an auto generated Application which will dynamically build the
controls
public class MyApp extends JFrame {
private AppController controller;
private addControls(ControlList controls) {
this.patient = p;
Enumeration e1 = controls.elements();
while (e1.hasMoreElements()) {
ControlObject co = (ControlObject) e1.nextElement();
if (co.getAddAction() == "addLabel") {
addLabel(co);
} else if (co.getAddAction() == "addPatietName") {
addPatientName(co);
} // repeats for all the unique controls in the
// the table above
}
}
private void addPatientName(ControlObject co) {
JTextField textField = new JTextField();
textField.setWidth(co.getWidth());
textField.setHeight(co.getHeight());
getCurrentContainer.add(textField);
}
private void addLocation(ControlObject co) {
JList list = new JList((ListModel) controller.getLocations());
list.setSize(200,60);
getCurrentContainer().add(list);
}
}
I guess the addControls should use reflection rather than generating a
large method - but I like the compile time check against the table by
auto generating the method name.
The controller has the lookup lists, each implementing ListModel to
directly update the application model and trigger additional
application logic. That works ok.
The part I am not thrilled with is that I have to map back text fields
back to the data model
e.g. in AppController
private PatientModel patient;
public void saveData() {
patient.setPatientName(myApp.getPatientName());
...
}
Ideally I could have a model for *every* GUI control - but the
javax.swing.text.Document looks too heavy for my datamodel to implement
for every field - so it seems better to map the data.
Any other thoughts on this architecture?
thanks
Tim
I have an architecture question for designing a suite of rich client
applications. The synatx is Java although there is little specific to
the language - I consider this a software engineering dilema.
What do you think of my solution as follows?
My general requirement is to avoid hand crafting each gui application.
Many are similar with a subset of controls others are using but
following a simple form data entry layout. There will be more complex
interactions between controls to be scripted.
I have a data/business layer which ultimately creates objects, here is
a simplified one as example - there are getter/setters per field
public class PatientObject {
private String patientName;
private Date birthDate;
private int genderId;
private int locationId;
}
I have a table which lists the gui controls in use for each app:
control_id addAction width height Text
1 addLabel 200 20 Patient Name
2 addPatientName 200 20
3 addLabel 200 20 Birth Date
4 addBirthDate 100 20
5 addLabel 200 20 Sex
6 addGenderId 100 20
7 addLabel 200 20 Location
8 addLocationId 100 20
I have an auto generated Application which will dynamically build the
controls
public class MyApp extends JFrame {
private AppController controller;
private addControls(ControlList controls) {
this.patient = p;
Enumeration e1 = controls.elements();
while (e1.hasMoreElements()) {
ControlObject co = (ControlObject) e1.nextElement();
if (co.getAddAction() == "addLabel") {
addLabel(co);
} else if (co.getAddAction() == "addPatietName") {
addPatientName(co);
} // repeats for all the unique controls in the
// the table above
}
}
private void addPatientName(ControlObject co) {
JTextField textField = new JTextField();
textField.setWidth(co.getWidth());
textField.setHeight(co.getHeight());
getCurrentContainer.add(textField);
}
private void addLocation(ControlObject co) {
JList list = new JList((ListModel) controller.getLocations());
list.setSize(200,60);
getCurrentContainer().add(list);
}
}
I guess the addControls should use reflection rather than generating a
large method - but I like the compile time check against the table by
auto generating the method name.
The controller has the lookup lists, each implementing ListModel to
directly update the application model and trigger additional
application logic. That works ok.
The part I am not thrilled with is that I have to map back text fields
back to the data model
e.g. in AppController
private PatientModel patient;
public void saveData() {
patient.setPatientName(myApp.getPatientName());
...
}
Ideally I could have a model for *every* GUI control - but the
javax.swing.text.Document looks too heavy for my datamodel to implement
for every field - so it seems better to map the data.
Any other thoughts on this architecture?
thanks
Tim