1 | package genius.gui.session;
|
---|
2 |
|
---|
3 | import javax.swing.event.ListDataEvent;
|
---|
4 | import javax.swing.event.ListDataListener;
|
---|
5 |
|
---|
6 | import genius.core.repository.PartyRepItem;
|
---|
7 | import genius.gui.panels.ComboboxSelectionPanel;
|
---|
8 | import genius.gui.panels.LabelAndComponent;
|
---|
9 | import genius.gui.panels.SingleSelectionModel;
|
---|
10 | import genius.gui.panels.TextModel;
|
---|
11 | import genius.gui.panels.TextPanel;
|
---|
12 | import genius.gui.panels.VflowPanelWithBorder;
|
---|
13 | import genius.gui.renderer.RepItemListCellRenderer;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * The mediator selector panel for single session. Visible only when the
|
---|
17 | * strategy list is non-empty.
|
---|
18 | */
|
---|
19 | @SuppressWarnings("serial")
|
---|
20 | public class MediatorPanel extends VflowPanelWithBorder {
|
---|
21 |
|
---|
22 | private SingleSelectionModel<PartyRepItem> partyModel;
|
---|
23 |
|
---|
24 | public MediatorPanel(TextModel nameModel, SingleSelectionModel<PartyRepItem> partyModel) {
|
---|
25 | super("Mediator");
|
---|
26 | this.partyModel = partyModel;
|
---|
27 | final ComboboxSelectionPanel<PartyRepItem> mediatorcomb = new ComboboxSelectionPanel<>("Mediator Strategy",
|
---|
28 | partyModel);
|
---|
29 |
|
---|
30 | mediatorcomb.setCellRenderer(new RepItemListCellRenderer());
|
---|
31 |
|
---|
32 | add(new LabelAndComponent("Mediator ID", new TextPanel(nameModel)));
|
---|
33 | add(mediatorcomb);
|
---|
34 | updateVisibility();
|
---|
35 |
|
---|
36 | connect();
|
---|
37 | }
|
---|
38 |
|
---|
39 | private void connect() {
|
---|
40 | partyModel.addListDataListener(new ListDataListener() {
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void intervalRemoved(ListDataEvent e) {
|
---|
44 | updateVisibility();
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public void intervalAdded(ListDataEvent e) {
|
---|
49 | updateVisibility();
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public void contentsChanged(ListDataEvent e) {
|
---|
54 | updateVisibility();
|
---|
55 | }
|
---|
56 | });
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void updateVisibility() {
|
---|
60 | setVisible(!partyModel.getAllItems().isEmpty());
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|