/**
*
*/
package org.mbhcare.client.ui;
import org.mbhcare.client.event.DiagnosisEventBus;
import org.mbhcare.client.i18n.DiagnosisConstants;
import org.mbhcare.shared.entity.DiagnosisDescription;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
/**
* @author MCOSTA
*
*/
public class DiagnosisPanel extends Composite implements HasValue<DiagnosisDescription> {
//@UiTemplate("DiagnosisPanel.ui.xml")
interface uiBinder extends UiBinder<Widget, DiagnosisPanel> {}
private static uiBinder uiBinder = GWT.create(uiBinder.class);
@UiField Label title;
@UiField CheckBox state;
@UiField Label statelabel;
@UiField TextArea description;
private DiagnosisConstants constants = DiagnosisEventBus.getConstants();
private String checkedLabel = "";
private String uncheckedLabel = "";
private String checkedDescription = "";
private String uncheckedDescription = "";
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.UIObject#setVisible(boolean)
*/
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
}
@Override
public void setTitle(String title){
super.setTitle(title);
this.title.setText(title);
}
/**
*
*/
public DiagnosisPanel() {
initWidget(uiBinder.createAndBindUi(this));
checkedLabel = constants.formNormalState();
uncheckedLabel = constants.formAbnormalState();
uncheckedDescription = "";
}
public void setState(Boolean state){
this.state.setValue(state);
changeText();
}
@UiHandler("state")
protected void stateClicked(ClickEvent event) {
changeText();
}
@UiHandler("state")
protected void stateValueChanged(ValueChangeEvent<Boolean> event) {
changeText();
}
private void changeText(){
if (state.getValue()){
this.statelabel.setText(checkedLabel);
this.description.setText(checkedDescription);
}
else {
this.statelabel.setText(uncheckedLabel);
this.description.setText(uncheckedDescription);
}
}
public Boolean getState(){
return this.state.getValue();
}
public void setCheckedlabel(String text){
checkedLabel = text;
}
public void setUncheckedlabel(String text){
uncheckedLabel = text;
}
public void setDescription(String description){
this.description.setValue(description);
}
public void setVisibledescription(Boolean visible){
this.description.setVisible(visible);
}
public String getDescription(){
return this.description.getValue();
}
public void setCheckeddescription(String text){
checkedDescription = text;
}
public void setUncheckeddescription(String text){
uncheckedDescription = text;
}
@Override
public DiagnosisDescription getValue() {
// TODO Auto-generated method stub
return new DiagnosisDescription(state.getValue(), description.getText());
}
@Override
public void setValue(DiagnosisDescription value) {
// TODO Auto-generated method stub
state.setValue(value.getState());
changeText();
description.setText(value.getDescription());
}
public void setDescheight(String height) {
description.setHeight(height);
}
@Override
public void setValue(DiagnosisDescription value, boolean fireEvents) {
// TODO Auto-generated method stub
state.setValue(value.getState());
changeText();
description.setText(value.getDescription());
}
@Override
public HandlerRegistration addValueChangeHandler(
ValueChangeHandler<DiagnosisDescription> handler) {
// TODO Auto-generated method stub
return null;
}
}