/** * Get the menu items to add to the menu bar, to get recent file functionality * * @return a List of JMenuItem and a JSeparator, representing recent files */ public static List<JComponent> getRecentFileMenuItems() { LinkedList<JComponent> menuItems = new LinkedList<JComponent>(); // Get the preference for the recent files for (int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) { // Create the menu item JMenuItem recentFile = new JMenuItem(); // Use the index as the name, used when processing the action recentFile.setName(Integer.toString(i)); recentFile.addActionListener(ActionRouter.getInstance()); recentFile.setActionCommand(ActionNames.OPEN_RECENT); // Set the KeyStroke to use int shortKey = getShortcutKey(i); if (shortKey >= 0) { recentFile.setMnemonic(shortKey); } // Add the menu item menuItems.add(recentFile); } // Add separator as the last item JSeparator separator = new JSeparator(); separator.setVisible(false); menuItems.add(separator); // Update menu items to reflect recent files updateMenuItems(menuItems); return menuItems; }
/** * Check if existing Test Plan has been modified and ask user what he wants to do if test plan is * dirty * * @param actionEvent {@link ActionEvent} */ private void checkDirtyAndLoad(final ActionEvent actionEvent) throws HeadlessException { final String selectedTemplate = templateList.getText(); final Template template = TemplateManager.getInstance().getTemplateByName(selectedTemplate); if (template == null) { return; } final boolean isTestPlan = template.isTestPlan(); // Check if the user wants to drop any changes if (isTestPlan) { ActionRouter.getInstance() .doActionNow( new ActionEvent( actionEvent.getSource(), actionEvent.getID(), ActionNames.CHECK_DIRTY)); GuiPackage guiPackage = GuiPackage.getInstance(); if (guiPackage.isDirty()) { // Check if the user wants to create from template int response = JOptionPane.showConfirmDialog( GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("cancel_new_from_template"), // $NON-NLS-1$ JMeterUtils.getResString("template_load?"), // $NON-NLS-1$ JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { ActionRouter.getInstance() .doActionNow( new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.SAVE)); } if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.CANCEL_OPTION) { return; // Don't clear the plan } } } ActionRouter.getInstance() .doActionNow( new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.STOP_THREAD)); final File parent = template.getParent(); final File fileToCopy = parent != null ? new File(parent, template.getFileName()) : new File(JMeterUtils.getJMeterHome(), template.getFileName()); Load.loadProjectFile(actionEvent, fileToCopy, !isTestPlan, false); this.setVisible(false); }
/** * Description of the Method * * @param e Description of Parameter */ public void doAction(ActionEvent e) { ActionRouter.getInstance() .doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.CHECK_DIRTY)); if (GuiPackage.getInstance().isDirty()) { int chosenOption = JOptionPane.showConfirmDialog( GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("cancel_exit_to_save"), // $NON-NLS-1$ JMeterUtils.getResString("save?"), // $NON-NLS-1$ JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (chosenOption == JOptionPane.NO_OPTION) { System.exit(0); } else if (chosenOption == JOptionPane.YES_OPTION) { ActionRouter.getInstance() .doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SAVE_ALL_AS)); if (!GuiPackage.getInstance().isDirty()) { System.exit(0); } } } else { System.exit(0); } }