@NotNull private JPopupMenu getPopupMenu(final PackageTemplateWrapper ptWrapper) { JPopupMenu popupMenu = new JBPopupMenu(); JMenuItem itemAddVariable = new JBMenuItem(Localizer.get("AddVariable"), AllIcons.Nodes.Variable); JMenuItem itemDelete = new JBMenuItem(Localizer.get("Delete"), AllIcons.Actions.Delete); itemAddVariable.addActionListener(e -> addVariable(ptWrapper)); itemDelete.addActionListener(e -> deleteVariable(ptWrapper)); popupMenu.add(itemAddVariable); addScriptMenuItems(popupMenu, ptWrapper.getProject()); if (!getGlobalVariable().getName().equals(ATTRIBUTE_BASE_NAME)) { popupMenu.add(itemDelete); } return popupMenu; }
private void addRightMouseButtonFunctionality(MouseEvent mouseEvent, final JBList list, JBScrollPane panel) { logger.info("Adding functionality for right mouse button. @CourseTabFactory"); if (!SwingUtilities.isRightMouseButton(mouseEvent)) { return; } int index = list.locationToIndex(mouseEvent.getPoint()); list.setSelectedIndex(index); PopUpMenu menu = new PopUpMenu(); JBMenuItem openInExplorer = new JBMenuItem("Open path"); final Object selectedItem = list.getSelectedValue(); JBMenuItem deleteFolder = new JBMenuItem("Delete folder"); openInExplorer.addActionListener(createOpenInExploreListener(list, selectedItem)); deleteFolder.addActionListener(createDeleteButtonActionListener(list, selectedItem)); menu.add(openInExplorer); menu.add(deleteFolder); menu.show(panel, mouseEvent.getX(), mouseEvent.getY()); menu.setLocation(mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen()); }
private void createPopupForEditMode(MouseEvent mouseEvent) { JPopupMenu popupMenu = new JBPopupMenu(); JMenuItem itemAddFile = new JBMenuItem(Localizer.get("AddFile"), AllIcons.FileTypes.Text); JMenuItem itemAddDirectory = new JBMenuItem(Localizer.get("AddDirectory"), AllIcons.Nodes.Package); JMenuItem itemChangeFileTemplate = new JBMenuItem(Localizer.get("action.ChangeFileTemplate"), AllIcons.Actions.Edit); JMenuItem itemDelete = new JBMenuItem(Localizer.get("Delete"), AllIcons.Actions.Delete); itemAddFile.addActionListener(e -> AddFile()); itemAddDirectory.addActionListener(e -> addDirectory()); itemDelete.addActionListener(e -> deleteElement()); popupMenu.add(itemAddFile); popupMenu.add(itemAddDirectory); // if NOT root element if (getParent() != null) { popupMenu.add(itemDelete); } // Dir Specific if (isDirectory()) { //nothing } else { // File Specific itemChangeFileTemplate.addActionListener(e -> changeFileTemplate()); popupMenu.add(itemChangeFileTemplate); } addScriptMenuItems(popupMenu); addCustomPathMenuItems(popupMenu); addWriteRulesMenuItems(popupMenu); popupMenu.show(jlName, mouseEvent.getX(), mouseEvent.getY()); }
private void addMenuItem(final String item) { if (myNativeSearchPopup != null) { myNativeSearchPopup.remove(myNoItems); final JMenuItem menuItem = new JBMenuItem(item); myNativeSearchPopup.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { myTextField.setText(item); addCurrentTextToHistory(); } }); } }
private void fillPredefined(JMenuItem parentMenu) { for (final PredefinedCodeStyle predefinedCodeStyle : myPredefinedCodeStyles) { JMenuItem predefinedItem = new JBMenuItem(predefinedCodeStyle.getName()); parentMenu.add(predefinedItem); predefinedItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applyPredefinedStyle(predefinedCodeStyle.getName()); } }); } }
protected List<JBMenuItem> getMenuItems(final ActionListener listener) { final List<JBMenuItem> menuItems = new ArrayList<JBMenuItem>(); menuItems.add(createMenuItem(TfPluginBundle.KEY_VCS_OPEN_IN_BROWSER, null, CMD_OPEN_SELECTED_ITEM_IN_BROWSER, listener)); // only show create branch option for Git repos if (isGitRepo) { menuItems.add(createMenuItem(TfPluginBundle.KEY_VCS_WIT_CREATE_BRANCH, null, CMD_CREATE_BRANCH, listener)); } return menuItems; }
/** * Display popup menu on the view * * @param component * @param x * @param y * @param listener */ protected void showPopupMenu(final Component component, final int x, final int y, final ActionListener listener) { final JBPopupMenu menu = new JBPopupMenu(); final List<JBMenuItem> openMenuItems = getMenuItems(listener); for (JBMenuItem menuItem : openMenuItems) { menu.add(menuItem); } menu.show(component, x, y); }
private JBMenuItem createMenuItem(final String resourceKey, final Icon icon, final String actionCommand) { final String text = TfPluginBundle.message(resourceKey); final JBMenuItem menuItem = new JBMenuItem(text, icon); menuItem.setActionCommand(actionCommand); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { menuItemAction(e); } }); return menuItem; }
@Test public void testGetMenuItems() { List<JBMenuItem> menuItemList = underTest.getMenuItems(null); assertEquals(2, menuItemList.size()); assertEquals(TabForm.CMD_OPEN_SELECTED_ITEM_IN_BROWSER, menuItemList.get(0).getActionCommand()); assertEquals(VcsPullRequestsForm.CMD_ABANDON_SELECTED_PR, menuItemList.get(1).getActionCommand()); }
@Test public void testGetMenuItems_Git() { List<JBMenuItem> menuItemList = underTest.getMenuItems(null); assertEquals(2, menuItemList.size()); assertEquals(TabForm.CMD_OPEN_SELECTED_ITEM_IN_BROWSER, menuItemList.get(0).getActionCommand()); assertEquals(VcsWorkItemsForm.CMD_CREATE_BRANCH, menuItemList.get(1).getActionCommand()); }
@Test public void testGetMenuItems_TFVC() { underTest = spy(new VcsWorkItemsForm(false, mockWorkItemQueryDropDown)); List<JBMenuItem> menuItemList = underTest.getMenuItems(null); assertEquals(1, menuItemList.size()); assertEquals(TabForm.CMD_OPEN_SELECTED_ITEM_IN_BROWSER, menuItemList.get(0).getActionCommand()); }
private void addMenuItem(final String item) { if (myNativeSearchPopup != null) { myNativeSearchPopup.remove(myNoItems); final JMenuItem menuItem = new JBMenuItem(item); myNativeSearchPopup.add(menuItem); menuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { myTextField.setText(item); } }); } }
private void addMenuItem(final String item) { if (myNativeSearchPopup != null) { myNativeSearchPopup.remove(myNoItems); final JMenuItem menuItem = new JBMenuItem(item); myNativeSearchPopup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { myTextField.setText(item); addCurrentTextToHistory(); } }); } }
public void addItemToMenu(JBMenuItem item) { add(item); }
@NotNull private static JBMenuItem createMenuItem(@NotNull DeviceUiAction action) { JBMenuItem item = new JBMenuItem(action); item.setText(action.getText()); return item; }
protected List<JBMenuItem> getMenuItems(final ActionListener listener) { return Arrays.asList( createMenuItem(TfPluginBundle.KEY_VCS_OPEN_IN_BROWSER, null, CMD_OPEN_SELECTED_ITEM_IN_BROWSER, listener), createMenuItem(TfPluginBundle.KEY_VCS_PR_ABANDON, null, VcsPullRequestsForm.CMD_ABANDON_SELECTED_PR, listener)); }
@Before @SuppressWarnings("unchecked") public void setUp() { underTest = Mockito.spy(new TabFormImpl<WorkItemsTableModel>(TAB_TITLE, CREATE_DIALOG_TITLE, REFRESH_TOOLTIP, TOOLBAR_LOCATION) { @Override protected void createCustomView() { scrollPanel = new JBScrollPane(); } @Override protected void addCustomTools(final JPanel panel) { } @Override protected List<JBMenuItem> getMenuItems(ActionListener listener) { return null; } @Override public void setModelForView(WorkItemsTableModel modelView) { } @Override public Operation.CredInputsImpl getOperationInputs() { return null; } @Override public void refresh(boolean isTeamServicesRepository) { } }); underTest.statusLabel = new JLabel(); underTest.statusLink = new Hyperlink(); // Mock needed for creating DefaultActionGroup in create group tests PowerMockito.mockStatic(ActionManager.class); ActionManager actionManager = Mockito.mock(ActionManager.class); Mockito.when(ActionManager.getInstance()).thenReturn(actionManager); }
@Test public void testCreateMenuItem() { JBMenuItem item = underTest.createMenuItem(TAB_TITLE, null, "action", null); assertEquals(TfPluginBundle.message(TAB_TITLE), item.getText()); assertEquals("action", item.getActionCommand()); }
@Override @Nonnull public JMenuItem makeMenuItem(@Nonnull final String s, final Icon icon) { return new JBMenuItem(s, icon); }
/** * Creates a menu item to use in the popup menu * * @param resourceKey * @param icon * @param actionCommand * @param listener * @return menu item */ protected JBMenuItem createMenuItem(final String resourceKey, final Icon icon, final String actionCommand, final ActionListener listener) { final String text = TfPluginBundle.message(resourceKey); final JBMenuItem menuItem = new JBMenuItem(text, icon); menuItem.setActionCommand(actionCommand); menuItem.addActionListener(listener); return menuItem; }
/** * Creates and returns the menu items to be shown in the popup menu * * @param listener * @return list of menu items */ protected abstract List<JBMenuItem> getMenuItems(final ActionListener listener);