public ExecutionWidget(final ExecutionTrace executionTrace, boolean showResults) { this.executionTrace = executionTrace; final HorizontalPanel simulDatePanel = simulDate(); simulDatePanel.setVisible(isScenarioSimulatedDateSet()); final ListBox choice = new ListBox(); choice.addItem(TestScenarioConstants.INSTANCE.UseRealDateAndTime()); choice.addItem(TestScenarioConstants.INSTANCE.UseASimulatedDateAndTime()); choice.setSelectedIndex((executionTrace.getScenarioSimulatedDate() == null) ? 0 : 1); choice.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { if (choice.getSelectedIndex() == 0) { simulDatePanel.setVisible(false); executionTrace.setScenarioSimulatedDate(null); } else { simulDatePanel.setVisible(true); } } }); HorizontalPanel layout = new HorizontalPanel(); layout.add(new Image(TestScenarioImages.INSTANCE.executionTrace())); layout.add(choice); layout.add(simulDatePanel); if (showResults && isResultNotNullAndHaveRulesFired()) { VerticalPanel replacingLayout = new VerticalPanel(); replacingLayout.add(new FiredRulesPanel(executionTrace)); replacingLayout.add(layout); initWidget(replacingLayout); } else { initWidget(layout); } }
private HorizontalPanel simulDate() { HorizontalPanel horizontalPanel = new HorizontalPanel(); final String format = "yyyy-MM-dd HH:mm"; // NON-NLS final TextBox textBox = new TextBox(); if (executionTrace.getScenarioSimulatedDate() == null) { textBox.setText("<" + format + ">"); } else { textBox.setText( DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT) .format(executionTrace.getScenarioSimulatedDate())); } final SmallLabel dateHint = new SmallLabel(); textBox.addKeyUpHandler( new KeyUpHandler() { public void onKeyUp(KeyUpEvent event) { try { String exampleDate = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT) .format(new Date()); String suggestedDate = textBox.getText() + exampleDate.substring(textBox.getText().length()); Date d = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT) .parse(suggestedDate); dateHint.setText( DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT) .format(d)); } catch (Exception e) { dateHint.setText("..."); } } }); textBox.addChangeHandler( new ChangeHandler() { public void onChange(ChangeEvent event) { if (textBox.getText().trim().equals("")) { textBox.setText(TestScenarioConstants.INSTANCE.currentDateAndTime()); } else { try { // Date d1 = new Date(); Date d = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT) .parse(textBox.getText()); executionTrace.setScenarioSimulatedDate(d); textBox.setText( DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT) .format(d)); dateHint.setText(""); } catch (Exception e) { ErrorPopup.showMessage( TestScenarioConstants.INSTANCE.BadDateFormatPleaseTryAgainTryTheFormatOf0( format)); } } } }); horizontalPanel.add(textBox); horizontalPanel.add(dateHint); return horizontalPanel; }
private boolean isScenarioSimulatedDateSet() { return executionTrace.getScenarioSimulatedDate() != null; }
private boolean isResultNotNullAndHaveRulesFired() { return executionTrace.getExecutionTimeResult() != null && executionTrace.getNumberOfRulesFired() != null; }