diff --git a/platform/platform-impl/src/com/intellij/openapi/options/binding/BeanValueAccessor.java b/platform/platform-impl/src/com/intellij/openapi/options/binding/BeanValueAccessor.java deleted file mode 100644 index 37e2f054d0a7..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/binding/BeanValueAccessor.java +++ /dev/null @@ -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; -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/binding/BindControl.java b/platform/platform-impl/src/com/intellij/openapi/options/binding/BindControl.java deleted file mode 100644 index ea066e1ebe2c..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/binding/BindControl.java +++ /dev/null @@ -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; -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/binding/ControlBinder.java b/platform/platform-impl/src/com/intellij/openapi/options/binding/ControlBinder.java deleted file mode 100644 index 6697a61eb189..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/binding/ControlBinder.java +++ /dev/null @@ -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> 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 binding = Pair.create(controlAccessor, beanAccessor); - myBindings.add(binding); - if (instant) { - controlAccessor.addChangeListener(() -> apply(binding)); - } - } - - public synchronized void reset() { - for (Pair 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 binding : myBindings) { - apply(binding); - } - } - - private static void apply(Pair 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 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); - } - } - } - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/binding/ControlValueAccessor.java b/platform/platform-impl/src/com/intellij/openapi/options/binding/ControlValueAccessor.java deleted file mode 100644 index fb10ebd3d33d..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/binding/ControlValueAccessor.java +++ /dev/null @@ -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 extends ValueAccessor { - - public abstract boolean isEnabled(); - public abstract void addChangeListener(Runnable listener); -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/binding/ValueAccessor.java b/platform/platform-impl/src/com/intellij/openapi/options/binding/ValueAccessor.java deleted file mode 100644 index 7ab798b11e8c..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/binding/ValueAccessor.java +++ /dev/null @@ -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 { - - public abstract V getValue(); - public abstract void setValue(V value); - public abstract Class getType(); - - public static ControlValueAccessor textFieldAccessor(final JTextField from) { - return new ControlValueAccessor() { - @Override - public String getValue() { - return from.getText(); - } - - @Override - public void setValue(String value) { - from.setText(value); - } - - @Override - public Class 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() { - @Override - public String getValue() { - return from.getText(); - } - - @Override - public void setValue(String value) { - from.setText(value); - } - - @Override - public Class 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() { - - @Override - public Boolean getValue() { - return from.isSelected(); - } - - @Override - public void setValue(Boolean value) { - from.setSelected(value.booleanValue()); - } - - @Override - public Class 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(); - } - }); - } - }; - } - -} diff --git a/platform/platform-impl/src/com/intellij/openapi/options/binding/ValueTypeConverter.java b/platform/platform-impl/src/com/intellij/openapi/options/binding/ValueTypeConverter.java deleted file mode 100644 index 5494c12398e7..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/options/binding/ValueTypeConverter.java +++ /dev/null @@ -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 { - - public abstract A to(B b); - public abstract B from(A a); - public abstract Class getSourceType(); - public abstract Class getTargetType(); - - public static final ValueTypeConverterSTRING_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 getSourceType() { - return String.class; - } - - @Override - public Class getTargetType() { - return Integer.class; - } - }; - - public static final ValueTypeConverter[] STANDARD = new ValueTypeConverter[] { - STRING_2_INTEGER - }; - -} diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java index f1c8e7326ffb..e5fa3188157d 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java @@ -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()) {