[1] | 1 | package genius.gui.session;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.Arrays;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
| 7 | import javax.swing.DefaultListModel;
|
---|
| 8 | import javax.swing.event.ListDataEvent;
|
---|
| 9 | import javax.swing.event.ListDataListener;
|
---|
| 10 |
|
---|
| 11 | import genius.core.AgentID;
|
---|
| 12 | import genius.core.listener.DefaultListenable;
|
---|
| 13 | import genius.core.persistent.PersistentDataType;
|
---|
| 14 | import genius.core.repository.DomainRepItem;
|
---|
| 15 | import genius.core.repository.MultiPartyProtocolRepItem;
|
---|
| 16 | import genius.core.repository.PartyRepItem;
|
---|
| 17 | import genius.core.session.MultilateralSessionConfiguration;
|
---|
| 18 | import genius.core.session.Participant;
|
---|
| 19 | import genius.core.session.SessionConfiguration;
|
---|
| 20 | import genius.gui.deadline.DeadlineModel;
|
---|
| 21 | import genius.gui.negosession.ContentProxy;
|
---|
| 22 | import genius.gui.panels.BooleanModel;
|
---|
| 23 | import genius.gui.panels.SingleSelectionModel;
|
---|
| 24 | import genius.gui.panels.TextModel;
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * Model that stores single session info for MVC.
|
---|
| 28 | */
|
---|
| 29 | public class SessionModel extends DefaultListenable<MultilateralSessionConfiguration> {
|
---|
| 30 |
|
---|
| 31 | // models are all final, as they will be used to hook up the GUI.
|
---|
| 32 | private final SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel;
|
---|
| 33 | private final SingleSelectionModel<DomainRepItem> domainModel;
|
---|
| 34 | private final DeadlineModel deadlineModel = new DeadlineModel();
|
---|
| 35 |
|
---|
| 36 | // currently selected participant
|
---|
| 37 | private final ParticipantModel participantModel;
|
---|
| 38 | // the list of participants in the nego session
|
---|
| 39 | private final DefaultListModel<Participant> participantsModel = new DefaultListModel<>();
|
---|
| 40 |
|
---|
| 41 | // selected mediator. Not used if protocol does not need mediator.
|
---|
| 42 | private final SingleSelectionModel<PartyRepItem> mediatorModel;
|
---|
| 43 | private final TextModel mediatorIdModel = new TextModel("Mediator");
|
---|
| 44 |
|
---|
| 45 | // bilateral-only options
|
---|
| 46 | private final BooleanModel showProgressChart = new BooleanModel(true);
|
---|
| 47 | private final BooleanModel bilateralShowUtilUtilPlot = new BooleanModel(true);
|
---|
| 48 | private final BooleanModel bilateralShowAllBids = new BooleanModel(true);
|
---|
| 49 | private final BooleanModel printEnabled = new BooleanModel(true);
|
---|
| 50 | private final SingleSelectionModel<PersistentDataType> persistentDatatypeModel = new SingleSelectionModel<PersistentDataType>(
|
---|
| 51 | Arrays.asList(PersistentDataType.values()));
|
---|
| 52 |
|
---|
| 53 | public SessionModel() {
|
---|
| 54 | protocolModel = new SingleSelectionModel<>(ContentProxy.fetchProtocols());
|
---|
| 55 | domainModel = new SingleSelectionModel<>(ContentProxy.fetchDomains());
|
---|
| 56 | participantModel = new ParticipantModel(protocolModel, domainModel);
|
---|
| 57 | mediatorModel = new SingleSelectionModel<PartyRepItem>(new ArrayList<PartyRepItem>());
|
---|
| 58 |
|
---|
| 59 | updateSubmodels();
|
---|
| 60 | addConstraints();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * @return the current single session run configuration
|
---|
| 65 | */
|
---|
| 66 | public MultilateralSessionConfiguration getConfiguration() {
|
---|
| 67 | List<Participant> participants = new ArrayList<>();
|
---|
| 68 |
|
---|
| 69 | MultiPartyProtocolRepItem protocol = (MultiPartyProtocolRepItem) protocolModel.getSelectedItem();
|
---|
| 70 |
|
---|
| 71 | Participant mediator = null;
|
---|
| 72 | if (protocol.getHasMediator()) {
|
---|
| 73 | // HACK #1463 use profile of participant 1 to avoid null profile.
|
---|
| 74 | mediator = new Participant(new AgentID(mediatorIdModel.getText()),
|
---|
| 75 | (PartyRepItem) mediatorModel.getSelectedItem(), participantsModel.get(0).getProfile());
|
---|
| 76 | }
|
---|
| 77 | for (int n = 0; n < participantsModel.size(); n++) {
|
---|
| 78 | participants.add(participantsModel.getElementAt(n));
|
---|
| 79 | }
|
---|
| 80 | return new SessionConfiguration(protocol, mediator, participants, deadlineModel.getDeadline(),
|
---|
| 81 | persistentDatatypeModel.getSelection());
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | /**
|
---|
| 85 | * @return the protocol data model.
|
---|
| 86 | */
|
---|
| 87 | public SingleSelectionModel<MultiPartyProtocolRepItem> getProtocolModel() {
|
---|
| 88 | return protocolModel;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public SingleSelectionModel<DomainRepItem> getDomainModel() {
|
---|
| 92 | return domainModel;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | * @return the {@link TextModel} for teh Mediator ID
|
---|
| 97 | */
|
---|
| 98 | public TextModel getMediatorIdModel() {
|
---|
| 99 | return mediatorIdModel;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /**
|
---|
| 103 | * @return the mediator model
|
---|
| 104 | */
|
---|
| 105 | public SingleSelectionModel<PartyRepItem> getMediatorModel() {
|
---|
| 106 | return mediatorModel;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public DeadlineModel getDeadlineModel() {
|
---|
| 110 | return deadlineModel;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public SingleSelectionModel<PersistentDataType> getPersistentDatatypeModel() {
|
---|
| 114 | return persistentDatatypeModel;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /**
|
---|
| 118 | * @return the settings for the 'participant information'. This setting is
|
---|
| 119 | * used when the user clicks the 'add' button.
|
---|
| 120 | */
|
---|
| 121 | public ParticipantModel getParticipantModel() {
|
---|
| 122 | return participantModel;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * Call this when model is completed (user clicked 'start'). TODO check that
|
---|
| 127 | * the model is indeed complete.
|
---|
| 128 | */
|
---|
| 129 | public void modelIsComplete() {
|
---|
| 130 | notifyChange(getConfiguration());
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | /**
|
---|
| 134 | * @return model holding the list of participants.
|
---|
| 135 | */
|
---|
| 136 | public DefaultListModel<Participant> getParticipantsModel() {
|
---|
| 137 | return participantsModel;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | *
|
---|
| 142 | * @return boolean whether to show all bid points in the util-util graph.
|
---|
| 143 | * Only has meaning if {@link #getBilateralUtilUtilPlot()} is true
|
---|
| 144 | */
|
---|
| 145 | public BooleanModel getBilateralShowAllBids() {
|
---|
| 146 | return bilateralShowAllBids;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /**
|
---|
| 150 | * @return A booleanModel containing a boolean. If true, a util-util graph
|
---|
| 151 | * instead of a default graph will be plotted. util-util graph is a
|
---|
| 152 | * graph with side A utilities on the X-axis and side B utilities on
|
---|
| 153 | * the Y axis. This visualization method allows us to also plot
|
---|
| 154 | * other points like the Pareto Frontier and Nash point.
|
---|
| 155 | *
|
---|
| 156 | */
|
---|
| 157 | public BooleanModel getBilateralUtilUtilPlot() {
|
---|
| 158 | return bilateralShowUtilUtilPlot;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /**
|
---|
| 162 | * a booleanModel holding true iff user asked to enable print to stdout.
|
---|
| 163 | *
|
---|
| 164 | * @return
|
---|
| 165 | */
|
---|
| 166 | public BooleanModel getPrintEnabled() {
|
---|
| 167 | return printEnabled;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | /**
|
---|
| 171 | *
|
---|
| 172 | * @return true iff a session progress chart should be shown.
|
---|
| 173 | */
|
---|
| 174 | public BooleanModel getShowChart() {
|
---|
| 175 | return showProgressChart;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /****************************** support funcs ******************/
|
---|
| 179 | /**
|
---|
| 180 | * connecting listeners that check the constraints between the fields in the
|
---|
| 181 | * model
|
---|
| 182 | */
|
---|
| 183 | private void addConstraints() {
|
---|
| 184 | // protocol has major impact on the submodels
|
---|
| 185 | protocolModel.addListDataListener(new ListDataListener() {
|
---|
| 186 |
|
---|
| 187 | @Override
|
---|
| 188 | public void intervalRemoved(ListDataEvent e) {
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | @Override
|
---|
| 192 | public void intervalAdded(ListDataEvent e) {
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | @Override
|
---|
| 196 | public void contentsChanged(ListDataEvent e) {
|
---|
| 197 | updateSubmodels();
|
---|
| 198 | }
|
---|
| 199 | });
|
---|
| 200 |
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /**
|
---|
| 204 | * Update the models after a protocol change.
|
---|
| 205 | *
|
---|
| 206 | * @param protocol
|
---|
| 207 | * the new protocol.
|
---|
| 208 | */
|
---|
| 209 | private void updateSubmodels() {
|
---|
| 210 | mediatorModel.setAllItems(ContentProxy.fetchMediatorsForProtocol(protocolModel.getSelection()));
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | }
|
---|