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:org.datacleaner.panels.DatabaseDriversPanel.java

private void updateComponents() {
    this.removeAll();

    final PopupButton addDriverButton = WidgetFactory.createDefaultPopupButton("Add database driver",
            IconUtils.ACTION_ADD);//w ww .  j  a v a2s .c o m
    final JPopupMenu addDriverMenu = addDriverButton.getMenu();

    final JMenu automaticDownloadAndInstallMenu = new JMenu("Automatic download and install");
    automaticDownloadAndInstallMenu
            .setIcon(imageManager.getImageIcon(IconUtils.ACTION_DOWNLOAD, IconUtils.ICON_SIZE_MENU_ITEM));

    final List<DatabaseDriverDescriptor> drivers = _databaseDriverCatalog.getDatabaseDrivers();
    for (DatabaseDriverDescriptor dd : drivers) {
        final String[] urls = dd.getDownloadUrls();
        if (urls != null && _databaseDriverCatalog.getState(dd) == DatabaseDriverState.NOT_INSTALLED) {
            final JMenuItem downloadAndInstallMenuItem = WidgetFactory.createMenuItem(dd.getDisplayName(),
                    dd.getIconImagePath());
            downloadAndInstallMenuItem.addActionListener(createDownloadActionListener(dd));
            automaticDownloadAndInstallMenu.add(downloadAndInstallMenuItem);
        }
    }

    if (automaticDownloadAndInstallMenu.getMenuComponentCount() == 0) {
        automaticDownloadAndInstallMenu.setEnabled(false);
    }

    final JMenuItem localJarFilesMenuItem = WidgetFactory.createMenuItem("Local JAR file(s)...",
            IconUtils.FILE_ARCHIVE);
    localJarFilesMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AddDatabaseDriverDialog dialog = new AddDatabaseDriverDialog(_databaseDriverCatalog,
                    DatabaseDriversPanel.this, _windowContext, _userPreferences);
            dialog.setVisible(true);
        }
    });

    addDriverMenu.add(automaticDownloadAndInstallMenu);
    addDriverMenu.add(localJarFilesMenuItem);

    final DCTable table = getDatabaseDriverTable();
    this.add(DCPanel.flow(Alignment.RIGHT, addDriverButton), BorderLayout.NORTH);
    this.add(table.toPanel(), BorderLayout.CENTER);
}

From source file:org.datacleaner.panels.WelcomePanel.java

private void refreshRecentJobs(final PopupButton recentJobsButton) {
    final List<FileObject> recentJobFiles = getRecentJobFiles();
    final JPopupMenu recentJobsMenu = recentJobsButton.getMenu();
    /*/*from   w  ww  .  j a v  a  2s  . c o m*/
     * The menu is rebuild every time the user clicks on the menu, so the
     * content is removed so that we do not have duplicates
     */
    recentJobsMenu.removeAll();

    for (int i = 0; i < recentJobFiles.size(); i++) {
        final FileObject jobFile = recentJobFiles.get(i);
        final JMenuItem menuItem = new OpenAnalysisJobMenuItem(jobFile, _openAnalysisJobActionListener);
        recentJobsMenu.add(menuItem);
    }
}

From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java

private JComponent getWindowPanelContent() {
    if (_datastore != null) {
        setDatastore(_datastore);/*from w w w  . j a v a 2s.c o m*/
    }

    final SaveAnalysisJobActionListener saveAnalysisJobActionListener = _saveAnalysisJobActionListenerProvider
            .get();
    _saveButton.addActionListener(saveAnalysisJobActionListener);
    _saveAsButton.addActionListener(saveAnalysisJobActionListener);
    _saveAsButton.setActionCommand(SaveAnalysisJobActionListener.ACTION_COMMAND_SAVE_AS);

    // Run analysis
    _executeButton.addActionListener(execute(_analysisJobBuilder));

    _executionAlternativesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JMenuItem executeNormallyMenutItem = WidgetFactory.createMenuItem("Run normally",
                    IconUtils.ACTION_EXECUTE);
            executeNormallyMenutItem.addActionListener(execute(_analysisJobBuilder));

            final JMenuItem executePreviewMenuItem = WidgetFactory.createMenuItem("Run first N records",
                    IconUtils.ACTION_PREVIEW);
            executePreviewMenuItem.addActionListener(executePreview());

            final JMenuItem executeSingleThreadedMenuItem = WidgetFactory.createMenuItem("Run single-threaded",
                    IconUtils.MODEL_ROW);
            executeSingleThreadedMenuItem.addActionListener(executeSingleThreaded());

            final JPopupMenu menu = new JPopupMenu();
            menu.add(executeNormallyMenutItem);
            menu.addSeparator();
            menu.add(executePreviewMenuItem);
            menu.add(executeSingleThreadedMenuItem);

            final int horizontalPosition = -1 * menu.getPreferredSize().width
                    + _executionAlternativesButton.getWidth();
            menu.show(_executionAlternativesButton, horizontalPosition,
                    _executionAlternativesButton.getHeight());
        }
    });

    final JButton newJobButton = createToolbarButton("New", IconUtils.MENU_NEW);
    newJobButton.addActionListener(_newAnalysisJobActionListenerProvider.get());

    final JButton openJobButton = createToolbarButton("Open", IconUtils.MENU_OPEN);
    openJobButton.addActionListener(_openAnalysisJobActionListenerProvider.get());

    final JToggleButton moreButton = createMoreMenuButton();

    final JButton logoButton = new JButton(imageManager.getImageIcon("images/menu/dc-logo-30.png"));
    logoButton.setToolTipText("About DataCleaner");
    logoButton.setBorder(new EmptyBorder(0, 4, 0, 10));
    logoButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new AboutDialog(getWindowContext()).open();
        }
    });

    final JToolBar toolBar = WidgetFactory.createToolBar();
    toolBar.add(logoButton);
    toolBar.add(newJobButton);
    toolBar.add(openJobButton);
    toolBar.add(_saveButton);
    toolBar.add(_saveAsButton);
    toolBar.add(DCLabel.bright(" | "));
    toolBar.add(moreButton);

    toolBar.add(WidgetFactory.createToolBarSeparator());
    toolBar.add(_executeButton);
    toolBar.add(DCLabel.bright("|"));
    toolBar.add(_executionAlternativesButton);

    final JXStatusBar statusBar = WidgetFactory.createStatusBar(_statusLabel);
    statusBar.add(_classicViewButton);
    statusBar.add(_graphViewButton);
    statusBar.add(Box.createHorizontalStrut(10));

    final LicenceAndEditionStatusLabel statusLabel = new LicenceAndEditionStatusLabel(_glassPane);
    statusBar.add(statusLabel);

    final DCPanel toolBarPanel = new DCPanel(WidgetUtils.BG_COLOR_DARK);
    toolBarPanel.setLayout(new BorderLayout());
    toolBarPanel.add(toolBar, BorderLayout.CENTER);

    final DCPanel panel = new DCPersistentSizedPanel(_windowSizePreference);
    panel.setLayout(new BorderLayout());
    panel.add(toolBarPanel, BorderLayout.NORTH);
    panel.add(_leftPanel, BorderLayout.WEST);

    // newPanel.add(_tabbedPane, BorderLayout.NORTH);
    panel.add(_contentContainerPanel, BorderLayout.CENTER);

    panel.add(statusBar, BorderLayout.SOUTH);

    // invoke to trigger enablement/disablement of buttons.
    onSourceColumnsChanged();
    updateStatusLabel();

    WidgetUtils.centerOnScreen(this);
    return panel;
}

From source file:org.domainmath.gui.FileTreePanel.java

/**
 * Add popup menu.//from   w  ww. jav  a  2  s  . c  om
 */
private void addPopupMenuToFileTree() {
    refreshItem = new JMenuItem(bundle.getString("fileTreeRefreshItem.text"));
    fileTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            addGlobalAction(e);

            if (SwingUtilities.isRightMouseButton(e)) {
                TreePath path = fileTree.getPathForLocation(e.getX(), e.getY());
                Rectangle pathBounds = fileTree.getUI().getPathBounds(fileTree, path);

                if (pathBounds != null && pathBounds.contains(e.getX(), e.getY())) {
                    JPopupMenu menu = new JPopupMenu();
                    File file = (File) fileTree.getLastSelectedPathComponent();
                    openItem = new JMenuItem(bundle.getString("fileTreeOpenItem.text"));
                    runScriptItem = new JMenuItem(bundle.getString("fileTreeRunItem.text"));
                    openOutsideItem = new JMenuItem(bundle.getString("fileTreeOpenOutsideItem.text"));
                    renameItem = new JMenuItem(bundle.getString("fileTreeRenameItem.text"));
                    deleteItem = new JMenuItem(bundle.getString("fileTreeDeleteItem.text"));

                    openItem.setAccelerator(keyOpenItem);
                    renameItem.setAccelerator(keyRenameItem);
                    deleteItem.setAccelerator(keyDeleteItem);
                    refreshItem.setAccelerator(keyRefreshItem);
                    menu.add(openItem);
                    menu.add(runScriptItem);
                    menu.add(openOutsideItem);
                    menu.addSeparator();
                    menu.add(renameItem);
                    menu.add(deleteItem);
                    menu.addSeparator();
                    menu.add(refreshItem);

                    fileTreeOpenItemActionPerformed(file);
                    fileTreeRunItemActionPerformed(file);
                    fileTreeOpenOutsideItemActionPerformed(file);
                    fileTreeRenameItemActionPerformed(fileTree.getSelectionPath());
                    fileTreeDeleteItemActionPerformed(fileTree.getSelectionModel().getSelectionPaths());
                    fileTreeRefreshItemActionPerformed((File) fileTree.getModel().getRoot());

                    if (file.isDirectory()) {
                        runScriptItem.setEnabled(false);
                    } else {
                        String name = file.getName();
                        if (!name.endsWith(".m")) {
                            runScriptItem.setEnabled(false);
                        }
                    }
                    menu.show(fileTree, e.getX(), e.getY());
                }
                if (pathBounds == null) {
                    JPopupMenu menu = new JPopupMenu();
                    newFolderItem = new JMenuItem(bundle.getString("fileTreeNewFolderItem.text"));
                    File file = (File) fileTree.getModel().getRoot();
                    menu.add(newFolderItem);
                    menu.add(refreshItem);

                    fileTreeNewFolderItemActionPerformed(file);
                    fileTreeRefreshItemActionPerformed(file);
                    menu.show(fileTree, e.getX(), e.getY());
                }
            }
        }
    });
}

From source file:org.domainmath.gui.MainFrame.java

private void popupTab() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem pcloseItem = new JMenuItem("Close");
    JMenuItem pcloseAllItem = new JMenuItem("Close All");

    popup.add(pcloseItem);
    popup.add(pcloseAllItem);// w  w  w.j  a v  a  2s  .c  o  m
    fileTab.addMouseListener(new MainFrame.PopupListener(popup));

    pcloseItem.addActionListener((ActionEvent e) -> {
        if (fileTab.getSelectedIndex() >= 0) {
            askSave(fileTab.getSelectedIndex());
        }
    });

    pcloseAllItem.addActionListener((ActionEvent e) -> {
        int i = fileTab.getTabCount() - 1;
        while (i != -1) {

            askSave(i);
            i--;
        }
    });
}

From source file:org.eobjects.datacleaner.panels.DatabaseDriversPanel.java

private void updateComponents() {
    this.removeAll();
    final JToolBar toolBar = WidgetFactory.createToolBar();
    toolBar.add(WidgetFactory.createToolBarSeparator());

    final JButton addDriverButton = new JButton("Add database driver",
            imageManager.getImageIcon(IconUtils.ACTION_ADD));
    addDriverButton.addActionListener(new ActionListener() {
        @Override/*w  w w  . j a v  a2  s  .  c o m*/
        public void actionPerformed(ActionEvent e) {

            final JMenu menu = new JMenu("Automatic download and install");
            menu.setIcon(imageManager.getImageIcon("images/actions/download.png"));

            final List<DatabaseDriverDescriptor> drivers = _databaseDriverCatalog.getDatabaseDrivers();
            for (DatabaseDriverDescriptor dd : drivers) {
                final String[] urls = dd.getDownloadUrls();
                if (urls != null && _databaseDriverCatalog.getState(dd) == DatabaseDriverState.NOT_INSTALLED) {
                    final JMenuItem downloadAndInstallMenuItem = WidgetFactory
                            .createMenuItem(dd.getDisplayName(), dd.getIconImagePath());
                    downloadAndInstallMenuItem.addActionListener(createDownloadActionListener(dd));
                    menu.add(downloadAndInstallMenuItem);
                }
            }

            if (menu.getMenuComponentCount() == 0) {
                menu.setEnabled(false);
            }

            final JMenuItem localJarFilesMenuItem = WidgetFactory.createMenuItem("Local JAR file(s)...",
                    "images/filetypes/archive.png");
            localJarFilesMenuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    AddDatabaseDriverDialog dialog = new AddDatabaseDriverDialog(_databaseDriverCatalog,
                            DatabaseDriversPanel.this, _windowContext, _userPreferences);
                    dialog.setVisible(true);
                }
            });

            final JPopupMenu popup = new JPopupMenu();
            popup.add(menu);
            popup.add(localJarFilesMenuItem);
            popup.show(addDriverButton, 0, addDriverButton.getHeight());
        }
    });
    toolBar.add(addDriverButton);

    final DCTable table = getDatabaseDriverTable();
    this.add(toolBar, BorderLayout.NORTH);
    this.add(table.toPanel(), BorderLayout.CENTER);
}

From source file:org.eobjects.datacleaner.panels.WelcomePanel.java

@Inject
protected WelcomePanel(AnalyzerBeansConfiguration configuration,
        AnalysisJobBuilderWindow analysisJobBuilderWindow, DCGlassPane glassPane,
        Provider<OptionsDialog> optionsDialogProvider, InjectorBuilder injectorBuilder,
        OpenAnalysisJobActionListener openAnalysisJobActionListener,
        DatabaseDriverCatalog databaseDriverCatalog, UserPreferences userPreferences) {
    super();/*from   w  w  w  . j av  a2s.  co  m*/
    _openAnalysisJobActionListener = openAnalysisJobActionListener;
    _configuration = configuration;
    _datastorePanels = new ArrayList<DatastorePanel>();
    _datastoreCatalog = (MutableDatastoreCatalog) configuration.getDatastoreCatalog();
    _analysisJobBuilderWindow = analysisJobBuilderWindow;
    _glassPane = glassPane;
    _optionsDialogProvider = optionsDialogProvider;
    _injectorBuilder = injectorBuilder;
    _databaseDriverCatalog = databaseDriverCatalog;
    _userPreferences = userPreferences;

    _browseJobsButton = new JButton("Browse jobs",
            imageManager.getImageIcon(IconUtils.MENU_OPEN, IconUtils.ICON_SIZE_SMALL));
    _browseJobsButton.setMargin(new Insets(1, 1, 1, 4));
    _browseJobsButton.addActionListener(openAnalysisJobActionListener);

    // initialize "analyze" button
    _analyzeButton = new JButton("Build job",
            imageManager.getImageIcon(IconUtils.MODEL_JOB, IconUtils.ICON_SIZE_SMALL));
    _analyzeButton.setMargin(new Insets(1, 1, 1, 1));
    _analyzeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (DatastorePanel datastorePanel : _datastorePanels) {
                if (datastorePanel.isSelected()) {
                    Datastore datastore = datastorePanel.getDatastore();

                    // open the connection here, to make any connection
                    // issues apparent early
                    try (DatastoreConnection datastoreConnection = datastore.openConnection()) {
                        datastoreConnection.getDataContext().getSchemaNames();
                        _analysisJobBuilderWindow.setDatastore(datastore);
                    }
                    return;
                }
            }
        }
    });

    // initialize search text field
    _searchDatastoreTextField = WidgetFactory.createTextField("Search/filter datastores");
    _searchDatastoreTextField
            .setBorder(new CompoundBorder(new EmptyBorder(4, 0, 0, 0), WidgetUtils.BORDER_THIN));
    _searchDatastoreTextField.setOpaque(false);
    _searchDatastoreTextField.getDocument().addDocumentListener(new DCDocumentListener() {
        @Override
        protected void onChange(DocumentEvent event) {
            String text = _searchDatastoreTextField.getText();
            if (StringUtils.isNullOrEmpty(text)) {
                // when there is no search query, set all datastores
                // visible
                for (DatastorePanel datastorePanel : _datastorePanels) {
                    datastorePanel.setVisible(true);
                }
            } else {
                // do a case insensitive search
                text = text.trim().toLowerCase();
                for (DatastorePanel datastorePanel : _datastorePanels) {
                    String name = datastorePanel.getDatastore().getName().toLowerCase();
                    datastorePanel.setVisible(name.indexOf(text) != -1);
                }
                selectFirstVisibleDatastore();
            }
        }
    });
    _searchDatastoreTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                clickAnalyzeButton();
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                selectNextVisibleDatastore();
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                selectPreviousVisibleDatastore();
            }
        }
    });

    setLayout(new VerticalLayout(4));

    add(Box.createVerticalStrut(10));

    final DCLabel jobsHeaderLabel = DCLabel.dark("Jobs");
    jobsHeaderLabel.setFont(WidgetUtils.FONT_HEADER1);
    add(jobsHeaderLabel);

    _jobsListPanel = new DCPanel();
    final GridLayout jobsListLayout = new GridLayout(1, MAX_JOB_PANELS);
    jobsListLayout.setHgap(10);
    _jobsListPanel.setBorder(new EmptyBorder(10, 10, 4, 0));
    _jobsListPanel.setLayout(jobsListLayout);

    final List<FileObject> recentJobFiles = getRecentJobFiles();

    updateJobsListPanel(recentJobFiles);

    add(_jobsListPanel);

    _moreRecentJobsButton = new JButton("More",
            imageManager.getImageIcon(IconUtils.FILE_FOLDER, IconUtils.ICON_SIZE_SMALL));
    _moreRecentJobsButton.setMargin(new Insets(1, 1, 1, 4));
    if (recentJobFiles.size() <= MAX_JOB_PANELS) {
        _moreRecentJobsButton.setEnabled(false);
    } else {
        _moreRecentJobsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                final JPopupMenu popup = new JPopupMenu();
                for (int i = 3; i < recentJobFiles.size(); i++) {
                    final FileObject jobFile = recentJobFiles.get(i);
                    final JMenuItem menuItem = new OpenAnalysisJobMenuItem(jobFile,
                            _openAnalysisJobActionListener);
                    popup.add(menuItem);
                }
                popup.show(_moreRecentJobsButton, 0, _moreRecentJobsButton.getHeight());
            }
        });
    }

    final DCPanel jobsButtonPanel = new DCPanel();
    jobsButtonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0));
    jobsButtonPanel.add(_moreRecentJobsButton);
    jobsButtonPanel.add(_browseJobsButton);
    add(jobsButtonPanel);

    add(Box.createVerticalStrut(40));

    final DCLabel datastoreHeaderLabel = DCLabel.dark("Datastores");
    datastoreHeaderLabel.setFont(WidgetUtils.FONT_HEADER1);
    add(datastoreHeaderLabel);

    final DCLabel registerNewDatastoreLabel = DCLabel.dark("Register new:");
    registerNewDatastoreLabel.setFont(WidgetUtils.FONT_HEADER2);

    final DCPanel newDatastorePanel = new DCPanel();
    newDatastorePanel.setLayout(new VerticalLayout(4));
    newDatastorePanel.setBorder(new EmptyBorder(10, 10, 10, 0));
    newDatastorePanel.add(registerNewDatastoreLabel);
    newDatastorePanel.add(createNewDatastorePanel());

    add(newDatastorePanel);

    _datastoreListPanel = new DCPanel();
    _datastoreListPanel.setLayout(new VerticalLayout(4));
    _datastoreListPanel.setBorder(new EmptyBorder(10, 10, 4, 0));
    add(_datastoreListPanel);
    updateDatastores();

    final DCPanel datastoresButtonPanel = new DCPanel();
    datastoresButtonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    datastoresButtonPanel.setBorder(new EmptyBorder(0, 10, 0, 0));
    datastoresButtonPanel.add(_analyzeButton);
    add(datastoresButtonPanel);
}

From source file:org.eobjects.datacleaner.panels.WelcomePanel.java

private DCPanel createNewDatastorePanel() {
    final DCPanel panel = new DCPanel();
    panel.setBorder(WidgetUtils.BORDER_LIST_ITEM);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
    panel.add(createNewDatastoreButton("CSV file",
            "Comma-separated values (CSV) file (or file with other separators)", IconUtils.CSV_IMAGEPATH,
            CsvDatastore.class, CsvDatastoreDialog.class));
    panel.add(createNewDatastoreButton("Excel spreadsheet",
            "Microsoft Excel spreadsheet. Either .xls (97-2003) or .xlsx (2007+) format.",
            IconUtils.EXCEL_IMAGEPATH, ExcelDatastore.class, ExcelDatastoreDialog.class));
    panel.add(createNewDatastoreButton("Access database", "Microsoft Access database file (.mdb).",
            IconUtils.ACCESS_IMAGEPATH, AccessDatastore.class, AccessDatastoreDialog.class));
    panel.add(createNewDatastoreButton("SAS library", "A directory of SAS library files (.sas7bdat).",
            IconUtils.SAS_IMAGEPATH, SasDatastore.class, SasDatastoreDialog.class));
    panel.add(createNewDatastoreButton("DBase database", "DBase database file (.dbf)",
            IconUtils.DBASE_IMAGEPATH, DbaseDatastore.class, DbaseDatastoreDialog.class));
    panel.add(createNewDatastoreButton("Fixed width file",
            "Text file with fixed width values. Each value spans a fixed amount of text characters.",
            IconUtils.FIXEDWIDTH_IMAGEPATH, FixedWidthDatastore.class, FixedWidthDatastoreDialog.class));
    panel.add(createNewDatastoreButton("XML file", "Extensible Markup Language file (.xml)",
            IconUtils.XML_IMAGEPATH, XmlDatastore.class, XmlDatastoreDialog.class));
    panel.add(createNewDatastoreButton("JSON file", "JavaScript Object NOtation file (.json).",
            IconUtils.JSON_IMAGEPATH, JsonDatastore.class, JsonDatastoreDialog.class));
    panel.add(/*ww w .java  2  s  .com*/
            createNewDatastoreButton("OpenOffice.org Base database", "OpenOffice.org Base database file (.odb)",
                    IconUtils.ODB_IMAGEPATH, OdbDatastore.class, OdbDatastoreDialog.class));

    panel.add(Box.createHorizontalStrut(10));

    panel.add(createNewDatastoreButton("Salesforce.com", "Connect to a Salesforce.com account",
            IconUtils.SALESFORCE_IMAGEPATH, SalesforceDatastore.class, SalesforceDatastoreDialog.class));
    panel.add(createNewDatastoreButton("SugarCRM", "Connect to a SugarCRM system",
            IconUtils.SUGAR_CRM_IMAGEPATH, SugarCrmDatastore.class, SugarCrmDatastoreDialog.class));

    panel.add(Box.createHorizontalStrut(10));

    panel.add(createNewDatastoreButton("MongoDB database", "Connect to a MongoDB database",
            IconUtils.MONGODB_IMAGEPATH, MongoDbDatastore.class, MongoDbDatastoreDialog.class));

    panel.add(createNewDatastoreButton("CouchDB database", "Connect to an Apache CouchDB database",
            IconUtils.COUCHDB_IMAGEPATH, CouchDbDatastore.class, CouchDbDatastoreDialog.class));

    panel.add(createNewDatastoreButton("HBase database", "Connect to an Apache HBase database",
            IconUtils.HBASE_IMAGEPATH, HBaseDatastore.class, HBaseDatastoreDialog.class));

    // set of databases that are displayed directly on panel
    final Set<String> databaseNames = new HashSet<String>();

    createDefaultDatabaseButtons(panel, databaseNames);

    final JButton moreDatastoreTypesButton = new JButton("More",
            imageManager.getImageIcon(IconUtils.FILE_FOLDER, IconUtils.ICON_SIZE_SMALL));
    moreDatastoreTypesButton.setMargin(new Insets(1, 1, 1, 4));
    moreDatastoreTypesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JPopupMenu popup = new JPopupMenu();

            // installed databases
            final List<DatabaseDriverDescriptor> databaseDrivers = _databaseDriverCatalog
                    .getInstalledWorkingDatabaseDrivers();
            for (DatabaseDriverDescriptor databaseDriver : databaseDrivers) {
                final String databaseName = databaseDriver.getDisplayName();
                if (!databaseNames.contains(databaseName)) {
                    final String imagePath = databaseDriver.getIconImagePath();
                    final ImageIcon icon = imageManager.getImageIcon(imagePath, IconUtils.ICON_SIZE_SMALL);
                    final JMenuItem menuItem = WidgetFactory.createMenuItem(databaseName, icon);
                    menuItem.addActionListener(createJdbcActionListener(databaseName));
                    popup.add(menuItem);
                }
            }

            // custom/other jdbc connection
            {
                final ImageIcon icon = imageManager.getImageIcon(IconUtils.GENERIC_DATASTORE_IMAGEPATH,
                        IconUtils.ICON_SIZE_SMALL);
                final JMenuItem menuItem = WidgetFactory.createMenuItem("Other database", icon);
                menuItem.addActionListener(createJdbcActionListener(null));
                popup.add(menuItem);
            }

            // composite datastore
            final JMenuItem compositeMenuItem = WidgetFactory.createMenuItem("Composite datastore",
                    imageManager.getImageIcon(IconUtils.COMPOSITE_IMAGEPATH, IconUtils.ICON_SIZE_SMALL));
            compositeMenuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    new CompositeDatastoreDialog(_datastoreCatalog,
                            _analysisJobBuilderWindow.getWindowContext()).setVisible(true);
                }
            });

            final JMenuItem databaseDriversMenuItem = WidgetFactory.createMenuItem("Manage database drivers...",
                    imageManager.getImageIcon(IconUtils.MENU_OPTIONS, IconUtils.ICON_SIZE_SMALL));
            databaseDriversMenuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    OptionsDialog dialog = _optionsDialogProvider.get();
                    dialog.selectDatabaseDriversTab();
                    dialog.setVisible(true);
                }
            });

            popup.add(databaseDriversMenuItem);
            popup.add(new JSeparator(JSeparator.HORIZONTAL));
            popup.add(compositeMenuItem);
            popup.setBorder(WidgetUtils.BORDER_THIN);

            popup.show(moreDatastoreTypesButton, 0, moreDatastoreTypesButton.getHeight());
        }
    });

    panel.add(Box.createHorizontalStrut(10));
    panel.add(moreDatastoreTypesButton);

    return panel;
}

From source file:org.esa.nest.dat.views.polarview.PolarView.java

@Override
public JPopupMenu createPopupMenu(MouseEvent event) {
    final JPopupMenu popup = new JPopupMenu();

    final JMenuItem itemNext = createMenuItem("Next");
    popup.add(itemNext);
    itemNext.setEnabled(currentRecord < numRecords);

    final JMenuItem itemPrev = createMenuItem("Previous");
    popup.add(itemPrev);/*  w w  w  .ja v  a2s  . c o  m*/
    itemPrev.setEnabled(currentRecord > 0);

    final JMenuItem itemColourScale = createMenuItem("Colour Scale");
    popup.add(itemColourScale);

    final JMenu unitMenu = new JMenu("Unit");
    popup.add(unitMenu);

    if (waveProductType == WaveProductType.WAVE_SPECTRA) {
        createCheckedMenuItem(unitTypes[Unit.AMPLITUDE.ordinal()], unitMenu, graphUnit == Unit.AMPLITUDE);
        createCheckedMenuItem(unitTypes[Unit.INTENSITY.ordinal()], unitMenu, graphUnit == Unit.INTENSITY);
    } else {
        createCheckedMenuItem(unitTypes[Unit.REAL.ordinal()], unitMenu, graphUnit == Unit.REAL);
        createCheckedMenuItem(unitTypes[Unit.IMAGINARY.ordinal()], unitMenu, graphUnit == Unit.IMAGINARY);
        createCheckedMenuItem(unitTypes[Unit.AMPLITUDE.ordinal()], unitMenu, graphUnit == Unit.AMPLITUDE);
        createCheckedMenuItem(unitTypes[Unit.INTENSITY.ordinal()], unitMenu, graphUnit == Unit.INTENSITY);
    }

    final JMenuItem itemExportReadout = createMenuItem("Export Readouts");
    popup.add(itemExportReadout);

    popup.setLabel("Justification");
    popup.setBorder(new BevelBorder(BevelBorder.RAISED));
    popup.addPopupMenuListener(this);
    popup.show(this, event.getX(), event.getY());

    return popup;
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

private void checkPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {

        final JPopupMenu popup = new JPopupMenu();
        popup.add(addMenu);

        if (selectedNode != null) {
            final JMenuItem item = new JMenuItem("Delete");
            popup.add(item);//w  ww .  jav  a 2  s.  co m
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            item.addActionListener(this);

            final NodeSource[] sources = selectedNode.getNode().getSources();
            if (sources.length > 0) {
                final JMenu removeSourcedMenu = new JMenu("Remove Source");
                for (NodeSource ns : sources) {
                    final JMenuItem nsItem = new JMenuItem(ns.getSourceNodeId());
                    removeSourcedMenu.add(nsItem);
                    nsItem.setHorizontalTextPosition(JMenuItem.RIGHT);
                    nsItem.addActionListener(removeSourceListener);
                }
                popup.add(removeSourcedMenu);
            }
        }

        if (!graphEx.getGraphNodeList().isGraphComplete()) {
            final JMenuItem connectItem = new JMenuItem("Connect Graph", null);
            connectItem.setHorizontalTextPosition(JMenuItem.RIGHT);
            connectItem.addActionListener(connectListener);
            popup.add(connectItem);
        }

        popup.setLabel("Justification");
        popup.setBorder(new BevelBorder(BevelBorder.RAISED));
        popup.addPopupMenuListener(this);
        popup.show(this, e.getX(), e.getY());
        showRightClickHelp = false;
    }
}