Control[] addCombo(Composite composite, final Preference preference, final EnumeratedDomain domain, int indentation) { Label labelControl= new Label(composite, SWT.NONE); labelControl.setText(preference.getName()); GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= indentation; labelControl.setLayoutData(gd); final Combo combo= new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); combo.setLayoutData(gd); combo.setToolTipText(preference.getDescription()); for (Iterator it= domain.fItems.iterator(); it.hasNext();) { EnumValue value= (EnumValue) it.next(); combo.add(value.getLabel()); } combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int index= combo.getSelectionIndex(); EnumValue value= domain.getValueByIndex(index); IStatus status= domain.validate(value); if (!status.matches(IStatus.ERROR)) fOverlayStore.setValue(preference.getKey(), value.getIntValue()); updateStatus(status); } }); fInitializers.add(fInitializerFactory.create(preference, combo, domain)); return new Control[] {labelControl, combo}; }
Control[] addCombo(Composite composite, final Preference preference, final EnumeratedDomain domain, int indentation) { Label labelControl= new Label(composite, SWT.NONE); labelControl.setText(preference.getName()); GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalIndent= indentation; labelControl.setLayoutData(gd); final Combo combo= new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); combo.setLayoutData(gd); combo.setToolTipText(preference.getDescription()); for (Iterator<EnumValue> it= domain.fItems.iterator(); it.hasNext();) { EnumValue value= it.next(); combo.add(value.getLabel()); } combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int index= combo.getSelectionIndex(); EnumValue value= domain.getValueByIndex(index); IStatus status= domain.validate(value); if (!status.matches(IStatus.ERROR)) fOverlayStore.setValue(preference.getKey(), value.getIntValue()); updateStatus(status); } }); fInitializers.add(fInitializerFactory.create(preference, combo, domain)); return new Control[] {labelControl, combo}; }
public IStatus validate(Object value) { StatusInfo status= new StatusInfo(); if (value instanceof String && ((String)value).length() == 0) { status.setError(TextEditorMessages.TextEditorPreferencePage_emptyInput); return status; } try { EnumValue e= parseEnumValue(value); if (!fValueSet.contains(e)) status.setError(NLSUtility.format(TextEditorMessages.TextEditorPreferencePage_invalidRange, new String[] {getValueByIndex(0).getLabel(), getValueByIndex(fItems.size() - 1).getLabel()})); } catch (NumberFormatException e) { status.setError(NLSUtility.format(TextEditorMessages.TextEditorPreferencePage_invalidInput, String.valueOf(value))); } return status; }
@Override public IStatus validate(Object value) { StatusInfo status= new StatusInfo(); if (value instanceof String && ((String)value).length() == 0) { status.setError(TextEditorMessages.TextEditorPreferencePage_emptyInput); return status; } try { EnumValue e= parseEnumValue(value); if (!fValueSet.contains(e)) status.setError(NLSUtility.format(TextEditorMessages.TextEditorPreferencePage_invalidRange, new String[] {getValueByIndex(0).getLabel(), getValueByIndex(fItems.size() - 1).getLabel()})); } catch (NumberFormatException e) { status.setError(NLSUtility.format(TextEditorMessages.TextEditorPreferencePage_invalidInput, String.valueOf(value))); } return status; }