Removed deprecated package com.intellij.openapi.options.binding

GitOrigin-RevId: cf4b7afc477c2472d90b7e5ec297df4a7c8f6985
This commit is contained in:
Pavel Porvatov
2025-07-16 13:08:22 +00:00
committed by intellij-monorepo-bot
parent ad2fe6a446
commit a8ec525d64
7 changed files with 3 additions and 524 deletions
@@ -1,103 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.options.binding;
import org.jetbrains.annotations.ApiStatus;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
/**
* @author Dmitry Avdeev
*
* @deprecated Use Kotlin UI DSL with bindings
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public abstract class BeanValueAccessor extends ValueAccessor {
public static BeanValueAccessor createAccessor(Object bean, final String propertyName) {
Field[] fields = bean.getClass().getFields();
for (final Field field : fields) {
if (field.getName().equals(propertyName)) {
return new BeanValueAccessor(bean, propertyName) {
@Override
protected Object doGetValue() throws IllegalAccessException {
return field.get(myBean);
}
@Override
protected void doSetValue(Object value) throws IllegalAccessException {
field.set(myBean, value);
}
@Override
public Class getType() {
return field.getType();
}
};
}
}
try {
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
for (final PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
if (descriptor.getName().equals(propertyName)) {
return new BeanValueAccessor(bean, propertyName) {
@Override
protected Object doGetValue() throws Exception {
return descriptor.getReadMethod().invoke(myBean);
}
@Override
protected void doSetValue(Object value) throws Exception {
descriptor.getWriteMethod().invoke(myBean, value);
}
@Override
public Class getType() {
return descriptor.getPropertyType();
}
};
}
}
throw new IllegalArgumentException("Property " + propertyName + " not found in " + bean.getClass());
}
catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
protected final Object myBean;
protected final String myPropertyName;
public BeanValueAccessor(Object bean, String propertyName) {
myBean = bean;
myPropertyName = propertyName;
}
@Override
public Object getValue() {
try {
return doGetValue();
}
catch (Exception e) {
throw new RuntimeException("Cannot access property " + myPropertyName, e);
}
}
@Override
public void setValue(Object value) {
try {
doSetValue(value);
}
catch (Exception e) {
throw new RuntimeException("Cannot access property " + myPropertyName, e);
}
}
protected abstract Object doGetValue() throws Exception;
protected abstract void doSetValue(Object value) throws Exception;
}
@@ -1,38 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.options.binding;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Dmitry Avdeev
*
* @deprecated Use Kotlin UI DSL with bindings
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public @interface BindControl {
@NonNls String value() default "";
boolean instant() default false;
}
@@ -1,154 +0,0 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.options.binding;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.ui.EditorTextField;
import org.jetbrains.annotations.ApiStatus;
import javax.swing.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* @author Dmitry Avdeev
*
* @deprecated Use {@see com.intellij.openapi.options.BoundConfigurable} instead
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public final class ControlBinder {
private static final Logger LOG = Logger.getInstance(ControlBinder.class);
private final Object myBean;
private final List<Pair<ControlValueAccessor, BeanValueAccessor>> myBindings = new ArrayList<>();
public ControlBinder(Object bean) {
myBean = bean;
}
public void bindControl(JComponent control, String propertyName, boolean instant) {
final ControlValueAccessor controlAccessor;
if (control instanceof JCheckBox) {
controlAccessor = ValueAccessor.checkBoxAccessor((JCheckBox)control);
}
else if (control instanceof JTextField){
controlAccessor = ValueAccessor.textFieldAccessor((JTextField)control);
}
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.");
}
bindControl(controlAccessor, propertyName, instant);
}
public synchronized void bindControl(ControlValueAccessor controlAccessor, String propertyName, boolean instant) {
BeanValueAccessor beanAccessor = BeanValueAccessor.createAccessor(myBean, propertyName);
final Pair<ControlValueAccessor, BeanValueAccessor> binding = Pair.create(controlAccessor, beanAccessor);
myBindings.add(binding);
if (instant) {
controlAccessor.addChangeListener(() -> apply(binding));
}
}
public synchronized void reset() {
for (Pair<ControlValueAccessor, BeanValueAccessor> binding : myBindings) {
if (!binding.first.isEnabled()) {
continue;
}
Object value = binding.second.getValue();
try {
value = convert(value, binding.first.getType());
binding.first.setValue(value);
}
catch (IllegalArgumentException e) {
LOG.debug(e);
}
}
}
public synchronized void apply() {
for (Pair<ControlValueAccessor, BeanValueAccessor> binding : myBindings) {
apply(binding);
}
}
private static void apply(Pair<ControlValueAccessor, BeanValueAccessor> binding) {
if (!binding.first.isEnabled()) {
return;
}
Object value = binding.first.getValue();
try {
value = convert(value, binding.second.getType());
binding.second.setValue(value);
}
catch (IllegalArgumentException e) {
LOG.debug(e);
}
}
public synchronized boolean isModified() {
for (Pair<ControlValueAccessor, BeanValueAccessor> binding : myBindings) {
if (!binding.first.isEnabled()) {
continue;
}
Object value = binding.first.getValue();
try {
value = convert(value, binding.second.getType());
if (!value.equals(binding.second.getValue())) {
return true;
}
}
catch (IllegalArgumentException e) {
LOG.debug(e);
}
}
return false;
}
private static Object convert(Object value, Class to) {
Class from = value.getClass();
if (!to.isAssignableFrom(from)) {
if (to.isPrimitive()) {
if (to.equals(Integer.TYPE)) {
to = Integer.class;
}
}
for (ValueTypeConverter converter : ValueTypeConverter.STANDARD) {
if (from.equals(converter.getSourceType()) && to.equals(converter.getTargetType())) {
return converter.from(value);
}
if (to.equals(converter.getSourceType()) && from.equals(converter.getTargetType())) {
return converter.to(value);
}
}
}
return value;
}
public void bindAnnotations(Object form) {
Field[] fields = form.getClass().getDeclaredFields();
for (Field field : fields) {
BindControl annotation = field.getAnnotation(BindControl.class);
if (annotation != null) {
String name = annotation.value();
if (name.isEmpty()) {
name = field.getName();
}
try {
field.setAccessible(true);
bindControl((JComponent)field.get(form), name, annotation.instant());
}
catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}
}
@@ -1,31 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.options.binding;
import org.jetbrains.annotations.ApiStatus;
/**
* @author Dmitry Avdeev
*
* @deprecated Use Kotlin UI DSL with bindings
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public abstract class ControlValueAccessor<V> extends ValueAccessor<V> {
public abstract boolean isEnabled();
public abstract void addChangeListener(Runnable listener);
}
@@ -1,132 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
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.ApiStatus;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author Dmitry Avdeev
*
* @deprecated Use Kotlin UI DSL with bindings
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public abstract class ValueAccessor<V> {
public abstract V getValue();
public abstract void setValue(V value);
public abstract Class<V> getType();
public static ControlValueAccessor textFieldAccessor(final JTextField 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 DocumentAdapter() {
@Override
protected void textChanged(@NotNull DocumentEvent e) {
listener.run();
}
});
}
};
}
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>() {
@Override
public Boolean getValue() {
return from.isSelected();
}
@Override
public void setValue(Boolean value) {
from.setSelected(value.booleanValue());
}
@Override
public Class<Boolean> getType() {
return Boolean.class;
}
@Override
public boolean isEnabled() {
return from.isEnabled();
}
@Override
public void addChangeListener(final Runnable listener) {
from.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.run();
}
});
}
};
}
}
@@ -1,60 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.options.binding;
import org.jetbrains.annotations.ApiStatus;
/**
* @author Dmitry Avdeev
*
* @deprecated Use Kotlin UI DSL with bindings
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public abstract class ValueTypeConverter<A, B> {
public abstract A to(B b);
public abstract B from(A a);
public abstract Class<A> getSourceType();
public abstract Class<B> getTargetType();
public static final ValueTypeConverter<String, Integer>STRING_2_INTEGER = new ValueTypeConverter<>() {
@Override
public String to(Integer integer) {
return integer.toString();
}
@Override
public Integer from(String s) {
return Integer.decode(s);
}
@Override
public Class<String> getSourceType() {
return String.class;
}
@Override
public Class<Integer> getTargetType() {
return Integer.class;
}
};
public static final ValueTypeConverter[] STANDARD = new ValueTypeConverter[] {
STRING_2_INTEGER
};
}
@@ -4,8 +4,6 @@ package com.intellij.tasks.actions;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.binding.BindControl;
import com.intellij.openapi.options.binding.ControlBinder;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
@@ -36,7 +34,6 @@ public class OpenTaskDialog extends DialogWrapper {
private static final String UPDATE_STATE_ENABLED = "tasks.open.task.update.state.enabled";
private JPanel myPanel;
@BindControl(value = "clearContext", instant = true)
private JCheckBox myClearContext;
private JBCheckBox myUpdateState;
private TaskStateCombo myTaskStateCombo;
@@ -59,9 +56,6 @@ public class OpenTaskDialog extends DialogWrapper {
myNameField.setEnabled(!task.isIssue());
TaskManagerImpl taskManager = (TaskManagerImpl)TaskManager.getManager(myProject);
ControlBinder binder = new ControlBinder(taskManager.getState());
binder.bindAnnotations(this);
binder.reset();
if (!TaskStateCombo.stateUpdatesSupportedFor(task)) {
myUpdateState.setVisible(false);
@@ -83,6 +77,9 @@ public class OpenTaskDialog extends DialogWrapper {
TaskManagerImpl.Config state = taskManager.getState();
myClearContext.setSelected(state.clearContext);
myClearContext.addActionListener(e -> {
state.clearContext = myClearContext.isSelected();
});
updateFields();
if (myUpdateState.isSelected()) {