JComponent () { JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints constr = new GridBagConstraints(); constr.fill = GridBagConstraints.HORIZONTAL; constr.anchor = GridBagConstraints.WEST; int gridy = 1; constr.insets = insets(4); constr.gridy = gridy++; constr.gridx = 0; constr.weightx = 0; final JLabel libLabel = new JLabel(JavaBundle.message("intention.create.test.dialog.testing.library")); libLabel.setLabelFor(myLibrariesCombo); panel.add(libLabel, constr); constr.gridx = 1; constr.weightx = 1; constr.gridwidth = GridBagConstraints.REMAINDER; panel.add(myLibrariesCombo, constr); myFixLibraryPanel = new JPanel(new BorderLayout()); myFixLibraryLabel = new JLabel(); myFixLibraryLabel.setIcon(AllIcons.Actions.IntentionBulb); myFixLibraryPanel.add(myFixLibraryLabel, BorderLayout.CENTER); myFixLibraryPanel.add(myFixLibraryButton, BorderLayout.EAST); constr.insets = insets(1); constr.gridy = gridy++; constr.gridx = 0; panel.add(myFixLibraryPanel, constr); constr.gridheight = 1; constr.insets = insets(6); constr.gridy = gridy++; constr.gridx = 0; constr.weightx = 0; constr.gridwidth = 1; panel.add(new JLabel(JavaBundle.message("intention.create.test.dialog.class.name")), constr); myTargetClassNameField = new EditorTextField(suggestTestClassName(myTargetClass)); myTargetClassNameField.getDocument().addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent e) { getOKAction().setEnabled(PsiNameHelper.getInstance(myProject).isIdentifier(getClassName())); } }); constr.gridx = 1; constr.weightx = 1; panel.add(myTargetClassNameField, constr); constr.insets = insets(1); constr.gridy = gridy++; constr.gridx = 0; constr.weightx = 0; panel.add(new JLabel(JavaBundle.message("intention.create.test.dialog.super.class")), constr); mySuperClassField = new ReferenceEditorComboWithBrowseButton(new MyChooseSuperClassAction(), null, myProject, true, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, RECENT_SUPERS_KEY); mySuperClassField.setMinimumSize(mySuperClassField.getPreferredSize()); constr.gridx = 1; constr.weightx = 1; panel.add(mySuperClassField, constr); constr.insets = insets(1); constr.gridy = gridy++; constr.gridx = 0; constr.weightx = 0; panel.add(new JLabel(JavaBundle.message("dialog.create.class.destination.package.label")), constr); constr.gridx = 1; constr.weightx = 1; String targetPackageName = myTargetPackage != null ? myTargetPackage.getQualifiedName() : ""; myTargetPackageField = new PackageNameReferenceEditorCombo(targetPackageName, myProject, RECENTS_KEY, JavaBundle.message("dialog.create.class.package.chooser.title")); new AnAction() { @Override public void actionPerformed(@NotNull AnActionEvent e) { myTargetPackageField.getButton().doClick(); } }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myTargetPackageField.getChildComponent()); JPanel targetPackagePanel = new JPanel(new BorderLayout()); targetPackagePanel.add(myTargetPackageField, BorderLayout.CENTER); panel.add(targetPackagePanel, constr); constr.insets = insets(6); constr.gridy = gridy++; constr.gridx = 0; constr.weightx = 0; panel.add(new JLabel(JavaBundle.message("intention.create.test.dialog.generate")), constr); constr.gridx = 1; constr.weightx = 1; panel.add(myGenerateBeforeBox, constr); constr.insets = insets(1); constr.gridy = gridy++; panel.add(myGenerateAfterBox, constr); constr.insets = insets(6); constr.gridy = gridy++; constr.gridx = 0; constr.weightx = 0; final JLabel membersLabel = new JLabel(JavaBundle.message("intention.create.test.dialog.select.methods")); membersLabel.setLabelFor(myMethodsTable); panel.add(membersLabel, constr); constr.gridx = 1; constr.weightx = 1; panel.add(myShowInheritedMethodsBox, constr); constr.insets = insets(1, 8); constr.gridy = gridy++; constr.gridx = 0; constr.gridwidth = GridBagConstraints.REMAINDER; constr.fill = GridBagConstraints.BOTH; constr.weighty = 1; panel.add(ScrollPaneFactory.createScrollPane(myMethodsTable), constr); myLibrariesCombo.setRenderer(SimpleListCellRenderer.create((label, value, index) -> { if (value != null) { label.setText(value.getName()); label.setIcon(value.getIcon()); } })); final boolean hasTestRoots = !ModuleRootManager.getInstance(myTargetModule).getSourceRoots(JavaModuleSourceRootTypes.TESTS).isEmpty(); final List<TestFramework> attachedLibraries = new ArrayList<>(); final String defaultLibrary = getDefaultLibraryName(); TestFramework defaultDescriptor = null; final DefaultComboBoxModel<TestFramework> model = (DefaultComboBoxModel<TestFramework>)myLibrariesCombo.getModel(); List<TestFramework> descriptors = new ArrayList<>(TestFramework.EXTENSION_NAME.getExtensionList()); descriptors.sort((d1, d2) -> Comparing.compare(d1.getName(), d2.getName())); Set<String> frameworkSet = new HashSet<>(); for (final TestFramework descriptor : descriptors) { if (!TestFrameworks.isSuitableByLanguage(myTargetClass, descriptor)) continue; if (!frameworkSet.add(descriptor.getName())) continue; model.addElement(descriptor); if (hasTestRoots && descriptor.isLibraryAttached(myTargetModule)) { attachedLibraries.add(descriptor); } if (Objects.equals(defaultLibrary, descriptor.getName())) { defaultDescriptor = descriptor; } } myLibrariesCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Object selectedItem = myLibrariesCombo.getSelectedItem(); if (selectedItem != null) { final DumbService dumbService = DumbService.getInstance(myProject); dumbService.runWithAlternativeResolveEnabled(() -> onLibrarySelected((TestFramework)selectedItem)); } } }); if (defaultDescriptor != null && (attachedLibraries.contains(defaultDescriptor) || attachedLibraries.isEmpty())) { myLibrariesCombo.setSelectedItem(defaultDescriptor); } else if (!descriptors.isEmpty()) { List<TestFramework> applicableFrameworks = attachedLibraries.isEmpty() ? descriptors : attachedLibraries; TestFramework preferredFramework = ObjectUtils.notNull(ContainerUtil.find(applicableFrameworks, d -> TestFrameworks.isSuitableByLanguage(myTargetClass, d)), applicableFrameworks.get(0)); myLibrariesCombo.setSelectedItem(preferredFramework); } myFixLibraryButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (mySelectedFramework instanceof JavaTestFramework) { ((JavaTestFramework)mySelectedFramework).setupLibrary(myTargetModule) .onSuccess(__ -> myFixLibraryPanel.setVisible(false)); } else { OrderEntryFix.addJarToRoots(mySelectedFramework.getLibraryPath(), myTargetModule, null); myFixLibraryPanel.setVisible(false); } } }); myShowInheritedMethodsBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateMethodsTable(); } }); restoreShowInheritedMembersStatus(); updateMethodsTable(); return panel; }