/* * @see Dialog#okPressed() */ @Override protected void okPressed() { chartTitle = chartTitleText.getText(); AxisUnit[] values = AxisUnit.values(); int selectionIndex = axisUnitCombo.getSelectionIndex(); if (selectionIndex < values.length) { unit = values[selectionIndex]; } super.okPressed(); }
/** * Creates the controls for chart configuration. * * @param parent The parent composite */ private void createChartConfigControls(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NONE).setText(Messages.chartTitleLabel); chartTitleText = new Text(composite, SWT.BORDER); chartTitleText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); chartTitleText.setText(chartTitle); chartTitleText.setSelection(0, chartTitle.length()); chartTitleText.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { validate(chartTitleText.getText()); } }); new Label(composite, SWT.NONE).setText(Messages.yAxisUnitLabel); axisUnitCombo = new Combo(composite, SWT.READ_ONLY); List<String> items = new ArrayList<String>(); int initialSelection = -1; AxisUnit[] values = AxisUnit.values(); for (int i = 0; i < values.length; i++) { items.add(values[i].name()); if (values[i] == unit) { initialSelection = i; } } axisUnitCombo.setItems(items.toArray(new String[items.size()])); if (initialSelection == -1) { initialSelection = items.size() - 1; } axisUnitCombo.select(initialSelection); axisUnitCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); }