1 package autotest.afe; 2 3 import autotest.common.SimpleCallback; 4 import autotest.common.StaticDataRepository; 5 import autotest.common.Utils; 6 import autotest.common.table.BooleanFilter; 7 import autotest.common.table.CheckboxFilter; 8 import autotest.common.table.ListFilter; 9 import autotest.common.table.SearchFilter; 10 import autotest.common.table.TableDecorator; 11 12 import com.google.gwt.json.client.JSONArray; 13 import com.google.gwt.json.client.JSONBoolean; 14 import com.google.gwt.json.client.JSONObject; 15 import com.google.gwt.json.client.JSONString; 16 import com.google.gwt.json.client.JSONValue; 17 18 import java.util.ArrayList; 19 import java.util.List; 20 21 class HostTableDecorator extends TableDecorator implements SimpleCallback { 22 SearchFilter hostnameFilter; 23 LabelFilter labelFilter; 24 ListFilter statusFilter; 25 BooleanFilter lockedFilter; 26 ListFilter lockedByFilter; 27 AclAccessibleFilter aclFilter; 28 AtomicGroupFilter excludeAtomicGroupsFilter; 29 30 static class AclAccessibleFilter extends CheckboxFilter { 31 private JSONValue username; 32 AclAccessibleFilter()33 public AclAccessibleFilter() { 34 super("aclgroup__users__login"); 35 username = new JSONString(StaticDataRepository.getRepository().getCurrentUserLogin()); 36 } 37 38 @Override getMatchValue()39 public JSONValue getMatchValue() { 40 return username; 41 } 42 } 43 44 static class AtomicGroupFilter extends CheckboxFilter { AtomicGroupFilter()45 public AtomicGroupFilter() { 46 super("exclude_atomic_group_hosts"); 47 } 48 49 @Override getMatchValue()50 public JSONValue getMatchValue() { 51 return JSONBoolean.getInstance(true); 52 } 53 } 54 HostTableDecorator(HostTable table, int rowsPerPage)55 public HostTableDecorator(HostTable table, int rowsPerPage) { 56 super(table); 57 table.sortOnColumn("hostname"); /* Case sensitive name */ 58 table.setRowsPerPage(rowsPerPage); 59 addPaginators(); 60 61 StaticDataRepository staticData = StaticDataRepository.getRepository(); 62 JSONArray statuses = staticData.getData("host_statuses").isArray(); 63 String[] statusStrings = Utils.JSONtoStrings(statuses); 64 65 JSONArray users = staticData.getData("users").isArray(); 66 List<String> userStrings = new ArrayList<String>(); 67 for (int i = 0; i < users.size(); i++) { 68 JSONObject user = users.get(i).isObject(); 69 userStrings.add(Utils.jsonToString(user.get("login"))); 70 } 71 72 hostnameFilter = new SearchFilter("hostname", true); 73 labelFilter = new LabelFilter(); 74 statusFilter = new ListFilter("status"); 75 statusFilter.setChoices(statusStrings); 76 lockedFilter = new BooleanFilter("locked"); 77 lockedByFilter = new ListFilter("locked_by__login"); 78 lockedByFilter.setChoices(userStrings.toArray(new String[userStrings.size()])); 79 aclFilter = new AclAccessibleFilter(); 80 excludeAtomicGroupsFilter = new AtomicGroupFilter(); 81 82 updateLockedByEnabled(); 83 lockedFilter.addCallback(this); 84 85 addFilter("Hostname", hostnameFilter); 86 addControl("Platform", labelFilter.getPlatformWidget()); 87 addFilter("Label", labelFilter); 88 addFilter("Status", statusFilter); 89 addFilter("Locked", lockedFilter); 90 addFilter("Locked By", lockedByFilter); 91 addFilter("ACL accessible only", aclFilter); 92 addFilter("Exclude atomic groups", excludeAtomicGroupsFilter); 93 } 94 95 @Override doCallback(Object source)96 public void doCallback(Object source) { 97 assert source == lockedFilter; 98 updateLockedByEnabled(); 99 } 100 updateLockedByEnabled()101 private void updateLockedByEnabled() { 102 if (lockedFilter.isActive() && lockedFilter.isSelected()) { 103 lockedByFilter.setEnabled(true); 104 } else { 105 lockedByFilter.setEnabled(false); 106 } 107 } 108 } 109