1 | package genius.gui.session;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | import javax.swing.event.ListDataEvent;
|
---|
6 | import javax.swing.event.ListDataListener;
|
---|
7 |
|
---|
8 | import genius.core.AgentID;
|
---|
9 | import genius.core.repository.DomainRepItem;
|
---|
10 | import genius.core.repository.MultiPartyProtocolRepItem;
|
---|
11 | import genius.core.repository.ParticipantRepItem;
|
---|
12 | import genius.core.repository.ProfileRepItem;
|
---|
13 | import genius.core.session.Participant;
|
---|
14 | import genius.gui.negosession.ContentProxy;
|
---|
15 | import genius.gui.panels.SingleSelectionModel;
|
---|
16 | import genius.gui.panels.TextModel;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Holds the MVC model information for a participant in the negotiation.
|
---|
20 | */
|
---|
21 | public class ParticipantModel {
|
---|
22 | private final TextModel partyIdModel = new TextModel("Party 1");
|
---|
23 | private final SingleSelectionModel<ParticipantRepItem> partyModel = new SingleSelectionModel<>(
|
---|
24 | new ArrayList<ParticipantRepItem>());
|
---|
25 | private final SingleSelectionModel<ProfileRepItem> profileModel = new SingleSelectionModel<ProfileRepItem>(
|
---|
26 | new ArrayList<ProfileRepItem>());
|
---|
27 | private final SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel;
|
---|
28 | private final SingleSelectionModel<DomainRepItem> domainModel;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | *
|
---|
32 | * @param protocolModel
|
---|
33 | * holding the protocol that this participant has to use.
|
---|
34 | * @param domainModel,
|
---|
35 | * holding the negotiation domain. It is used also for the
|
---|
36 | * selection of domain specific preference profiles
|
---|
37 | */
|
---|
38 |
|
---|
39 | public ParticipantModel(
|
---|
40 | SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel,
|
---|
41 | SingleSelectionModel<DomainRepItem> domainModel) {
|
---|
42 | this.protocolModel = protocolModel;
|
---|
43 | this.domainModel = domainModel;
|
---|
44 | connect();
|
---|
45 | protocolChanged();
|
---|
46 | domainChanged();
|
---|
47 | }
|
---|
48 |
|
---|
49 | public TextModel getIdModel() {
|
---|
50 | return partyIdModel;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public SingleSelectionModel<ParticipantRepItem> getPartyModel() {
|
---|
54 | return partyModel;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public SingleSelectionModel<DomainRepItem> getDomainModel() {
|
---|
58 | return domainModel;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public SingleSelectionModel<ProfileRepItem> getProfileModel() {
|
---|
62 | return profileModel;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Automatically increments the current ID, strategy and profile.
|
---|
67 | */
|
---|
68 | public void increment() {
|
---|
69 | partyIdModel.increment();
|
---|
70 | partyModel.increment();
|
---|
71 | profileModel.increment();
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * @return {@link Participant} as set at this moment in this model
|
---|
76 | */
|
---|
77 | public Participant getParticipant() {
|
---|
78 | return new Participant(new AgentID(partyIdModel.getText()),
|
---|
79 | (ParticipantRepItem) partyModel.getSelectedItem(),
|
---|
80 | (ProfileRepItem) profileModel.getSelectedItem());
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*************************** private support funcs ********************/
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * connect. protocol changes -> update available parties.
|
---|
87 | */
|
---|
88 | private void connect() {
|
---|
89 | protocolModel.addListDataListener(new ListDataListener() {
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public void intervalRemoved(ListDataEvent e) {
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Override
|
---|
97 | public void intervalAdded(ListDataEvent e) {
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public void contentsChanged(ListDataEvent e) {
|
---|
102 | protocolChanged();
|
---|
103 | }
|
---|
104 | });
|
---|
105 |
|
---|
106 | domainModel.addListDataListener(new ListDataListener() {
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public void intervalRemoved(ListDataEvent e) {
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | @Override
|
---|
114 | public void intervalAdded(ListDataEvent e) {
|
---|
115 | }
|
---|
116 |
|
---|
117 | @Override
|
---|
118 | public void contentsChanged(ListDataEvent e) {
|
---|
119 | domainChanged();
|
---|
120 | }
|
---|
121 | });
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void protocolChanged() {
|
---|
126 | partyModel.setAllItems(ContentProxy
|
---|
127 | .fetchPartiesForProtocol(protocolModel.getSelection()));
|
---|
128 |
|
---|
129 | }
|
---|
130 |
|
---|
131 | private void domainChanged() {
|
---|
132 | profileModel.setAllItems(ContentProxy
|
---|
133 | .fetchDomainSpecificProfiles(domainModel.getSelection()));
|
---|
134 | }
|
---|
135 |
|
---|
136 | }
|
---|