Hey there,
I'm using RCP to create the standalone desktop application. If you're not familiar, RCP uses SWT as graphic engine. But the question is rather about general programming
pattern on how to organize the GUI code in readable way (doesn't have to be SWT code). Here we go:
I have a class which implements a composite. A composite is a rectangle that contains:
- Checkbox with text next to it
- Two radio buttons, one under another, each with text next to is; these radio buttons are active only if the checkbox above is checked
- Yet another checkbox with text next to it
- a table with some editable data
- two buttons: "create new" and "delete existing", used to create new row in table and to delete existing row from table.
The point is, the display of this composite depends on the previous user actions.
Sometimes I don't want to display radio buttone, only two checkboxes one under another, and table with buttons
Sometimes I don't want to display the table and buttons, only checkbox, 2 radios and checkbox again
Sometimes I want to display everything: checkbox, 2 radios, checkbox, table and 2 buttons
It's easy to do with lot's of "ifs" in the code but it makes the code much less readable. Maybe you know a pattern which would be useful in this case?
I need to:
- provide the information about display conditions from the outside of class (constructor? flags with setters and getters? others?)
- manage the internal code in the class in a readable way (inheritance? division of class to smaller parts? some "smart" methods for each graphic element? others?)