Search in sources :

Example 1 with MainTableSelectionListener

use of org.jabref.gui.maintable.MainTableSelectionListener in project jabref by JabRef.

the class BasePanel method createMainTable.

private void createMainTable() {
    bibDatabaseContext.getDatabase().registerListener(tableModel.getListSynchronizer());
    bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance());
    tableFormat = new MainTableFormat(bibDatabaseContext.getDatabase());
    tableFormat.updateTableFormat();
    mainTable = new MainTable(tableFormat, tableModel, frame, this);
    selectionListener = new MainTableSelectionListener(this, mainTable);
    mainTable.updateFont();
    mainTable.addSelectionListener(selectionListener);
    mainTable.addMouseListener(selectionListener);
    mainTable.addKeyListener(selectionListener);
    mainTable.addFocusListener(selectionListener);
    // Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX)
    mainTable.addSelectionListener(listEvent -> Platform.runLater(() -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries())));
    String clearSearch = "clearSearch";
    mainTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), clearSearch);
    mainTable.getActionMap().put(clearSearch, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // need to close these here, b/c this action overshadows the responsible actions when the main table is selected
            switch(mode) {
                case SHOWING_NOTHING:
                    frame.getGlobalSearchBar().endSearch();
                    break;
                case SHOWING_PREVIEW:
                    getPreviewPanel().close();
                    break;
                case SHOWING_EDITOR:
                case WILL_SHOW_EDITOR:
                    getCurrentEditor().close();
                    break;
                default:
                    LOGGER.warn("unknown BasePanelMode: '" + mode + "', doing nothing");
                    break;
            }
        }
    });
    mainTable.getActionMap().put(Actions.CUT, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.CUT);
            } catch (Throwable ex) {
                LOGGER.warn("Could not cut", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.COPY, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.COPY);
            } catch (Throwable ex) {
                LOGGER.warn("Could not copy", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.PASTE);
            } catch (Throwable ex) {
                LOGGER.warn("Could not paste", ex);
            }
        }
    });
    mainTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            if (e.isControlDown()) {
                switch(keyCode) {
                    case KeyEvent.VK_PAGE_DOWN:
                        frame.nextTab.actionPerformed(null);
                        e.consume();
                        break;
                    case KeyEvent.VK_PAGE_UP:
                        frame.prevTab.actionPerformed(null);
                        e.consume();
                        break;
                    default:
                        break;
                }
            } else if (keyCode == KeyEvent.VK_ENTER) {
                e.consume();
                try {
                    runCommand(Actions.EDIT);
                } catch (Throwable ex) {
                    LOGGER.warn("Could not run action based on key press", ex);
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MainTableFormat(org.jabref.gui.maintable.MainTableFormat) MainTableSelectionListener(org.jabref.gui.maintable.MainTableSelectionListener) MainTable(org.jabref.gui.maintable.MainTable) AbstractAction(javax.swing.AbstractAction)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 AbstractAction (javax.swing.AbstractAction)1 MainTable (org.jabref.gui.maintable.MainTable)1 MainTableFormat (org.jabref.gui.maintable.MainTableFormat)1 MainTableSelectionListener (org.jabref.gui.maintable.MainTableSelectionListener)1