mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support EditorTextField
This commit is contained in:
@@ -18,6 +18,7 @@ package com.intellij.openapi.options.binding;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -45,7 +46,11 @@ public class ControlBinder {
|
||||
}
|
||||
else if (control instanceof JTextField){
|
||||
controlAccessor = ValueAccessor.textFieldAccessor((JTextField)control);
|
||||
} else {
|
||||
}
|
||||
else if (control instanceof EditorTextField) {
|
||||
controlAccessor = ValueAccessor.editorTextFieldAccessor((EditorTextField)control);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Cannot bind control of type " + control.getClass() + ".\n" +
|
||||
"Use bindControl(ControlValueAccessor, String) instead.");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
package com.intellij.openapi.options.binding;
|
||||
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -53,6 +55,40 @@ public abstract class ValueAccessor<V> {
|
||||
};
|
||||
}
|
||||
|
||||
public static ControlValueAccessor editorTextFieldAccessor(final EditorTextField from) {
|
||||
return new ControlValueAccessor<String>() {
|
||||
@Override
|
||||
public String getValue() {
|
||||
return from.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
from.setText(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<String> getType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return from.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChangeListener(final Runnable listener) {
|
||||
from.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void documentChanged(@NotNull com.intellij.openapi.editor.event.DocumentEvent event) {
|
||||
listener.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ControlValueAccessor checkBoxAccessor(final JCheckBox from) {
|
||||
return new ControlValueAccessor<Boolean>() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user