[1] | 1 | package genius.gui.session;
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | import java.util.ArrayList;
|
---|
| 5 |
|
---|
| 6 | import javax.swing.event.ListDataEvent;
|
---|
| 7 | import javax.swing.event.ListDataListener;
|
---|
| 8 |
|
---|
| 9 | import genius.core.AgentID;
|
---|
| 10 | import genius.core.listener.Listener;
|
---|
| 11 | import genius.core.repository.DomainRepItem;
|
---|
| 12 | import genius.core.repository.MultiPartyProtocolRepItem;
|
---|
| 13 | import genius.core.repository.ParticipantRepItem;
|
---|
| 14 | import genius.core.repository.ProfileRepItem;
|
---|
| 15 | import genius.core.session.Participant;
|
---|
| 16 | import genius.gui.negosession.ContentProxy;
|
---|
| 17 | import genius.gui.panels.BooleanModel;
|
---|
| 18 | import genius.gui.panels.SingleSelectionModel;
|
---|
| 19 | import genius.gui.panels.TextModel;
|
---|
| 20 | import genius.gui.uncertainty.UncertaintyOptionModel;
|
---|
| 21 | import genius.gui.uncertainty.UncertaintyOptionPanel;
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * Holds the MVC model information for a participant in the negotiation.
|
---|
| 25 | */
|
---|
| 26 | public class ParticipantModel {
|
---|
| 27 | private final TextModel partyIdModel = new TextModel("Party 1");
|
---|
| 28 | private final SingleSelectionModel<ParticipantRepItem> partyModel = new SingleSelectionModel<>(
|
---|
| 29 | new ArrayList<ParticipantRepItem>());
|
---|
| 30 | private final SingleSelectionModel<ProfileRepItem> profileModel = new SingleSelectionModel<ProfileRepItem>(
|
---|
| 31 | new ArrayList<ProfileRepItem>());
|
---|
| 32 | private final SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel;
|
---|
| 33 | private final SingleSelectionModel<DomainRepItem> domainModel;
|
---|
| 34 | private final BooleanModel uncertaintyOptionBox = new BooleanModel(false);
|
---|
| 35 |
|
---|
| 36 | private UncertaintyOptionModel uncertaintyModel;
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | *
|
---|
| 41 | * @param protocolModel
|
---|
| 42 | * holding the protocol that this participant has to use.
|
---|
| 43 | * @param domainModel, holding the negotiation domain. It is used also for the selection of domain specific preference profiles
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | public ParticipantModel(SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel, SingleSelectionModel<DomainRepItem> domainModel) {
|
---|
| 47 | this.protocolModel = protocolModel;
|
---|
| 48 | this.domainModel = domainModel;
|
---|
| 49 | connect();
|
---|
| 50 | protocolChanged();
|
---|
| 51 | domainChanged();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public TextModel getIdModel() {
|
---|
| 55 | return partyIdModel;
|
---|
| 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 | public BooleanModel getUncertaintyOptionBox() {
|
---|
| 71 | return uncertaintyOptionBox;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * Automatically increments the current ID, strategy and profile.
|
---|
| 76 | */
|
---|
| 77 | public void increment() {
|
---|
| 78 | partyIdModel.increment();
|
---|
| 79 | partyModel.increment();
|
---|
| 80 | profileModel.increment();
|
---|
| 81 | uncertaintyOptionBox.setValue(false);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | /**
|
---|
| 85 | * @return {@link Participant} as set at this moment in this model
|
---|
| 86 | */
|
---|
| 87 | public Participant getParticipant()
|
---|
| 88 | {
|
---|
| 89 | return new Participant(new AgentID(partyIdModel.getText()), (ParticipantRepItem) partyModel.getSelectedItem(),
|
---|
| 90 | (ProfileRepItem) profileModel.getSelectedItem() , uncertaintyOptionBox.getValue() == false ? null : uncertaintyModel.getUncertainPrefContainer());
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /*************************** private support funcs ********************/
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
| 96 | * connect. protocol changes -> update available parties.
|
---|
| 97 | */
|
---|
| 98 | private void connect() {
|
---|
| 99 | protocolModel.addListDataListener(new ListDataListener() {
|
---|
| 100 |
|
---|
| 101 | @Override
|
---|
| 102 | public void intervalRemoved(ListDataEvent e) {
|
---|
| 103 |
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | @Override
|
---|
| 107 | public void intervalAdded(ListDataEvent e) {
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | @Override
|
---|
| 111 | public void contentsChanged(ListDataEvent e) {
|
---|
| 112 | protocolChanged();
|
---|
| 113 | }
|
---|
| 114 | });
|
---|
| 115 |
|
---|
| 116 | domainModel.addListDataListener(new ListDataListener() {
|
---|
| 117 |
|
---|
| 118 | @Override
|
---|
| 119 | public void intervalRemoved(ListDataEvent e) {
|
---|
| 120 |
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | @Override
|
---|
| 124 | public void intervalAdded(ListDataEvent e) {
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | @Override
|
---|
| 128 | public void contentsChanged(ListDataEvent e) {
|
---|
| 129 | domainChanged();
|
---|
| 130 | }
|
---|
| 131 | });
|
---|
| 132 |
|
---|
| 133 | uncertaintyOptionBox.addListener (new Listener<Boolean>() {
|
---|
| 134 |
|
---|
| 135 | @Override
|
---|
| 136 | public void notifyChange(Boolean data) {
|
---|
| 137 |
|
---|
| 138 | if (uncertaintyOptionBox.getValue() == true) {
|
---|
| 139 | uncertaintyModel = new UncertaintyOptionModel((ProfileRepItem)getProfileModel().getSelectedItem());
|
---|
| 140 | UncertaintyOptionPanel uncertaintyPanel = new UncertaintyOptionPanel(uncertaintyModel);
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | });
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | private void protocolChanged() {
|
---|
| 147 | partyModel.setAllItems(ContentProxy.fetchPartiesForProtocol(protocolModel.getSelection()));
|
---|
| 148 |
|
---|
| 149 | }
|
---|
| 150 | private void domainChanged() {
|
---|
| 151 | profileModel.setAllItems(ContentProxy.fetchDomainSpecificProfiles(domainModel.getSelection()));
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | }
|
---|