posted 10 years ago
Hi,
If I have a panel that changes according to projects, how should I implement it? Assuming the amount of changes is unknown.
Lets say I have a panel having a,b,c,d,e text fields for project A and a,b,c,x,y,z for Project B, a,b,m,n for Project C.
Here, a,b is common for all projects, c is common for projects A,B. d,e is specific to Project A... etc. Also my panels have some methods like
createGUIComponents(), guiLayout(), refresh(), save(), getErrorMessages()...
Question is: how should I design my panel? Possible approaches I thought are as follows:
1) define a common base class MyAbstractPanelBase containing (a,b) and methods listed above for these two fields. Then extend MyPanelBase, add (m,n) for Project C, override methods(for m,n).
Extend MyPanelBase, add (c) and name it MyAbstractPanelBase2 and override methods (for c). Extend MyAbstractPanelBase2, add (d,e) for Project A and override methods (for d,e). Extend MyAbstractPanelBase2, add(x,y,z) for Project B and override methods (for x,y,z)
2) Define one panel. Define all fields, layout all fields. Set visibilities of the fields (a,b,c,d,e,x,y,z,m,n) according to some contstructor arguments... This means use IF statements almost every methods of the panels. For example in refresh method some code like this: if(a.isVisible()) {....}
3) Define one panel, define all fields as in the case 2. But extract IF statements to external customizer classes such as MyPanelCustomizerForProjectA. In that classes write methods like customizeGuiLayout(), customizeSave().... and call these from myPanel. For example in guiLayout: customizer.guiLayout is called....
4) ???
Any suggestion is welcome. thank you much....