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