model view controller - Updating button states in a Java Swing application -


i've implemented basic swing gui based on concept of playlist part of larger dj audio mixing application (think primitive virtual dj(!)). playlist consists of jtable onto tracks can tracks can dragged n' dropped jtree. jpanel incorporates table contains suite of buttons saving, loading, , deleting playlists loading player(s). these button states need updated (enabled/disabled) based on current state of application (i.e. playlist loaded? there tracks in playlist? etc.)

i'm trying follow mvc pattern whereby underlying tablemodel separated table , button ui through controller.

my question is...what elegant/efficient way handle button updates? @ moment, reference loaded playlist file stored in controller, , controller determines whether playlist empty model. sends 2 boolean values (isempty, isloaded) view, determines buttons enable based on these values. method seems little inelegant, i'd welcome suggestions.

thanks!

as understand mvc, theoretically:

  1. controller updates model
  2. view reads model , updates itself

the problem in practice domain model (your classes) not same swing model classes. question syncing domain , swing models: controller or view?

  1. controller syncs them. when domain data changes (playlist empty or not) controller pushes changes view. in case controller more complex , dependent on both domain model , swing model. model becomes complex when have 1 domain model , multiple views (tree , table showing same underlying data).

  2. view adapts domain model. when domain model data changes, controller indicates view should update itself. in case view dependent on domain classes, controller not dependent on swing model or view, except requests update.

as see implemented option 1.

personally i'd use option 2., controllers deal business logic , domain model , view deals syncing domain model , building view hierarchy.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -