• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing GUI according to projects

 
ertan eyimaya
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Define base abstract class. This should have logic for all common fields/methods. Break down this class into logical chunks and chain them accordingly. e.g. Construtor invokes say initComponents(), registerListeners(), buildUI() etc. in this sequence. Make required methods abstract.
2) Define panels as per project. This would extend the abstract class above and provide full implementation
3) Have a factory which returns the proper project panel based on some differentiating parameter which tells the factory which panel implementation to return.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!