From d7375e0dc43035f93e93f7de6d3eb5895db8364f Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Fri, 5 Jun 2015 16:00:47 +0300 Subject: [PATCH] Create custom panel for field watchpoints --- .../KotlinFieldBreakpointPropertiesPanel.kt | 95 +++++++++++++++++++ .../breakpoints/KotlinFieldBreakpointType.kt | 8 +- .../KotlinPropertyBreakpointProperties.kt | 26 +++++ 3 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointPropertiesPanel.kt create mode 100644 idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinPropertyBreakpointProperties.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointPropertiesPanel.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointPropertiesPanel.kt new file mode 100644 index 00000000000..875ead28016 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointPropertiesPanel.kt @@ -0,0 +1,95 @@ +/* + * Copyright 2010-2015 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 org.jetbrains.kotlin.idea.debugger.breakpoints + +import com.intellij.debugger.DebuggerBundle +import com.intellij.ui.IdeBorderFactory +import com.intellij.util.ui.DialogUtil +import com.intellij.xdebugger.breakpoints.XLineBreakpoint +import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel +import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase +import java.awt.BorderLayout +import java.awt.event.ActionEvent +import java.awt.event.ActionListener +import javax.swing.Box +import javax.swing.JCheckBox +import javax.swing.JComponent +import javax.swing.JPanel +import kotlin.properties.Delegates + +public class KotlinFieldBreakpointPropertiesPanel: XBreakpointCustomPropertiesPanel>() { + private var myWatchAccessCheckBox: JCheckBox by Delegates.notNull() + private var myWatchModificationCheckBox: JCheckBox by Delegates.notNull() + + override fun getComponent(): JComponent { + myWatchAccessCheckBox = JCheckBox(DebuggerBundle.message("label.filed.breakpoint.properties.panel.field.access")) + myWatchModificationCheckBox = JCheckBox(DebuggerBundle.message("label.filed.breakpoint.properties.panel.field.modification")) + + DialogUtil.registerMnemonic(myWatchAccessCheckBox) + DialogUtil.registerMnemonic(myWatchModificationCheckBox) + + fun Box.addNewPanelForCheckBox(checkBox: JCheckBox) { + val panel = JPanel(BorderLayout()) + panel.add(checkBox, BorderLayout.NORTH) + this.add(panel) + } + + val watchBox = Box.createVerticalBox() + watchBox.addNewPanelForCheckBox(myWatchAccessCheckBox) + watchBox.addNewPanelForCheckBox(myWatchModificationCheckBox) + + val mainPanel = JPanel(BorderLayout()) + val innerPanel = JPanel(BorderLayout()) + innerPanel.add(watchBox, BorderLayout.CENTER) + innerPanel.add(Box.createHorizontalStrut(3), BorderLayout.WEST) + innerPanel.add(Box.createHorizontalStrut(3), BorderLayout.EAST) + mainPanel.add(innerPanel, BorderLayout.NORTH) + mainPanel.setBorder(IdeBorderFactory.createTitledBorder(DebuggerBundle.message("label.group.watch.events"), true)) + + val listener = object : ActionListener { + override fun actionPerformed(e: ActionEvent) { + if (!myWatchAccessCheckBox.isSelected() && !myWatchModificationCheckBox.isSelected()) { + when(e.getSource()) { + myWatchAccessCheckBox -> myWatchModificationCheckBox.setSelected(true) + myWatchModificationCheckBox -> myWatchAccessCheckBox.setSelected(true) + } + } + } + } + myWatchAccessCheckBox.addActionListener(listener) + myWatchModificationCheckBox.addActionListener(listener) + + return mainPanel + } + + override fun loadFrom(breakpoint: XLineBreakpoint) { + myWatchAccessCheckBox.setSelected(breakpoint.getProperties().WATCH_ACCESS) + myWatchModificationCheckBox.setSelected(breakpoint.getProperties().WATCH_MODIFICATION) + } + + override fun saveTo(breakpoint: XLineBreakpoint) { + var changed = breakpoint.getProperties().WATCH_ACCESS != myWatchAccessCheckBox.isSelected() + breakpoint.getProperties().WATCH_ACCESS = myWatchAccessCheckBox.isSelected() + + changed = breakpoint.getProperties().WATCH_MODIFICATION != myWatchModificationCheckBox.isSelected() || changed + breakpoint.getProperties().WATCH_MODIFICATION = myWatchModificationCheckBox.isSelected() + + if (changed) { + (breakpoint as XBreakpointBase<*, *, *>).fireBreakpointChanged() + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt index bbc3ff3d3f7..b25bf808be1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt @@ -121,7 +121,7 @@ public class KotlinFieldBreakpointType : JavaBreakpointType? { @@ -186,7 +186,7 @@ public class KotlinFieldBreakpointType : JavaBreakpointType>? { - return delegate.createCustomPropertiesPanel() + return KotlinFieldBreakpointPropertiesPanel() as XBreakpointCustomPropertiesPanel> } override fun getDisplayText(breakpoint: XLineBreakpoint?): String? { diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinPropertyBreakpointProperties.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinPropertyBreakpointProperties.kt new file mode 100644 index 00000000000..d48650e7297 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinPropertyBreakpointProperties.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2015 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 org.jetbrains.kotlin.idea.debugger.breakpoints + +import com.intellij.util.xmlb.annotations.Attribute +import org.jetbrains.java.debugger.breakpoints.properties.JavaBreakpointProperties +import org.jetbrains.java.debugger.breakpoints.properties.JavaFieldBreakpointProperties + +public class KotlinPropertyBreakpointProperties( + propertyName: String = "", + className: String = "" +): JavaFieldBreakpointProperties(propertyName, className) \ No newline at end of file