use of com.intellij.refactoring.ui.MethodCellRenderer in project intellij-community by JetBrains.
the class EnclosingMethodSelectionDialog method createNorthPanel.
protected JComponent createNorthPanel() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.insets = JBUI.insets(4, 8);
gbConstraints.weighty = 0;
gbConstraints.weightx = 1;
gbConstraints.gridy = 0;
gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
gbConstraints.gridheight = 1;
gbConstraints.fill = GridBagConstraints.BOTH;
gbConstraints.anchor = GridBagConstraints.WEST;
panel.add(new JLabel(RefactoringBundle.message("introduce.parameter.to.method")), gbConstraints);
gbConstraints.weighty = 1;
myEnclosingMethodsList = new JBList(myEnclosingMethods.toArray());
myEnclosingMethodsList.setCellRenderer(new MethodCellRenderer());
myEnclosingMethodsList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
int indexToSelect = 0;
myEnclosingMethodsList.setSelectedIndex(indexToSelect);
gbConstraints.gridy++;
panel.add(ScrollPaneFactory.createScrollPane(myEnclosingMethodsList), gbConstraints);
return panel;
}
use of com.intellij.refactoring.ui.MethodCellRenderer in project intellij-community by JetBrains.
the class IntroduceParameterHandler method chooseMethodToIntroduceParameter.
private void chooseMethodToIntroduceParameter(final Editor editor, final List<PsiMethod> validEnclosingMethods, final PairConsumer<PsiMethod, PsiMethod> consumer) {
final boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode();
if (validEnclosingMethods.size() == 1 || unitTestMode) {
final PsiMethod methodToIntroduceParameterTo = validEnclosingMethods.get(0);
if (methodToIntroduceParameterTo.findDeepestSuperMethod() == null || unitTestMode) {
consumer.consume(methodToIntroduceParameterTo, methodToIntroduceParameterTo);
return;
}
}
final JPanel panel = new JPanel(new BorderLayout());
final JCheckBox superMethod = new JCheckBox("Refactor super method", true);
superMethod.setMnemonic('U');
panel.add(superMethod, BorderLayout.SOUTH);
final JBList list = new JBList(validEnclosingMethods.toArray());
list.setVisibleRowCount(5);
list.setCellRenderer(new MethodCellRenderer());
list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
final List<RangeHighlighter> highlighters = new ArrayList<>();
final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(final ListSelectionEvent e) {
final PsiMethod selectedMethod = (PsiMethod) list.getSelectedValue();
if (selectedMethod == null)
return;
dropHighlighters(highlighters);
updateView(selectedMethod, editor, attributes, highlighters, superMethod);
}
});
updateView(validEnclosingMethods.get(0), editor, attributes, highlighters, superMethod);
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list);
scrollPane.setBorder(null);
panel.add(scrollPane, BorderLayout.CENTER);
final List<Pair<ActionListener, KeyStroke>> keyboardActions = Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final PsiMethod methodToSearchIn = (PsiMethod) list.getSelectedValue();
if (myEnclosingMethodsPopup != null && myEnclosingMethodsPopup.isVisible()) {
myEnclosingMethodsPopup.cancel();
}
final PsiMethod methodToSearchFor = superMethod.isEnabled() && superMethod.isSelected() ? methodToSearchIn.findDeepestSuperMethod() : methodToSearchIn;
consumer.consume(methodToSearchIn, methodToSearchFor);
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)));
myEnclosingMethodsPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list).setTitle("Introduce parameter to method").setMovable(false).setResizable(false).setRequestFocus(true).setKeyboardActions(keyboardActions).addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
dropHighlighters(highlighters);
}
}).createPopup();
myEnclosingMethodsPopup.showInBestPositionFor(editor);
}
Aggregations