1package autotest.afe.create;
2
3import autotest.afe.CheckBoxPanel;
4import autotest.afe.CheckBoxPanelDisplay;
5import autotest.afe.ControlTypeSelect;
6import autotest.afe.ControlTypeSelectDisplay;
7import autotest.afe.HostSelector;
8import autotest.afe.HostSelectorDisplay;
9import autotest.afe.IButton;
10import autotest.afe.IButton.ButtonImpl;
11import autotest.afe.ICheckBox;
12import autotest.afe.ICheckBox.CheckBoxImpl;
13import autotest.afe.ITextArea;
14import autotest.afe.ITextArea.TextAreaImpl;
15import autotest.afe.ITextBox;
16import autotest.afe.ITextBox.TextBoxImpl;
17import autotest.afe.RadioChooser;
18import autotest.afe.RadioChooserDisplay;
19import autotest.afe.TestSelector;
20import autotest.afe.TestSelectorDisplay;
21import autotest.common.ui.ExtendedListBox;
22import autotest.common.ui.SimplifiedList;
23import autotest.common.ui.ToolTip;
24
25import com.google.gwt.event.dom.client.HasClickHandlers;
26import com.google.gwt.event.logical.shared.HasCloseHandlers;
27import com.google.gwt.event.logical.shared.HasOpenHandlers;
28import com.google.gwt.user.client.ui.Anchor;
29import com.google.gwt.user.client.ui.Button;
30import com.google.gwt.user.client.ui.CheckBox;
31import com.google.gwt.user.client.ui.DisclosurePanel;
32import com.google.gwt.user.client.ui.FlexTable;
33import com.google.gwt.user.client.ui.HTMLPanel;
34import com.google.gwt.user.client.ui.HTMLTable;
35import com.google.gwt.user.client.ui.HasText;
36import com.google.gwt.user.client.ui.HasValue;
37import com.google.gwt.user.client.ui.HorizontalPanel;
38import com.google.gwt.user.client.ui.Label;
39import com.google.gwt.user.client.ui.Panel;
40import com.google.gwt.user.client.ui.TextBox;
41import com.google.gwt.user.client.ui.VerticalPanel;
42
43public class CreateJobViewDisplay implements CreateJobViewPresenter.Display {
44    public static final int CHECKBOX_PANEL_COLUMNS = 5;
45
46    private TextBox jobName = new TextBox();
47    private ToolTip jobNameToolTip = new ToolTip(
48        "?",
49        "Name for the job. The string should be meaningful when viewing a list of jobs.");
50    private ExtendedListBox priorityList = new ExtendedListBox();
51    private ToolTip priorityListToolTip = new ToolTip(
52        "?",
53        "Lowest to highest: Weekly, Daily, PostBuild, Default.");
54    private TextBoxImpl kernel = new TextBoxImpl();
55    private ToolTip kernelToolTip = new ToolTip(
56        "?",
57        "A URL pointing to a kernel source tarball or a .rpm or .deb package to " +
58        "install on the test machine before testing. Leave blank to skip this step. " +
59        "Example: \"2.6.18-rc3\" or \"http://example.com/kernel-2.6.30.rpm\". " +
60        "Separate multiple kernels with a comma and/or space.");
61    private TextBoxImpl kernel_cmdline = new TextBoxImpl();
62    private TextBoxImpl image_url = new TextBoxImpl();
63    private ToolTip image_urlToolTip = new ToolTip(
64        "?",
65        "Name of the test image to use. Example: \"x86-alex-release/R27-3837.0.0\". " +
66        "If no image is specified, regular tests will use current image on the Host. " +
67        "Please note that an image is required to run a test suite.");
68    private Button fetchImageTestsButton = new Button("Fetch Tests from Build");
69    private TextBox timeout = new TextBox();
70    private ToolTip timeoutToolTip = new ToolTip(
71        "?",
72        "The number of minutes after the job creation before the scheduler " +
73        "automatically aborts an incomplete job.");
74    private TextBox maxRuntime = new TextBox();
75    private ToolTip maxRuntimeToolTip = new ToolTip(
76        "?",
77        "The number of minutes after the job starts running before the scheduler " +
78        "automatically aborts an incomplete job.");
79    private TextBox testRetry = new TextBox();
80    private ToolTip testRetryToolTip = new ToolTip(
81        "?",
82        "Number of times to retry test if the test did not complete successfully.");
83    private TextBox emailList = new TextBox();
84    private ToolTip emailListToolTip = new ToolTip(
85        "?",
86        "Email addresses to notify when this job completes. " +
87        "Use a comma or space to separate multiple addresses.");
88    private CheckBoxImpl skipVerify = new CheckBoxImpl();
89    private ToolTip skipVerifyToolTip = new ToolTip(
90        "?",
91        "Skips the host verification step before running the job. " +
92        "This is useful for machine reinstalls, for example.");
93    private CheckBoxImpl skipReset = new CheckBoxImpl();
94    private ToolTip skipResetToolTip = new ToolTip(
95        "?",
96        "Skips the host reset step before running the job.");
97    private RadioChooserDisplay rebootBefore = new RadioChooserDisplay();
98    private ToolTip rebootBeforeToolTip = new ToolTip(
99        "?",
100        "Reboots all assigned hosts before the job runs. " +
101        "Click If dirty to reboot the host only if it hasn’t been rebooted " +
102        "since it was added, locked, or after running the last job.");
103    private RadioChooserDisplay rebootAfter = new RadioChooserDisplay();
104    private ToolTip rebootAfterToolTip = new ToolTip(
105        "?",
106        "Reboots all assigned hosts after the job runs. Click If all tests passed " +
107        "to skip rebooting the host if any test in the job fails.");
108    private CheckBox parseFailedRepair = new CheckBox();
109    private ToolTip parseFailedRepairToolTip = new ToolTip(
110        "?",
111        "When a host fails repair, displays repair and verify test entries in " +
112        "the results database along with a SERVER_JOB entry. " +
113        "Otherwise, no information is displayed in TKO (Result Database).");
114    private CheckBoxImpl hostless = new CheckBoxImpl();
115    private ToolTip hostlessToolTip = new ToolTip(
116        "?",
117        "Check to run a suite of tests, and select Server from the Test type dropdown list.");
118    private CheckBoxImpl require_ssp = new CheckBoxImpl();
119    private ToolTip require_sspToolTip = new ToolTip(
120        "?",
121        "Check to force a server side test to use server-side packaging. This " +
122        "option has no effect on suite job. Test jobs created by a suite job " +
123        "will use SSP if enable_ssp_container is set to True in global config " +
124        "and there exists a drone supporting SSP.");
125    private TextBox pool = new TextBox();
126    private ToolTip poolToolTip = new ToolTip(
127        "?",
128        "Specify the pool of machines to use for suite job.");
129    private TextBoxImpl args = new TextBoxImpl();
130    private ToolTip argsToolTip = new ToolTip(
131        "?",
132        "Example: \"device_addrs=00:1F:20:33:6A:1E, arg2=value2, arg3=value3\". " +
133        "Separate multiple args with commas.");
134    private TextBoxImpl firmwareRWBuild = new TextBoxImpl();
135    private ToolTip firmwareRWBuildToolTip = new ToolTip(
136        "?",
137        "Name of the firmware build to update RW firmware of the DUT. Example: " +
138        "\"x86-alex-firmware/R41-6588.9.0\". If no firmware build is specified, " +
139        "the RW firmware of the DUT will not be updated.");
140    private TextBoxImpl firmwareROBuild = new TextBoxImpl();
141    private ToolTip firmwareROBuildToolTip = new ToolTip(
142        "?",
143        "Name of the firmware build to update RO firmware of the DUT. Example: " +
144        "\"x86-alex-firmware/R41-6588.9.0\". If no firmware RO build is specified, " +
145        "the RO firmware of the DUT will not be updated.");
146    private ExtendedListBox testSourceBuildList = new ExtendedListBox();
147    private ToolTip testSourceBuildListToolTip = new ToolTip(
148        "?",
149        "The image/build from which the tests will be fetched and ran from. It can " +
150        "be one of the specified Build Image, Firmware RW Build or the Firmware RO Build.");
151    private TestSelectorDisplay testSelector = new TestSelectorDisplay();
152    private CheckBoxPanelDisplay profilersPanel = new CheckBoxPanelDisplay(CHECKBOX_PANEL_COLUMNS);
153    private CheckBoxImpl runNonProfiledIteration =
154        new CheckBoxImpl("Run each test without profilers first");
155    private ExtendedListBox droneSet = new ExtendedListBox();
156    private TextAreaImpl controlFile = new TextAreaImpl();
157    private DisclosurePanel controlFilePanel = new DisclosurePanel("");
158    private ControlTypeSelectDisplay controlTypeSelect = new ControlTypeSelectDisplay();
159    private TextBoxImpl synchCountInput = new TextBoxImpl();
160    private ButtonImpl editControlButton = new ButtonImpl();
161    private HostSelectorDisplay hostSelector = new HostSelectorDisplay();
162    private ButtonImpl submitJobButton = new ButtonImpl("Submit Job");
163    private Button createTemplateJobButton = new Button("Create Template Job");
164    private Button resetButton = new Button("Reset");
165    private Label viewLink = new Label("");
166    private DisclosurePanel advancedOptionsPanel = new DisclosurePanel("");
167    private DisclosurePanel firmwareBuildOptionsPanel = new DisclosurePanel("");
168
169    public void initialize(HTMLPanel panel) {
170        jobName.addStyleName("jobname-image-boundedwidth");
171        image_url.addStyleName("jobname-image-boundedwidth");
172
173        Panel profilerControls = new VerticalPanel();
174        profilerControls.add(profilersPanel);
175        profilerControls.add(runNonProfiledIteration);
176
177        controlFile.setSize("100%", "30em");
178
179        HorizontalPanel controlOptionsPanel = new HorizontalPanel();
180        controlOptionsPanel.setVerticalAlignment(HorizontalPanel.ALIGN_BOTTOM);
181        controlOptionsPanel.add(controlTypeSelect);
182        Label useLabel = new Label("Use");
183        useLabel.getElement().getStyle().setProperty("marginLeft", "1em");
184        synchCountInput.setSize("3em", ""); // set width only
185        synchCountInput.getElement().getStyle().setProperty("margin", "0 0.5em 0 0.5em");
186        controlOptionsPanel.add(useLabel);
187        controlOptionsPanel.add(synchCountInput);
188        controlOptionsPanel.add(new Label("host(s) per execution"));
189        Panel controlEditPanel = new VerticalPanel();
190        controlEditPanel.add(controlOptionsPanel);
191        controlEditPanel.add(controlFile);
192        controlEditPanel.setWidth("100%");
193
194        Panel controlHeaderPanel = new HorizontalPanel();
195        controlHeaderPanel.add(controlFilePanel.getHeader());
196        controlHeaderPanel.add(viewLink);
197        controlHeaderPanel.add(editControlButton);
198
199        controlFilePanel.setHeader(controlHeaderPanel);
200        controlFilePanel.add(controlEditPanel);
201        controlFilePanel.addStyleName("panel-boundedwidth");
202
203        // Setup the Advanced options panel
204        advancedOptionsPanel.getHeaderTextAccessor().setText("Advanced Options");
205
206        FlexTable advancedOptionsLayout = new FlexTable();
207
208        Panel priorityPanel = new HorizontalPanel();
209        priorityPanel.add(priorityList);
210        priorityPanel.add(priorityListToolTip);
211        advancedOptionsLayout.setWidget(0, 0, new Label("Priority:"));
212        advancedOptionsLayout.setWidget(0, 1, priorityPanel);
213
214        Panel kernelPanel = new HorizontalPanel();
215        kernelPanel.add(kernel);
216        kernelPanel.add(kernelToolTip);
217        advancedOptionsLayout.setWidget(1, 0, new Label("Kernel(s): (optional)"));
218        advancedOptionsLayout.setWidget(1, 1, kernelPanel);
219
220        advancedOptionsLayout.setWidget(2, 0, new Label("Kernel 'cmd': (optional)"));
221        advancedOptionsLayout.setWidget(2, 1, kernel_cmdline);
222
223        Panel timeoutPanel = new HorizontalPanel();
224        timeoutPanel.add(timeout);
225        timeoutPanel.add(timeoutToolTip);
226        advancedOptionsLayout.setWidget(3, 0, new Label("Timeout (minutes):"));
227        advancedOptionsLayout.setWidget(3, 1, timeoutPanel);
228
229        Panel maxRuntimePanel = new HorizontalPanel();
230        maxRuntimePanel.add(maxRuntime);
231        maxRuntimePanel.add(maxRuntimeToolTip);
232        advancedOptionsLayout.setWidget(4, 0, new Label("Max runtime (minutes):"));
233        advancedOptionsLayout.setWidget(4, 1, maxRuntimePanel);
234
235        Panel testRetryPanel = new HorizontalPanel();
236        testRetryPanel.add(testRetry);
237        testRetryPanel.add(testRetryToolTip);
238        advancedOptionsLayout.setWidget(5, 0, new Label("Test Retries: (optional)"));
239        advancedOptionsLayout.setWidget(5, 1, testRetryPanel);
240
241        Panel emailListPanel = new HorizontalPanel();
242        emailListPanel.add(emailList);
243        emailListPanel.add(emailListToolTip);
244        advancedOptionsLayout.setWidget(6, 0, new Label("Email List: (optional)"));
245        advancedOptionsLayout.setWidget(6, 1, emailListPanel);
246
247        Panel skipVerifyPanel = new HorizontalPanel();
248        skipVerifyPanel.add(skipVerify);
249        skipVerifyPanel.add(skipVerifyToolTip);
250        advancedOptionsLayout.setWidget(7, 0, new Label("Skip verify:"));
251        advancedOptionsLayout.setWidget(7, 1, skipVerifyPanel);
252
253        Panel skipResetPanel = new HorizontalPanel();
254        skipResetPanel.add(skipReset);
255        skipResetPanel.add(skipResetToolTip);
256        advancedOptionsLayout.setWidget(8, 0, new Label("Skip reset:"));
257        advancedOptionsLayout.setWidget(8, 1, skipResetPanel);
258
259        Panel rebootBeforePanel = new HorizontalPanel();
260        rebootBeforePanel.add(rebootBefore);
261        rebootBeforePanel.add(rebootBeforeToolTip);
262        advancedOptionsLayout.setWidget(9, 0, new Label("Reboot before:"));
263        advancedOptionsLayout.setWidget(9, 1, rebootBeforePanel);
264
265        Panel rebootAfterPanel = new HorizontalPanel();
266        rebootAfterPanel.add(rebootAfter);
267        rebootAfterPanel.add(rebootAfterToolTip);
268        advancedOptionsLayout.setWidget(10, 0, new Label("Reboot after:"));
269        advancedOptionsLayout.setWidget(10, 1, rebootAfterPanel);
270
271        Panel parseFailedRepairPanel = new HorizontalPanel();
272        parseFailedRepairPanel.add(parseFailedRepair);
273        parseFailedRepairPanel.add(parseFailedRepairToolTip);
274        advancedOptionsLayout.setWidget(11, 0, new Label("Include failed repair results:"));
275        advancedOptionsLayout.setWidget(11, 1, parseFailedRepairPanel);
276
277        Panel hostlessPanel = new HorizontalPanel();
278        hostlessPanel.add(hostless);
279        hostlessPanel.add(hostlessToolTip);
280        advancedOptionsLayout.setWidget(12, 0, new Label("Hostless (Suite Job):"));
281        advancedOptionsLayout.setWidget(12, 1, hostlessPanel);
282
283        Panel require_sspPanel = new HorizontalPanel();
284        require_sspPanel.add(require_ssp);
285        require_sspPanel.add(require_sspToolTip);
286        advancedOptionsLayout.setWidget(13, 0, new Label("Require server-side packaging:"));
287        advancedOptionsLayout.setWidget(13, 1, require_sspPanel);
288
289        Panel poolPanel = new HorizontalPanel();
290        poolPanel.add(pool);
291        poolPanel.add(poolToolTip);
292        advancedOptionsLayout.setWidget(14, 0, new Label("Pool: (optional)"));
293        advancedOptionsLayout.setWidget(14, 1, poolPanel);
294
295        Panel argsPanel = new HorizontalPanel();
296        argsPanel.add(args);
297        argsPanel.add(argsToolTip);
298        advancedOptionsLayout.setWidget(15, 0, new Label("Args: (optional)"));
299        advancedOptionsLayout.setWidget(15, 1, argsPanel);
300
301        advancedOptionsLayout.setWidget(16, 0, new Label("Profilers: (optional)"));
302        advancedOptionsLayout.setWidget(16, 1, profilerControls);
303
304        HTMLTable.RowFormatter advOptLayoutFormatter = advancedOptionsLayout.getRowFormatter();
305        for (int row = 0; row < advancedOptionsLayout.getRowCount(); ++row)
306        {
307          if (row % 2 == 0) {
308              advOptLayoutFormatter.addStyleName(row, "data-row");
309          }
310          else {
311              advOptLayoutFormatter.addStyleName(row, "data-row-alternate");
312          }
313
314        }
315        advancedOptionsLayout.setWidth("100%");
316        advancedOptionsPanel.addStyleName("panel-boundedwidth");
317        advancedOptionsPanel.add(advancedOptionsLayout);
318
319        // Setup the Firmware Build options panel
320        firmwareBuildOptionsPanel.getHeaderTextAccessor().setText("Firmware Build Options (optional)");
321        FlexTable firmwareBuildOptionsLayout = new FlexTable();
322
323        firmwareBuildOptionsLayout.getFlexCellFormatter().setColSpan(0, 0, 2);
324        firmwareBuildOptionsLayout.setWidget(0, 0, new Label("Image URL/Build must be specified for " +
325            "updating the firmware of the test device with given firmware build. A servo may be " +
326            "required to be attached to the test device in order to have firmware updated."));
327
328        Panel firmwareRWBuildPanel = new HorizontalPanel();
329        firmwareRWBuild.addStyleName("jobname-image-boundedwidth");
330        firmwareRWBuildPanel.add(firmwareRWBuild);
331        firmwareRWBuildPanel.add(firmwareRWBuildToolTip);
332        firmwareBuildOptionsLayout.setWidget(1, 0, new Label("Firmware RW build:"));
333        firmwareBuildOptionsLayout.setWidget(1, 1, firmwareRWBuildPanel);
334
335        Panel firmwareROBuildPanel = new HorizontalPanel();
336        firmwareROBuild.addStyleName("jobname-image-boundedwidth");
337        firmwareROBuildPanel.add(firmwareROBuild);
338        firmwareROBuildPanel.add(firmwareROBuildToolTip);
339        firmwareBuildOptionsLayout.setWidget(2, 0, new Label("Firmware RO build:"));
340        firmwareBuildOptionsLayout.setWidget(2, 1, firmwareROBuildPanel);
341
342        firmwareBuildOptionsLayout.setWidth("100%");
343        firmwareBuildOptionsPanel.addStyleName("panel-boundedwidth");
344        firmwareBuildOptionsPanel.add(firmwareBuildOptionsLayout);
345        firmwareRWBuild.setEnabled(false);
346        firmwareROBuild.setEnabled(false);
347
348        testSourceBuildList.getElement().getStyle().setProperty("minWidth", "15em");
349
350        // Add the remaining widgets to the main panel
351        panel.add(jobName, "create_job_name");
352        panel.add(jobNameToolTip, "create_job_name");
353        panel.add(image_url, "create_image_url");
354        panel.add(image_urlToolTip, "create_image_url");
355        panel.add(testSourceBuildList, "create_test_source_build");
356        panel.add(testSourceBuildListToolTip, "create_test_source_build");
357        panel.add(fetchImageTestsButton, "fetch_image_tests");
358        panel.add(testSelector, "create_tests");
359        panel.add(controlFilePanel, "create_edit_control");
360        panel.add(hostSelector, "create_host_selector");
361        panel.add(submitJobButton, "create_submit");
362        panel.add(createTemplateJobButton, "create_template_job");
363        panel.add(resetButton, "create_reset");
364        panel.add(droneSet, "create_drone_set");
365
366        panel.add(advancedOptionsPanel, "create_advanced_options");
367        panel.add(firmwareBuildOptionsPanel, "create_firmware_build_options");
368    }
369
370    public CheckBoxPanel.Display getCheckBoxPanelDisplay() {
371        return profilersPanel;
372    }
373
374    public ControlTypeSelect.Display getControlTypeSelectDisplay() {
375        return controlTypeSelect;
376    }
377
378    public ITextArea getControlFile() {
379        return controlFile;
380    }
381
382    public HasCloseHandlers<DisclosurePanel> getControlFilePanelClose() {
383        return controlFilePanel;
384    }
385
386    public HasOpenHandlers<DisclosurePanel> getControlFilePanelOpen() {
387        return controlFilePanel;
388    }
389
390    public HasClickHandlers getCreateTemplateJobButton() {
391        return createTemplateJobButton;
392    }
393
394    public SimplifiedList getDroneSet() {
395        return droneSet;
396    }
397
398    public IButton getEditControlButton() {
399        return editControlButton;
400    }
401
402    public HasText getEmailList() {
403        return emailList;
404    }
405
406    public HostSelector.Display getHostSelectorDisplay() {
407        return hostSelector;
408    }
409
410    public ICheckBox getHostless() {
411        return hostless;
412    }
413
414    public ICheckBox getRequireSSP() {
415      return require_ssp;
416    }
417
418    public HasText getPool() {
419        return pool;
420    }
421
422    public ITextBox getArgs() {
423        return args;
424    }
425
426    public HasText getJobName() {
427        return jobName;
428    }
429
430    public ITextBox getKernel() {
431        return kernel;
432    }
433
434    public ITextBox getKernelCmdline() {
435        return kernel_cmdline;
436    }
437
438    public ITextBox getImageUrl() {
439        return image_url;
440    }
441
442    public HasText getMaxRuntime() {
443        return maxRuntime;
444    }
445
446    public HasText getTestRetry() {
447        return testRetry;
448    }
449
450    public HasValue<Boolean> getParseFailedRepair() {
451        return parseFailedRepair;
452    }
453
454    public ExtendedListBox getPriorityList() {
455        return priorityList;
456    }
457
458    public RadioChooser.Display getRebootAfter() {
459        return rebootAfter;
460    }
461
462    public RadioChooser.Display getRebootBefore() {
463        return rebootBefore;
464    }
465
466    public HasClickHandlers getResetButton() {
467        return resetButton;
468    }
469
470    public ICheckBox getRunNonProfiledIteration() {
471        return runNonProfiledIteration;
472    }
473
474    public ICheckBox getSkipVerify() {
475        return skipVerify;
476    }
477
478    public ICheckBox getSkipReset() {
479      return skipReset;
480    }
481
482    public IButton getSubmitJobButton() {
483        return submitJobButton;
484    }
485
486    public ITextBox getSynchCountInput() {
487        return synchCountInput;
488    }
489
490    public TestSelector.Display getTestSelectorDisplay() {
491        return testSelector;
492    }
493
494    public HasText getTimeout() {
495        return timeout;
496    }
497
498    public HasText getViewLink() {
499        return viewLink;
500    }
501
502    public void setControlFilePanelOpen(boolean isOpen) {
503        controlFilePanel.setOpen(isOpen);
504    }
505
506    public HasClickHandlers getFetchImageTestsButton() {
507        return fetchImageTestsButton;
508    }
509
510    public ITextBox getFirmwareRWBuild() {
511      return firmwareRWBuild;
512    }
513
514    public ITextBox getFirmwareROBuild() {
515      return firmwareROBuild;
516    }
517
518    public ExtendedListBox getTestSourceBuildList() {
519      return testSourceBuildList;
520    }
521}
522