From e99bd89139be935b035f2bb4409c04997d0ac21a Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 8 Jun 2015 16:12:26 +0300 Subject: [PATCH] Copy AddFieldBreakpointDialog from IDEA --- .../breakpoints/KotlinFieldBreakpointType.kt | 8 +- .../dialog/AddFieldBreakpointDialog.form | 62 ++++++++ .../dialog/AddFieldBreakpointDialog.java | 149 ++++++++++++++++++ 3 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.form create mode 100644 idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.java 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 7f7b1d09c38..4c8f0eb367e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt @@ -17,7 +17,10 @@ package org.jetbrains.kotlin.idea.debugger.breakpoints import com.intellij.debugger.DebuggerBundle -import com.intellij.debugger.ui.breakpoints.* +import com.intellij.debugger.ui.breakpoints.Breakpoint +import com.intellij.debugger.ui.breakpoints.BreakpointManager +import com.intellij.debugger.ui.breakpoints.BreakpointWithHighlighter +import com.intellij.debugger.ui.breakpoints.JavaBreakpointType import com.intellij.icons.AllIcons import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project @@ -32,7 +35,6 @@ import com.intellij.xdebugger.breakpoints.XBreakpoint import com.intellij.xdebugger.breakpoints.XLineBreakpoint import com.intellij.xdebugger.breakpoints.XLineBreakpointType import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel -import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider import org.jetbrains.kotlin.asJava.KotlinLightClass import org.jetbrains.kotlin.asJava.KotlinLightClassForExplicitDeclaration import org.jetbrains.kotlin.asJava.KotlinLightClassForPackage @@ -41,10 +43,10 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.idea.JetBundle import org.jetbrains.kotlin.idea.JetFileType import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult +import org.jetbrains.kotlin.idea.debugger.breakpoints.dialog.AddFieldBreakpointDialog import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext -import javax.swing.Icon import javax.swing.JComponent public class KotlinFieldBreakpointType : JavaBreakpointType, XLineBreakpointType( diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.form b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.form new file mode 100644 index 00000000000..f57e113c7c6 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.form @@ -0,0 +1,62 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.java b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.java new file mode 100644 index 00000000000..312e0b22fb7 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/AddFieldBreakpointDialog.java @@ -0,0 +1,149 @@ +/* + * 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. + */ + +/* + * @author: Eugene Zhuravlev + * Date: Sep 11, 2002 + * Time: 5:23:47 PM + */ +package org.jetbrains.kotlin.idea.debugger.breakpoints.dialog; + +import com.intellij.codeInsight.generation.PsiFieldMember; +import com.intellij.debugger.DebuggerBundle; +import com.intellij.ide.util.MemberChooser; +import com.intellij.ide.util.TreeClassChooser; +import com.intellij.ide.util.TreeClassChooserFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.TextFieldWithBrowseButton; +import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.ui.DocumentAdapter; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +public abstract class AddFieldBreakpointDialog extends DialogWrapper { + private final Project myProject; + private JPanel myPanel; + private TextFieldWithBrowseButton myFieldChooser; + private TextFieldWithBrowseButton myClassChooser; + + public AddFieldBreakpointDialog(Project project) { + super(project, true); + myProject = project; + setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.title")); + init(); + } + + protected JComponent createCenterPanel() { + myClassChooser.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { + public void textChanged(DocumentEvent event) { + updateUI(); + } + }); + + myClassChooser.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PsiClass currentClass = getSelectedClass(); + TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createAllProjectScopeChooser( + DebuggerBundle.message("add.field.breakpoint.dialog.classchooser.title")); + if (currentClass != null) { + PsiFile containingFile = currentClass.getContainingFile(); + if (containingFile != null) { + PsiDirectory containingDirectory = containingFile.getContainingDirectory(); + if (containingDirectory != null) { + chooser.selectDirectory(containingDirectory); + } + } + } + chooser.showDialog(); + PsiClass selectedClass = chooser.getSelected(); + if (selectedClass != null) { + myClassChooser.setText(selectedClass.getQualifiedName()); + } + } + }); + + myFieldChooser.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PsiClass selectedClass = getSelectedClass(); + if (selectedClass != null) { + PsiField[] fields = selectedClass.getFields(); + MemberChooser chooser = new MemberChooser( + ContainerUtil.map2Array(fields, PsiFieldMember.class, new Function() { + public PsiFieldMember fun(final PsiField s) { + return new PsiFieldMember(s); + } + }), false, false, myProject); + chooser.setTitle(DebuggerBundle.message("add.field.breakpoint.dialog.field.chooser.title", fields.length)); + chooser.setCopyJavadocVisible(false); + chooser.show(); + List selectedElements = chooser.getSelectedElements(); + if (selectedElements != null && selectedElements.size() == 1) { + PsiField field = selectedElements.get(0).getElement(); + myFieldChooser.setText(field.getName()); + } + } + } + }); + myFieldChooser.setEnabled(false); + return myPanel; + } + + private void updateUI() { + PsiClass selectedClass = getSelectedClass(); + myFieldChooser.setEnabled(selectedClass != null); + } + + private PsiClass getSelectedClass() { + final PsiManager psiManager = PsiManager.getInstance(myProject); + String classQName = myClassChooser.getText(); + if ("".equals(classQName)) { + return null; + } + return JavaPsiFacade.getInstance(psiManager.getProject()).findClass(classQName, GlobalSearchScope.allScope(myProject)); + } + + public JComponent getPreferredFocusedComponent() { + return myClassChooser.getTextField(); + } + + public String getClassName() { + return myClassChooser.getText(); + } + + protected String getDimensionServiceKey(){ + return "#com.intellij.debugger.ui.breakpoints.BreakpointsConfigurationDialogFactory.BreakpointsConfigurationDialog.AddFieldBreakpointDialog"; + } + + public String getFieldName() { + return myFieldChooser.getText(); + } + + protected abstract boolean validateData(); + + protected void doOKAction() { + if(validateData()) { + super.doOKAction(); + } + } +}