migrate fields for classes and packages to EditorTextFieldWithBrowseButton

This commit is contained in:
Eugene Kudelevsky
2012-07-13 22:56:57 +04:00
parent 598e0e19c3
commit 4d9f2ecae0
5 changed files with 96 additions and 19 deletions
@@ -0,0 +1,52 @@
package org.jetbrains.android.run;
import com.intellij.execution.ui.ConfigurationModuleSelector;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
/**
* @author Eugene.Kudelevsky
*/
public class AndroidClassVisibilityChecker implements JavaCodeFragment.VisibilityChecker {
private final Project myProject;
private final ConfigurationModuleSelector myModuleSelector;
private final String myBaseClassName;
public AndroidClassVisibilityChecker(@NotNull Project project,
@NotNull ConfigurationModuleSelector moduleSelector,
@NotNull String baseClassName) {
myProject = project;
myModuleSelector = moduleSelector;
myBaseClassName = baseClassName;
}
@Override
public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
if (!(declaration instanceof PsiClass)) {
return Visibility.NOT_VISIBLE;
}
final Module module = myModuleSelector.getModule();
if (module == null) {
return Visibility.NOT_VISIBLE;
}
final PsiFile file = declaration.getContainingFile();
final VirtualFile vFile = file != null ? file.getVirtualFile() : null;
if (vFile == null) {
return Visibility.NOT_VISIBLE;
}
final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
final PsiClass baseClass = facade.findClass(myBaseClassName, module.getModuleWithDependenciesAndLibrariesScope(true));
if (baseClass == null ||
!((PsiClass)declaration).isInheritor(baseClass, true)) {
return Visibility.NOT_VISIBLE;
}
return Visibility.VISIBLE;
}
}
@@ -8,12 +8,6 @@
<properties/>
<border type="none"/>
<children>
<component id="d4024" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myActivityField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="87e92" class="javax.swing.JRadioButton" binding="myLaunchDefaultButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -24,7 +18,7 @@
</component>
<component id="8a8dd" class="javax.swing.JRadioButton" binding="myLaunchCustomButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<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 value="L&amp;aunch:"/>
@@ -46,6 +40,12 @@
<text resource-bundle="messages/AndroidBundle" key="android.run.confguration.deploy.and.install.check.box"/>
</properties>
</component>
<component id="ec4e0" class="com.intellij.ui.EditorTextFieldWithBrowseButton" binding="myActivityField" custom-create="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<buttonGroups>
@@ -23,10 +23,10 @@ import com.intellij.ide.util.TreeClassChooserFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.ProjectScope;
import com.intellij.ui.EditorTextFieldWithBrowseButton;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.android.util.AndroidUtils;
@@ -43,14 +43,19 @@ import java.awt.event.ActionListener;
* To change this template use File | Settings | File Templates.
*/
class ApplicationRunParameters implements ConfigurationSpecificEditor<AndroidRunConfiguration> {
private TextFieldWithBrowseButton myActivityField;
private EditorTextFieldWithBrowseButton myActivityField;
private JRadioButton myLaunchDefaultButton;
private JRadioButton myLaunchCustomButton;
private JPanel myPanel;
private JRadioButton myDoNothingButton;
private JCheckBox myDeployAndInstallCheckBox;
private final Project myProject;
private final ConfigurationModuleSelector myModuleSelector;
ApplicationRunParameters(final Project project, final ConfigurationModuleSelector moduleSelector) {
myProject = project;
myModuleSelector = moduleSelector;
myActivityField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!project.isInitialized()) {
@@ -130,4 +135,10 @@ class ApplicationRunParameters implements ConfigurationSpecificEditor<AndroidRun
@Override
public void setAnchor(JComponent anchor) {
}
private void createUIComponents() {
myActivityField = new EditorTextFieldWithBrowseButton(myProject, true,
new AndroidClassVisibilityChecker(myProject, myModuleSelector,
AndroidUtils.ACTIVITY_BASE_CLASS_NAME));
}
}
@@ -67,7 +67,7 @@
<grid row="1" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<componentClass value="javax.swing.JPanel"/>
<labelLocation value="West"/>
<text resource-bundle="messages/AndroidBundle" key="android.run.configuration.package.label"/>
</properties>
@@ -77,7 +77,7 @@
<grid row="2" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<componentClass value="javax.swing.JPanel"/>
<labelLocation value="West"/>
<text resource-bundle="messages/AndroidBundle" key="android.run.configuration.class.label"/>
</properties>
@@ -97,7 +97,7 @@
<grid row="4" column="0" row-span="1" col-span="6" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<componentClass value="javax.swing.JPanel"/>
<enabled value="true"/>
<labelLocation value="North"/>
<text resource-bundle="messages/AndroidBundle" key="android.test.run.configuration.instrumentation.label"/>
@@ -24,14 +24,17 @@ import com.intellij.execution.ui.ConfigurationModuleSelector;
import com.intellij.ide.util.PackageChooserDialog;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiPackage;
import com.intellij.ui.EditorTextFieldWithBrowseButton;
import com.intellij.ui.components.JBLabel;
import org.jetbrains.android.run.AndroidClassBrowser;
import org.jetbrains.android.run.AndroidClassVisibilityChecker;
import org.jetbrains.android.run.ConfigurationSpecificEditor;
import org.jetbrains.android.util.AndroidBundle;
import org.jetbrains.android.util.AndroidUtils;
@@ -57,11 +60,11 @@ class TestRunParameters implements ConfigurationSpecificEditor<AndroidTestRunCon
private JRadioButton myClassButton;
private JRadioButton myTestMethodButton;
private JRadioButton myAllInModuleButton;
private LabeledComponent<TextFieldWithBrowseButton> myPackageComponent;
private LabeledComponent<TextFieldWithBrowseButton> myClassComponent;
private LabeledComponent<EditorTextFieldWithBrowseButton> myPackageComponent;
private LabeledComponent<EditorTextFieldWithBrowseButton> myClassComponent;
private LabeledComponent<TextFieldWithBrowseButton> myMethodComponent;
private JPanel myPanel;
private LabeledComponent<TextFieldWithBrowseButton> myRunnerComponent;
private LabeledComponent<EditorTextFieldWithBrowseButton> myRunnerComponent;
private JBLabel myLabelTest;
private final JRadioButton[] myTestingType2RadioButton = new JRadioButton[4];
@@ -72,13 +75,23 @@ class TestRunParameters implements ConfigurationSpecificEditor<AndroidTestRunCon
TestRunParameters(Project project, ConfigurationModuleSelector moduleSelector) {
myProject = project;
myModuleSelector = moduleSelector;
myPackageComponent.setComponent(new EditorTextFieldWithBrowseButton(project, false));
bind(myPackageComponent, new MyPackageBrowser());
bind(myClassComponent, new AndroidClassBrowser(myProject, myModuleSelector, ANDROID_TEST_BASE_CLASS_NAME,
myClassComponent.setComponent(new EditorTextFieldWithBrowseButton(project, true,
new AndroidClassVisibilityChecker(myProject, moduleSelector,
ANDROID_TEST_BASE_CLASS_NAME)));
bind(myClassComponent, new AndroidClassBrowser(project, moduleSelector, ANDROID_TEST_BASE_CLASS_NAME,
AndroidBundle.message("android.browse.test.class.dialog.title"), false, null));
bind(myMethodComponent, new MyMethodBrowser());
bind(myRunnerComponent, new AndroidClassBrowser(myProject, myModuleSelector, AndroidUtils.INSTRUMENTATION_RUNNER_BASE_CLASS,
myRunnerComponent.setComponent(new EditorTextFieldWithBrowseButton(project, true,
new AndroidClassVisibilityChecker(myProject, moduleSelector,
AndroidUtils.INSTRUMENTATION_RUNNER_BASE_CLASS)));
bind(myRunnerComponent, new AndroidClassBrowser(project, moduleSelector, AndroidUtils.INSTRUMENTATION_RUNNER_BASE_CLASS,
AndroidBundle.message("android.browse.instrumentation.class.dialog.title"), true,
null));
bind(myMethodComponent, new MyMethodBrowser());
addTestingType(TEST_ALL_IN_MODULE, myAllInModuleButton);
addTestingType(TEST_ALL_IN_PACKAGE, myAllInPackageButton);
@@ -111,7 +124,8 @@ class TestRunParameters implements ConfigurationSpecificEditor<AndroidTestRunCon
myLabelTest.setAnchor(anchor);
}
private static void bind(final LabeledComponent<TextFieldWithBrowseButton> labeledComponent, BrowseModuleValueActionListener browser) {
private static void bind(final LabeledComponent<? extends ComponentWithBrowseButton<?>> labeledComponent,
BrowseModuleValueActionListener browser) {
browser.setField(labeledComponent.getComponent());
}