2

I'm trying to notify event to my view when my model change. My model already extends another class (Agent from JADE platform) so I can't use Observale. I don't want to do true MVC, just want to trigger an event from my model and change my view. Only one view, model, controller in my case.

Model

public class AgentSeeker extends Agent {
    private List<Music> musicsPurchased = new ArrayList<Music>();
    private List<ScoredMusic> musicsToBuy = new ArrayList<ScoredMusic>();

    public void buyMusic(ScoredMusic sm) {
        Music music = sm.getMusic();
        musicsPurchased.add(music);
        musicsToBuy.remove(sm);
    }
}

View

public class AgentSeekerView extends AbstractAgentView {
    TextView textViewMusicPurchased;

    public AgentSeekerView() {
        super("AgentSeeker.glade");
    }

    protected void initComposant() {
        super.initComposant();
        textViewMusicPurchased = (TextView) builder.getObject("music_purchased");
    }

    public void addMusicPurchasedToConsole(String music) {
        TextBuffer textBuffer = textViewMusicPurchased.getBuffer();
        textBuffer.insert(textBuffer.getIterEnd(), music + '\n');
    }

}

My controller

public class SeekerController {
    private final AgentSeeker model;
    private final AgentSeekerView view;

    public SeekerController(AgentSeeker model, AgentSeekerView view) {
        this.model = model;
        this.view = view;
    }
}

When I add music to my musicsPurchased list, I want to add this music to my TextBuffer from the view too.

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
melkir
  • 405
  • 1
  • 5
  • 22
  • What is calling `AgentSeeker.buyMusic()`? And are your model and view both GObjects? – andlabs Apr 20 '15 at 21:05
  • It's an agent from JADE with an OneShotBehaviour who call buyMusic(). To be simple it's the model itself. My view use a TextView (GObject) and my model an ArrayList (Object). There is no link between those two for the moment. You can see the full implementation code here https://github.com/melkir/MusicTrading – melkir Apr 20 '15 at 21:36

0 Answers0