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