package net.helipilot50.stocktrade.client;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Status;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.FieldEvent;
public class PropertiesDialog extends Dialog {
private TextField<String> txtfldHost;
private NumberField nmbrfldPort;
private Status status;
private Button reload;
private String hostName = "127.0.0.1";
private int port = 3000;
public PropertiesDialog() {
setHideOnButtonClick(true);
setHeading("Aerospike Cluster properties");
setButtons(Dialog.OKCANCEL);
setLayout(new FormLayout());
this.txtfldHost = new TextField<String>();
this.txtfldHost.addListener(Events.Change, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent e) {
hostName = txtfldHost.getValue();
}
});
add(this.txtfldHost, new FormData("100%"));
this.txtfldHost.setFieldLabel("Host");
this.nmbrfldPort = new NumberField();
this.nmbrfldPort.addListener(Events.Change, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent e) {
port = (Integer) nmbrfldPort.getValue();
}
});
add(this.nmbrfldPort, new FormData("100%"));
this.nmbrfldPort.setFieldLabel("Port");
}
@Override
protected void createButtons() {
super.createButtons();
status = new Status();
status.setBusy("please wait...");
status.hide();
status.setAutoWidth(true);
getButtonBar().add(status);
getButtonBar().add(new FillToolItem());
reload = new Button("Reload data");
reload.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
CustomerServiceAsync customerSO = Registry.get("CustomerService");
customerSO.reloadData(new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
Info.display("Success", "Data reloaded");
}
@Override
public void onFailure(Throwable caught) {
MessageBox.alert("Reload data failed", caught.getMessage(), null);
}
});
}
});
addButton(reload);
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
this.txtfldHost.setValue(this.hostName);
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
this.nmbrfldPort.setValue(this.port);
}
public String getHostString() {
return hostName + ":" + port;
}
}