View Javadoc

1   package org.whatsitcalled.webflange.webapp;
2   
3   import org.apache.wicket.validation.IValidatable;
4   import org.apache.wicket.validation.ValidationError;
5   import org.apache.wicket.validation.validator.StringValidator;
6   import org.whatsitcalled.webflange.ResourceFactory;
7   import org.whatsitcalled.webflange.model.LoadTest;
8   
9   public class TestNotEnabledValidator extends StringValidator {
10  	String message;
11  	Long testId;
12  
13  	public TestNotEnabledValidator(Long testId, String msg) {
14  		this.message = msg;
15  		this.testId = testId;
16  	}
17  
18  	@Override
19  	protected void onValidate(IValidatable val) {
20  		LoadTest test = ResourceFactory.getLoadTestService()
21  				.getLoadTest(testId);
22  		if (test == null) {
23  			ValidationError error = new ValidationError();
24  			error.setMessage("There is nothing to action on");
25  			val.error(error);
26  			return;
27  		}
28  		if (test.getEnabled() || test.getRunning()) {
29  			ValidationError error = new ValidationError();
30  			error.setMessage(message);
31  			val.error(error);
32  		}
33  	}
34  
35  }