| OLD | NEW |
| 1 package autotest.afe; | 1 package autotest.afe; |
| 2 | 2 |
| 3 import autotest.common.JsonRpcCallback; | 3 import autotest.common.JsonRpcCallback; |
| 4 import autotest.common.JsonRpcProxy; | 4 import autotest.common.JsonRpcProxy; |
| 5 import autotest.common.StaticDataRepository; | 5 import autotest.common.StaticDataRepository; |
| 6 import autotest.common.StaticDataRepository.FinishedCallback; |
| 6 import autotest.common.Utils; | 7 import autotest.common.Utils; |
| 7 import autotest.common.StaticDataRepository.FinishedCallback; | |
| 8 import autotest.common.ui.RadioChooser; | 8 import autotest.common.ui.RadioChooser; |
| 9 import autotest.common.ui.RadioChooserDisplay; |
| 9 import autotest.common.ui.TabView; | 10 import autotest.common.ui.TabView; |
| 10 | 11 |
| 11 import com.google.gwt.event.dom.client.ClickEvent; | 12 import com.google.gwt.event.dom.client.ClickEvent; |
| 12 import com.google.gwt.event.dom.client.ClickHandler; | 13 import com.google.gwt.event.dom.client.ClickHandler; |
| 13 import com.google.gwt.json.client.JSONBoolean; | 14 import com.google.gwt.json.client.JSONBoolean; |
| 14 import com.google.gwt.json.client.JSONObject; | 15 import com.google.gwt.json.client.JSONObject; |
| 15 import com.google.gwt.json.client.JSONString; | 16 import com.google.gwt.json.client.JSONString; |
| 16 import com.google.gwt.json.client.JSONValue; | 17 import com.google.gwt.json.client.JSONValue; |
| 17 import com.google.gwt.user.client.ui.Button; | 18 import com.google.gwt.user.client.ui.Button; |
| 18 import com.google.gwt.user.client.ui.CheckBox; | 19 import com.google.gwt.user.client.ui.CheckBox; |
| 19 import com.google.gwt.user.client.ui.FlexTable; | 20 import com.google.gwt.user.client.ui.FlexTable; |
| 20 import com.google.gwt.user.client.ui.HTMLTable; | 21 import com.google.gwt.user.client.ui.HTMLTable; |
| 21 import com.google.gwt.user.client.ui.ListBox; | 22 import com.google.gwt.user.client.ui.ListBox; |
| 22 import com.google.gwt.user.client.ui.Panel; | 23 import com.google.gwt.user.client.ui.Panel; |
| 23 import com.google.gwt.user.client.ui.VerticalPanel; | 24 import com.google.gwt.user.client.ui.VerticalPanel; |
| 24 import com.google.gwt.user.client.ui.Widget; | 25 import com.google.gwt.user.client.ui.Widget; |
| 25 | 26 |
| 26 public class UserPreferencesView extends TabView implements ClickHandler { | 27 public class UserPreferencesView extends TabView implements ClickHandler { |
| 27 private static final StaticDataRepository staticData = StaticDataRepository.
getRepository(); | 28 private static final StaticDataRepository staticData = StaticDataRepository.
getRepository(); |
| 28 private static final JsonRpcProxy proxy = JsonRpcProxy.getProxy(); | 29 private static final JsonRpcProxy proxy = JsonRpcProxy.getProxy(); |
| 29 | 30 |
| 30 public static interface UserPreferencesListener { | 31 public static interface UserPreferencesListener { |
| 31 public void onPreferencesChanged(); | 32 public void onPreferencesChanged(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 private JSONObject user; | 35 private JSONObject user; |
| 35 private UserPreferencesListener listener; | 36 private UserPreferencesListener listener; |
| 36 | 37 |
| 37 private RadioChooser rebootBefore = new RadioChooser(); | 38 private RadioChooser rebootBefore = new RadioChooser(); |
| 38 private RadioChooser rebootAfter = new RadioChooser(); | 39 private RadioChooser rebootAfter = new RadioChooser(); |
| 39 private ListBox droneSet = new ListBox(); | 40 private ListBox droneSet = new ListBox(); |
| 40 private CheckBox showExperimental = new CheckBox(); | 41 private CheckBox showExperimental = new CheckBox(); |
| 41 private Button saveButton = new Button("Save preferences"); | 42 private Button saveButton = new Button("Save preferences"); |
| 42 private HTMLTable preferencesTable = new FlexTable(); | 43 private HTMLTable preferencesTable = new FlexTable(); |
| 43 | 44 |
| 44 public UserPreferencesView(UserPreferencesListener listener) { | 45 public UserPreferencesView(UserPreferencesListener listener) { |
| 45 this.listener = listener; | 46 this.listener = listener; |
| 46 } | 47 } |
| 47 | 48 |
| 48 @Override | 49 @Override |
| 49 public String getElementId() { | 50 public String getElementId() { |
| 50 return "user_preferences"; | 51 return "user_preferences"; |
| 51 } | 52 } |
| 52 | 53 |
| 53 @Override | 54 @Override |
| 54 public void initialize() { | 55 public void initialize() { |
| 55 super.initialize(); | 56 super.initialize(); |
| 57 |
| 58 RadioChooserDisplay rebootBeforeDisplay = new RadioChooserDisplay(); |
| 59 RadioChooserDisplay rebootAfterDisplay = new RadioChooserDisplay(); |
| 60 rebootBefore.bindDisplay(rebootBeforeDisplay); |
| 61 rebootAfter.bindDisplay(rebootAfterDisplay); |
| 62 |
| 56 Panel container = new VerticalPanel(); | 63 Panel container = new VerticalPanel(); |
| 57 AfeUtils.populateRadioChooser(rebootBefore, "reboot_before"); | 64 AfeUtils.populateRadioChooser(rebootBefore, "reboot_before"); |
| 58 AfeUtils.populateRadioChooser(rebootAfter, "reboot_after"); | 65 AfeUtils.populateRadioChooser(rebootAfter, "reboot_after"); |
| 59 | 66 |
| 60 saveButton.addClickHandler(this); | 67 saveButton.addClickHandler(this); |
| 61 | 68 |
| 62 addOption("Reboot before", rebootBefore); | 69 addOption("Reboot before", rebootBeforeDisplay); |
| 63 addOption("Reboot after", rebootAfter); | 70 addOption("Reboot after", rebootAfterDisplay); |
| 64 addOption("Show experimental tests", showExperimental); | 71 addOption("Show experimental tests", showExperimental); |
| 65 if (staticData.getData("drone_sets_enabled").isBoolean().booleanValue())
{ | 72 if (staticData.getData("drone_sets_enabled").isBoolean().booleanValue())
{ |
| 66 AfeUtils.popualateListBox(droneSet, "drone_sets"); | 73 AfeUtils.populateListBox(droneSet, "drone_sets"); |
| 67 addOption("Drone set", droneSet); | 74 addOption("Drone set", droneSet); |
| 68 } | 75 } |
| 69 | 76 |
| 70 container.add(preferencesTable); | 77 container.add(preferencesTable); |
| 71 container.add(saveButton); | 78 container.add(saveButton); |
| 72 addWidget(container, "user_preferences_table"); | 79 addWidget(container, "user_preferences_table"); |
| 73 } | 80 } |
| 74 | 81 |
| 75 @Override | 82 @Override |
| 76 public void refresh() { | 83 public void refresh() { |
| 77 staticData.refresh(new FinishedCallback() { | 84 staticData.refresh(new FinishedCallback() { |
| 78 public void onFinished() { | 85 public void onFinished() { |
| 79 user = staticData.getData("current_user").isObject(); | 86 user = staticData.getData("current_user").isObject(); |
| 80 updateValues(); | 87 updateValues(); |
| 81 if (listener != null) { | 88 if (listener != null) { |
| 82 listener.onPreferencesChanged(); | 89 listener.onPreferencesChanged(); |
| 83 } | 90 } |
| 84 } | 91 } |
| 85 }); | 92 }); |
| 86 } | 93 } |
| 87 | 94 |
| 88 private void updateValues() { | 95 private void updateValues() { |
| 89 rebootBefore.setSelectedChoice(getValue("reboot_before")); | 96 rebootBefore.setSelectedChoice(getValue("reboot_before")); |
| 90 rebootAfter.setSelectedChoice(getValue("reboot_after")); | 97 rebootAfter.setSelectedChoice(getValue("reboot_after")); |
| 91 AfeUtils.setSelectedItem(droneSet, getValue("drone_set")); | 98 AfeUtils.setSelectedItem(droneSet, getValue("drone_set")); |
| 92 | 99 |
| 93 showExperimental.setValue(user.get("show_experimental").isBoolean().bool
eanValue()); | 100 showExperimental.setValue(user.get("show_experimental").isBoolean().bool
eanValue()); |
| 94 } | 101 } |
| 95 | 102 |
| 96 private String getValue(String key) { | 103 private String getValue(String key) { |
| 97 return Utils.jsonToString(user.get(key)); | 104 return Utils.jsonToString(user.get(key)); |
| 98 } | 105 } |
| 99 | 106 |
| 100 public void onClick(ClickEvent event) { | 107 public void onClick(ClickEvent event) { |
| 101 assert event.getSource() == saveButton; | 108 assert event.getSource() == saveButton; |
| 102 saveValues(); | 109 saveValues(); |
| 103 } | 110 } |
| 104 | 111 |
| 105 private void saveValues() { | 112 private void saveValues() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 116 } | 123 } |
| 117 }); | 124 }); |
| 118 } | 125 } |
| 119 | 126 |
| 120 private void addOption(String name, Widget widget) { | 127 private void addOption(String name, Widget widget) { |
| 121 int row = preferencesTable.getRowCount(); | 128 int row = preferencesTable.getRowCount(); |
| 122 preferencesTable.setText(row, 0, name); | 129 preferencesTable.setText(row, 0, name); |
| 123 preferencesTable.setWidget(row, 1, widget); | 130 preferencesTable.setWidget(row, 1, widget); |
| 124 } | 131 } |
| 125 } | 132 } |
| OLD | NEW |