Search in sources :

Example 26 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project otapij by FellowTraveler.

the class MainPage method initMainTab.

private void initMainTab() {
    jPanel_TopPanel.setLayout(new CardLayout());
    jPanel_BottomPanel.setLayout(new CardLayout());
    jTable_AccountTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            System.out.println("valueChanged Action Listener :" + jTable_AccountTable.getSelectedRow() + "e:" + e.getSource());
            if (jTable_AccountTable.getSelectedRow() >= 0) {
                try {
                    jPanel_TopPanel.setVisible(true);
                    jPanel_BottomPanel.setVisible(true);
                    CardLayout topLayout = (CardLayout) (jPanel_TopPanel.getLayout());
                    CardLayout bottomlayout = (CardLayout) (jPanel_BottomPanel.getLayout());
                    String type = null;
                    String accountID = null;
                    type = (String) jTable_AccountTable.getModel().getValueAt(jTable_AccountTable.getSelectedRow(), 2);
                    accountID = (String) jTable_AccountTable.getModel().getValueAt(jTable_AccountTable.getSelectedRow(), 3);
                    System.out.println("Type:" + type);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    for (int i = 0; i < Account.allAccounts.length; i++) {
                        if (Account.allAccounts[i].equalsIgnoreCase(type)) {
                            try {
                                topLayout.show(jPanel_TopPanel, type + "TopPanel");
                                bottomlayout.show(jPanel_BottomPanel, type + "BottomPanel");
                                Class obj = Class.forName("com.moneychanger.core." + type);
                                Account account = (Account) obj.newInstance();
                                Object details = account.getAccountDetails(accountID);
                                if (details == null) {
                                    JOptionPane.showMessageDialog(null, "Error loading details", "Details Error", JOptionPane.ERROR_MESSAGE);
                                    break;
                                }
                                if ("OpenTransactionAccount".equalsIgnoreCase(type)) {
                                    OTDetails otDetails = (OTDetails) details;
                                    Helpers.populateOTDetails(otDetails);
                                    ((AccountTableModel) jTable_AccountTable.getModel()).setValueAt(otDetails.getBalance(), jTable_AccountTable.getSelectedRow(), 1);
                                } else if ("CashPurseAccount".equalsIgnoreCase(type)) {
                                    CashPurseDetails cashDetails = (CashPurseDetails) details;
                                    populateCashPurseDetails(cashDetails, cashDetails.getBalance());
                                }
                                break;
                            } catch (InstantiationException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IllegalAccessException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (ClassNotFoundException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            repaint();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {
                    setCursor(Cursor.getDefaultCursor());
                }
            }
        }
    });
    nymMap = new NYM().loadNYM();
    jComboBox_Nyms.addItem(new ComboObject("ALL"));
    jComboBoxServerContracts.addItem(new ComboObject("ALL"));
    jComboBox_AssetContracts.addItem(new ComboObject("ALL"));
    Helpers.populateCombo(nymMap, jComboBox_Nyms);
    Contract contract = new Contract();
    serverMap = contract.loadServerContract();
    Helpers.populateCombo(serverMap, jComboBoxServerContracts);
    assetMap = contract.loadAssetContract();
    Helpers.populateCombo(assetMap, jComboBox_AssetContracts);
    Account account = null;
    for (int i = 0; i < Account.allAccounts.length; i++) {
        try {
            if ("OpenTransactionAccount".equals(Account.allAccounts[i]) || "CashPurseAccount".equals(Account.allAccounts[i])) {
                Class obj = Class.forName("com.moneychanger.core." + Account.allAccounts[i]);
                account = (Account) obj.newInstance();
                try {
                    account.loadAccount("ALL", "ALL", "ALL");
                } catch (Exception ex) {
                    Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                }
                Class obj1 = Class.forName("com.moneychanger.ui.panels." + Account.allAccounts[i] + "TopPanel");
                JPanel topPanel = (JPanel) obj1.newInstance();
                jPanel_TopPanel.add(topPanel, Account.allAccounts[i] + "TopPanel");
                Class obj2 = Class.forName("com.moneychanger.ui.panels." + Account.allAccounts[i] + "BottomPanel");
                JPanel bottomPanel = (JPanel) obj2.newInstance();
                jPanel_BottomPanel.add(bottomPanel, Account.allAccounts[i] + "BottomPanel");
            }
        } catch (InstantiationException ex) {
        //Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        ///Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
        //Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : CardLayout(java.awt.CardLayout) OpenTransactionAccount(com.moneychanger.core.OpenTransactionAccount) RippleAccount(com.moneychanger.core.RippleAccount) Account(com.moneychanger.core.Account) JPanel(javax.swing.JPanel) NYM(com.moneychanger.core.NYM) CashPurseDetails(com.moneychanger.core.dataobjects.CashPurseDetails) ListSelectionEvent(javax.swing.event.ListSelectionEvent) AWTException(java.awt.AWTException) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) OTDetails(com.moneychanger.core.dataobjects.OTDetails) ComboObject(com.moneychanger.core.util.ComboObject) ComboObject(com.moneychanger.core.util.ComboObject) Contract(com.moneychanger.core.Contract)

Example 27 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project otapij by FellowTraveler.

the class MainPage method initOtherTab.

private void initOtherTab() {
    try {
        jPanel27.setLayout(new CardLayout());
        jPanel28.setLayout(new CardLayout());
        System.out.println("in initOtherTab");
        //load servers here
        loadOtherTabServers();
        jTable4.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    return;
                }
                System.out.println("selectedRow:" + jTable4.getSelectedRow());
                if (jTable4.getSelectedRow() >= 0) {
                    String serverID = (String) jTable4.getModel().getValueAt(jTable4.getSelectedRow(), 2);
                    String type = (String) jTable4.getModel().getValueAt(jTable4.getSelectedRow(), 1);
                    System.out.println("selected serverID:" + serverID + " type:" + type);
                    if ("BitcoinAccount".equals(type)) {
                        Account account = null;
                        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        try {
                            try {
                                account = (Account) (Class.forName("com.moneychanger.core." + type)).newInstance();
                                account.setServerID(serverID);
                            } catch (InstantiationException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IllegalAccessException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        /*if (type.contains("Bitcoin")) {
                            account = new BitcoinAccount(serverID);
                            }*/
                        try {
                            account.loadAccount("", serverID, "");
                            ((OtherTabAccountModel) jTable3.getModel()).setValue(account.getAccountList(), jTable3);
                        } catch (Exception ex) {
                            System.out.println("In BTC load exception:" + ex);
                            JOptionPane.showMessageDialog(null, "Cannot connect to bitcoin service - Connection refused", "Connection Error", JOptionPane.ERROR_MESSAGE);
                        //jTable4.setRowSelectionInterval(WIDTH, WIDTH);
                        } finally {
                            setCursor(Cursor.getDefaultCursor());
                        }
                    } else if ("RippleAccount".equalsIgnoreCase(type)) {
                        CardLayout topLayout = (CardLayout) (jPanel27.getLayout());
                        CardLayout bottomlayout = (CardLayout) (jPanel28.getLayout());
                        topLayout.show(jPanel27, "BlankTop");
                        bottomlayout.show(jPanel28, "BlankBottom");
                        ((OtherTabAccountModel) jTable3.getModel()).clearValue();
                        String[] details = new RippleAccount().loadServerDetails(serverID);
                        if (details != null) {
                            RippleAccountTopPanel.openBrowser(details[0], details[1], details[2], details[3], details[4]);
                        }
                    }
                }
            }
        });
        //((OtherTabServerTableModel) jTable4.getModel()).setValue(new NYM().loadNYM(), jTable4);
        jTable3.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    return;
                }
                System.out.println("valueChanged Action Listener :" + jTable3.getSelectedRow() + "e:" + e.getSource());
                if (jTable3.getSelectedRow() >= 0) {
                    try {
                        jPanel27.setVisible(true);
                        jPanel28.setVisible(true);
                        CardLayout topLayout = (CardLayout) (jPanel27.getLayout());
                        CardLayout bottomlayout = (CardLayout) (jPanel28.getLayout());
                        String type = null;
                        String accountID = null;
                        type = (String) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 2);
                        accountID = (String) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 3);
                        System.out.println("Type:" + type);
                        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        for (int i = 0; i < Account.allAccounts.length; i++) {
                            if (Account.allAccounts[i].equalsIgnoreCase(type)) {
                                try {
                                    topLayout.show(jPanel27, type + "TopPanel");
                                    bottomlayout.show(jPanel28, type + "BottomPanel");
                                    Class obj = Class.forName("com.moneychanger.core." + type);
                                    Account account = (Account) obj.newInstance();
                                    account.setServerID((String) jTable4.getModel().getValueAt(jTable4.getSelectedRow(), 2));
                                    Object details = account.getAccountDetails(accountID);
                                    if (details == null) {
                                        JOptionPane.showMessageDialog(null, "Error loading details", "Details Error", JOptionPane.ERROR_MESSAGE);
                                        break;
                                    }
                                    if ("BitcoinAccount".equalsIgnoreCase(type)) {
                                        BitcoinDetails btcDetails = (BitcoinDetails) details;
                                        populateBitcoinDetails(btcDetails);
                                    }
                                //}
                                } catch (InstantiationException ex) {
                                    Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                                } catch (IllegalAccessException ex) {
                                    Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                                } catch (ClassNotFoundException ex) {
                                    Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                                }
                                repaint();
                            }
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        setCursor(Cursor.getDefaultCursor());
                    }
                }
            }
        });
        jPanel27.add(new BlankPanel(), "BlankTop");
        jPanel28.add(new BlankPanel(), "BlankBottom");
        for (int i = 0; i < Account.allAccounts.length; i++) {
            try {
                System.out.println("in initOtherTabloop");
                if (!"OpenTransactionAccount".equals(Account.allAccounts[i]) && !"CashPurseAccount".equals(Account.allAccounts[i])) {
                    System.out.println("initOtherTabloop --- Account.allAccounts[i]:" + Account.allAccounts[i]);
                    Class obj1 = Class.forName("com.moneychanger.ui.panels." + Account.allAccounts[i] + "TopPanel");
                    JPanel topPanel = (JPanel) obj1.newInstance();
                    jPanel27.add(topPanel, Account.allAccounts[i] + "TopPanel");
                    Class obj2 = Class.forName("com.moneychanger.ui.panels." + Account.allAccounts[i] + "BottomPanel");
                    JPanel bottomPanel = (JPanel) obj2.newInstance();
                    // Setting the account account to retrieve in bottom panel
                    jPanel28.add(bottomPanel, Account.allAccounts[i] + "BottomPanel");
                }
            } catch (InstantiationException ex) {
            //Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
            ///Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
            //Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        // TODO might need to uncomment
        //loadOtherTabAccount("");
        OtherTabAccountModel.removeCols(jTable3);
        OtherTabServerTableModel.removeCols(jTable4);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CardLayout(java.awt.CardLayout) OpenTransactionAccount(com.moneychanger.core.OpenTransactionAccount) RippleAccount(com.moneychanger.core.RippleAccount) Account(com.moneychanger.core.Account) JPanel(javax.swing.JPanel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) BlankPanel(com.moneychanger.ui.panels.BlankPanel) OtherTabAccountModel(com.moneychanger.ui.model.OtherTabAccountModel) AWTException(java.awt.AWTException) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) ComboObject(com.moneychanger.core.util.ComboObject) RippleAccount(com.moneychanger.core.RippleAccount) BitcoinDetails(com.moneychanger.core.dataobjects.BitcoinDetails)

Example 28 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.

the class ModuleAwareProjectConfigurable method createComponent.

@Override
public JComponent createComponent() {
    if (myProject.isDefault()) {
        T configurable = createDefaultProjectConfigurable();
        if (configurable != null) {
            myModuleConfigurables.put(null, configurable);
            return configurable.createComponent();
        }
    }
    final List<Module> modules = ContainerUtil.filter(ModuleAttachProcessor.getSortedModules(myProject), module -> isSuitableForModule(module));
    final T projectConfigurable = createProjectConfigurable();
    if (modules.size() == 1 && projectConfigurable == null) {
        Module module = modules.get(0);
        final T configurable = createModuleConfigurable(module);
        myModuleConfigurables.put(module, configurable);
        return configurable.createComponent();
    }
    final Splitter splitter = new Splitter(false, 0.25f);
    CollectionListModel<Module> listDataModel = new CollectionListModel<>(modules);
    final JBList moduleList = new JBList(listDataModel);
    new ListSpeedSearch(moduleList, (Function<Object, String>) o -> {
        if (o == null) {
            return getProjectConfigurableItemName();
        } else if (o instanceof Module) {
            return ((Module) o).getName();
        }
        return null;
    });
    moduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    moduleList.setCellRenderer(new ModuleListCellRenderer() {

        @Override
        public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) {
            if (module == null) {
                setText(getProjectConfigurableItemName());
                setIcon(getProjectConfigurableItemIcon());
            } else {
                super.customize(list, module, index, selected, hasFocus);
            }
        }
    });
    splitter.setFirstComponent(new JBScrollPane(moduleList));
    final CardLayout layout = new CardLayout();
    final JPanel cardPanel = new JPanel(layout);
    splitter.setSecondComponent(cardPanel);
    if (projectConfigurable != null) {
        myModuleConfigurables.put(null, projectConfigurable);
        final JComponent component = projectConfigurable.createComponent();
        cardPanel.add(component, PROJECT_ITEM_KEY);
        listDataModel.add(0, null);
    }
    for (Module module : modules) {
        final T configurable = createModuleConfigurable(module);
        myModuleConfigurables.put(module, configurable);
        final JComponent component = configurable.createComponent();
        cardPanel.add(component, module.getName());
    }
    moduleList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            final Module value = (Module) moduleList.getSelectedValue();
            layout.show(cardPanel, value == null ? PROJECT_ITEM_KEY : value.getName());
        }
    });
    if (moduleList.getItemsCount() > 0) {
        moduleList.setSelectedIndex(0);
        Module module = listDataModel.getElementAt(0);
        layout.show(cardPanel, module == null ? PROJECT_ITEM_KEY : module.getName());
    }
    return splitter;
}
Also used : ModuleAttachProcessor(com.intellij.platform.ModuleAttachProcessor) AllIcons(com.intellij.icons.AllIcons) HashMap(java.util.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) Nls(org.jetbrains.annotations.Nls) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Splitter(com.intellij.openapi.ui.Splitter) JBList(com.intellij.ui.components.JBList) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) Configurable(com.intellij.openapi.options.Configurable) CollectionListModel(com.intellij.ui.CollectionListModel) JBScrollPane(com.intellij.ui.components.JBScrollPane) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) javax.swing(javax.swing) Splitter(com.intellij.openapi.ui.Splitter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) JBList(com.intellij.ui.components.JBList) Module(com.intellij.openapi.module.Module) CollectionListModel(com.intellij.ui.CollectionListModel) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 29 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.

the class GotoActionAction method createPopup.

@Nullable
private static ChooseByNamePopup createPopup(@Nullable Project project, @NotNull final GotoActionModel model, String initialText, int initialIndex, final Component component, final AnActionEvent e) {
    ChooseByNamePopup oldPopup = project == null ? null : project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
    if (oldPopup != null) {
        oldPopup.close(false);
    }
    final Disposable disposable = Disposer.newDisposable();
    final ChooseByNamePopup popup = new ChooseByNamePopup(project, model, new GotoActionItemProvider(model), oldPopup, initialText, false, initialIndex) {

        private boolean myPaintInternalInfo;

        @Override
        protected void initUI(Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            myList.addListSelectionListener(new ListSelectionListener() {

                @Override
                public void valueChanged(ListSelectionEvent e) {
                    Object value = myList.getSelectedValue();
                    String text = getText(value);
                    if (text != null && myDropdownPopup != null) {
                        myDropdownPopup.setAdText(text, SwingConstants.LEFT);
                    }
                    String description = getValueDescription(value);
                    ActionMenu.showDescriptionInStatusBar(true, myList, description);
                }

                @Nullable
                private String getText(@Nullable Object o) {
                    if (o instanceof GotoActionModel.MatchedValue) {
                        GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue) o;
                        if (myPaintInternalInfo) {
                            if (mv.value instanceof GotoActionModel.ActionWrapper) {
                                AnAction action = ((GotoActionModel.ActionWrapper) mv.value).getAction();
                                String actionId = ActionManager.getInstance().getId(action);
                                return StringUtil.notNullize(actionId, "class: " + action.getClass().getName());
                            }
                        }
                        if (mv.value instanceof BooleanOptionDescription || mv.value instanceof GotoActionModel.ActionWrapper && ((GotoActionModel.ActionWrapper) mv.value).getAction() instanceof ToggleAction) {
                            return "Press " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)) + " to toggle option";
                        }
                    }
                    return getAdText();
                }
            });
            myList.addMouseMotionListener(new MouseMotionAdapter() {

                @Override
                public void mouseMoved(MouseEvent e) {
                    int index = myList.locationToIndex(e.getPoint());
                    if (index == -1)
                        return;
                    Object value = myList.getModel().getElementAt(index);
                    String description = getValueDescription(value);
                    ActionMenu.showDescriptionInStatusBar(true, myList, description);
                }
            });
            if (Registry.is("show.configurables.ids.in.settings")) {
                new HeldDownKeyListener() {

                    @Override
                    protected void heldKeyTriggered(JComponent component, boolean pressed) {
                        myPaintInternalInfo = pressed;
                        // an easy way to repaint the AdText
                        ListSelectionEvent event = new ListSelectionEvent(this, -1, -1, false);
                        for (ListSelectionListener listener : myList.getListSelectionListeners()) {
                            listener.valueChanged(event);
                        }
                    }
                }.installOn(myTextField);
            }
        }

        @Nullable
        private String getValueDescription(@Nullable Object value) {
            if (value instanceof GotoActionModel.MatchedValue) {
                GotoActionModel.MatchedValue mv = (GotoActionModel.MatchedValue) value;
                if (mv.value instanceof GotoActionModel.ActionWrapper) {
                    AnAction action = ((GotoActionModel.ActionWrapper) mv.value).getAction();
                    return action.getTemplatePresentation().getDescription();
                }
            }
            return null;
        }

        @NotNull
        @Override
        protected Set<Object> filter(@NotNull Set<Object> elements) {
            return super.filter(model.sortItems(elements));
        }

        @Override
        protected boolean closeForbidden(boolean ok) {
            if (!ok)
                return false;
            Object element = getChosenElement();
            return element instanceof GotoActionModel.MatchedValue && processOptionInplace(((GotoActionModel.MatchedValue) element).value, this, component, e) || super.closeForbidden(true);
        }

        @Override
        public void setDisposed(boolean disposedFlag) {
            super.setDisposed(disposedFlag);
            Disposer.dispose(disposable);
            ActionMenu.showDescriptionInStatusBar(true, myList, null);
            for (ListSelectionListener listener : myList.getListSelectionListeners()) {
                myList.removeListSelectionListener(listener);
            }
            UIUtil.dispose(myList);
        }
    };
    ApplicationManager.getApplication().getMessageBus().connect(disposable).subscribe(ProgressWindow.TOPIC, new ProgressWindow.Listener() {

        @Override
        public void progressWindowCreated(ProgressWindow pw) {
            Disposer.register(pw, new Disposable() {

                @Override
                public void dispose() {
                    if (!popup.checkDisposed()) {
                        popup.repaintList();
                    }
                }
            });
        }
    });
    if (project != null) {
        project.putUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY, popup);
    }
    popup.addMouseClickListener(new MouseAdapter() {

        @Override
        public void mouseClicked(@NotNull MouseEvent me) {
            Object element = popup.getSelectionByPoint(me.getPoint());
            if (element instanceof GotoActionModel.MatchedValue) {
                if (processOptionInplace(((GotoActionModel.MatchedValue) element).value, popup, component, e)) {
                    me.consume();
                }
            }
        }
    });
    CustomShortcutSet shortcutSet = new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS));
    new DumbAwareAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            Object o = popup.getChosenElement();
            if (o instanceof GotoActionModel.MatchedValue) {
                Comparable value = ((GotoActionModel.MatchedValue) o).value;
                if (value instanceof GotoActionModel.ActionWrapper) {
                    GotoActionModel.ActionWrapper aw = (GotoActionModel.ActionWrapper) value;
                    boolean available = aw.isAvailable();
                    if (available) {
                        AnAction action = aw.getAction();
                        String id = ActionManager.getInstance().getId(action);
                        KeymapManagerImpl km = ((KeymapManagerImpl) KeymapManager.getInstance());
                        Keymap k = km.getActiveKeymap();
                        if (!k.canModify())
                            return;
                        KeymapPanel.addKeyboardShortcut(id, ActionShortcutRestrictions.getInstance().getForActionId(id), k, component);
                        popup.repaintListImmediate();
                    }
                }
            }
        }
    }.registerCustomShortcutSet(shortcutSet, popup.getTextField(), disposable);
    return popup;
}
Also used : Set(java.util.Set) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) GotoActionItemProvider(com.intellij.ide.util.gotoByName.GotoActionItemProvider) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) Disposable(com.intellij.openapi.Disposable) GotoActionModel(com.intellij.ide.util.gotoByName.GotoActionModel) HeldDownKeyListener(com.intellij.ui.HeldDownKeyListener) ListSelectionListener(javax.swing.event.ListSelectionListener) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) ModalityState(com.intellij.openapi.application.ModalityState) Nullable(org.jetbrains.annotations.Nullable) KeymapManagerImpl(com.intellij.openapi.keymap.impl.KeymapManagerImpl) Keymap(com.intellij.openapi.keymap.Keymap) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with ListSelectionListener

use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.

the class RenameChooser method showChooser.

public void showChooser(final Collection<PsiReference> refs, final Collection<Pair<PsiElement, TextRange>> stringUsages) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        runRenameTemplate(RefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_FILE ? stringUsages : new ArrayList<>());
        return;
    }
    final DefaultListModel model = new DefaultListModel();
    model.addElement(CODE_OCCURRENCES);
    model.addElement(ALL_OCCURRENCES);
    final JList list = new JBList(model);
    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            final String selectedValue = (String) list.getSelectedValue();
            if (selectedValue == null)
                return;
            dropHighlighters();
            final MarkupModel markupModel = myEditor.getMarkupModel();
            if (selectedValue.equals(ALL_OCCURRENCES)) {
                for (Pair<PsiElement, TextRange> pair : stringUsages) {
                    final TextRange textRange = pair.second.shiftRight(pair.first.getTextOffset());
                    final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.SELECTION - 1, myAttributes, HighlighterTargetArea.EXACT_RANGE);
                    myRangeHighlighters.add(rangeHighlighter);
                }
            }
            for (PsiReference reference : refs) {
                final PsiElement element = reference.getElement();
                if (element == null)
                    continue;
                final TextRange textRange = element.getTextRange();
                final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.SELECTION - 1, myAttributes, HighlighterTargetArea.EXACT_RANGE);
                myRangeHighlighters.add(rangeHighlighter);
            }
        }
    });
    JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("String occurrences found").setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> runRenameTemplate(ALL_OCCURRENCES.equals(list.getSelectedValue()) ? stringUsages : new ArrayList<>())).addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            dropHighlighters();
        }
    }).createPopup().showInBestPositionFor(myEditor);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) ListSelectionListener(javax.swing.event.ListSelectionListener) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) JBList(com.intellij.ui.components.JBList) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

ListSelectionListener (javax.swing.event.ListSelectionListener)106 ListSelectionEvent (javax.swing.event.ListSelectionEvent)102 ActionEvent (java.awt.event.ActionEvent)28 ActionListener (java.awt.event.ActionListener)22 MouseEvent (java.awt.event.MouseEvent)20 JScrollPane (javax.swing.JScrollPane)20 JPanel (javax.swing.JPanel)19 JBList (com.intellij.ui.components.JBList)17 JButton (javax.swing.JButton)17 BorderLayout (java.awt.BorderLayout)14 JLabel (javax.swing.JLabel)13 NotNull (org.jetbrains.annotations.NotNull)13 FlowLayout (java.awt.FlowLayout)10 MouseAdapter (java.awt.event.MouseAdapter)10 List (java.util.List)10 Insets (java.awt.Insets)9 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9 ArrayList (java.util.ArrayList)8 JTextField (javax.swing.JTextField)8