Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.workbench.screens.testscenario.client;
 
 import java.util.Date;
 
 
 public class ExecutionWidget extends Composite {
 
     private final ExecutionTrace executionTrace;
 
     public ExecutionWidget(final ExecutionTrace executionTrace,
                            boolean showResults) {
 
         this. = executionTrace;
 
         final HorizontalPanel simulDatePanel = simulDate();
         simulDatePanel.setVisibleisScenarioSimulatedDateSet() );
 
         final ListBox choice = new ListBox();
 
         choice.setSelectedIndex( (executionTrace.getScenarioSimulatedDate() == null) ? 0 : 1 );
         choice.addChangeHandlernew ChangeHandler() {
 
             public void onChange(ChangeEvent event) {
                 if ( choice.getSelectedIndex() == 0 ) {
                     simulDatePanel.setVisiblefalse );
                     executionTrace.setScenarioSimulatedDatenull );
                 } else {
                     simulDatePanel.setVisibletrue );
                 }
             }
         } );
 
         HorizontalPanel layout = new HorizontalPanel();
         layout.addnew Image..executionTrace() ) );
         layout.addchoice );
         layout.addsimulDatePanel );
 
         if ( showResults && isResultNotNullAndHaveRulesFired() ) {
             VerticalPanel replacingLayout = new VerticalPanel();
 
             replacingLayout.addnew FiredRulesPanelexecutionTrace ) );
             replacingLayout.addlayout );
             initWidgetreplacingLayout );
         } else {
             initWidgetlayout );
         }
     }
 
     private boolean isResultNotNullAndHaveRulesFired() {
         return .getExecutionTimeResult() != null && .getNumberOfRulesFired() != null;
     }
 
     private boolean isScenarioSimulatedDateSet() {
         return .getScenarioSimulatedDate() != null;
     }
 
     private HorizontalPanel simulDate() {
         HorizontalPanel horizontalPanel = new HorizontalPanel();
         final String format = "yyyy-MM-dd HH:mm"//NON-NLS
         final TextBox textBox = new TextBox();
         if ( .getScenarioSimulatedDate() == null ) {
             textBox.setText"<" + format + ">" );
         } else {
         }
        final SmallLabel dateHint = new SmallLabel();
        textBox.addKeyUpHandlernew KeyUpHandler() {
            public void onKeyUp(KeyUpEvent event) {
                try {
                    String exampleDate = DateTimeFormat.getFormat(..).format(new Date());
                    String suggestedDate = textBox.getText() + exampleDate.substring(textBox.getText().length());
                    Date d = DateTimeFormat.getFormat(..).parse(suggestedDate);
                    dateHint.setText( DateTimeFormat.getFormat(..).format(d) );
                } catch ( Exception e ) {
                    dateHint.setText"..."  );
                }
            }
        } );
        textBox.addChangeHandlernew ChangeHandler() {
            public void onChange(ChangeEvent event) {
                if ( textBox.getText().trim().equals"" ) ) {
                    textBox.setText..currentDateAndTime() );
                } else {
                    try {
                        //Date d1 = new Date();
                        Date d = DateTimeFormat.getFormat(..).parse(textBox.getText());
                        .setScenarioSimulatedDated );
                        textBox.setText( DateTimeFormat.getFormat(..).format(d) );
                        dateHint.setText"" );
                    } catch ( Exception e ) {
                        ErrorPopup.showMessage(..BadDateFormatPleaseTryAgainTryTheFormatOf0(format));
                    }
                }
            }
        } );
        horizontalPanel.addtextBox );
        horizontalPanel.adddateHint );
        return horizontalPanel;
    }
New to GrepCode? Check out our FAQ X