Example usage for javax.swing SwingUtilities isLeftMouseButton

List of usage examples for javax.swing SwingUtilities isLeftMouseButton

Introduction

In this page you can find the example usage for javax.swing SwingUtilities isLeftMouseButton.

Prototype

public static boolean isLeftMouseButton(MouseEvent anEvent) 

Source Link

Document

Returns true if the mouse event specifies the left mouse button.

Usage

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void songData_TableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_songData_TableMouseClicked
        try {/* w  w w.ja v  a  2 s.c  o m*/
            if (evt.getClickCount() == 2 | next == 1 | previous == 1 && SwingUtilities.isLeftMouseButton(evt)) {
                currentSongRow = songData_Table.getSelectedRow();
                songLocation = songData[currentSongRow];
                sd.addToRecent(songLocation);
                for (ObjectBean list1 : list) {
                    list1.getMpg().addJmenuItemsToRecentSongs();
                }
                songPlay();
            } else if (SwingUtilities.isRightMouseButton(evt)) {
                Point point = evt.getPoint();
                int alreadySelectedRow = songData_Table.getSelectedRow();
                int currentRow = songData_Table.rowAtPoint(point);
                songData_Table.setRowSelectionInterval(alreadySelectedRow, currentRow);
                if (songData_Table.isRowSelected(currentRow)) {
                    songTable_PopUp.show(songData_Table, evt.getX(), evt.getY());
                } else {
                    songTable_PopUp.show(songTable_PopUp, evt.getX(), evt.getY());
                }
            }
        } catch (Exception e) {
            currentSongRow = songData_Table.getSelectedRow();
            songLocation = songData[currentSongRow];
            sd.addToRecent(songLocation);
            for (ObjectBean list1 : list) {
                list1.getMpg().addJmenuItemsToRecentSongs();
            }
            songPlay();
        }
        ;
    }

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void folder_Playlist_TreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_folder_Playlist_TreeMouseClicked
        DefaultMutableTreeNode selectedNode;

        if (evt.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(evt)) {
            selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath().getLastPathComponent();
            getSongTable(selectedNode.toString());
            lastOpen = selectedNode.toString();
            for (ObjectBean list1 : list) {
                if (list1.getTitle().equals("library")) {
                    list1.setLastOpen(lastOpen);
                }/*from   w  w w . j ava  2  s  .com*/
            }
        } else if (SwingUtilities.isRightMouseButton(evt)) {
            DefaultTreeModel myModel = (DefaultTreeModel) folder_Playlist_Tree.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();

            TreeNode[] nodes = myModel.getPathToRoot(root);
            TreePath treepath = new TreePath(nodes);
            folder_Playlist_Tree.setSelectionPath(treepath);
            folder_Playlist_Tree.scrollPathToVisible(treepath);

            TreePath path = folder_Playlist_Tree.getPathForLocation(evt.getX(), evt.getY());
            folder_Playlist_Tree.setSelectionPath(path);
            folder_Playlist_Tree.scrollPathToVisible(path);
            if (!folder_Playlist_Tree.isSelectionEmpty()) {
                selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath()
                        .getLastPathComponent();
                if (!"playlist".equals(selectedNode.toString()) && !"library".equals(selectedNode.toString())) {
                    folderTree_PopUp.show(folder_Playlist_Tree, evt.getX(), evt.getY());
                }
            }
        }
    }

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

@Override
public void mouseDragged(final MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e)) {
        final HexPosition hexNumber = this.hexMapPanel.getHexPosition(e.getPoint());
        useCurrentToolAtPosition(hexNumber);
    } else if (this.dragging) {
        this.hexMapPanelDesktop.processDrag(e.getPoint());
    }/*from  w w  w .  j  av a 2  s. co m*/
}

From source file:org.alex73.skarynka.scan.ui.book.BooksController.java

public BooksController() {
    try {/*from www  . j  av a2  s .  c  o  m*/
        panel = new BooksPanel();
        ((AbstractDocument) panel.txtNewName.getDocument()).setDocumentFilter(bookNameFilter);

        listScanDirs();

        panel.table.setModel(model());
        panel.table.setRowSelectionAllowed(true);
        panel.table.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
                    BookRow b = books.get(panel.table.getSelectedRow());
                    DataStorage.openBook(b.bookName, true);
                }
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    for (int i = 0; i < panel.menuProcess.getComponentCount(); i++) {
                        Component item = panel.menuProcess.getComponent(i);
                        if ((item instanceof JMenuItem) && (item.getName() != null)) {
                            panel.menuProcess.remove(i);
                            i--;
                        }
                    }
                    if (Context.getPermissions().BookControl) {
                        for (int scale : new int[] { 25, 50, 75, 100, 200 }) {
                            JMenuItem item = new JMenuItem(scale + "%");
                            item.setName(scale + "%");
                            item.addActionListener(new ChangeScale(scale));
                            panel.menuProcess.add(item);
                        }
                    }

                    currentBooksNames.clear();
                    int[] selected = panel.table.getSelectedRows();
                    boolean allLocals = true;
                    boolean processAllowed = Context.getPermissions().BookControl;
                    for (int row : selected) {
                        BookRow b = books.get(panel.table.convertRowIndexToModel(row));
                        currentBooksNames.add(b.bookName);
                        if (!b.local) {
                            allLocals = false;
                        }
                    }
                    panel.itemFinish.setVisible(allLocals);
                    if (processAllowed) {
                        for (Map.Entry<String, String> en : Context.getProcessCommands().entrySet()) {
                            JMenuItem item = new JMenuItem(en.getValue());
                            item.setName(en.getKey());
                            item.addActionListener(commandListener);
                            panel.menuProcess.add(item);
                        }
                    }
                    panel.menuProcess.show(panel.table, e.getX(), e.getY());
                }
            }
        });

        panel.btnCreate.setEnabled(false);
        panel.btnCreate.addActionListener(
                new ActionErrorListener(panel, "ERROR_BOOK_CREATE", LOG, "Error create book") {
                    protected void action(ActionEvent e) throws Exception {
                        File bookDir = new File(Context.getBookDir(), panel.txtNewName.getText());
                        if (bookDir.exists()) {
                            JOptionPane.showMessageDialog(panel,
                                    Messages.getString("PANEL_BOOK_NEW_BOOK_EXIST"),
                                    Messages.getString("PANEL_BOOK_TITLE"), JOptionPane.WARNING_MESSAGE);
                            return;
                        }

                        DataStorage.openBook(panel.txtNewName.getText(), true);
                    }
                });

        setMenuListeners();
    } catch (Throwable ex) {
        LOG.error("Error list books", ex);
        JOptionPane.showMessageDialog(DataStorage.mainFrame,
                "Error: " + ex.getClass() + " / " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.isatools.isacreator.filechooser.FileChooserUI.java

/**
 * Create the Navigation Tree panel/*from  www . j ava 2 s . c om*/
 *
 * @return @see JPanel containing the navigation tree to browse a file system.
 */
private JPanel createNavTree() {
    JPanel treeContainer = new JPanel(new BorderLayout());
    treeContainer.setBackground(UIHelper.BG_COLOR);
    treeContainer
            .setBorder(new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    JPanel navigationControls = new JPanel();
    navigationControls.setLayout(new BoxLayout(navigationControls, BoxLayout.LINE_AXIS));
    navigationControls.setOpaque(false);

    final JLabel navToParentDir = new JLabel(upIcon);
    navToParentDir.setOpaque(false);
    navToParentDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToParentDir.setIcon(upIcon);
            try {
                updateTree(fileBrowser.getParentDirectory());
            } catch (IOException e) {
                errorAction("problem occurred!");
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToParentDir.setIcon(upIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToParentDir.setIcon(upIcon);
        }
    });

    navigationControls.add(navToParentDir);
    navigationControls.add(Box.createHorizontalStrut(5));

    final JLabel navToHomeDir = new JLabel(homeIcon);
    navToHomeDir.setOpaque(false);
    navToHomeDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToHomeDir.setIcon(homeIcon);
            try {
                updateTree(fileBrowser.getHomeDirectory());

            } catch (IOException e) {
                if (e instanceof ConnectionException) {
                    status.setText("<html>status: not connected!</html>");
                }
                FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                        FileBrowserTreeNode.DIRECTORY);
                updateTree(defaultFTPNode);
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToHomeDir.setIcon(homeIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToHomeDir.setIcon(homeIcon);
        }
    });

    navigationControls.add(navToHomeDir);
    navigationControls.add(Box.createGlue());

    treeContainer.add(navigationControls, BorderLayout.NORTH);

    try {
        treeModel = new DefaultTreeModel(fileBrowser.getHomeDirectory());
        directoryTree = new JTree(treeModel);
        directoryTree.setFont(UIHelper.VER_11_PLAIN);
        directoryTree.setCellRenderer(new FileSystemTreeCellRenderer());
    } catch (IOException e) {
        FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                FileBrowserTreeNode.DIRECTORY);
        updateTree(defaultFTPNode);
    }

    directoryTree.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            int selRow = directoryTree.getRowForLocation(event.getX(), event.getY());

            TreePath selPath = directoryTree.getPathForLocation(event.getX(), event.getY());

            if (selRow != -1) {
                final FileBrowserTreeNode node = (FileBrowserTreeNode) selPath.getLastPathComponent();

                if (SwingUtilities.isLeftMouseButton(event)) {

                    if (event.getClickCount() == 2) {
                        if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                            String newPath;
                            if (fileBrowser instanceof LocalBrowser) {
                                newPath = ((File) fileBrowser.getDirFiles().get(node.toString())).getPath();
                            } else {
                                newPath = node.toString();
                            }
                            updateTree(fileBrowser.changeDirectory(newPath));
                        }

                        // else, if a leaf node, then add file to to list
                        if (node.isLeaf() && (node.getType() != FileBrowserTreeNode.DIRECTORY)) {
                            String extension = node.toString().substring(node.toString().lastIndexOf(".") + 1)
                                    .trim().toUpperCase();

                            FileChooserFile toAdd = null;

                            for (Object o : fileBrowser.getFileMap().get(extension)) {
                                String fileName;
                                String filePath;
                                if (fileBrowser instanceof LocalBrowser) {
                                    File file = (File) o;
                                    fileName = file.getName();
                                    filePath = file.getPath();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFile(filePath);
                                        break;
                                    }
                                } else {
                                    FTPFile ftpFile = (FTPFile) o;
                                    fileName = ftpFile.getName();
                                    filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFTPFile(ftpFile, filePath);
                                        break;
                                    }
                                }

                            }

                            if (toAdd != null && !checkIfInList(toAdd)) {
                                selectedFiles.addFileItem(toAdd);
                            }
                        }
                    }
                } else {
                    if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                        // show popup to add the directory to the selected files
                        JPopupMenu popup = new JPopupMenu();

                        JMenuItem addDirectory = new JMenuItem("add directory");
                        addDirectory.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {

                                Object fileToAdd = fileBrowser.getDirFiles().get(node.toString());
                                FileChooserFile toAdd;

                                if (fileToAdd instanceof File) {
                                    toAdd = new CustomFile(((File) fileToAdd).getPath());
                                } else {
                                    FTPFile ftpFile = (FTPFile) fileToAdd;
                                    String filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    toAdd = new CustomFTPFile(ftpFile, filePath);
                                }

                                if (!checkIfInList(toAdd)) {
                                    selectedFiles.addDirectoryItem(toAdd);
                                }
                            }
                        });

                        popup.add(addDirectory);
                        popup.show(directoryTree, event.getX(), event.getY());
                    }
                }
            }
        }

    });

    BasicTreeUI ui = new BasicTreeUI() {
        public Icon getCollapsedIcon() {
            return null;
        }

        public Icon getExpandedIcon() {
            return null;
        }
    };

    directoryTree.setUI(ui);
    directoryTree.setFont(UIHelper.VER_12_PLAIN);

    JScrollPane treeScroll = new JScrollPane(directoryTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    treeScroll.setPreferredSize(new Dimension(300, 200));
    treeScroll.setBorder(new EmptyBorder(0, 0, 0, 0));
    treeContainer.add(treeScroll, BorderLayout.CENTER);

    IAppWidgetFactory.makeIAppScrollPane(treeScroll);

    return treeContainer;
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

public void mousePressed(MouseEvent event) {

    if (event.getSource() instanceof JLabel) {

    } else {//from   w  w w. j av a  2s. c om
        if (SwingUtilities.isRightMouseButton(event)) {
            String columnName = table.getColumnModel().getColumn(table.columnAtPoint(event.getPoint()))
                    .getHeaderValue().toString();
            SwingUtilities.convertPointFromScreen(event.getPoint(), table);
            spreadsheetPopups.popupMenu(table, event.getX() + 10, event.getY() + 10, columnName);
        }

        if (SwingUtilities.isLeftMouseButton(event)) {
            startRow = table.rowAtPoint(event.getPoint());
            startCol = table.columnAtPoint(event.getPoint());
        }
    }
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

public void mouseReleased(MouseEvent event) {

    if (SwingUtilities.isLeftMouseButton(event) && (table.rowAtPoint(event.getPoint()) - startRow) > 1) {
        SwingUtilities.convertPointFromScreen(event.getPoint(), table);
        spreadsheetPopups.dragCellPopupMenu(table, event.getX(), event.getY());
    }/*www .j a v a  2s.  co  m*/
}

From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java

private void createMouseListener() {
    graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {

        @Override/*  w w  w. j  a  va2s.  c  o m*/
        public void mousePressed(MouseEvent e) {
            if (isPopupShown) {
                isPopupShown = false;
                mxCell cell = (mxCell) graphComponent.getGraph().getSelectionModel().getCell();
                getGraphModel().remove(cell);
                return;
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                xPos = e.getX();
                yPos = e.getY();
                Object obj = graphComponent.getCellAt(e.getX(), e.getY());

                if (obj instanceof mxCell) {
                    mxCell cell = (mxCell) obj;
                    if (cell.getStyle() != null && cell.getStyle().indexOf(ENTITYSTYLE) >= 0
                            && cell.getValue() instanceof EntityMetaDataVO) {
                        JPopupMenu pop = createPopupMenuEntity(cell, false);
                        pop.show(e.getComponent(), e.getX(), e.getY());
                    } else if (cell.getStyle() != null && cell.getStyle().indexOf(ENTITYSTYLE) >= 0) {
                        JPopupMenu pop = createPopupMenuEntity(cell, true);
                        pop.show(e.getComponent(), e.getX(), e.getY());
                    } else {
                        if (cell.getStyle() != null && cell.getStyle().indexOf("oval") >= 0) {
                            JPopupMenu pop = createRelationPopupMenu(cell, true, true);
                            pop.show(e.getComponent(), e.getX(), e.getY());
                        } else {
                            JPopupMenu pop = createRelationPopupMenu(cell, true, false);
                            pop.show(e.getComponent(), e.getX(), e.getY());
                        }
                    }
                } else {
                    JPopupMenu pop = createPopupMenu();
                    pop.show(e.getComponent(), e.getX(), e.getY());
                }
            } else if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
                mxCell cell = (mxCell) graphComponent.getGraph().getSelectionModel().getCell();
                if (cell == null)
                    return;
                if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) {
                    EntityMetaDataVO voMeta = (EntityMetaDataVO) cell.getValue();
                    EntityMetaDataVO vo = MetaDataClientProvider.getInstance().getEntity(voMeta.getEntity());
                    new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run();
                } else if (cell.getValue() != null && cell.getValue() instanceof EntityFieldMetaDataVO) {
                    if (cell.getStyle() != null && cell.getStyle().indexOf(OPENARROW) >= 0)
                        editMasterdataRelation(cell);
                    else if (cell.getStyle() != null && cell.getStyle().indexOf(DIAMONDARROW) >= 0) {
                        editSubformRelation(cell);
                    }

                } else if (cell.getValue() != null) {
                    if (cell.getStyle() != null && cell.getStyle().indexOf(OVALARROW) >= 0) {
                        try {

                            mxCell cellSource = (mxCell) cell.getSource();
                            mxCell cellTarget = (mxCell) cell.getTarget();

                            EntityMetaDataVO sourceModule = (EntityMetaDataVO) cellSource.getValue();
                            EntityMetaDataVO targetModule = (EntityMetaDataVO) cellTarget.getValue();

                            String sSourceModule = sourceModule.getEntity();
                            String sTargetModule = targetModule.getEntity();

                            boolean blnFound = false;

                            for (MasterDataVO voGeneration : MasterDataCache.getInstance()
                                    .get(NuclosEntity.GENERATION.getEntityName())) {
                                String sSource = (String) voGeneration.getField("sourceModule");
                                String sTarget = (String) voGeneration.getField("targetModule");

                                if (org.apache.commons.lang.StringUtils.equals(sSource, sSourceModule)
                                        && org.apache.commons.lang.StringUtils.equals(sTarget, sTargetModule)) {
                                    GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory
                                            .getInstance().newMasterDataCollectController(
                                                    NuclosEntity.GENERATION.getEntityName(), null, null);
                                    gcc.runViewSingleCollectableWithId(voGeneration.getId());
                                    blnFound = true;
                                    break;
                                }

                            }
                            if (!blnFound) {
                                GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory
                                        .getInstance().newMasterDataCollectController(
                                                NuclosEntity.GENERATION.getEntityName(), null, null);
                                Map<String, Object> mp = new HashMap<String, Object>();
                                mp.put("sourceModule", sSourceModule);
                                mp.put("sourceModuleId", new Integer(MetaDataClientProvider.getInstance()
                                        .getEntity(sSourceModule).getId().intValue()));
                                mp.put("targetModule", sTargetModule);
                                mp.put("targetModuleId", new Integer(MetaDataClientProvider.getInstance()
                                        .getEntity(sTargetModule).getId().intValue()));
                                MasterDataVO vo = new MasterDataVO(NuclosEntity.GENERATION.getEntityName(),
                                        null, null, null, null, null, null, mp);
                                gcc.runWithNewCollectableWithSomeFields(vo);
                            }
                        } catch (NuclosBusinessException e1) {
                            LOG.warn("mousePressed failed: " + e1, e1);
                        } catch (CommonPermissionException e1) {
                            LOG.warn("mousePressed failed: " + e1, e1);
                        } catch (CommonFatalException e1) {
                            LOG.warn("mousePressed failed: " + e1, e1);
                        } catch (CommonBusinessException e1) {
                            LOG.warn("mousePressed failed: " + e1, e1);
                        }
                    }
                }
            }
        }

    });
}

From source file:org.nuclos.client.ui.collect.CollectController.java

/**
 * alternative entry point: lookup a <code>Collectable</code> (in a foreign entity).
 *//* ww w  . j  av  a 2s.  c  o m*/
public void runLookupCollectable(final ICollectableListOfValues clctlovSource) throws CommonBusinessException {

    // show the internal frame in the front of the modal layer:
    final MainFrameTab ifrm = this.getTab();

    ifrm.setVisible(true);

    if (!clctlovSource.isSearchComponent()) {
        String label = getSpringLocaleDelegate().getMessage("CollectController.41", "Auswahl bernehmen");
        String description = getSpringLocaleDelegate().getMessage("CollectController.42",
                "Findet die bernahme in einem Unterformular statt werden mittels Mehrfachauswahl zustzliche Datenstze im Unterformular erzeugt.");
        if (clctlovSource instanceof CollectableListOfValues) {
            final CollectableListOfValues clov = (CollectableListOfValues) clctlovSource;
            if (clov.getValueListProvider() instanceof DatasourceBasedCollectableFieldsProvider) {
                ss.setValueListProviderDatasource(
                        ((DatasourceBasedCollectableFieldsProvider) clov.getValueListProvider())
                                .getDatasourceVO());
                ss.setValueListProviderDatasourceParameter(
                        ((DatasourceBasedCollectableFieldsProvider) clov.getValueListProvider())
                                .getValueListParameter());
            } else if (clov
                    .getValueListProvider() instanceof CollectableFieldsProviderCache.CachingCollectableFieldsProvider) {
                CollectableFieldsProvider delegate = ((CollectableFieldsProviderCache.CachingCollectableFieldsProvider) clov
                        .getValueListProvider()).getDelegate();
                if (delegate instanceof DatasourceBasedCollectableFieldsProvider) {
                    ss.setValueListProviderDatasource(
                            ((DatasourceBasedCollectableFieldsProvider) delegate).getDatasourceVO());
                    ss.setValueListProviderDatasourceParameter(
                            ((DatasourceBasedCollectableFieldsProvider) delegate).getValueListParameter());
                }
            }
        } else if (clctlovSource instanceof EntityListOfValues) {
            label = getSpringLocaleDelegate().getMessage("CollectController.lookup.generation",
                    "Objekte ausw\u00e4hlen");
            description = getSpringLocaleDelegate().getMessage(
                    "CollectController.lookup.generation.description",
                    "Parameterobjekte fr die Objektgenerierung ausw\u00e4hlen.");
        }
        final JMenuItem miPopupApplySelection = new JMenuItem(label);
        miPopupApplySelection.setToolTipText(description);

        getResultPanel().popupmenuRow.removeAll();//.addSeparator();
        getResultPanel().popupmenuRow.add(miPopupApplySelection);
        miPopupApplySelection.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                acceptLookedUpCollectable(clctlovSource);
                getTab().dispose();
            }
        });
    }

    // remove mouse listener for double click in table:
    getResultPanel().removeDoubleClickMouseListener(this.getMouseListenerForTableDoubleClick());

    // add alternative mouse listener for foreign key lookup:
    foreignKeyMouseListenerForTableDoubleClick = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent ev) {
            if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) {
                int iRow = getResultTable().rowAtPoint(ev.getPoint());
                if (iRow >= 0 && iRow < getResultTable().getRowCount()) {
                    getResultTable().getSelectionModel().setSelectionInterval(iRow, iRow);
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            acceptLookedUpCollectable(clctlovSource);
                            getTab().dispose();
                        }
                    });
                }
            }
        }
    };

    getResultPanel().addDoubleClickMouseListener(foreignKeyMouseListenerForTableDoubleClick);
    // @see NUCLOS-432
    //getResultTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    getResultTable().getActionMap().put(KeyBindingProvider.EDIT_2.getKey(), new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            acceptLookedUpCollectable(clctlovSource);
            getTab().dispose();
        }
    });

    if (this.isSearchPanelAvailable()) {
        if (ss.getValueListProviderDatasource() != null) {
            this.runViewAll();
        } else {
            this.runSearch();
        }
    } else {
        this.runViewAll();
    }

    final Boolean modalLookup = (Boolean) clctlovSource
            .getProperty(ICollectableListOfValues.PROPERTY_MODAL_LOOKUP);
    if (Boolean.TRUE.equals(modalLookup)) {
        JDialog d = new JDialog(Main.getInstance().getMainFrame(), ifrm.getTitle(), true);
        FrameUtils.externalizeIntoWindow(ifrm, d);
        d.pack();
        d.setVisible(true);
    }
}

From source file:org.nuclos.client.ui.collect.CollectController.java

/**
 * alternative entry point: view search result (in Results tab)
 * @precondition this.isSearchPanelAvailable()
 *
 * @deprecated Move to ResultController.
 *///from  ww  w.j  a v a 2 s .co  m
public final void runViewResults(final ICollectableListOfValues clctlovSource) throws CommonBusinessException {
    // remove mouse listener for double click in table:
    final JTable tbl = this.getResultTable();
    tbl.removeMouseListener(this.getMouseListenerForTableDoubleClick());

    // add alternative mouse listener for foreign key lookup:
    foreignKeyMouseListenerForTableDoubleClick = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent ev) {
            if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) {
                try {
                    final Collectable clctSelected = CollectController.this.getCompleteSelectedCollectable();
                    // TODO assert clctSelected != null ?
                    if (clctSelected != null) {
                        clctlovSource.acceptLookedUpCollectable(clctSelected);

                        // remove the mouse listener after it has done its job:
                        // tbl.removeMouseListener(this);

                        // TODO may whatever mouselistener was installed should be removed from the table in "close()"

                        // Note that Controller.close() is called implicitly here:
                        getTab().dispose();
                    }
                } catch (Exception ex) {
                    Errors.getInstance().showExceptionDialog(getTab(), ex);
                }
            }
        }
    };

    tbl.addMouseListener(foreignKeyMouseListenerForTableDoubleClick);
    if (!this.isSearchPanelAvailable()) {
        throw new IllegalStateException("this.isSearchPanelAvailable()");
    }
    this.setCollectableSearchConditionInSearchPanel(clctlovSource.getCollectableSearchCondition());
    this.selectTab();
    getResultController().getSearchResultStrategy().cmdSearch();
    this.getCollectPanel().setTabbedPaneEnabledAt(CollectState.OUTERSTATE_DETAILS, false);
    this.getCollectPanel().setTabbedPaneEnabledAt(CollectState.OUTERSTATE_SEARCH, false);
}