mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[249478] [preferences] Improve validation feedback in DSF preference page
This commit is contained in:
parent
81d3982175
commit
d48e11698b
5 changed files with 217 additions and 7 deletions
|
@ -0,0 +1,95 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.dd.dsf.debug.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.fieldassist.ControlDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
|
||||
import org.eclipse.jface.preference.IntegerFieldEditor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.FocusAdapter;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* An {@link IntegerFieldEditor} with field decoration.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public class DecoratingIntegerFieldEditor extends IntegerFieldEditor {
|
||||
|
||||
private ControlDecoration fDecoration;
|
||||
|
||||
protected DecoratingIntegerFieldEditor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an integer field editor.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param parent the parent of the field editor's control
|
||||
*/
|
||||
public DecoratingIntegerFieldEditor(String name, String labelText, Composite parent) {
|
||||
super(name, labelText, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an integer field editor.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param parent the parent of the field editor's control
|
||||
* @param textLimit the maximum number of characters in the text.
|
||||
*/
|
||||
public DecoratingIntegerFieldEditor(String name, String labelText, Composite parent, int textLimit) {
|
||||
super(name, labelText, parent, textLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getTextControl(Composite parent) {
|
||||
Text control = super.getTextControl(parent);
|
||||
if (fDecoration == null) {
|
||||
fDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
|
||||
FieldDecoration errorDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
|
||||
fDecoration.setImage(errorDecoration.getImage());
|
||||
fDecoration.setDescriptionText(getErrorMessage());
|
||||
|
||||
// validate on focus gain
|
||||
control.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
refreshValidState();
|
||||
}
|
||||
});
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showErrorMessage(String msg) {
|
||||
super.showErrorMessage(msg);
|
||||
if (fDecoration != null) {
|
||||
fDecoration.setDescriptionText(msg);
|
||||
fDecoration.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearErrorMessage() {
|
||||
super.clearErrorMessage();
|
||||
if (fDecoration != null) {
|
||||
fDecoration.hide();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.dd.dsf.debug.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.fieldassist.ControlDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecoration;
|
||||
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
|
||||
import org.eclipse.jface.preference.StringFieldEditor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.FocusAdapter;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* A {@link StringFieldEditor} with field decoration.
|
||||
* @since 1.1
|
||||
*/
|
||||
public class DecoratingStringFieldEditor extends StringFieldEditor {
|
||||
|
||||
private ControlDecoration fDecoration;
|
||||
|
||||
protected DecoratingStringFieldEditor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string field editor of unlimited width.
|
||||
* Use the method <code>setTextLimit</code> to limit the text.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param parent the parent of the field editor's control
|
||||
*/
|
||||
public DecoratingStringFieldEditor(String name, String labelText, Composite parent) {
|
||||
super(name, labelText, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string field editor.
|
||||
* Use the method <code>setTextLimit</code> to limit the text.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param width the width of the text input field in characters,
|
||||
* or <code>UNLIMITED</code> for no limit
|
||||
* @param parent the parent of the field editor's control
|
||||
*/
|
||||
public DecoratingStringFieldEditor(String name, String labelText, int width, Composite parent) {
|
||||
super(name, labelText, width, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string field editor.
|
||||
* Use the method <code>setTextLimit</code> to limit the text.
|
||||
*
|
||||
* @param name the name of the preference this field editor works on
|
||||
* @param labelText the label text of the field editor
|
||||
* @param width the width of the text input field in characters,
|
||||
* or <code>UNLIMITED</code> for no limit
|
||||
* @param strategy either <code>VALIDATE_ON_KEY_STROKE</code> to perform
|
||||
* on the fly checking (the default), or <code>VALIDATE_ON_FOCUS_LOST</code> to
|
||||
* perform validation only after the text has been typed in
|
||||
* @param parent the parent of the field editor's control
|
||||
*/
|
||||
public DecoratingStringFieldEditor(String name, String labelText, int width, int strategy, Composite parent) {
|
||||
super(name, labelText, width, strategy, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getTextControl(Composite parent) {
|
||||
Text control = super.getTextControl(parent);
|
||||
if (fDecoration == null) {
|
||||
fDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
|
||||
FieldDecoration errorDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
|
||||
fDecoration.setImage(errorDecoration.getImage());
|
||||
fDecoration.setDescriptionText(getErrorMessage());
|
||||
|
||||
// validate on focus gain
|
||||
control.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
refreshValidState();
|
||||
}
|
||||
});
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showErrorMessage(String msg) {
|
||||
super.showErrorMessage(msg);
|
||||
if (fDecoration != null) {
|
||||
fDecoration.setDescriptionText(msg);
|
||||
fDecoration.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clearErrorMessage() {
|
||||
super.clearErrorMessage();
|
||||
if (fDecoration != null) {
|
||||
fDecoration.hide();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.eclipse.jface.preference.BooleanFieldEditor;
|
|||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.IntegerFieldEditor;
|
||||
import org.eclipse.jface.preference.StringFieldEditor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
|
@ -73,6 +74,7 @@ public class DsfDebugPreferencePage extends FieldEditorPreferencePage implements
|
|||
performanceGroup);
|
||||
|
||||
limitEditor.setValidRange(1, Integer.MAX_VALUE);
|
||||
limitEditor.setValidateStrategy(StringFieldEditor.VALIDATE_ON_FOCUS_LOST);
|
||||
limitEditor.fillIntoGrid(performanceGroup, 3);
|
||||
addField(limitEditor);
|
||||
|
||||
|
@ -86,7 +88,7 @@ public class DsfDebugPreferencePage extends FieldEditorPreferencePage implements
|
|||
addField(syncSteppingEditor);
|
||||
|
||||
// minimum step interval
|
||||
IntegerFieldEditor minIntervalEditor= new IntegerFieldEditor(
|
||||
IntegerFieldEditor minIntervalEditor= new DecoratingIntegerFieldEditor(
|
||||
IDsfDebugUIConstants.PREF_MIN_STEP_INTERVAL,
|
||||
MessagesForPreferences.DsfDebugPreferencePage_minStepInterval_label,
|
||||
performanceGroup);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.dd.dsf.debug.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.preference.IntegerFieldEditor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
|
@ -22,7 +21,7 @@ import org.eclipse.swt.widgets.Label;
|
|||
/**
|
||||
* An integer field editor with an enablement check box.
|
||||
*/
|
||||
public class IntegerWithBooleanFieldEditor extends IntegerFieldEditor {
|
||||
public class IntegerWithBooleanFieldEditor extends DecoratingIntegerFieldEditor {
|
||||
|
||||
private final String fEnableKey;
|
||||
private Button fCheckbox;
|
||||
|
@ -83,8 +82,8 @@ public class IntegerWithBooleanFieldEditor extends IntegerFieldEditor {
|
|||
}
|
||||
|
||||
protected void valueChanged(boolean oldValue, boolean newValue) {
|
||||
setPresentsDefaultValue(false);
|
||||
if (oldValue != newValue) {
|
||||
valueChanged();
|
||||
fireStateChanged(VALUE, oldValue, newValue);
|
||||
getTextControl().setEnabled(newValue);
|
||||
getLabelControl().setEnabled(newValue);
|
||||
|
@ -94,6 +93,7 @@ public class IntegerWithBooleanFieldEditor extends IntegerFieldEditor {
|
|||
@Override
|
||||
protected boolean checkState() {
|
||||
if (fCheckbox != null && !fCheckbox.getSelection()) {
|
||||
clearErrorMessage();
|
||||
return true;
|
||||
}
|
||||
return super.checkState();
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.dd.dsf.debug.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.preference.StringFieldEditor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
|
@ -22,7 +21,7 @@ import org.eclipse.swt.widgets.Label;
|
|||
/**
|
||||
* A string field editor with an enablement check box.
|
||||
*/
|
||||
public class StringWithBooleanFieldEditor extends StringFieldEditor {
|
||||
public class StringWithBooleanFieldEditor extends DecoratingStringFieldEditor {
|
||||
|
||||
private final String fEnableKey;
|
||||
private Button fCheckbox;
|
||||
|
@ -88,8 +87,8 @@ public class StringWithBooleanFieldEditor extends StringFieldEditor {
|
|||
}
|
||||
|
||||
protected void valueChanged(boolean oldValue, boolean newValue) {
|
||||
setPresentsDefaultValue(false);
|
||||
if (oldValue != newValue) {
|
||||
valueChanged();
|
||||
fireStateChanged(VALUE, oldValue, newValue);
|
||||
getTextControl().setEnabled(newValue);
|
||||
getLabelControl().setEnabled(newValue);
|
||||
|
@ -99,6 +98,7 @@ public class StringWithBooleanFieldEditor extends StringFieldEditor {
|
|||
@Override
|
||||
protected boolean checkState() {
|
||||
if (fCheckbox != null && !fCheckbox.getSelection()) {
|
||||
clearErrorMessage();
|
||||
return true;
|
||||
}
|
||||
return super.checkState();
|
||||
|
|
Loading…
Add table
Reference in a new issue