Example usage for javax.swing JPopupMenu show

List of usage examples for javax.swing JPopupMenu show

Introduction

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

Prototype

public void show(Component invoker, int x, int y) 

Source Link

Document

Displays the popup menu at the position x,y in the coordinate space of the component invoker.

Usage

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void rootRightClickAction(final MouseEvent evt) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem refreshItem = new JMenuItem("Refresh Templates");
    JMenuItem resetConnectionItem = new JMenuItem("Reset Connection");
    menu.add(refreshItem);//from ww  w.ja va  2  s .c  om
    menu.add(resetConnectionItem);

    refreshItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            // simulate close and open to refresh the tree
            componentClosed();
            componentOpened();
        }
    });

    resetConnectionItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent evt) {
            ServerDetailsView serverDetails = getRefreshServerDetails();
            // set previous preferences
            Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class);
            serverDetails.setDetails(prefs.get("scheme", "http"), prefs.get("host", "localhost"),
                    prefs.get("port", "8080"), prefs.get("username", StringUtils.EMPTY),
                    prefs.get("password", StringUtils.EMPTY));
            // reset connection preferences
            prefs.remove("scheme");
            prefs.remove("host");
            prefs.remove("port");
            prefs.remove("username");
            prefs.remove("password");
            serverDetails.setVisible(true);
        }
    });
    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void folderRightClickAction(final MouseEvent evt, final DefaultMutableTreeNode node) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem addItem = new JMenuItem("New");
    menu.add(addItem);//from  www . j  a  v a 2 s .  c o m

    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String name = JOptionPane.showInputDialog("Enter Name");
            boolean added = false;
            if (!"exit".equals(e.getActionCommand())) {

                if (node.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) {
                    MailTemplateTO mailTemplate = new MailTemplateTO();
                    mailTemplate.setKey(name);
                    added = mailTemplateManagerService.create(mailTemplate);
                    mailTemplateManagerService.setFormat(name, MailTemplateFormat.HTML,
                            IOUtils.toInputStream("//Enter Content here", encodingPattern));
                    mailTemplateManagerService.setFormat(name, MailTemplateFormat.TEXT,
                            IOUtils.toInputStream("//Enter Content here", encodingPattern));
                    try {
                        openMailEditor(name);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                } else {
                    ReportTemplateTO reportTemplate = new ReportTemplateTO();
                    reportTemplate.setKey(name);
                    added = reportTemplateManagerService.create(reportTemplate);
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.FO,
                            IOUtils.toInputStream("//Enter content here", encodingPattern));
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.CSV,
                            IOUtils.toInputStream("//Enter content here", encodingPattern));
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.HTML,
                            IOUtils.toInputStream("//Enter content here", encodingPattern));
                    try {
                        openReportEditor(name);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }

                if (added) {
                    node.add(new DefaultMutableTreeNode(name));
                    treeModel.reload(node);
                } else {
                    JOptionPane.showMessageDialog(null, "Error while creating new element", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void leafRightClickAction(final MouseEvent evt, final DefaultMutableTreeNode node) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");
    menu.add(deleteItem);//from w ww . j  a  va 2  s . c  o  m

    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(null, "Are you sure to delete the item?");
            if (result == JOptionPane.OK_OPTION) {
                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                boolean deleted;
                if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) {
                    deleted = mailTemplateManagerService.delete((String) node.getUserObject());
                } else {
                    deleted = reportTemplateManagerService.delete((String) node.getUserObject());
                }
                if (deleted) {
                    node.removeFromParent();
                    treeModel.reload(parent);
                } else {
                    JOptionPane.showMessageDialog(null, "Error while deleting new element", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java

public static void addPopupMenu(final JComponent component, final JPopupMenu menu) {
    component.addMouseListener(new MouseAdapter() {
        @Override/* w  ww.  j  a  v  a 2  s . co  m*/
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

        private void showMenu(MouseEvent e) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }
    });
}

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 om
    }

    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.//w  w w .j  av  a 2s . c  o m
 */
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.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 va 2  s . co  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();/*  www  . j a  va  2s  . 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(//from  ww  w. j  a v a  2  s.c om
            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);//ww  w.j a v a 2s.c o  m
    itemNext.setEnabled(currentRecord < numRecords);

    final JMenuItem itemPrev = createMenuItem("Previous");
    popup.add(itemPrev);
    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;
}