layout.maxNumColumns = MAX_COLS;
layout.minNumColumns = MIN_COLS;
form.getBody().setLayout(layout);
toolkit.decorateFormHeading(form.getForm());
final Section section = toolkit.createSection(form.getBody(), SECTION_STYLE);
section.setText("Country Details");
section.setDescription("Update country details below.");
section.addExpansionListener(new ExpansionAdapter(){
public void expansionStateChanged( ExpansionEvent e ) {
// Nothing
}
});
final Composite client = toolkit.createComposite(section, SWT.NONE);
GridLayout sectionLayout = new GridLayout();
sectionLayout.numColumns = 4;
client.setLayout(sectionLayout);
section.setClient(client);
// SWT Widgets
Label label = toolkit.createLabel(client, NAME_FORMA_LBL, LABEL_STYLE);
FormTextCellEditor nameFormalEditor = new FormTextCellEditor(client, form.getMessageManager());
nameFormal = (Text) nameFormalEditor.getControl();
nameFormal.setData(NAME_FORMA_LBL);
nameFormal.addKeyListener(this);
GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 3;
nameFormal.setLayoutData(layoutData);
label = toolkit.createLabel(client, NAME_SORT_LBL, LABEL_STYLE);
FormTextCellEditor nameSortEditor = new FormTextCellEditor(client, form.getMessageManager());
nameSort = (Text) nameSortEditor.getControl();
nameSort.setData(NAME_SORT_LBL);
nameSort.addKeyListener(this);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 3;
nameSort.setLayoutData(layoutData);
label = toolkit.createLabel(client, POP_EST_LBL, LABEL_STYLE);
FormTextCellEditor populationEditor = new FormTextCellEditor(client, form.getMessageManager());
population = (Text) populationEditor.getControl();
population.setData(POP_EST_LBL);
population.addKeyListener(this);
layoutData = new GridData(GridData.FILL_HORIZONTAL);
layoutData.horizontalSpan = 3;
population.setLayoutData(layoutData);
label = toolkit.createLabel(client, TYPE_LBL, LABEL_STYLE);
FormComboBoxCellEditor typeEditor = new FormComboBoxCellEditor(client, TYPE_OPTS, form.getMessageManager());
type = (CCombo) typeEditor.getControl();
type.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected( SelectionEvent e ) {
setEnabled(true);
}
});
layoutData = new GridData();
layoutData.horizontalSpan = 3;
type.setLayoutData(layoutData);
// JFace Viewer
label = toolkit.createLabel(client, COLOR_MAP_LBL, LABEL_STYLE);
FormComboBoxCellEditor colorEditor = new FormComboBoxCellEditor(client, new String[]{}, form.getMessageManager());
CCombo colorCombo = (CCombo) colorEditor.getControl();
colorMap = new ComboViewer(colorCombo);
colorMap.addSelectionChangedListener(this);
layoutData = new GridData();
layoutData.horizontalSpan = 3;
colorMap.getControl().setLayoutData(layoutData);
// hook up to data
colorMap.setContentProvider(new IStructuredContentProvider(){
public Object[] getElements( Object inputElement ) {
if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
}
return null;
}
public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) {
// For dynamic content we would register listeners here
}
public void dispose() {
// Nothing
}
});
colorMap.setLabelProvider(new LabelProvider(){
public String getText( Object element ) {
return " " + element + " color";
}
});
colorMap.setInput(COLOR_MAP_OPTS);
// Other sample section - to try out ColumnLayout
final Section sectionOther = toolkit.createSection(form.getBody(), SECTION_STYLE);
sectionOther.setText("Others");
sectionOther
.setDescription("Sample section to demo ColumnLayout, make the view width smaller to force it to relayout.");
sectionOther.addExpansionListener(new ExpansionAdapter(){
public void expansionStateChanged( ExpansionEvent e ) {
// Nothing
}
});
final Composite clientOther = toolkit.createComposite(sectionOther, SWT.NONE);
sectionLayout = new GridLayout();
sectionLayout.numColumns = 4;
clientOther.setLayout(sectionLayout);
sectionOther.setClient(clientOther);
Label remarksLbl = toolkit.createLabel(clientOther, REMARKS_LBL, LABEL_STYLE);
FormTextCellEditor remarksEditor = new FormTextCellEditor(clientOther, form.getMessageManager());
Text remarks = (Text) remarksEditor.getControl();
remarks.setData(REMARKS_LBL);