163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowpackage autotest.moblab;
263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport autotest.common.ui.TabView;
463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport autotest.moblab.rpc.ConnectedDutInfo;
563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport autotest.moblab.rpc.MoblabRpcCallbacks;
663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport autotest.moblab.rpc.MoblabRpcHelper;
763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.event.dom.client.ChangeEvent;
863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.event.dom.client.ChangeHandler;
963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.event.dom.client.ClickEvent;
1063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.event.dom.client.ClickHandler;
1163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.Window;
1263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.Button;
1363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.CheckBox;
1463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.FlexTable;
1563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.HasVerticalAlignment;
1663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.HorizontalPanel;
1763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.Label;
1863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.ListBox;
1963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.TextArea;
2063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.TextBox;
2163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowimport com.google.gwt.user.client.ui.VerticalPanel;
2263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
2363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow/**
2463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow * Implement a tab that makes it easier to add/remove/maintain duts.
2563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow */
2663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddowpublic class DutManagementView extends TabView {
2763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
2863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private FlexTable dutInfoTable;
2963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private VerticalPanel dutSetupPanel;
3063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private ListBox options;
3163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private TextArea informationArea;
3263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private Button actionButton;
3363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private CheckBox poolCheckBox;
3463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private TextBox poolLabelName;
3563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private Label poolLabel;
3649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private TextBox attributeName;
3749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private TextBox attributeValue;
3849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private HorizontalPanel labelActionRow;
3949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private HorizontalPanel attribActionRow;
4049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private HorizontalPanel attribValueActionRow;
4163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
4263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private static final int DHCP_IP_COLUMN = 0;
4363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private static final int DHCP_MAC_COLUMN = 1;
4463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private static final int SELECTION_COLUMN = 2;
4563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private static final int LABELS_COLUMN = 3;
4663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
4763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  @Override
4863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  public String getElementId() {
4963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    return "dut_manage";
5063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
5163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
5263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  @Override
5363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  public void refresh() {
5463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    super.refresh();
5563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.removeAllRows();
5663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolCheckBox.setValue(false);
5763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolLabelName.setText("");
5849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeName.setText("");
5949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeValue.setValue("");
6049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
6149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    labelActionRow.setVisible(false);
6249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribActionRow.setVisible(false);
6349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
6463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    loadData();
6563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
6663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
6763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  @Override
6863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  public void initialize() {
6963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    super.initialize();
7063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // Main table of connected DUT information.
7163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable = new FlexTable();
7249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
7363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // The row of controls underneath the main data table.
7463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutSetupPanel = new VerticalPanel();
7563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
7663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // List of actions to be applied to connected DUT's.
7763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options = new ListBox();
7863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options.addItem("Add Selected DUT's");
7963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options.addItem("Remove Selected DUT's");
8063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options.addItem("Add Label Selected DUT's");
8163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options.addItem("Remove Label Selected DUT's");
8249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    options.addItem("Add Attribute to Selected DUT's");
8349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    options.addItem("Remove Attribute from Selected DUT's");
8463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options.setStyleName("dut_manage_action_row");
8563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    options.addChangeHandler(new ChangeHandler() {
8663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      @Override
8763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      public void onChange(ChangeEvent event) {
8863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        if (options.getSelectedIndex() == 2 || options.getSelectedIndex() == 3) {
8963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          poolCheckBox.setValue(false);
9063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          poolLabelName.setText("");
9149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          labelActionRow.setVisible(true);
9249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          attribActionRow.setVisible(false);
9349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow        } else if (options.getSelectedIndex() == 4 || options.getSelectedIndex() == 5) {
9449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          attributeName.setText("");
9549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          attributeValue.setValue("");
9649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          labelActionRow.setVisible(false);
9749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          attribActionRow.setVisible(true);
9849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          if (options.getSelectedIndex() == 4) {
9949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow            attribValueActionRow.setVisible(true);
10049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          } else {
10149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow            attribValueActionRow.setVisible(false);
10249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          }
10363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        } else {
10449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          labelActionRow.setVisible(false);
10549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow          attribActionRow.setVisible(false);
10663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        }
10763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      }
10863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    });
10963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
11063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // Logging area at the end of the screen that gives status messages about bulk
11163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // actions requested.
11263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    informationArea = new TextArea();
11363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    informationArea.setVisibleLines(10);
11463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    informationArea.setCharacterWidth(80);
11563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    informationArea.setReadOnly(true);
11663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
11763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // Apply button, each action needs to be applied after selecting the devices and
11863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // the action to be performed.
11963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    actionButton = new Button("Apply", new ClickHandler() {
12063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      public void onClick(ClickEvent event) {
12163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        ((Button)event.getSource()).setEnabled(false);
12263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        int action = options.getSelectedIndex();
12363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        try {
12463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          for (int i = 1; i < dutInfoTable.getRowCount(); i++) {
12563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            if (((CheckBox)dutInfoTable.getWidget(i, SELECTION_COLUMN)).getValue()) {
12663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow              if (action == 0) {
12763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow                  addDut(i);
12863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow              } else if (action == 1) {
12963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow                removeDut(i);
13063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow              } else if (action == 2) {
13149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow                addLabel(i, getPoolLabelString());
13263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow              } else if (action == 3) {
13349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow                removeLabel(i, getPoolLabelString());
13449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow              } else if (action == 4) {
13549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow                addAttribute(i, attributeName.getText(), attributeValue.getText());
13649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow              } else if (action == 5) {
13749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow                removeAttribute(i, attributeName.getText());
13863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow              }
13963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            }
14063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          }
14163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        } finally {
14263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          ((Button)event.getSource()).setEnabled(true);
14363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        }
14463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      }});
14563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
14663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
14763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // For adding and removing labels a text input of the label is required.
14863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolCheckBox = new CheckBox();
14963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
15063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // Pools are just special labels, this is just a helper to so users get
15163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // it correct more of the time.
15263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolCheckBox.setText("Is pool label ?");
15363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolCheckBox.setStyleName("dut_manage_action_row_item");
15463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
15563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // The text label explaining the text box is for entering the label.
15663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolLabel = new Label();
15763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolLabel.setText("Label name:");
15863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolLabel.setStyleName("dut_manage_action_row_item");
15963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
16063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    // The text entry of the label to add or remove.
16163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolLabelName = new TextBox();
16263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    poolLabelName.setStyleName("dut_manage_action_row_item");
1637e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow
16449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    labelActionRow = new HorizontalPanel();
16549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    labelActionRow.add(poolCheckBox);
16649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    labelActionRow.add(poolLabel);
16749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    labelActionRow.add(poolLabelName);
16849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
16949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    // The name/value pair required to set an attribute
17049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    Label attributeNameLabel = new Label();
17149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeNameLabel.setText("Attribute:");
17249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeNameLabel.setStyleName("dut_manage_action_row_item");
17349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeName = new TextBox();
17449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeName.setStyleName("dut_manage_action_row_item");
17549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
17649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    Label attributeValueLabel = new Label();
17749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeValueLabel.setText("Value:");
17849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeValueLabel.setStyleName("dut_manage_action_row_item");
17949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeValue = new TextBox();
18049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attributeValue.setStyleName("dut_manage_action_row_item");
18149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
18249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribActionRow = new HorizontalPanel();
18349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribActionRow.add(attributeNameLabel);
18449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribActionRow.add(attributeName);
18549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribValueActionRow = new HorizontalPanel();
18649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribValueActionRow.add(attributeValueLabel);
18749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribValueActionRow.add(attributeValue);
18849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    attribActionRow.add(attribValueActionRow);
18949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
1907e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow   // Assemble the display panels in the correct order.
1917e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    dutSetupPanel.add(dutInfoTable);
1927e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    HorizontalPanel actionRow = new HorizontalPanel();
1937e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    actionRow.setStyleName("dut_manage_action_row");
1947e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    actionRow.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
1957e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    actionRow.add(options);
19649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    actionRow.add(labelActionRow);
19749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    actionRow.add(attribActionRow);
1987e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    actionRow.add(actionButton);
1997e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    dutSetupPanel.add(actionRow);
2007e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    dutSetupPanel.add(informationArea);
2017e2b0da6e67376e3176a14cdada317638bab609eKeith Haddow    addWidget(dutSetupPanel, "view_dut_manage");
20263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
20363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
20449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private String getPoolLabelString() {
20563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    StringBuilder builder = new StringBuilder(poolLabelName.getText());
20663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    if (poolCheckBox.getValue()) {
20763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      builder.insert(0, "pool:");
20863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    }
20963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    return builder.toString();
21063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
21163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
21263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void loadData() {
21363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    MoblabRpcHelper.fetchDutInformation(new MoblabRpcCallbacks.FetchConnectedDutInfoCallback() {
21463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      @Override
21563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      public void onFetchConnectedDutInfoSubmitted(ConnectedDutInfo info) {
21663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        addTableHeader();
21763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        // The header is row 0
21863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        int row = 1;
21963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        for (final String dutIpAddress : info.getConnectedIpsToMacAddress().keySet()) {
22063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          addRowStyles(row);
22163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          String labelString;
22263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          if (info.getConfiguredIpsToLabels().keySet().contains(dutIpAddress)) {
22363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            labelString = info.getConfiguredIpsToLabels().get(dutIpAddress);
22463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          } else {
2253b5a7067d8e5ef20ad3723236a724506e5675c98Matt Mallett            boolean sshOk =
2263b5a7067d8e5ef20ad3723236a724506e5675c98Matt Mallett                info.getConnectedIpsToSshConnection().get(dutIpAddress);
2273b5a7067d8e5ef20ad3723236a724506e5675c98Matt Mallett            labelString = sshOk ? "DUT Not Configured in Autotest" :
228f5321f056459ea0073df92983a1daebe425875d4Matt Mallett                "Unable to connect to DUT over SSH, check device is powered " +
229f5321f056459ea0073df92983a1daebe425875d4Matt Mallett                "on, connected and has a test image on it.";
23063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          }
23163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          addRow(row, dutIpAddress, info.getConnectedIpsToMacAddress().get(dutIpAddress), labelString);
23263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          row++;
23363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        }
23463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        for (final String dutIpAddress : info.getConfiguredIpsToLabels().keySet()) {
23563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          if (!info.getConnectedIpsToMacAddress().keySet().contains(dutIpAddress)) {
23663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            // Device is in AFE but not detected in the DHCP table.
23763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            addRowStyles(row);
23863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            addRow(row, dutIpAddress, "",
23963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow                "DUT Configured in Autotest but does not appear to be attached.");
24063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow            row++;
24163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          }
24263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        }
24363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      }
24463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    });
24563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
24663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
24763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
24863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Add the correct css styles for each data row.
24963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param row index of the row to apply the styles for, first data row is 1.
25063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
25163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void addRowStyles(int row) {
25263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(row, DHCP_IP_COLUMN,"ip_cell");
25363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(row,DHCP_MAC_COLUMN,"mac_cell");
25463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(row,SELECTION_COLUMN,"selection_cell");
25563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(row,LABELS_COLUMN,"labels_cell");
25663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
25763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
25863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
25963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Insert or update the data in the table for a given row.
26063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param row  The row index to update, first data row is 1.
26163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param ipColumn String to be added into the first column.
26263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param macColumn String to be added to the second column.
26363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param labelsColumn String to be added to the fourth column.
26463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
26563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void addRow(int row, String ipColumn, String macColumn, String labelsColumn) {
26663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(row, DHCP_IP_COLUMN, new Label(ipColumn));
26763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(row, DHCP_MAC_COLUMN, new Label(macColumn));
26863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(row, SELECTION_COLUMN, new CheckBox());
26963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(row, LABELS_COLUMN, new Label(labelsColumn));
27063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
27163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
27263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
27363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Add the column headers with the correct css styling into the data table.
27463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
27563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void addTableHeader() {
27663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.addStyleName("dut_info_table");
27763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(0, DHCP_IP_COLUMN,
27863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        "dut_manage_column_label_c");
27963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(0, DHCP_MAC_COLUMN,
28063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        "dut_manage_column_label_c");
28163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(0, SELECTION_COLUMN,
28263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        "dut_manage_column_label_c");
28363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.getCellFormatter().addStyleName(0, LABELS_COLUMN,
28463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow        "dut_manage_column_label_c");
28563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(0, DHCP_IP_COLUMN, new Label("DCHP Lease Address"));
28663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(0, DHCP_MAC_COLUMN, new Label("DCHP MAC Address"));
28763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    dutInfoTable.setWidget(0, LABELS_COLUMN, new Label("DUT Labels"));
28863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
28963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
29063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
29163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Make an RPC call to the autotest system to enroll the DUT listed at the given row number.
29263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param row_number the row number in the table that has details of the device to enroll.
29363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
29463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void addDut(int row_number) {
29563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    String ipAddress = ((Label)dutInfoTable.getWidget(row_number, DHCP_IP_COLUMN)).getText();
29663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    MoblabRpcHelper.addMoblabDut(ipAddress, new LogAction(informationArea));
29763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
29863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
29963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
30063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Make an RPC to to the autotest system to delete information about the DUT listed at the given
30163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * row.
30263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param row_number the row number in the table that has details of the device to remove.
30363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
30463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void removeDut(int row_number) {
30563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    String ipAddress = ((Label)dutInfoTable.getWidget(row_number, DHCP_IP_COLUMN)).getText();
30663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    MoblabRpcHelper.removeMoblabDut(ipAddress, new LogAction(informationArea));
30763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
30863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
30963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
31063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Make an RPC to to the autotest system to add a label to a DUT whoes details are in the given
31163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * row.
31263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param row_number row in the data table that has the information about the DUT
31363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param labelName the label string to be added.
31463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
31563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void addLabel(int row_number, String labelName) {
31663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    String ipAddress = ((Label)dutInfoTable.getWidget(row_number, DHCP_IP_COLUMN)).getText();
31763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    MoblabRpcHelper.addMoblabLabel(ipAddress, labelName, new LogAction(informationArea));
31863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
31963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
32063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
32163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Make an RPC to to the autotest system to remove a label to a DUT whoes details are in the
32263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * given row.
32363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param row_number row in the data table that has the information about the DUT
32463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * @param labelName the label string to be removed.
32563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
32663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private void removeLabel(int row_number, String labelName) {
32763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    String ipAddress = ((Label)dutInfoTable.getWidget(row_number, DHCP_IP_COLUMN)).getText();
32863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    MoblabRpcHelper.removeMoblabLabel(ipAddress, labelName, new LogAction(informationArea));
32963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
33063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
33149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow /**
33249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * Make an RPC to to the autotest system to add an attribute to a DUT whoes details are in the
33349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * given row.
33449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * @param row_number row in the data table that has the information about the DUT
33549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * @param attributeName the attribute name to be set.
33649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * @param attributeValue the attribute value to be associated with the attributeName.
33749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   */
33849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private void addAttribute(int row_number, String attributeName, String attributeValue) {
33949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    String ipAddress = ((Label)dutInfoTable.getWidget(row_number, DHCP_IP_COLUMN)).getText();
34049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    MoblabRpcHelper.setMoblabAttribute(ipAddress, attributeName, attributeValue, new LogAction(informationArea));
34149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  }
34249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
34349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow /**
34449f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * Make an RPC to to the autotest system to remove an attribute to a DUT whoes details are in the
34549f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * given row.
34649f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * @param row_number row in the data table that has the information about the DUT
34749f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   * @param attributeName the attribute name to be removed.
34849f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow   */
34949f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  private void removeAttribute(int row_number, String attributeName) {
35049f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    String ipAddress = ((Label)dutInfoTable.getWidget(row_number, DHCP_IP_COLUMN)).getText();
35149f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow    MoblabRpcHelper.removeMoblabAttribute(ipAddress, attributeName, new LogAction(informationArea));
35249f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow  }
35349f089396b0ffbe152fb734cffb84f9de038c426Keith Haddow
35463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  /**
35563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   * Call back that inserts a string from an completed RPC into the UI.
35663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow   */
35763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  private static class LogAction implements MoblabRpcCallbacks.LogActionCompleteCallback {
35863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    private TextArea informationArea;
35963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow
36063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    LogAction(TextArea informationArea){
36163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      this.informationArea = informationArea;
36263cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    }
36363cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    @Override
36463cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    public void onLogActionComplete(boolean status, String information) {
36563cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      String currentText = informationArea.getText();
36663cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow      informationArea
36763cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow          .setText(new StringBuilder().append(information).append(
36863cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow              "\n").append(currentText).toString());
36963cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow    }
37063cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow  }
37163cc4470e13cf7dab9edb7e18c0c39e9cd65ba47Keith Haddow}
372