Sunday, January 3, 2010

Eclipse : Tips - How to use PageBook for caching and dynamically displaying ui-controls ?

Lets consider the following scenario : If user selects a data type in a combo, then dynamically we need to display the control corresponding to the data-type.

dynamicallyShowDataTypeControl(PageBook dataTypePageBook, int dataType) {
Control currentPage = (Control) dataTypePageBook.getData(dataType);
if(currentPage == null){
currentPage = createValueControl(dataTypePageBook, dataType);
dataTypePageBook.setData(dataType, currentPage);
}
dataTypePageBook.showPage(currentPage);
}

createValueControl(PageBook dataTypePageBook, int dataType) {
switch (dataType) {
case BOOLEAN:
valueControl = new Button(dataTypePageBook, SWT.CHECK);
break;
case INTEGER:
valueControl = new Spinner(dataTypePageBook, SWT.ARROW_DOWN | SWT.BORDER);
break;
case STRING:
valueControl = new Text(dataTypePageBook, SWT.NONE);
break;
case PASSWORD:
valueControl = new Text(dataTypePageBook, SWT.PASSWORD);
break;
}
return valueControl;
}

No comments: