Created
July 12, 2010 16:32
-
-
Save lenards/472685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.iplantc.de.client.views.panels; | |
import org.iplantc.de.client.I18N; | |
import org.iplantc.de.client.formatters.AddQuotesFormatter; | |
import org.iplantc.de.client.metadata.property.Property; | |
import org.iplantc.de.client.utils.ComponentValueTable; | |
import org.iplantc.de.client.utils.ComponentValueTableValidator; | |
import org.iplantc.de.client.utils.ValidatorHelper; | |
import org.iplantc.de.client.validator.IPlantValidator; | |
import com.extjs.gxt.ui.client.event.BaseEvent; | |
import com.extjs.gxt.ui.client.event.Events; | |
import com.extjs.gxt.ui.client.event.Listener; | |
import com.extjs.gxt.ui.client.widget.Label; | |
import com.extjs.gxt.ui.client.widget.VerticalPanel; | |
import com.extjs.gxt.ui.client.widget.form.TextField; | |
public class ComplexMatePanel extends SimpleMatePanel | |
{ | |
private TextField<String> fldExpected; | |
private TextField<String> fldDeviant; | |
private IPlantValidator validatorExpected; | |
private IPlantValidator validatorDeviant; | |
private final static String expectedInnerDistanceId = "expectedInnerDistance"; | |
private final static String innerDistanceDeviationId = "innerDistanceStdDev"; | |
public ComplexMatePanel(Property property, ComponentValueTable tblComponentVals) | |
{ | |
super(property, tblComponentVals); | |
} | |
private TextField<String> buildTextField(String id, String value, IPlantValidator validator) | |
{ | |
TextField<String> ret = new TextField<String>(); | |
ret.setId(id); | |
ret.setValue(value); | |
ret.setWidth(54); | |
ret.setSelectOnFocus(true); | |
ret.setAllowBlank(false); | |
ret.setValidateOnBlur(true); | |
ret.setValidator(validator); | |
ret.addListener(Events.OnBlur, new Listener<BaseEvent>() | |
{ | |
public void handleEvent(final BaseEvent be) | |
{ | |
updateComponentValueTable(); | |
ComponentValueTableValidator.validate(tblComponentVals); | |
} | |
}); | |
return ret; | |
} | |
private VerticalPanel buildTextFieldPanel(String caption, TextField<String> field) | |
{ | |
VerticalPanel ret = new VerticalPanel(); | |
ret.add(new Label(caption)); | |
ret.add(field); | |
return ret; | |
} | |
@Override | |
protected void updateValidators(boolean enabled) | |
{ | |
super.updateValidators(enabled); | |
if(enabled) | |
{ | |
// set our validators if the user checks the 'has mate pair' checkbox | |
tblComponentVals.setValidator(expectedInnerDistanceId, validatorExpected); | |
tblComponentVals.setValidator(innerDistanceDeviationId, validatorDeviant); | |
} | |
else | |
{ | |
// if the user does not have a mate pair, we do not need to validate | |
tblComponentVals.clearValidator(expectedInnerDistanceId); | |
tblComponentVals.clearValidator(innerDistanceDeviationId); | |
} | |
} | |
@Override | |
protected void addSupportingComponentVals() | |
{ | |
super.addSupportingComponentVals(); | |
tblComponentVals.setValue(expectedInnerDistanceId, fldExpected.getValue()); | |
tblComponentVals.setFormatter(expectedInnerDistanceId, new AddQuotesFormatter()); | |
tblComponentVals.setValue(innerDistanceDeviationId, fldDeviant.getValue()); | |
tblComponentVals.setFormatter(innerDistanceDeviationId, new AddQuotesFormatter()); | |
} | |
@Override | |
protected void initInstanceVariables(final Property property) | |
{ | |
super.initInstanceVariables(property); | |
fldExpected = buildTextField(expectedInnerDistanceId, "200", validatorExpected); | |
fldDeviant = buildTextField(innerDistanceDeviationId, "10", validatorDeviant); | |
} | |
@Override | |
protected void composeMatePanel() | |
{ | |
VerticalPanel panelInner = new VerticalPanel(); | |
panelInner.setSpacing(5); | |
panelInner.addStyleName("accordianbody"); | |
panelInner.setSize(400, 180); | |
panelInner.add(new Label(I18N.DISPLAY.matePairSelection() + ":")); | |
panelInner.add(fileSelector); | |
panelInner.add(buildTextFieldPanel(I18N.DISPLAY.expectedInnerDistance() + ":", fldExpected)); | |
panelInner.add(buildTextFieldPanel(I18N.DISPLAY.expectedDistanceDeviation() + ":", fldDeviant)); | |
pnlMate.add(panelInner); | |
} | |
@Override | |
protected void initValidators() | |
{ | |
super.initValidators(); | |
String json = "{\"name\" : \"Expected inner distance field\", \"required\": true, \"rules\": [{\"IntAbove\" : [-1]}]}"; | |
validatorExpected = new IPlantValidator(ValidatorHelper.buildValidator(json)); | |
json = "{\"name\" : \"Inner distance deviation field\", \"required\": true, \"rules\": [{\"IntAbove\" : [-1]}]}"; | |
validatorDeviant = new IPlantValidator(ValidatorHelper.buildValidator(json)); | |
} | |
@Override | |
protected void updateComponentValueTable() | |
{ | |
super.updateComponentValueTable(); | |
tblComponentVals.setValue(expectedInnerDistanceId, fldExpected.getValue()); | |
tblComponentVals.setValue(innerDistanceDeviationId, fldDeviant.getValue()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment