In general, whenever we have a table of hosts, we should be able to show
some profile information. There are 3 cases that I think are worth
supporting:
1) No checkbox, No profile information (HostTable.java)
Used on the Available Host sub-tab of Create Job
2) No checkbox, profile listbox (ProfileSelectTable.java)
Used on the Selected Host sub-tab of Create job
3) Checkbox, current profile statically listed (ProfileStaticTable.java)
Used on the View Host tab
4) Checkbox, no profile information (SelectableHostTable.java)
Kept for backwards compatibility/support
Add the corresponding classes as sub-classes of HostTable.
Populate the data appropriately in SelectionManager and show the data to
the end user.
Signed-off-by: Nishanth Aravamudan <[email protected]>
---
To fix: "current_profile" should be a well-defined constant in some
class.
frontend/client/src/autotest/afe/HostListView.java | 4 +-
frontend/client/src/autotest/afe/HostSelector.java | 10 ++++-
frontend/client/src/autotest/afe/HostTable.java | 20 +++------
.../src/autotest/afe/ProfileSelectHostTable.java | 21 ++++++++++
.../src/autotest/afe/ProfileStaticHostTable.java | 25 +++++++++++
.../src/autotest/afe/SelectableHostTable.java | 21 ++++++++++
.../autotest/common/table/SelectionManager.java | 43 ++++++++++++++++---
7 files changed, 120 insertions(+), 24 deletions(-)
create mode 100644 frontend/client/src/autotest/afe/ProfileSelectHostTable.java
create mode 100644 frontend/client/src/autotest/afe/ProfileStaticHostTable.java
create mode 100644 frontend/client/src/autotest/afe/SelectableHostTable.java
diff --git a/frontend/client/src/autotest/afe/HostListView.java
b/frontend/client/src/autotest/afe/HostListView.java
index 55d1610..199e6b9 100644
--- a/frontend/client/src/autotest/afe/HostListView.java
+++ b/frontend/client/src/autotest/afe/HostListView.java
@@ -35,7 +35,7 @@ public class HostListView extends TabView implements
TableActionsListener {
return "hosts";
}
- protected HostTable table;
+ protected ProfileStaticHostTable table;
protected HostTableDecorator hostTableDecorator;
protected SelectionManager selectionManager;
@@ -43,7 +43,7 @@ public class HostListView extends TabView implements
TableActionsListener {
public void initialize() {
super.initialize();
- table = new HostTable(new HostDataSource(), true);
+ table = new ProfileStaticHostTable(new HostDataSource());
hostTableDecorator = new HostTableDecorator(table, HOSTS_PER_PAGE);
selectionManager = hostTableDecorator.addSelectionManager(false);
diff --git a/frontend/client/src/autotest/afe/HostSelector.java
b/frontend/client/src/autotest/afe/HostSelector.java
index b4c9838..cad55a0 100644
--- a/frontend/client/src/autotest/afe/HostSelector.java
+++ b/frontend/client/src/autotest/afe/HostSelector.java
@@ -45,6 +45,7 @@ public class HostSelector implements ClickHandler {
public static class HostSelection {
public List<String> hosts = new ArrayList<String>();
+ public List<String> profiles = new ArrayList<String>();
public List<String> metaHosts = new ArrayList<String>();
public List<String> oneTimeHosts = new ArrayList<String>();
}
@@ -71,7 +72,7 @@ public class HostSelector implements ClickHandler {
private HostTable availableTable = new HostTable(new HostDataSource());
private HostTableDecorator availableDecorator =
new HostTableDecorator(availableTable, TABLE_SIZE);
- private HostTable selectedTable = new HostTable(selectedHostData);
+ private ProfileSelectHostTable selectedTable = new
ProfileSelectHostTable(selectedHostData);
private TableDecorator selectedDecorator = new
TableDecorator(selectedTable);
private boolean enabled = true;
@@ -140,6 +141,8 @@ public class HostSelector implements ClickHandler {
display.getAddByHostnameButton().addClickHandler(this);
display.getAddByLabelButton().addClickHandler(this);
display.addTables(availableDecorator, selectedDecorator);
+ availableTable.setWidgetFactory(availableSelection);
+ selectedTable.setWidgetFactory(availableSelection);
populateLabels(display.getLabelList());
}
@@ -274,6 +277,10 @@ public class HostSelector implements ClickHandler {
}
}
+ private String getProfile(JSONObject row) {
+ return row.get("profile").isString().stringValue();
+ }
+
private String getHostname(JSONObject row) {
return row.get("hostname").isString().stringValue();
}
@@ -317,6 +324,7 @@ public class HostSelector implements ClickHandler {
selection.oneTimeHosts.add(hostname);
} else {
selection.hosts.add(hostname);
+ selection.profiles.add(getProfile(row));
}
}
}
diff --git a/frontend/client/src/autotest/afe/HostTable.java
b/frontend/client/src/autotest/afe/HostTable.java
index 71a5fd7..8b1b526 100644
--- a/frontend/client/src/autotest/afe/HostTable.java
+++ b/frontend/client/src/autotest/afe/HostTable.java
@@ -7,25 +7,17 @@ import java.util.ArrayList;
import java.util.Arrays;
public class HostTable extends DynamicTable {
- private static final String[][] HOST_COLUMNS = {
+ protected static final String[][] HOST_COLUMNS = {
{"hostname", "Hostname"}, {"platform", "Platform"},
{HostDataSource.OTHER_LABELS, "Other labels"}, {"status", "Status"},
- {HostDataSource.LOCKED_TEXT, "Locked"}
+ {HostDataSource.LOCKED_TEXT, "Locked"},
};
- private static final String[][] HOST_COLUMNS_SELECT;
-
- static {
- ArrayList<String[]> list = new
ArrayList<String[]>(Arrays.asList(HOST_COLUMNS));
- list.add(0, new String[] {CLICKABLE_WIDGET_COLUMN, "Select"});
- HOST_COLUMNS_SELECT = list.toArray(new String[0][0]);
- }
-
public HostTable(DataSource dataSource) {
- this(dataSource, false);
+ super(HOST_COLUMNS, dataSource);
}
-
- public HostTable(DataSource dataSource, boolean wantSelect) {
- super(wantSelect ? HOST_COLUMNS_SELECT : HOST_COLUMNS, dataSource);
+
+ public HostTable(String[][] columns, DataSource dataSource) {
+ super(columns, dataSource);
}
}
diff --git a/frontend/client/src/autotest/afe/ProfileSelectHostTable.java
b/frontend/client/src/autotest/afe/ProfileSelectHostTable.java
new file mode 100644
index 0000000..44fe548
--- /dev/null
+++ b/frontend/client/src/autotest/afe/ProfileSelectHostTable.java
@@ -0,0 +1,21 @@
+package autotest.afe;
+
+import autotest.common.table.DataSource;
+import autotest.common.table.DynamicTable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class ProfileSelectHostTable extends HostTable {
+ private static final String[][] HOST_COLUMNS_PROFILE;
+
+ static {
+ ArrayList<String[]> list = new
ArrayList<String[]>(Arrays.asList(HOST_COLUMNS));
+ list.add(new String[] {"current_profile", "Selected Profile"});
+ HOST_COLUMNS_PROFILE = list.toArray(new String[0][0]);
+ }
+
+ public ProfileSelectHostTable(DataSource dataSource) {
+ super(HOST_COLUMNS_PROFILE, dataSource);
+ }
+}
diff --git a/frontend/client/src/autotest/afe/ProfileStaticHostTable.java
b/frontend/client/src/autotest/afe/ProfileStaticHostTable.java
new file mode 100644
index 0000000..2d6b307
--- /dev/null
+++ b/frontend/client/src/autotest/afe/ProfileStaticHostTable.java
@@ -0,0 +1,25 @@
+package autotest.afe;
+
+import autotest.common.table.DataSource;
+import autotest.common.table.DynamicTable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class ProfileStaticHostTable extends HostTable {
+ private static final String[][] HOST_COLUMNS_PROFILE;
+
+ static {
+ ArrayList<String[]> list = new
ArrayList<String[]>(Arrays.asList(HOST_COLUMNS));
+ list.add(new String[] {"current_profile", "Current Profile"});
+ HOST_COLUMNS_PROFILE = list.toArray(new String[0][0]);
+ }
+
+ public ProfileStaticHostTable(DataSource dataSource) {
+ super(HOST_COLUMNS_PROFILE, dataSource);
+ }
+
+ protected boolean isProfileColumn(int column) {
+ return false;
+ }
+}
diff --git a/frontend/client/src/autotest/afe/SelectableHostTable.java
b/frontend/client/src/autotest/afe/SelectableHostTable.java
new file mode 100644
index 0000000..e0cdf14
--- /dev/null
+++ b/frontend/client/src/autotest/afe/SelectableHostTable.java
@@ -0,0 +1,21 @@
+package autotest.afe;
+
+import autotest.common.table.DataSource;
+import autotest.common.table.DynamicTable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class SelectableHostTable extends HostTable {
+ private static final String[][] HOST_COLUMNS_SELECT;
+
+ static {
+ ArrayList<String[]> list = new
ArrayList<String[]>(Arrays.asList(HOST_COLUMNS));
+ list.add(0, new String[] {CLICKABLE_WIDGET_COLUMN, "Select"});
+ HOST_COLUMNS_SELECT = list.toArray(new String[0][0]);
+ }
+
+ public SelectableHostTable(DataSource dataSource) {
+ super(HOST_COLUMNS_SELECT, dataSource);
+ }
+}
diff --git a/frontend/client/src/autotest/common/table/SelectionManager.java
b/frontend/client/src/autotest/common/table/SelectionManager.java
index 536b31c..186152b 100644
--- a/frontend/client/src/autotest/common/table/SelectionManager.java
+++ b/frontend/client/src/autotest/common/table/SelectionManager.java
@@ -6,7 +6,10 @@ import
autotest.common.table.TableClickWidget.TableWidgetClickListener;
import autotest.common.ui.TableSelectionPanel.SelectionPanelListener;
import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.ui.CheckBox;
+import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
import java.util.ArrayList;
@@ -172,21 +175,47 @@ public class SelectionManager implements
TableWidgetFactory, TableWidgetClickLis
// code for acting as a TableWidgetFactory/TableWidgetClickListener
- public Widget createWidget(int row, int cell, JSONObject rowObject) {
+ public Widget createWidget(int row, int cell, JSONObject rowObject, int
type) {
if (!isSelectable(rowObject)) {
return null;
}
- CheckBox checkBox = new CheckBox();
- if(selectedObjects.contains(rowObject)) {
- checkBox.setValue(true);
+ if (type == 0) {
+ CheckBox checkBox = new CheckBox();
+ if(selectedObjects.contains(rowObject)) {
+ checkBox.setValue(true);
+ }
+ return new TableClickWidget(checkBox, this, row, cell);
+ } else {
+ int i;
+ ListBox listBox = new ListBox();
+ listBox.setVisibleItemCount(1);
+ JSONArray profiles = (JSONArray)rowObject.get("profiles");
+ for (i = 0; i < profiles.size(); i++) {
+ String s = profiles.get(i).toString();
+ // sigh, for some reason getting extra quotes from cobbler here
+ listBox.addItem(s.substring(1, s.length()-1));
+ }
+ for (i = 0; i < listBox.getItemCount(); i++) {
+ if (listBox.getItemText(i) ==
rowObject.get("current_profile").isString().toString()) {
+ rowObject.put("profile", new
JSONString(listBox.getItemText(i)));
+ listBox.setSelectedIndex(i);
+ break;
+ }
+ }
+ return new TableClickWidget(listBox, this, row, cell);
}
- return new TableClickWidget(checkBox, this, row, cell);
}
public void onClick(TableClickWidget widget) {
- toggleSelected(attachedTable.getRow(widget.getRow()));
- refreshSelection();
+ if (widget.getContainedWidget() instanceof CheckBox) {
+ toggleSelected(attachedTable.getRow(widget.getRow()));
+ refreshSelection();
+ } else {
+ ListBox l = (ListBox)widget.getContainedWidget();
+ JSONObject row = attachedTable.getRow(widget.getRow());
+ row.put("profile", new
JSONString(l.getItemText(l.getSelectedIndex())));
+ }
}
// code for acting as a SelectionPanelListener
--
1.7.7.6
--
Nishanth Aravamudan <[email protected]>
IBM Linux Technology Center
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest