OLD | NEW |
1 package autotest.afe; | 1 package autotest.afe; |
2 | 2 |
3 import autotest.afe.create.CreateJobViewPresenter.JobCreateListener; | 3 import autotest.afe.CreateJobView.JobCreateListener; |
4 import autotest.common.SimpleCallback; | 4 import autotest.common.SimpleCallback; |
| 5 import autotest.common.table.SelectionManager; |
5 import autotest.common.table.DynamicTable.DynamicTableListener; | 6 import autotest.common.table.DynamicTable.DynamicTableListener; |
6 import autotest.common.table.SelectionManager; | |
7 import autotest.common.ui.ContextMenu; | 7 import autotest.common.ui.ContextMenu; |
8 import autotest.common.ui.NotifyManager; | 8 import autotest.common.ui.NotifyManager; |
9 import autotest.common.ui.TabView; | 9 import autotest.common.ui.TabView; |
10 import autotest.common.ui.TableActionsPanel.TableActionsListener; | 10 import autotest.common.ui.TableActionsPanel.TableActionsListener; |
11 | 11 |
12 import com.google.gwt.json.client.JSONArray; | 12 import com.google.gwt.json.client.JSONArray; |
13 import com.google.gwt.json.client.JSONObject; | 13 import com.google.gwt.json.client.JSONObject; |
14 import com.google.gwt.user.client.Command; | 14 import com.google.gwt.user.client.Command; |
15 | 15 |
16 import java.util.Set; | 16 import java.util.Set; |
17 | 17 |
18 public class HostListView extends TabView implements TableActionsListener { | 18 public class HostListView extends TabView implements TableActionsListener { |
19 protected static final int HOSTS_PER_PAGE = 30; | 19 protected static final int HOSTS_PER_PAGE = 30; |
20 | 20 |
21 public interface HostListListener { | 21 public interface HostListListener { |
22 public void onHostSelected(String hostname); | 22 public void onHostSelected(String hostname); |
23 } | 23 } |
24 | 24 |
25 protected HostListListener hostListListener = null; | 25 protected HostListListener hostListListener = null; |
26 private JobCreateListener jobCreateListener = null; | 26 private JobCreateListener jobCreateListener = null; |
27 | 27 |
28 public HostListView(HostListListener hostListListener, JobCreateListener job
CreateListener) { | 28 public HostListView(HostListListener hostListListener, JobCreateListener job
CreateListener) { |
29 this.hostListListener = hostListListener; | 29 this.hostListListener = hostListListener; |
30 this.jobCreateListener = jobCreateListener; | 30 this.jobCreateListener = jobCreateListener; |
31 } | 31 } |
32 | 32 |
33 @Override | 33 @Override |
34 public String getElementId() { | 34 public String getElementId() { |
35 return "hosts"; | 35 return "hosts"; |
36 } | 36 } |
37 | 37 |
38 protected HostTable table; | 38 protected HostTable table; |
39 protected HostTableDecorator hostTableDecorator; | 39 protected HostTableDecorator hostTableDecorator; |
40 protected SelectionManager selectionManager; | 40 protected SelectionManager selectionManager; |
41 | 41 |
42 @Override | 42 @Override |
43 public void initialize() { | 43 public void initialize() { |
44 super.initialize(); | 44 super.initialize(); |
45 | 45 |
46 table = new HostTable(new HostDataSource(), true); | 46 table = new HostTable(new HostDataSource(), true); |
47 hostTableDecorator = new HostTableDecorator(table, HOSTS_PER_PAGE); | 47 hostTableDecorator = new HostTableDecorator(table, HOSTS_PER_PAGE); |
48 | 48 |
49 selectionManager = hostTableDecorator.addSelectionManager(false); | 49 selectionManager = hostTableDecorator.addSelectionManager(false); |
50 table.setWidgetFactory(selectionManager); | 50 table.setWidgetFactory(selectionManager); |
51 hostTableDecorator.addTableActionsPanel(this, true); | 51 hostTableDecorator.addTableActionsPanel(this, true); |
52 | 52 |
53 table.setClickable(true); | 53 table.setClickable(true); |
54 table.addListener(new DynamicTableListener() { | 54 table.addListener(new DynamicTableListener() { |
55 public void onRowClicked(int rowIndex, JSONObject row, boolean isRig
htClick) { | 55 public void onRowClicked(int rowIndex, JSONObject row, boolean isRig
htClick) { |
56 String hostname = row.get("hostname").isString().stringValue(); | 56 String hostname = row.get("hostname").isString().stringValue(); |
57 hostListListener.onHostSelected(hostname); | 57 hostListListener.onHostSelected(hostname); |
58 } | 58 } |
59 | 59 |
60 public void onTableRefreshed() {} | 60 public void onTableRefreshed() {} |
61 }); | 61 }); |
62 | 62 |
63 addWidget(hostTableDecorator, "hosts_list"); | 63 addWidget(hostTableDecorator, "hosts_list"); |
64 } | 64 } |
65 | 65 |
66 @Override | 66 @Override |
67 public void refresh() { | 67 public void refresh() { |
68 super.refresh(); | 68 super.refresh(); |
69 table.refresh(); | 69 table.refresh(); |
70 } | 70 } |
71 | 71 |
72 private void reverifySelectedHosts() { | 72 private void reverifySelectedHosts() { |
73 JSONObject params = new JSONObject(); | 73 JSONObject params = new JSONObject(); |
74 JSONArray hostIds = getSelectedHostIds(); | 74 JSONArray hostIds = getSelectedHostIds(); |
75 if (hostIds == null) { | 75 if (hostIds == null) { |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 params.put("id__in", hostIds); | 79 params.put("id__in", hostIds); |
80 AfeUtils.callReverify(params, new SimpleCallback() { | 80 AfeUtils.callReverify(params, new SimpleCallback() { |
81 public void doCallback(Object source) { | 81 public void doCallback(Object source) { |
82 refresh(); | 82 refresh(); |
83 } | 83 } |
84 }, "Hosts"); | 84 }, "Hosts"); |
85 } | 85 } |
86 | 86 |
87 private void changeLockStatus(final boolean lock) { | 87 private void changeLockStatus(final boolean lock) { |
88 JSONArray hostIds = getSelectedHostIds(); | 88 JSONArray hostIds = getSelectedHostIds(); |
89 if (hostIds == null) { | 89 if (hostIds == null) { |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 AfeUtils.changeHostLocks(hostIds, lock, "Hosts", new SimpleCallback() { | 93 AfeUtils.changeHostLocks(hostIds, lock, "Hosts", new SimpleCallback() { |
94 public void doCallback(Object source) { | 94 public void doCallback(Object source) { |
95 refresh(); | 95 refresh(); |
96 } | 96 } |
97 }); | 97 }); |
98 } | 98 } |
99 | 99 |
100 private void reinstallSelectedHosts() { | 100 private void reinstallSelectedHosts() { |
101 Set<JSONObject> selectedSet = getSelectedHosts(); | 101 Set<JSONObject> selectedSet = getSelectedHosts(); |
102 if (selectedSet == null) { | 102 if (selectedSet == null) { |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 JSONArray array = new JSONArray(); | 106 JSONArray array = new JSONArray(); |
107 for (JSONObject host : selectedSet) { | 107 for (JSONObject host : selectedSet) { |
108 array.set(array.size(), host.get("hostname")); | 108 array.set(array.size(), host.get("hostname")); |
109 } | 109 } |
110 AfeUtils.scheduleReinstall(array, "Hosts", jobCreateListener); | 110 AfeUtils.scheduleReinstall(array, "Hosts", jobCreateListener); |
111 } | 111 } |
112 | 112 |
113 private Set<JSONObject> getSelectedHosts() { | 113 private Set<JSONObject> getSelectedHosts() { |
114 Set<JSONObject> selectedSet = selectionManager.getSelectedObjects(); | 114 Set<JSONObject> selectedSet = selectionManager.getSelectedObjects(); |
115 if (selectedSet.isEmpty()) { | 115 if (selectedSet.isEmpty()) { |
116 NotifyManager.getInstance().showError("No hosts selected"); | 116 NotifyManager.getInstance().showError("No hosts selected"); |
117 return null; | 117 return null; |
118 } | 118 } |
119 return selectedSet; | 119 return selectedSet; |
120 } | 120 } |
121 | 121 |
122 private JSONArray getSelectedHostIds() { | 122 private JSONArray getSelectedHostIds() { |
123 Set<JSONObject> selectedSet = getSelectedHosts(); | 123 Set<JSONObject> selectedSet = getSelectedHosts(); |
124 if (selectedSet == null) { | 124 if (selectedSet == null) { |
125 return null; | 125 return null; |
126 } | 126 } |
127 | 127 |
128 JSONArray ids = new JSONArray(); | 128 JSONArray ids = new JSONArray(); |
129 for (JSONObject jsonObj : selectedSet) { | 129 for (JSONObject jsonObj : selectedSet) { |
130 ids.set(ids.size(), jsonObj.get("id")); | 130 ids.set(ids.size(), jsonObj.get("id")); |
131 } | 131 } |
132 | 132 |
133 return ids; | 133 return ids; |
134 } | 134 } |
135 | 135 |
136 public ContextMenu getActionMenu() { | 136 public ContextMenu getActionMenu() { |
137 ContextMenu menu = new ContextMenu(); | 137 ContextMenu menu = new ContextMenu(); |
138 menu.addItem("Reverify hosts", new Command() { | 138 menu.addItem("Reverify hosts", new Command() { |
139 public void execute() { | 139 public void execute() { |
140 reverifySelectedHosts(); | 140 reverifySelectedHosts(); |
141 } | 141 } |
142 }); | 142 }); |
143 menu.addItem("Lock hosts", new Command() { | 143 menu.addItem("Lock hosts", new Command() { |
144 public void execute() { | 144 public void execute() { |
145 changeLockStatus(true); | 145 changeLockStatus(true); |
146 } | 146 } |
147 }); | 147 }); |
148 menu.addItem("Unlock hosts", new Command() { | 148 menu.addItem("Unlock hosts", new Command() { |
149 public void execute() { | 149 public void execute() { |
150 changeLockStatus(false); | 150 changeLockStatus(false); |
151 } | 151 } |
152 }); | 152 }); |
153 menu.addItem("Reinstall hosts", new Command() { | 153 menu.addItem("Reinstall hosts", new Command() { |
154 public void execute() { | 154 public void execute() { |
155 reinstallSelectedHosts(); | 155 reinstallSelectedHosts(); |
156 } | 156 } |
157 }); | 157 }); |
158 | 158 |
159 return menu; | 159 return menu; |
160 } | 160 } |
161 } | 161 } |
OLD | NEW |