Example usage for javax.swing JPopupMenu add

List of usage examples for javax.swing JPopupMenu add

Introduction

In this page you can find the example usage for javax.swing JPopupMenu add.

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Appends a new menu item to the end of the menu which dispatches the specified Action object.

Usage

From source file:com.clough.android.adbv.view.UpdateTableDialog.java

private void showTableChangeOptionMenu(int x, int y, final int rowIndex) {
    JPopupMenu tableChangeOptionPopupMenu = new JPopupMenu();
    JMenuItem newRowMenuItem = new JMenuItem("Add row");
    newRowMenuItem.addActionListener(new ActionListener() {

        @Override//  w  ww . j ava2s . c om
        public void actionPerformed(ActionEvent e) {
            new AddUpdateRowDialog(defaultTableModel, rowController, columnNames, null, -1).setVisible(true);
        }
    });
    JMenuItem updateRowMenuItem = new JMenuItem("Update row");
    updateRowMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Object[] row = new Object[columnNames.length];
            for (int columnIndex = 0; columnIndex < row.length; columnIndex++) {
                row[columnIndex] = defaultTableModel.getValueAt(rowIndex, columnIndex);
            }
            new AddUpdateRowDialog(defaultTableModel, rowController, columnNames, row, rowIndex)
                    .setVisible(true);
            tableColumnAdjuster.adjustColumns();
        }
    });
    JMenuItem removeRowMenuItem = new JMenuItem("Remove row");
    removeRowMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this row?", "Remove row",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                defaultTableModel.removeRow(rowIndex);
                rowController.removeRow(rowIndex);
                tableColumnAdjuster.adjustColumns();
            }
        }
    });
    tableChangeOptionPopupMenu.add(newRowMenuItem);
    tableChangeOptionPopupMenu.add(updateRowMenuItem);
    tableChangeOptionPopupMenu.add(removeRowMenuItem);
    tableChangeOptionPopupMenu.show(this, x, y);
}

From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

private void showSettingsPopup() {
    JPopupMenu menu = new JPopupMenu();
    final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem(
            Localization.lang("Automatically sync bibliography when inserting citations"),
            preferences.syncWhenCiting());
    final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in the active tab only"));
    final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in all open databases"));
    final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(useActiveBase);//from  w  ww  .j  a v  a2 s  .  c o  m
    bg.add(useAllBases);
    if (preferences.useAllDatabases()) {
        useAllBases.setSelected(true);
    } else {
        useActiveBase.setSelected(true);
    }

    autoSync.addActionListener(e -> preferences.setSyncWhenCiting(autoSync.isSelected()));

    useAllBases.addActionListener(e -> preferences.setUseAllDatabases(useAllBases.isSelected()));

    useActiveBase.addActionListener(e -> preferences.setUseAllDatabases(!useActiveBase.isSelected()));

    clearConnectionSettings.addActionListener(e -> frame.output(preferences.clearConnectionSettings()));

    menu.add(autoSync);
    menu.addSeparator();
    menu.add(useActiveBase);
    menu.add(useAllBases);
    menu.addSeparator();
    menu.add(clearConnectionSettings);
    menu.show(settingsB, 0, settingsB.getHeight());
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Creates a popup menu for the panel.// w  w w .  j av  a  2 s. co  m
 *
 * @param properties  include a menu item for the chart property editor.
 * @param save  include a menu item for saving the chart.
 * @param print  include a menu item for printing the chart.
 * @param zoom  include menu items for zooming.
 *
 * @return The popup menu.
 */
protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) {

    JPopupMenu result = new JPopupMenu("Chart:");
    boolean separator = false;

    if (properties) {
        JMenuItem propertiesItem = new JMenuItem(localizationResources.getString("Properties..."));
        propertiesItem.setActionCommand(PROPERTIES_ACTION_COMMAND);
        propertiesItem.addActionListener(this);
        result.add(propertiesItem);
        separator = true;
    }

    if (save) {
        if (separator) {
            result.addSeparator();
            separator = false;
        }
        JMenuItem saveItem = new JMenuItem(localizationResources.getString("Save_as..."));
        saveItem.setActionCommand(SAVE_ACTION_COMMAND);
        saveItem.addActionListener(this);
        result.add(saveItem);
        separator = true;
    }

    if (print) {
        if (separator) {
            result.addSeparator();
            separator = false;
        }
        JMenuItem printItem = new JMenuItem(localizationResources.getString("Print..."));
        printItem.setActionCommand(PRINT_ACTION_COMMAND);
        printItem.addActionListener(this);
        result.add(printItem);
        separator = true;
    }

    if (zoom) {
        if (separator) {
            result.addSeparator();
            separator = false;
        }

        JMenu zoomInMenu = new JMenu(localizationResources.getString("Zoom_In"));

        zoomInBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes"));
        zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_ACTION_COMMAND);
        zoomInBothMenuItem.addActionListener(this);
        zoomInMenu.add(zoomInBothMenuItem);

        zoomInMenu.addSeparator();

        zoomInHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis"));
        zoomInHorizontalMenuItem.setActionCommand(ZOOM_IN_HORIZONTAL_ACTION_COMMAND);
        zoomInHorizontalMenuItem.addActionListener(this);
        zoomInMenu.add(zoomInHorizontalMenuItem);

        zoomInVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis"));
        zoomInVerticalMenuItem.setActionCommand(ZOOM_IN_VERTICAL_ACTION_COMMAND);
        zoomInVerticalMenuItem.addActionListener(this);
        zoomInMenu.add(zoomInVerticalMenuItem);

        result.add(zoomInMenu);

        JMenu zoomOutMenu = new JMenu(localizationResources.getString("Zoom_Out"));

        zoomOutBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes"));
        zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_ACTION_COMMAND);
        zoomOutBothMenuItem.addActionListener(this);
        zoomOutMenu.add(zoomOutBothMenuItem);

        zoomOutMenu.addSeparator();

        zoomOutHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis"));
        zoomOutHorizontalMenuItem.setActionCommand(ZOOM_OUT_HORIZONTAL_ACTION_COMMAND);
        zoomOutHorizontalMenuItem.addActionListener(this);
        zoomOutMenu.add(zoomOutHorizontalMenuItem);

        zoomOutVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis"));
        zoomOutVerticalMenuItem.setActionCommand(ZOOM_OUT_VERTICAL_ACTION_COMMAND);
        zoomOutVerticalMenuItem.addActionListener(this);
        zoomOutMenu.add(zoomOutVerticalMenuItem);

        result.add(zoomOutMenu);

        JMenu autoRangeMenu = new JMenu(localizationResources.getString("Auto_Range"));

        autoRangeBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes"));
        autoRangeBothMenuItem.setActionCommand(AUTO_RANGE_BOTH_ACTION_COMMAND);
        autoRangeBothMenuItem.addActionListener(this);
        autoRangeMenu.add(autoRangeBothMenuItem);

        autoRangeMenu.addSeparator();
        autoRangeHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis"));
        autoRangeHorizontalMenuItem.setActionCommand(AUTO_RANGE_HORIZONTAL_ACTION_COMMAND);
        autoRangeHorizontalMenuItem.addActionListener(this);
        autoRangeMenu.add(autoRangeHorizontalMenuItem);

        autoRangeVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis"));
        autoRangeVerticalMenuItem.setActionCommand(AUTO_RANGE_VERTICAL_ACTION_COMMAND);
        autoRangeVerticalMenuItem.addActionListener(this);
        autoRangeMenu.add(autoRangeVerticalMenuItem);

        result.addSeparator();
        result.add(autoRangeMenu);

    }

    return result;

}

From source file:net.sf.jabref.gui.MainTableSelectionListener.java

/**
 * Process popup trigger events occurring on an icon cell in the table. Show
 * a menu where the user can choose which external resource to open for the
 * entry. If no relevant external resources exist, let the normal popup trigger
 * handler do its thing instead./*from   ww w.j a  v a  2 s .c o m*/
 * @param e The mouse event defining this popup trigger.
 * @param row The row where the event occurred.
 * @param iconType A string array containing the resource fields associated with
 *  this table cell.
 */
private void showIconRightClickMenu(MouseEvent e, int row, String[] iconType) {
    BibtexEntry entry = tableRows.get(row);
    JPopupMenu menu = new JPopupMenu();
    boolean showDefaultPopup = true;

    // See if this is a simple file link field, or if it is a file-list
    // field that can specify a list of links:
    if (iconType[0].equals(Globals.FILE_FIELD)) {
        // We use a FileListTableModel to parse the field content:
        Object o = entry.getField(iconType[0]);
        FileListTableModel fileList = new FileListTableModel();
        fileList.setContent((String) o);
        // If there are one or more links, open the first one:
        for (int i = 0; i < fileList.getRowCount(); i++) {
            FileListEntry flEntry = fileList.getEntry(i);

            //If file types are specified, ignore files of other types.
            if (iconType.length > 1) {
                boolean correctType = false;
                for (int j = 1; j < iconType.length; j++) {
                    if (flEntry.getType().toString().equals(iconType[j])) {
                        correctType = true;
                    }
                }
                if (!correctType) {
                    continue;
                }
            }

            String description = flEntry.getDescription();
            if ((description == null) || (description.trim().isEmpty())) {
                description = flEntry.getLink();
            }
            menu.add(new ExternalFileMenuItem(panel.frame(), entry, description, flEntry.getLink(),
                    flEntry.getType().getIcon(), panel.metaData(), flEntry.getType()));
            showDefaultPopup = false;
        }
    } else {
        SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]);
        if (field != null) {
            //                for (SpecialFieldValue val: field.getValues()) {
            //                   menu.add(val.getMenuAction(panel.frame()));
            //                }
            // full pop should be shown as left click already shows short popup
            showDefaultPopup = true;
        } else {
            for (String anIconType : iconType) {
                Object o = entry.getField(anIconType);
                if (o != null) {
                    menu.add(new ExternalFileMenuItem(panel.frame(), entry, (String) o, (String) o,
                            GUIGlobals.getTableIcon(anIconType).getIcon(), panel.metaData(), anIconType));
                    showDefaultPopup = false;
                }
            }
        }
    }
    if (showDefaultPopup) {
        processPopupTrigger(e, row);
    } else {
        menu.show(table, e.getX(), e.getY());
    }
}

From source file:gui.DownloadPanel.java

private JPopupMenu initPopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();

    openItem = new JMenuItem(bundle.getString("downloadPanel.openItem.name"));
    openItem.addActionListener(this);
    openFolderItem = new JMenuItem(bundle.getString("downloadPanel.openFolderItem.name"));
    openFolderItem.addActionListener(this);

    resumeItem = new JMenuItem(bundle.getString("downloadPanel.resumeItem.name"));
    resumeItem.addActionListener(this);
    pauseItem = new JMenuItem(bundle.getString("downloadPanel.pauseItem.name"));
    pauseItem.addActionListener(this);
    clearItem = new JMenuItem(bundle.getString("downloadPanel.clearItem.name"));
    clearItem.addActionListener(this);

    reJoinItem = new JMenuItem(bundle.getString("downloadPanel.reJoinItem.name"));
    reJoinItem.addActionListener(this);
    reDownloadItem = new JMenuItem(bundle.getString("downloadPanel.reDownloadItem.name"));
    reDownloadItem.addActionListener(this);

    moveToQueueItem = new JMenuItem(bundle.getString("downloadPanel.moveToQueueItem.name"));
    moveToQueueItem.addActionListener(this);
    removeFromQueueItem = new JMenuItem(bundle.getString("downloadPanel.removeFromQueueItem.name"));
    removeFromQueueItem.addActionListener(this);

    propertiesItem = new JMenuItem(bundle.getString("downloadPanel.propertiesItem.name"));
    propertiesItem.addActionListener(this);

    popupMenu.add(openItem);
    popupMenu.add(openFolderItem);//  ww w . java 2s  . c  o  m
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(resumeItem);
    popupMenu.add(pauseItem);
    popupMenu.add(clearItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(reJoinItem);
    popupMenu.add(reDownloadItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(moveToQueueItem);
    popupMenu.add(removeFromQueueItem);
    popupMenu.add(new JPopupMenu.Separator());
    popupMenu.add(propertiesItem);

    setStateOfMenuItems();

    return popupMenu;
}

From source file:net.pms.newgui.NavigationShareTab.java

private PanelBuilder initSharedFoldersGuiComponents(CellConstraints cc) {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(SHARED_FOLDER_COL_SPEC, orientation);

    FormLayout layoutFolders = new FormLayout(colSpec, SHARED_FOLDER_ROW_SPEC);
    PanelBuilder builderFolder = new PanelBuilder(layoutFolders);
    builderFolder.opaque(true);/*from ww w .  j a  v  a 2  s  .  co m*/

    JComponent cmp = builderFolder.addSeparator(Messages.getString("FoldTab.7"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 7), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    folderTableModel = new SharedFoldersTableModel();
    sharedFolders = new JTable(folderTableModel);

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItemMarkPlayed = new JMenuItem(Messages.getString("FoldTab.75"));
    JMenuItem menuItemMarkUnplayed = new JMenuItem(Messages.getString("FoldTab.76"));

    menuItemMarkPlayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, true);
        }
    });

    menuItemMarkUnplayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, false);
        }
    });

    popupMenu.add(menuItemMarkPlayed);
    popupMenu.add(menuItemMarkUnplayed);

    sharedFolders.setComponentPopupMenu(popupMenu);

    /* An attempt to set the correct row height adjusted for font scaling.
     * It sets all rows based on the font size of cell (0, 0). The + 4 is
     * to allow 2 pixels above and below the text. */
    DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) sharedFolders.getCellRenderer(0, 0);
    FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    sharedFolders.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    sharedFolders.setIntercellSpacing(new Dimension(8, 2));

    final JPanel tmpsharedPanel = sharedPanel;

    addButton.setToolTipText(Messages.getString("FoldTab.9"));
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog((Component) e.getSource());
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                int firstSelectedRow = sharedFolders.getSelectedRow();
                if (firstSelectedRow >= 0) {
                    ((SharedFoldersTableModel) sharedFolders.getModel()).insertRow(firstSelectedRow,
                            new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                } else {
                    ((SharedFoldersTableModel) sharedFolders.getModel())
                            .addRow(new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                }
            }
        }
    });
    builderFolder.add(addButton, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));

    removeButton.setToolTipText(Messages.getString("FoldTab.36"));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = sharedFolders.getSelectedRows();
            if (rows.length > 0) {
                if (rows.length > 1) {
                    if (JOptionPane.showConfirmDialog(tmpsharedPanel,
                            String.format(Messages.getString("SharedFolders.ConfirmRemove"), rows.length),
                            Messages.getString("Dialog.Confirm"), JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    }
                }
                for (int i = rows.length - 1; i >= 0; i--) {
                    PMS.get().getDatabase().removeMediaEntriesInFolder(
                            (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0));
                    ((SharedFoldersTableModel) sharedFolders.getModel()).removeRow(rows[i]);
                }
            }
        }
    });
    builderFolder.add(removeButton, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));

    arrowDownButton.setToolTipText(Messages.getString("SharedFolders.ArrowDown"));
    arrowDownButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < sharedFolders.getRowCount() - 1; i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i + 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i + 1, 1);
                    sharedFolders.changeSelection(i + 1, 1, false, false);

                    break;
                }
            }
        }
    });
    builderFolder.add(arrowDownButton, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));

    arrowUpButton.setToolTipText(Messages.getString("SharedFolders.ArrowUp"));
    arrowUpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < sharedFolders.getRowCount(); i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i - 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i - 1, 1);
                    sharedFolders.changeSelection(i - 1, 1, false, false);

                    break;

                }
            }
        }
    });
    builderFolder.add(arrowUpButton, FormLayoutUtil.flip(cc.xy(5, 3), colSpec, orientation));

    scanButton.setToolTipText(Messages.getString("FoldTab.2"));
    scanBusyIcon.start();
    scanBusyDisabledIcon.start();
    scanButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (configuration.getUseCache()) {
                DLNAMediaDatabase database = PMS.get().getDatabase();

                if (database != null) {
                    if (database.isScanLibraryRunning()) {
                        int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("FoldTab.10"),
                                Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
                        if (option == JOptionPane.YES_OPTION) {
                            database.stopScanLibrary();
                            looksFrame.setStatusLine(Messages.getString("FoldTab.41"));
                            scanButton.setEnabled(false);
                            scanButton.setToolTipText(Messages.getString("FoldTab.41"));
                        }
                    } else {
                        database.scanLibrary();
                        scanButton.setIcon(scanBusyIcon);
                        scanButton.setRolloverIcon(scanBusyRolloverIcon);
                        scanButton.setPressedIcon(scanBusyPressedIcon);
                        scanButton.setDisabledIcon(scanBusyDisabledIcon);
                        scanButton.setToolTipText(Messages.getString("FoldTab.40"));
                    }
                }
            }
        }
    });

    /*
     * Hide the scan button in basic mode since it's better to let it be done in
     * realtime.
     */
    if (!configuration.isHideAdvancedOptions()) {
        builderFolder.add(scanButton, FormLayoutUtil.flip(cc.xy(6, 3), colSpec, orientation));
    }

    scanButton.setEnabled(configuration.getUseCache());

    isScanSharedFoldersOnStartup = new JCheckBox(Messages.getString("NetworkTab.StartupScan"),
            configuration.isScanSharedFoldersOnStartup());
    isScanSharedFoldersOnStartup.setToolTipText(Messages.getString("NetworkTab.StartupScanTooltip"));
    isScanSharedFoldersOnStartup.setContentAreaFilled(false);
    isScanSharedFoldersOnStartup.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setScanSharedFoldersOnStartup((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    builderFolder.add(isScanSharedFoldersOnStartup, FormLayoutUtil.flip(cc.xy(7, 3), colSpec, orientation));

    updateSharedFolders();

    JScrollPane pane = new JScrollPane(sharedFolders);
    Dimension d = sharedFolders.getPreferredSize();
    pane.setPreferredSize(new Dimension(d.width, sharedFolders.getRowHeight() * 2));
    builderFolder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 5, 7, CellConstraints.DEFAULT, CellConstraints.FILL),
            colSpec, orientation));

    return builderFolder;
}

From source file:net.sf.nmedit.jtheme.component.JTModuleContainer.java

public void installModulesMenu(JPopupMenu menu) {
    PModuleContainer container = getModuleContainer();
    ModuleDescriptions modules = getModuleContainer().getPatch().getModuleDescriptions();
    Map<String, List<PModuleDescriptor>> categoryMap = new HashMap<String, List<PModuleDescriptor>>();

    for (PModuleDescriptor module : modules) {
        if (module.isInstanciable() && container.canAdd(module)) {
            String cat = module.getCategory();
            List<PModuleDescriptor> catList = categoryMap.get(cat);
            if (catList == null) {
                catList = new ArrayList<PModuleDescriptor>();
                categoryMap.put(cat, catList);
            }//from   w  ww  . ja  va 2s.c  o m
            catList.add(module);
        }
    }

    Comparator<PModuleDescriptor> order = new DescriptorNameComparator<PModuleDescriptor>();
    List<String> categories = new ArrayList<String>();
    categories.addAll(categoryMap.keySet());
    Collections.sort(categories);

    for (String cat : categories) {
        List<PModuleDescriptor> catList = categoryMap.get(cat);
        Collections.sort(catList, order);

        JMenu catMenu = new JMenu(cat);
        for (PModuleDescriptor m : catList) {
            catMenu.add(new InsertModuleAction(m, this));
        }

        menu.add(catMenu);
    }
}

From source file:com.clough.android.adbv.view.MainFrame.java

private void showTreeNodePopup(int x, int y, boolean isDatabasePopup) {
    JPopupMenu treeNodePopup = new JPopupMenu();
    if (isDatabasePopup) {
        JMenuItem newTableMenuItem = new JMenuItem("New table");
        newTableMenuItem.addActionListener(new ActionListener() {

            @Override//from  ww w  .  j  a  va 2s .  c  o  m
            public void actionPerformed(ActionEvent e) {
                System.out.println("new table");
                new CreateTableDialog(MainFrame.this, true).setVisible(true);
                if (tableQueryList != null && tableQueryList.size() > 0) {
                    for (String query : tableQueryList.values()) {
                        inputQuery = query;
                        runQuery();
                    }
                    refreshDatabase();
                    tableQueryList = null;
                }
            }
        });
        treeNodePopup.add(newTableMenuItem);
    } else {
        JMenuItem viewAllMenuItem = new JMenuItem("View table");
        viewAllMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("view all");
                inputQuery = "select * from `" + selectedTreeNodeValue + "`";
                queryingTextArea.setText(inputQuery);
                runQuery();
            }
        });
        treeNodePopup.add(viewAllMenuItem);
        JMenuItem dropTableMenuItem = new JMenuItem("Drop table");
        dropTableMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("drop table");
                if (JOptionPane.showConfirmDialog(null,
                        "All the data in table " + selectedTreeNodeValue
                                + " will be lost!\nClick OK to delete the table",
                        "Sqlite table dropping", JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
                    inputQuery = "drop table `" + selectedTreeNodeValue + "`";
                    queryingTextArea.setText(inputQuery);
                    runQuery();
                    refreshDatabase();
                }
            }
        });
        treeNodePopup.add(dropTableMenuItem);
        JMenuItem updateTableMenuItem = new JMenuItem("Update table");
        updateTableMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                System.out.println("update table");

                final Object[] columnsOfTable = getColumnsOfTable(selectedTreeNodeValue);

                new SwingWorker<Void, Void>() {
                    String result;

                    @Override
                    protected Void doInBackground() throws Exception {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                        }
                        result = ioManager.executeQuery("select * from `" + selectedTreeNodeValue + "`");
                        return null;
                    }

                    @Override
                    protected void done() {
                        closeProgressDialog();
                        new UpdateTableDialog(MainFrame.this, true, result, selectedTreeNodeValue,
                                columnsOfTable).setVisible(true);
                    }

                }.execute();
                showProgressDialog(true, 0, "Recieving data from table " + selectedTreeNodeValue);

                if ((rowsToInsert != null && rowsToInsert.size() > 0)
                        || (rowsToUpdate != null && rowsToUpdate.size() > 0)
                        || (rowsToDelete != null && rowsToDelete.size() > 0)) {
                    new SwingWorker<Void, Void>() {

                        @Override
                        protected Void doInBackground() {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException ex) {
                            }
                            String result = "";
                            try {
                                for (Row row : rowsToInsert) {
                                    String insertQuery = createTableInsertQuery(selectedTreeNodeValue, row);
                                    System.out.println("insertQuery : " + insertQuery);
                                    result = ioManager.executeQuery(insertQuery);
                                    if (result.equals("[]")) {
                                        waitingDialog.incrementProgressBar();
                                    } else {
                                        throw new Exception();
                                    }
                                }
                                for (Row row : rowsToUpdate) {
                                    String updateQuery = createTableUpdateQuery(selectedTreeNodeValue, row);
                                    System.out.println("updateQuery : " + updateQuery);
                                    result = ioManager.executeQuery(updateQuery);
                                    if (result.equals("[]")) {
                                        waitingDialog.incrementProgressBar();
                                    } else {
                                        throw new Exception();
                                    }
                                }
                                for (Row row : rowsToDelete) {
                                    String deleteQuery = createTableDeleteQuery(selectedTreeNodeValue, row);
                                    System.out.println("deleteQuery : " + deleteQuery);
                                    result = ioManager.executeQuery(deleteQuery);
                                    if (result.equals("[]")) {
                                        waitingDialog.incrementProgressBar();
                                    } else {
                                        throw new Exception();
                                    }
                                }
                            } catch (Exception ex) {
                                JOptionPane.showMessageDialog(null, result, "Result error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                            return null;
                        }

                        @Override
                        protected void done() {
                            closeProgressDialog();
                            refreshDatabase();
                            rowsToInsert = null;
                            rowsToUpdate = null;
                            rowsToDelete = null;
                        }

                    }.execute();
                    showProgressDialog(false, rowsToInsert.size() + rowsToUpdate.size() + rowsToDelete.size(),
                            "Applying changes to the dialog " + selectedTreeNodeValue);
                }

            }
        });
        treeNodePopup.add(updateTableMenuItem);
        JMenuItem copyCreateStatementMenuItem = new JMenuItem("Copy create statement");
        copyCreateStatementMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("copy create statement");
                for (int i = 0; i < tables.length; i++) {
                    if (tables[i].equals(selectedTreeNodeValue)) {
                        StringSelection selection = new StringSelection(queries[i]);
                        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
                        JOptionPane.showMessageDialog(null,
                                "Copied create statement of the table `" + selectedTreeNodeValue
                                        + "` to the clipboard",
                                "Copy create statement", JOptionPane.INFORMATION_MESSAGE);
                        break;
                    }
                }
            }
        });
        treeNodePopup.add(copyCreateStatementMenuItem);
        JMenuItem copyColumnNamesMenuItem = new JMenuItem("Copy column names");
        copyColumnNamesMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("copy column names");
                for (int i = 0; i < tables.length; i++) {
                    if (tables[i].equals(selectedTreeNodeValue)) {
                        String columnNames = "";
                        for (String column : columns[i]) {
                            columnNames = columnNames.concat(column + ",");
                        }
                        StringSelection selection = new StringSelection(
                                columnNames.substring(0, columnNames.length() - 1));
                        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
                        JOptionPane.showMessageDialog(null,
                                "Copied create statement of the table `" + selectedTreeNodeValue
                                        + "` to the clipboard",
                                "Copy create statement", JOptionPane.INFORMATION_MESSAGE);
                        break;
                    }
                }
            }
        });
        treeNodePopup.add(copyColumnNamesMenuItem);
    }

    treeNodePopup.show(tableInfoTree, x, y);
}

From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java

/**
 * Adds the Context PopupMenu for the RecordSet.
 * @param roc the RolloverCommand btn to add the pop to
 *///  w w w  .j  ava 2s  .c  o m
public void addPopMenu(final RolloverCommand roc, final PickList pickList) {
    if (roc.getLabelText() != null) {
        final JPopupMenu popupMenu = new JPopupMenu();

        JMenuItem delMenuItem = new JMenuItem(getResourceString("Delete"));
        if (!pickList.getIsSystem()) {
            delMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    CommandDispatcher.dispatch(new CommandAction(SYSTEMSETUPTASK, DELETE_CMD_ACT, roc));
                }
            });
        } else {
            delMenuItem.setEnabled(false);
        }
        popupMenu.add(delMenuItem);

        JMenuItem viewMenuItem = new JMenuItem(getResourceString("EDIT"));
        viewMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                startEditor(edu.ku.brc.specify.datamodel.PickList.class, "name", roc.getName(), roc.getName(),
                        PICKLIST);
            }
        });
        popupMenu.add(viewMenuItem);

        MouseListener mouseListener = new MouseAdapter() {
            private boolean showIfPopupTrigger(MouseEvent mouseEvent) {
                if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) {
                    popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
                return false;
            }

            @Override
            public void mousePressed(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }

            @Override
            public void mouseReleased(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }
        };
        roc.addMouseListener(mouseListener);
    }
}