Search in sources :

Example 1 with Template

use of org.apache.jmeter.gui.action.template.Template in project jmeter by apache.

the class SelectTemplatesDialog method populateTemplatePage.

private void populateTemplatePage() {
    String selectedTemplate = templateList.getText();
    Template template = TemplateManager.getInstance().getTemplateByName(selectedTemplate);
    helpDoc.setText(template.getDescription());
    applyTemplateButton.setText(template.isTestPlan() ? JMeterUtils.getResString("template_create_from") : JMeterUtils.getResString("template_merge_from"));
}
Also used : Template(org.apache.jmeter.gui.action.template.Template)

Example 2 with Template

use of org.apache.jmeter.gui.action.template.Template in project jmeter by apache.

the class SelectTemplatesDialog method checkDirtyAndLoad.

/**
     * 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(), // $NON-NLS-1$
            JMeterUtils.getResString("cancel_new_from_template"), // $NON-NLS-1$
            JMeterUtils.getResString("template_load?"), 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) {
                // Don't clear the plan
                return;
            }
        }
    }
    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);
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) Template(org.apache.jmeter.gui.action.template.Template)

Aggregations

Template (org.apache.jmeter.gui.action.template.Template)2 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 GuiPackage (org.apache.jmeter.gui.GuiPackage)1