List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". 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/* ww w. jav a2s . 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:ca.phon.app.project.ProjectWindow.java
/** * Displays the corpus list menu// w w w . j a v a 2 s . co m * * @param clickPoint */ private void showCorpusListContextMenu(Point clickPoint) { List<String> corpora = getSelectedCorpora(); JPopupMenu contextMenu = new JPopupMenu(); if (corpora.size() == 1) { // new session item JMenuItem newSessionItem = new JMenuItem(new NewSessionAction(this)); contextMenu.add(newSessionItem); contextMenu.addSeparator(); JMenuItem templateItem = new JMenuItem(new OpenCorpusTemplateAction(this)); contextMenu.add(templateItem); contextMenu.addSeparator(); } JMenuItem dupItem = new JMenuItem(new DuplicateCorpusAction(this)); if (corpora.size() > 1) { dupItem.setText("Duplicate Corpora"); } contextMenu.add(dupItem); if (corpora.size() == 1) { // rename JMenuItem renameItem = new JMenuItem(new RenameCorpusAction(this)); contextMenu.add(renameItem); } // delete JMenuItem deleteItem = new JMenuItem(new DeleteCorpusAction(this)); if (corpora.size() > 1) { deleteItem.setText("Delete Corpora"); } contextMenu.add(deleteItem); contextMenu.show(corpusList, clickPoint.x, clickPoint.y); }
From source file:edu.ku.brc.af.tasks.BaseTask.java
@Override public JPopupMenu getPopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem mi = new JMenuItem(getResourceString("BaseTask.CONFIGURE")); //$NON-NLS-1$ popupMenu.add(mi);/* w w w .j a va 2s. c om*/ mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doConfigure(); } }); return popupMenu; }
From source file:ca.phon.app.project.ProjectWindow.java
/** * Displays the session list menu/*from w ww . j av a 2s . co m*/ * * @param clickPoint */ private void showSessionListContextMenu(Point clickPoint) { List<String> selectedSessions = getSelectedSessionNames(); JPopupMenu contextMenu = new JPopupMenu(); if (selectedSessions.size() == 1) { // open item JMenuItem openItem = new JMenuItem(new OpenSessionAction(this)); contextMenu.add(openItem); contextMenu.addSeparator(); } // rename item JMenuItem duplicateItem = new JMenuItem(new DuplicateSessionAction(this)); if (selectedSessions.size() > 1) { duplicateItem.setText("Duplicate Sessions"); } contextMenu.add(duplicateItem); if (selectedSessions.size() == 1) { JMenuItem renameItem = new JMenuItem(new RenameSessionAction(this)); contextMenu.add(renameItem); } // delete item JMenuItem deleteItem = new JMenuItem(new DeleteSessionAction(this)); if (selectedSessions.size() > 1) { deleteItem.setText("Delete Sessions"); } contextMenu.add(deleteItem); contextMenu.show(sessionList, clickPoint.x, clickPoint.y); }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JPopupMenu createWindowPopupMenu(final Window window) { JPopupMenu popupMenu = new JPopupMenu(); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); if (clientConfig.getManualScreenSettingsSaving()) { JMenuItem saveSettingsItem = new JMenuItem(messages.getMainMessage("actions.saveSettings")); saveSettingsItem.addActionListener(new ActionListener() { @Override//from w w w .j a v a 2 s .co m public void actionPerformed(ActionEvent e) { window.saveSettings(); } }); popupMenu.add(saveSettingsItem); JMenuItem restoreToDefaultsItem = new JMenuItem(messages.getMainMessage("actions.restoreToDefaults")); restoreToDefaultsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.deleteSettings(); } }); popupMenu.add(restoreToDefaultsItem); } if (clientConfig.getLayoutAnalyzerEnabled()) { JMenuItem analyzeLayoutItem = new JMenuItem(messages.getMainMessage("actions.analyzeLayout")); analyzeLayoutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LayoutAnalyzer analyzer = new LayoutAnalyzer(); List<LayoutTip> tipsList = analyzer.analyze(window); if (tipsList.isEmpty()) { showNotification("No layout problems found", NotificationType.HUMANIZED); } else { window.openWindow("layoutAnalyzer", OpenType.DIALOG, ParamsMap.of("tipsList", tipsList)); } } }); popupMenu.add(analyzeLayoutItem); } return popupMenu; }
From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java
private void createPopupMenu() { JMenuItem menuItem;// ww w . j ava 2s . co m //Create the popup menu. JPopupMenu popup = new JPopupMenu(); /*menuItem = new JMenuItem("Constrain Item ..."); menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK)); menuItem.addActionListener(this); popup.add(menuItem);*/ menuItem = new JMenuItem("Delete Item"); menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK)); menuItem.addActionListener(this); popup.add(menuItem); /*popup.add(new javax.swing.JSeparator()); menuItem = new JMenuItem("Exclude All Items"); menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); menuItem.addActionListener(this); popup.add(menuItem);*/ //Add listener to the tree MouseListener popupListener = new ConceptTreePopupListener(popup); jTree1.addMouseListener(popupListener); }
From source file:de.codesourcery.jasm16.ide.ui.views.SourceEditorView.java
@Override protected JPopupMenu createPopupMenu(ASTNode node, int caretPosition, String currentSelection) { final JPopupMenu popup = new JPopupMenu(); boolean gotEntries = false; final ICompilationUnit unit = getCurrentCompilationUnit(); if (getCurrentProject() != null && unit != null && unit.getAST() != null && !unit.hasErrors()) { try {/*from w w w . j a v a 2 s.c o m*/ if (WorkspaceExplorer.canOpenInDebugPerspective(getCurrentProject())) { final IResource executable = getCurrentProject().getProjectBuilder().getExecutable(); addMenuEntry(popup, "Open in debugger", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { WorkspaceExplorer.openDebugPerspective(getCurrentProject(), executable, viewContainerManager); } catch (IOException e1) { LOG.error("actionPerformed(): ", e1); } } }); gotEntries = true; } } catch (IOException e) { LOG.error("createPopupMenu(): ", e); } } return gotEntries ? popup : null; }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initTablePopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteMenuItem = new JMenuItem("(D)", new ImageIcon(getClass().getResource("edit-delete-6.png"))); deleteMenuItem.setMnemonic('D'); popupMenu.add(deleteMenuItem);//from w w w . j av a 2s .co m deleteMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteRecord(); } }); popupMenu.addSeparator(); JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png"))); editMenuItem.setMnemonic('E'); popupMenu.add(editMenuItem); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow())); showUpdateRecordDialog(record); } }); // ??popup menu table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (disable) return; JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(e.getPoint()); if (SwingUtilities.isRightMouseButton(e)) { if (row >= 0 && col >= 0) { table.setRowSelectionInterval(row, row); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } else if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 2) { if (row >= 0 && col >= 0) { // Record record = model.getRecord(table.convertRowIndexToModel(row)); // showUpdateRecordDialog(record); } } } } }); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table.getActionMap().put("Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { if (disable) return; //do something on JTable enter pressed int row = table.getSelectedRow(); if (row >= 0) { Record record = model.getRecord(table.convertRowIndexToModel(row)); showUpdateRecordDialog(record); } } }); }
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);//ww w . ja 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:gdt.jgui.entity.index.JIndexPanel.java
private void initPopup() { try {//from ww w . j av a 2 s. c o m //System.out.println("IndexPanel:initPopup:selection="+selection$); Properties locator = Locator.toProperties(selection$); String nodeType$ = locator.getProperty(NODE_TYPE); //System.out.println("IndexPanel:initPopup:node type="+nodeType$); if (NODE_TYPE_ROOT.equals(nodeType$)) { popup = null; return; } if (NODE_TYPE_GROUP.equals(nodeType$)) { popup = new JPopupMenu(); JMenuItem newGroupItem = new JMenuItem("New group"); newGroupItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JIndexPanel:popup:new parent group: selection="+selection$); Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String title$ = "New group" + Identity.key().substring(0, 4); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, title$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT_TITLE, "Create group"); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_CREATE_GROUP); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(newGroupItem); popup.addSeparator(); JMenuItem renameItem = new JMenuItem("Rename"); renameItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String title$ = locator.getProperty(Locator.LOCATOR_TITLE); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, title$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_RENAME_GROUP); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(renameItem); JMenuItem setIconItem = new JMenuItem("Set icon"); setIconItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); JIconSelector is = new JIconSelector(); String isLocator$ = is.getLocator(); isLocator$ = Locator.append(isLocator$, Entigrator.ENTIHOME, entihome$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_SET_ICON_GROUP); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); isLocator$ = Locator.append(isLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, isLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(setIconItem); JMenuItem orderItem = new JMenuItem("Order"); orderItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); String nodeKey$ = locator.getProperty(NODE_KEY); index = orderGroupDefault(index, nodeKey$); index.putElementItem("index.selection", new Core(null, "selection", nodeKey$)); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(orderItem); popup.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cut = false; console.clipboard.clear(); if (selection$ != null) console.clipboard.putString(selection$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(copyItem); JMenuItem cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cut = true; console.clipboard.clear(); if (selection$ != null) console.clipboard.putString(selection$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(cutItem); final String[] sa = console.clipboard.getContent(); if (sa != null && sa.length > 0) { JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JIndexPanel:popup:new parent group: selection="+selection$); Properties selectionLocator = Locator.toProperties(selection$); String indexLocator$ = getLocator(); String groupKey$ = selectionLocator.getProperty(NODE_KEY); Properties indexLocator = Locator.toProperties(indexLocator$); String entihome$ = indexLocator.getProperty(Entigrator.ENTIHOME); String entityKey$ = indexLocator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); for (String aSa : sa) { index = pasteItemToGroup(index, groupKey$, aSa); } entigrator.save(index); cut = false; JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(pasteItem); } popup.addSeparator(); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try { Properties locator = Locator.toProperties(selection$); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); String nodeKey$ = locator.getProperty(NODE_KEY); String groupKey$ = locator.getProperty(NODE_GROUP_KEY); index = removeNode(index, nodeKey$); index.putElementItem("index.selection", new Core(null, "selection", groupKey$)); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } } }); popup.add(deleteItem); return; } if (NODE_TYPE_REFERENCE.equals(nodeType$)) { popup = new JPopupMenu(); final String locatorType$ = locator.getProperty(Locator.LOCATOR_TYPE); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Properties locator = Locator.toProperties(selection$); // String locatorType$=locator.getProperty(Locator.LOCATOR_TYPE); // System.out.println("IndexPanel:open:node type="+locatorType$); if (JFolderPanel.LOCATOR_TYPE_FILE.equals(locatorType$)) { String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File itemFile = new File(filePath$); try { Desktop.getDesktop().open(itemFile); } catch (Exception ee) { LOGGER.info(ee.toString()); } return; } if (JWeblinksPanel.LOCATOR_TYPE_WEB_LINK.equals(locatorType$)) { try { String url$ = locator.getProperty(JWeblinksPanel.WEB_LINK_URL); Desktop.getDesktop().browse(new URI(url$)); } catch (Exception ee) { LOGGER.info(ee.toString()); } return; } String responseLocator$ = getLocator(); // System.out.println("IndexPanel:open:response locator="+Locator.remove(responseLocator$,Locator.LOCATOR_ICON)); selection$ = Locator.append(selection$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(responseLocator$)); // System.out.println("IndexPanel:open:selection="+Locator.remove(Locator.remove(selection$, Locator.LOCATOR_ICON),JRequester.REQUESTER_RESPONSE_LOCATOR)); selection$ = Locator.append(selection$, Entigrator.ENTIHOME, entihome$); JConsoleHandler.execute(console, selection$); } }); popup.add(openItem); if (JFolderPanel.LOCATOR_TYPE_FILE.equals(locator.getProperty(Locator.LOCATOR_TYPE))) { JMenuItem openFolderItem = new JMenuItem("Open folder"); openFolderItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Properties locator = Locator.toProperties(selection$); String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File itemFile = new File(filePath$); try { Desktop.getDesktop().open(itemFile.getParentFile()); } catch (Exception ee) { LOGGER.info(ee.toString()); } return; } }); popup.add(openFolderItem); } JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { Properties selectionLocator = Locator.toProperties(selection$); String indexLocator$ = getLocator(); Properties indexLocator = Locator.toProperties(indexLocator$); String entihome$ = indexLocator.getProperty(Entigrator.ENTIHOME); String entityKey$ = indexLocator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); String nodeKey$ = selectionLocator.getProperty(NODE_KEY); String groupKey$ = selectionLocator.getProperty(NODE_GROUP_KEY); index.removeElementItem("index.jlocator", nodeKey$); index.putElementItem("index.selection", new Core(null, "selection", groupKey$)); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } } }); popup.add(deleteItem); popup.addSeparator(); JMenuItem renameItem = new JMenuItem("Rename"); renameItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, selection$); try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String nodeKey$ = locator.getProperty(NODE_KEY); String title$; Core title = index.getElementItem("index.title", nodeKey$); if (title != null && title.value != null) title$ = title.value; else title$ = locator.getProperty(Locator.LOCATOR_TITLE); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, title$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_RENAME_REFERENCE); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(renameItem); JMenuItem setIconItem = new JMenuItem("Set icon"); setIconItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, selection$); try { Properties locator = Locator.toProperties(selection$); JIconSelector is = new JIconSelector(); String isLocator$ = is.getLocator(); isLocator$ = Locator.append(isLocator$, Entigrator.ENTIHOME, entihome$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_SET_ICON_REFERENCE); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); isLocator$ = Locator.append(isLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, isLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(setIconItem); JMenuItem resetItem = new JMenuItem("Reset"); resetItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, selection$); try { Properties locator = Locator.toProperties(selection$); String nodeKey$ = locator.getProperty(NODE_KEY); Core title = index.getElementItem("index.title", nodeKey$); if (title != null) { index.removeElementItem("index.title", nodeKey$); Entigrator entigrator = console.getEntigrator(entihome$); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(resetItem); popup.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cut = false; console.clipboard.clear(); console.clipboard.putString(selection$); } }); popup.add(copyItem); JMenuItem cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cut = true; console.clipboard.clear(); console.clipboard.putString(selection$); } }); popup.add(cutItem); } } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } }