List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionChart(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) { OpenChartAction openAction = new OpenChartAction(); openAction.setChartName(selectedNode.getDBObject().getName()); openAction.setChartPath(selectedNode.getDBObject().getAbsolutePath()); if (e.getClickCount() == 2) { if (pressed) { openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "")); }// w w w. ja v a 2 s. c o m } else { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(openAction); popupMenu.add(menuItem); DeleteChartAction deleteAction = new DeleteChartAction(instance, selectedNode); JMenuItem menuItem2 = new JMenuItem(deleteAction); popupMenu.add(menuItem2); RenameChartAction renameAction = new RenameChartAction(instance, selectedNode); JMenuItem menuItem3 = new JMenuItem(renameAction); popupMenu.add(menuItem3); ExportChartAction exportAction = new ExportChartAction(instance, selectedNode); JMenuItem menuItem4 = new JMenuItem(exportAction); popupMenu.add(menuItem4); Chart chart = ChartUtil.loadChart(selectedNode.getDBObject().getAbsolutePath()); PreviewChartAction previewHTML5Action = new PreviewChartAction(ChartRunner.GRAPHIC_FORMAT, ChartRunner.HTML5_TYPE, I18NSupport.getString("preview.html5")); previewHTML5Action.setChart(chart); popupMenu.add(previewHTML5Action); PreviewChartAction previewFlashAction = new PreviewChartAction(ChartRunner.GRAPHIC_FORMAT, ChartRunner.FLASH_TYPE, I18NSupport.getString("preview.flash")); previewFlashAction.setChart(chart); popupMenu.add(previewFlashAction); previewFlashAction.setEnabled(!ChartType.hasNoFlashSupport(chart.getType().getType())); PreviewChartAction previewImageAction = new PreviewChartAction(ChartRunner.IMAGE_FORMAT, ChartRunner.NO_TYPE, I18NSupport.getString("preview.image")); previewImageAction.setChart(chart); popupMenu.add(previewImageAction); PublishChartAction publishAction = new PublishChartAction(selectedNode.getDBObject().getAbsolutePath()); JMenuItem menuItem5 = new JMenuItem(publishAction); popupMenu.add(menuItem5); JMenuItem menuItem6 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem6); JMenuItem menuItem7 = new JMenuItem(new AddToFavoritesAction(selectedNode.getDBObject())); popupMenu.add(menuItem7); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); } }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionDatabase(TreePath selPath, DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//from w w w . j a v a2 s . c om } boolean connected = false; String name = selectedNode.getDBObject().getName(); DataSourceManager manager = DefaultDataSourceManager.getInstance(); DataSource ds = manager.getDataSource(name); if (ds.getStatus() == DataSourceType.CONNECTED) { connected = true; } else { connected = false; } // try to create source directory (may not exists if we copy datasource.xml) (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator + FileReportPersistence.QUERIES_FOLDER)).mkdirs(); (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator + FileReportPersistence.REPORTS_FOLDER)).mkdirs(); (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator + FileReportPersistence.CHARTS_FOLDER)).mkdirs(); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(new DataSourceConnectAction(instance, selPath)); popupMenu.add(menuItem); if (connected) { menuItem.setEnabled(false); } else { menuItem.setEnabled(true); } JMenuItem menuItem2 = new JMenuItem(new DataSourceDisconnectAction(instance, selectedNode)); popupMenu.add(menuItem2); if (connected) { menuItem2.setEnabled(true); } else { menuItem2.setEnabled(false); } JMenuItem menuItem5 = new JMenuItem(new DataSourceViewInfoAction(selectedNode)); popupMenu.add(menuItem5); JMenuItem menuItem3 = new JMenuItem(new DataSourceEditAction(instance, selectedNode)); popupMenu.add(menuItem3); if (connected) { menuItem3.setEnabled(false); } else { menuItem3.setEnabled(true); } JMenuItem menuItem4 = new JMenuItem(new DataSourceDeleteAction(instance, selectedNode)); popupMenu.add(menuItem4); if (connected) { menuItem4.setEnabled(false); } else { menuItem4.setEnabled(true); } if (!DefaultDataSourceManager.memoryDataSources()) { JMenuItem menuItem6 = new JMenuItem(new DataSourceSchemaSelectionAction(instance, selectedNode)); popupMenu.add(menuItem6); } popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionTableOrView(DBBrowserNode selectedNode, MouseEvent e) { boolean isTable = true; if (selectedNode.getDBObject().getType() == DBObject.VIEW) { isTable = false;//from w w w.j a v a 2 s . c o m } ViewTableColumnsInfoAction infoAction = new ViewTableColumnsInfoAction(selectedNode.getDBObject(), isTable); if (e.getClickCount() == 2) { infoAction.actionPerformed(null); } else { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(infoAction); popupMenu.add(menuItem); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); } }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionProcedure(DBBrowserNode selectedNode, MouseEvent e) { ViewProcedureColumnsInfoAction infoAction = new ViewProcedureColumnsInfoAction(selectedNode.getDBObject()); if (e.getClickCount() == 2) { infoAction.actionPerformed(null); } else {/*from w ww .j a v a 2 s . c o m*/ JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(infoAction); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem(new ValidateProceduresAction(selectedNode.getDBObject())); popupMenu.add(menuItem2); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); } }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionProcedureGroup(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//from w w w .jav a 2 s . co m } ValidateProceduresAction validateAction = new ValidateProceduresAction(); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(validateAction); popupMenu.add(menuItem); NamePatternAction patternAction = new NamePatternAction(NamePatternAction.PROCEDURE_NAME_PATTERN); JMenuItem menuItem2 = new JMenuItem(patternAction); popupMenu.add(menuItem2); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionTablesGroup(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//w w w. ja v a2 s . c o m } JPopupMenu popupMenu = new JPopupMenu(); NamePatternAction patternAction = new NamePatternAction(NamePatternAction.TABLE_NAME_PATTERN); JMenuItem menuItem = new JMenuItem(patternAction); popupMenu.add(menuItem); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionViewsGroup(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//from ww w. j a v a 2 s .co m } JPopupMenu popupMenu = new JPopupMenu(); NamePatternAction patternAction = new NamePatternAction(NamePatternAction.VIEW_NAME_PATTERN); JMenuItem menuItem = new JMenuItem(patternAction); popupMenu.add(menuItem); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionFolder(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;/*from w w w .j a v a2 s .com*/ } JPopupMenu popupMenu = new JPopupMenu(); boolean testSql = false; if (selectedNode.getDBObject().getType() == DBObject.FOLDER_QUERY) { testSql = true; JMenuItem menuItem = new JMenuItem(new ImportQueryAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem); } else if (selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT) { testSql = true; JMenuItem menuItem = new JMenuItem( new ImportReportAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem( new DownloadBulkReportAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem2); } else if (selectedNode.getDBObject().getType() == DBObject.FOLDER_CHART) { testSql = true; JMenuItem menuItem = new JMenuItem(new ImportChartAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem( new DownloadBulkChartAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem2); } JMenuItem menuItem = new JMenuItem( new AddFolderAction(this, selectedNode, selectedNode.getDBObject().getType())); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem(new RenameFolderAction(this, selectedNode)); popupMenu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem(new DeleteFolderAction(this, selectedNode)); popupMenu.add(menuItem3); if (testSql) { JMenuItem menuItem4 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem4); } popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.SelectionColumnPanel.java
private void buildUI() { setLayout(new GridBagLayout()); final DBViewer viewer = Globals.getDBViewer(); schemaCombo = new JComboBox(); schemaCombo.setPreferredSize(comboDim); schemaCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { String schema = (String) e.getItem(); shownColumnModel.clear();//from w w w. ja v a2 s . co m columnModel.clear(); tableModel.clear(); try { DBInfo dbInfo = viewer.getDBInfo(schema, DBInfo.TABLES | DBInfo.VIEWS); List<DBTable> tables = dbInfo.getTables(); Collections.sort(tables); for (DBTable table : tables) { tableModel.addElement(table); } } catch (NextSqlException ex) { LOG.error(ex.getMessage(), ex); ex.printStackTrace(); } } }); try { List<String> schemas = viewer.getSchemas(); String schemaName = viewer.getUserSchema(); Collections.sort(schemas); boolean added = false; for (String schema : schemas) { if (DefaultSchemaManager.getInstance().isVisible( DefaultDataSourceManager.getInstance().getConnectedDataSource().getName(), schema)) { added = true; schemaCombo.addItem(schema); } } if ((schema == null) || schema.equals(DefaultDBViewer.NO_SCHEMA_NAME)) { schema = DefaultDBViewer.NO_SCHEMA_NAME;//viewer.getUserSchema(); } if (!added) { schemaCombo.addItem(schema); } schemaCombo.setSelectedItem(schema); } catch (NextSqlException e) { LOG.error(e.getMessage(), e); e.printStackTrace(); } // create table list tableList = new JXList(tableModel); tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableList.setCellRenderer(new DBTableCellRenderer()); // create column list columnList = new JXList(columnModel); if (singleSelection) { columnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } columnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList = new JXList(shownColumnModel); if (singleSelection) { shownColumnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } addDoubleClick(); shownColumnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { if ((mouseEvent.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(new DeselectListAction(shownColumnList)); popupMenu.add(menuItem); popupMenu.show((Component) mouseEvent.getSource(), mouseEvent.getX(), mouseEvent.getY()); } } }); tableList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { int index = tableList.getSelectedIndex(); if (index == -1) { return; } DBTable table = (DBTable) tableModel.getElementAt(index); try { List<DBColumn> columns = null; try { columns = viewer.getColumns(table.getSchema(), table.getName()); } catch (MalformedTableNameException e1) { Show.error("Malformed table name : " + table.getName()); return; } Collections.sort(columns); columnModel.clear(); shownColumnModel.clear(); for (DBColumn column : columns) { columnModel.addElement(column); shownColumnModel.addElement(column); } } catch (NextSqlException e1) { LOG.error(e1.getMessage(), e1); e1.printStackTrace(); Show.error(e1); } } } }); columnList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { shownColumnList.clearSelection(); } }); scrTable = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrTable.setPreferredSize(scrDim); scrTable.setMinimumSize(scrDim); scrTable.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.tables"))); scrColumn = new JScrollPane(columnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrColumn.setPreferredSize(scrDim); scrColumn.setMinimumSize(scrDim); scrColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.columns"))); scrShownColumn = new JScrollPane(shownColumnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrShownColumn.setPreferredSize(scrDim); scrShownColumn.setMinimumSize(scrDim); scrShownColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.shown.columns"))); JPanel schemaPanel = new JPanel(); schemaPanel.setLayout(new BoxLayout(schemaPanel, BoxLayout.X_AXIS)); schemaPanel.add(new JLabel("Schema")); schemaPanel.add(Box.createHorizontalStrut(5)); schemaPanel.add(schemaCombo); add(schemaPanel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(scrTable, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); add(scrColumn, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); if (show) { add(scrShownColumn, new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } }
From source file:ro.nextreports.designer.wizpublish.JcrBrowserTree.java
public JcrBrowserTree(final byte typeRoot, WebServiceClient client) { super();//w w w . java 2 s .c o m this.client = client; populateTree(typeRoot); setCellRenderer(new JcrBrowserTreeRenderer()); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); instance = this; addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { job(e, true); } public void mouseReleased(MouseEvent e) { job(e, false); } private void job(MouseEvent e, boolean pressed) { if (e.isPopupTrigger()) { final TreePath selPath = getPathForLocation(e.getX(), e.getY()); if (selPath == null) { return; } setSelectionPath(selPath); try { final DBBrowserNode selectedNode = (DBBrowserNode) selPath.getLastPathComponent(); if (selectedNode != null) { JPopupMenu popupMenu = new JPopupMenu(); boolean show = false; if ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT) || (selectedNode.getDBObject().getType() == DBObject.DATABASE) || (selectedNode.getDBObject().getType() == DBObject.REPORTS_GROUP) || (selectedNode.getDBObject().getType() == DBObject.CHARTS_GROUP)) { JMenuItem menuItem = new JMenuItem(new PublishFolderAction(selectedNode)); popupMenu.add(menuItem); show = true; } if ((typeRoot == DBObject.DATABASE) && ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT) || (selectedNode.getDBObject().getType() == DBObject.DATABASE))) { PublishDataSourceAction publishDSAction = new PublishDataSourceAction(selectedNode); JMenuItem menuItem2 = new JMenuItem(publishDSAction); popupMenu.add(menuItem2); show = true; } if (show) { popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); } } } catch (Exception ex) { Show.error(ex); } } } }); }