use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class UnwrapHandler method showPopup.
private static void showPopup(final List<AnAction> options, Editor editor) {
final ScopeHighlighter highlighter = new ScopeHighlighter(editor);
DefaultListModel<String> m = new DefaultListModel<>();
for (AnAction a : options) {
m.addElement(((MyUnwrapAction) a).getName());
}
final JList list = new JBList(m);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(options.size());
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int index = list.getSelectedIndex();
if (index < 0)
return;
MyUnwrapAction a = (MyUnwrapAction) options.get(index);
List<PsiElement> toExtract = new ArrayList<>();
PsiElement wholeRange = a.collectAffectedElements(toExtract);
highlighter.highlight(wholeRange, toExtract);
}
});
PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
builder.setTitle(CodeInsightBundle.message("unwrap.popup.title")).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
MyUnwrapAction a = (MyUnwrapAction) options.get(list.getSelectedIndex());
a.actionPerformed(null);
}).addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
highlighter.dropHighlight();
}
});
JBPopup popup = builder.createPopup();
popup.showInBestPositionFor(editor);
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class MoveInstanceMethodDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel mainPanel = new JPanel(new GridBagLayout());
final TitledSeparator separator = new TitledSeparator();
mainPanel.add(separator, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
myList = createTargetVariableChooser();
myList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
validateTextFields(e.getFirstIndex());
}
});
separator.setText(RefactoringBundle.message("moveInstanceMethod.select.an.instance.parameter"));
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myList);
mainPanel.add(scrollPane, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));
myVisibilityPanel = createVisibilityPanel();
mainPanel.add(myVisibilityPanel, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, JBUI.emptyInsets(), 0, 0));
final JPanel parametersPanel = createParametersPanel();
if (parametersPanel != null) {
mainPanel.add(parametersPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
}
mainPanel.add(initOpenInEditorCb(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
separator.setLabelFor(myList);
validateTextFields(myList.getSelectedIndex());
updateOnChanged(myList);
return mainPanel;
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class FileTypeConfigurable method createComponent.
@Override
public JComponent createComponent() {
myFileTypePanel = new FileTypePanel();
myRecognizedFileType = myFileTypePanel.myRecognizedFileType;
myPatterns = myFileTypePanel.myPatterns;
myRecognizedFileType.attachActions(this);
myRecognizedFileType.myFileTypesList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(@Nullable ListSelectionEvent e) {
updateExtensionList();
}
});
myPatterns.attachActions(this);
myFileTypePanel.myIgnoreFilesField.setColumns(30);
return myFileTypePanel.getComponent();
}
use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.
the class MasterDetailPopupBuilder method setList.
@NotNull
public MasterDetailPopupBuilder setList(@NotNull JBList list) {
myChooserComponent = list;
myDetailController.setList(list);
list.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
removeSelectedItems();
} else if (e.getModifiersEx() == 0) {
myDelegate.handleMnemonic(e, myProject, myPopup);
}
}
});
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
chooseItems(true);
}
}.registerCustomShortcutSet(CommonShortcuts.ENTER, list);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
chooseItems(true);
}
}.registerCustomShortcutSet(CommonShortcuts.DOUBLE_CLICK_1, list);
list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent event) {
myDetailController.updateDetailView();
}
});
return this;
}
use of javax.swing.event.ListSelectionEvent in project jabref by JabRef.
the class EntryCustomizationDialog method applyChanges.
private void applyChanges() {
valueChanged(new ListSelectionEvent(new JList<>(), 0, 0, false));
List<String> actuallyChangedTypes = new ArrayList<>();
// Iterate over our map of required fields, and list those types if necessary:
List<String> types = typeComp.getFields();
for (Map.Entry<String, List<String>> stringListEntry : reqLists.entrySet()) {
if (!types.contains(stringListEntry.getKey())) {
continue;
}
List<String> requiredFieldsList = stringListEntry.getValue();
List<String> optionalFieldsList = optLists.get(stringListEntry.getKey());
List<String> secondaryOptionalFieldsLists = opt2Lists.get(stringListEntry.getKey());
if (secondaryOptionalFieldsLists == null) {
secondaryOptionalFieldsLists = new ArrayList<>(0);
}
// If this type is already existing, check if any changes have
// been made
boolean changesMade = true;
if (defaulted.contains(stringListEntry.getKey())) {
// This type should be reverted to its default setup.
EntryTypes.removeType(stringListEntry.getKey(), bibDatabaseMode);
actuallyChangedTypes.add(stringListEntry.getKey().toLowerCase(Locale.ENGLISH));
defaulted.remove(stringListEntry.getKey());
continue;
}
Optional<EntryType> oldType = EntryTypes.getType(stringListEntry.getKey(), bibDatabaseMode);
if (oldType.isPresent()) {
List<String> oldRequiredFieldsList = oldType.get().getRequiredFieldsFlat();
List<String> oldOptionalFieldsList = oldType.get().getOptionalFields();
if (biblatexMode) {
List<String> oldPrimaryOptionalFieldsLists = oldType.get().getPrimaryOptionalFields();
List<String> oldSecondaryOptionalFieldsList = oldType.get().getSecondaryOptionalFields();
if (equalLists(oldRequiredFieldsList, requiredFieldsList) && equalLists(oldPrimaryOptionalFieldsLists, optionalFieldsList) && equalLists(oldSecondaryOptionalFieldsList, secondaryOptionalFieldsLists)) {
changesMade = false;
}
} else if (equalLists(oldRequiredFieldsList, requiredFieldsList) && equalLists(oldOptionalFieldsList, optionalFieldsList)) {
changesMade = false;
}
}
if (changesMade) {
CustomEntryType customType = biblatexMode ? new CustomEntryType(StringUtil.capitalizeFirst(stringListEntry.getKey()), requiredFieldsList, optionalFieldsList, secondaryOptionalFieldsLists) : new CustomEntryType(StringUtil.capitalizeFirst(stringListEntry.getKey()), requiredFieldsList, optionalFieldsList);
EntryTypes.addOrModifyCustomEntryType(customType, bibDatabaseMode);
actuallyChangedTypes.add(customType.getName().toLowerCase(Locale.ENGLISH));
}
}
// update all affected entries if something has been changed
if (!actuallyChangedTypes.isEmpty()) {
updateEntriesForChangedTypes(actuallyChangedTypes);
}
Set<String> typesToRemove = new HashSet<>();
for (String existingType : EntryTypes.getAllTypes(bibDatabaseMode)) {
if (!types.contains(existingType)) {
typesToRemove.add(existingType);
}
}
// Remove those that should be removed:
if (!typesToRemove.isEmpty()) {
for (String typeToRemove : typesToRemove) {
deleteType(typeToRemove);
}
}
updateTables();
CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
}
Aggregations