source: src/main/java/genius/gui/session/ParticipantModel.java@ 209

Last change on this file since 209 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 3.5 KB
Line 
1package genius.gui.session;
2
3import java.util.ArrayList;
4
5import javax.swing.event.ListDataEvent;
6import javax.swing.event.ListDataListener;
7
8import genius.core.AgentID;
9import genius.core.repository.DomainRepItem;
10import genius.core.repository.MultiPartyProtocolRepItem;
11import genius.core.repository.ParticipantRepItem;
12import genius.core.repository.ProfileRepItem;
13import genius.core.session.Participant;
14import genius.gui.negosession.ContentProxy;
15import genius.gui.panels.SingleSelectionModel;
16import genius.gui.panels.TextModel;
17
18/**
19 * Holds the MVC model information for a participant in the negotiation.
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.