use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class IntentionHintComponent method recreateMyPopup.
private void recreateMyPopup(@NotNull ListPopupStep step) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (myPopup != null) {
Disposer.dispose(myPopup);
}
myPopup = JBPopupFactory.getInstance().createListPopup(step);
if (myPopup instanceof WizardPopup) {
Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
for (Shortcut shortcut : shortcuts) {
if (shortcut instanceof KeyboardShortcut) {
KeyboardShortcut keyboardShortcut = (KeyboardShortcut) shortcut;
if (keyboardShortcut.getSecondKeyStroke() == null) {
((WizardPopup) myPopup).registerAction("activateSelectedElement", keyboardShortcut.getFirstKeyStroke(), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
myPopup.handleSelect(true);
}
});
}
}
}
}
boolean committed = PsiDocumentManager.getInstance(myFile.getProject()).isCommitted(myEditor.getDocument());
final PsiFile injectedFile = committed ? InjectedLanguageUtil.findInjectedPsiNoCommit(myFile, myEditor.getCaretModel().getOffset()) : null;
final Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
final ScopeHighlighter highlighter = new ScopeHighlighter(myEditor);
final ScopeHighlighter injectionHighlighter = new ScopeHighlighter(injectedEditor);
myPopup.addListener(new JBPopupListener.Adapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
highlighter.dropHighlight();
injectionHighlighter.dropHighlight();
myPopupShown = false;
}
});
myPopup.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(@NotNull ListSelectionEvent e) {
final Object source = e.getSource();
highlighter.dropHighlight();
injectionHighlighter.dropHighlight();
if (source instanceof DataProvider) {
final Object selectedItem = PlatformDataKeys.SELECTED_ITEM.getData((DataProvider) source);
if (selectedItem instanceof IntentionActionWithTextCaching) {
final IntentionAction action = ((IntentionActionWithTextCaching) selectedItem).getAction();
if (action instanceof SuppressIntentionActionFromFix) {
if (injectedFile != null && ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
final PsiElement at = injectedFile.findElementAt(injectedEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
if (container != null) {
injectionHighlighter.highlight(container, Collections.singletonList(container));
}
} else {
final PsiElement at = myFile.findElementAt(myEditor.getCaretModel().getOffset());
final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
if (container != null) {
highlighter.highlight(container, Collections.singletonList(container));
}
}
}
}
}
}
});
if (myEditor.isOneLineMode()) {
// hide popup on combobox popup show
final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, myEditor.getContentComponent());
if (ancestor != null) {
final JComboBox comboBox = (JComboBox) ancestor;
myOuterComboboxPopupListener = new PopupMenuListenerAdapter() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
hide();
}
};
comboBox.addPopupMenuListener(myOuterComboboxPopupListener);
}
}
Disposer.register(this, myPopup);
Disposer.register(myPopup, new Disposable() {
@Override
public void dispose() {
ApplicationManager.getApplication().assertIsDispatchThread();
}
});
}
use of javax.swing.event.ListSelectionEvent 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);
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class JvmSmartStepIntoHandler method handleTargets.
protected final boolean handleTargets(SourcePosition position, DebuggerSession session, TextEditor fileEditor, List<SmartStepTarget> targets) {
if (!targets.isEmpty()) {
SmartStepTarget firstTarget = targets.get(0);
if (targets.size() == 1) {
doStepInto(session, Registry.is("debugger.single.smart.step.force"), firstTarget);
} else {
Editor editor = fileEditor.getEditor();
PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets, chosenTarget -> doStepInto(session, true, chosenTarget));
ListPopupImpl popup = new ListPopupImpl(popupStep);
DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO, XDebuggerActions.SMART_STEP_INTO);
popup.setAdText(DebuggerUIUtil.getSelectionShortcutsAdText(XDebuggerActions.STEP_INTO, XDebuggerActions.SMART_STEP_INTO));
UIUtil.maybeInstall(popup.getList().getInputMap(JComponent.WHEN_FOCUSED), "selectNextRow", KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
popup.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
popupStep.getScopeHighlighter().dropHighlight();
if (!e.getValueIsAdjusting()) {
final SmartStepTarget selectedTarget = (SmartStepTarget) ((JBList) e.getSource()).getSelectedValue();
if (selectedTarget != null) {
highlightTarget(popupStep, selectedTarget);
}
}
}
});
highlightTarget(popupStep, firstTarget);
DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine());
}
return true;
}
return false;
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class MavenRepositoriesConfigurable method configControls.
private void configControls() {
myServiceList.setModel(myModel);
myServiceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myAddButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final String value = (String) myServiceList.getSelectedValue();
final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Add Service URL", Messages.getQuestionIcon(), value == null ? "http://" : value, new URLInputVaslidator());
if (StringUtil.isNotEmpty(text)) {
myModel.add(text);
myServiceList.setSelectedValue(text, true);
}
}
});
myEditButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final int index = myServiceList.getSelectedIndex();
final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Edit Service URL", Messages.getQuestionIcon(), myModel.getElementAt(index), new URLInputVaslidator());
if (StringUtil.isNotEmpty(text)) {
myModel.setElementAt(text, index);
}
}
});
ListUtil.addRemoveListener(myRemoveButton, myServiceList);
ListUtil.disableWhenNoSelection(myTestButton, myServiceList);
ListUtil.disableWhenNoSelection(myEditButton, myServiceList);
myTestButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final String value = (String) myServiceList.getSelectedValue();
if (value != null) {
testServiceConnection(value);
}
}
});
myUpdateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doUpdateIndex();
}
});
myIndicesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
updateButtonsState();
}
});
myIndicesTable.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
int row = myIndicesTable.rowAtPoint(e.getPoint());
if (row == -1)
return;
updateIndexHint(row);
}
});
myIndicesTable.setDefaultRenderer(Object.class, new MyCellRenderer());
myIndicesTable.setDefaultRenderer(MavenIndicesManager.IndexUpdatingState.class, new MyIconCellRenderer());
myServiceList.getEmptyText().setText("No services");
myIndicesTable.getEmptyText().setText("No remote repositories");
updateButtonsState();
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class PaletteWindow method clearActiveItem.
public void clearActiveItem() {
if (getActiveItem() == null)
return;
for (PaletteGroupHeader group : myGroupHeaders) {
group.getComponentList().clearSelection();
}
ListSelectionEvent event = new ListSelectionEvent(this, -1, -1, false);
notifySelectionChanged(event);
}
Aggregations