Knowledge Base Nr: 00330 DialogBoxSelectItem.java - http://www.swe-kaiser.de

Java: GWT: modale dialogbox für auswahl

  
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.VerticalPanel;

public class CDialogBoxSelectItem extends DialogBox
{
ListBox m_lbItem = new ListBox();
PushButton m_btnOK = new PushButton();
PushButton m_btnCancel = new PushButton();

String m_strBtnOkCaption = "Ok";
String m_strBtnCancelCaption = "Abbrechen";
String m_strDialogText = "";

int getItemIndex()
{
int i = m_lbItem.getSelectedIndex();
return i;
}

String getItem()
{
int i = m_lbItem.getSelectedIndex();
if (i<0)
return "";
return m_lbItem.getItemText(i);
}

CDialogBoxSelectItem(String strDialogText,String strOkBtnCaption,String strCancelBtnCaption, String[] strItem, ClickHandler chButtonClickHandler)
{
setText(strDialogText);

// Enable animation.
setAnimationEnabled(true);

// Enable glass background.
setGlassEnabled(true);

m_btnOK.setText(strOkBtnCaption);
m_btnCancel.setText(strCancelBtnCaption);

m_lbItem.clear();
for (int n=0; n < strItem.length; n++)
m_lbItem.addItem(strItem[n]);

// Click-Handler verdrahten
m_btnOK.addClickHandler(chButtonClickHandler);
m_btnCancel.addClickHandler(chButtonClickHandler);

VerticalPanel vp = new VerticalPanel();
vp.add(m_lbItem);

HorizontalPanel hp = new HorizontalPanel();
hp.setStyleName(".ync-dialog-buttons");
hp.add(m_btnOK);
hp.add(m_btnCancel);

vp.add(hp);
setWidget(vp);
}
}