Copy AddFieldBreakpointDialog from IDEA
This commit is contained in:
+5
-3
@@ -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<KotlinPropertyBreakpointProperties>, XLineBreakpointType<KotlinPropertyBreakpointProperties>(
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.kotlin.idea.debugger.breakpoints.dialog.AddFieldBreakpointDialog">
|
||||
<grid id="dbe86" binding="myPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="6">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="74" y="134" width="245" height="152"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9636d" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myClassChooser">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c2ef3" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myFieldChooser">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<xy id="3cfba" layout-manager="XYLayout" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="1"/>
|
||||
<maximum-size width="-1" height="1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-raised"/>
|
||||
<children/>
|
||||
</xy>
|
||||
<vspacer id="339be">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="e8c64" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/DebuggerBundle" key="label.add.field.breakpoint.dialog.field.name"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c159b" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text resource-bundle="messages/DebuggerBundle" key="label.add.field.breakpoint.dialog.fq.name"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+149
@@ -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<PsiFieldMember> chooser = new MemberChooser<PsiFieldMember>(
|
||||
ContainerUtil.map2Array(fields, PsiFieldMember.class, new Function<PsiField, PsiFieldMember>() {
|
||||
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<PsiFieldMember> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user