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.guvnor.client.qa.testscenarios;
 
 import  com.gwtext.client.util.Format;
 import  org.drools.guvnor.client.common.ErrorPopup;
 import  org.drools.guvnor.client.common.SmallLabel;
 
 import java.util.Date;

Created by IntelliJ IDEA. User: nheron Date: 7 nov. 2009 Time: 19:32:35 To change this template use File | Settings | File Templates.
 
 public class ExecutionWidget extends Composite {
     private Constants constants = ((Constants) GWT.create(Constants.class));
 
     public ExecutionWidget(final ExecutionTrace extboolean showResults) {
 
 
     	final Widget dt = simulDate(ext);
     	dt.setVisible(ext.scenarioSimulatedDate != null);
 
     	final ListBox choice = new ListBox();
 
         choice.addItem(.UseRealDateAndTime());
     	choice.setSelectedIndex((ext.scenarioSimulatedDate == null) ? 0 : 1);
     	choice.addChangeListener(new ChangeListener() {
 			public void onChange(Widget w) {
 				if (choice.getSelectedIndex() == 0) {
 					dt.setVisiblefalse );
 					ext.scenarioSimulatedDate = null;
 				} else {
 					dt.setVisible(true);
 				}
 			}
 		});
 
     	HorizontalPanel p = new HorizontalPanel();
     	p.add(new Image("images/execution_trace.gif"));   //NON-NLS
     	p.add(choice);
     	p.add(dt);
 
     	VerticalPanel vert = new VerticalPanel();
     	if (showResults && ext.executionTimeResult != null
     			&& ext.numberOfRulesFired != null) {
             HTML rep = new HTML("<i><small>" + Format.format(.property0RulesFiredIn1Ms(), ext.numberOfRulesFired.toString(), ext.executionTimeResult.toString()) + "</small></i>");
 
 
     		final HorizontalPanel h = new HorizontalPanel();
     		h.add(rep);
     		vert.add(h);
 
     		final Button show = new Button(.ShowRulesFired());
     		show.addClickListener(new ClickListener() {
 				public void onClick(Widget w) {
 					ListBox rules = new ListBox(true);
 					for (int i = 0; i < ext.rulesFired.lengthi++) {
 						rules.addItem(ext.rulesFired[i]);
 					}
 					h.add(new SmallLabel("&nbsp:" + .RulesFired()));
 					h.add(rules);
 					show.setVisible(false);
 				}
     		});
     		h.add(show);
 
 
     		vert.add(p);
     		initWidget(vert);
     	} else {
     		initWidget(p);
     	}
     }
 
 
 
    private Widget simulDate(final ExecutionTrace ext) {
    	HorizontalPanel ab = new HorizontalPanel();
        final String fmt = "dd-MMM-YYYY"//NON-NLS
        final TextBox dt = new TextBox();
        if (ext.scenarioSimulatedDate == null) {
            dt.setText("<" + fmt + ">");
        } else {
            dt.setText(ext.scenarioSimulatedDate.toLocaleString());
        }
        final SmallLabel dateHint = new SmallLabel();
        dt.addKeyboardListener(new KeyboardListener() {
			public void onKeyDown(Widget arg0char arg1int arg2) {}
			public void onKeyPress(Widget arg0char arg1int arg2) {}
			public void onKeyUp(Widget wchar arg1int arg2) {
				try {
					Date d = new Date(dt.getText());
					dateHint.setText(d.toLocaleString());
catch (Exception e) {
					dateHint.setText("...");
				}
			}
        });
        dt.addChangeListener(new ChangeListener() {
            public void onChange(Widget w) {
                if (dt.getText().trim().equals("")) {
                    dt.setText(.currentDateAndTime());
                } else {
                    try {
                        Date d = new Date(dt.getText());
                        ext.scenarioSimulatedDate = d;
                        dt.setText(d.toLocaleString());
                        dateHint.setText("");
                    } catch (Exception e) {
                        ErrorPopup.showMessage(Format.format(.BadDateFormatPleaseTryAgainTryTheFormatOf0(), fmt));
                    }
                }
            }
        });
        ab.add(dt);
        ab.add(dateHint);
        return ab;
    }
New to GrepCode? Check out our FAQ X