org.apache.jmeter.gui.GuiPackage Java Examples

The following examples show how to use org.apache.jmeter.gui.GuiPackage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {
    log.debug("Showing dialog");
    if (GuiPackage.getInstance() != null) {
        savedDirty = GuiPackage.getInstance().isDirty();
    }
    this.debugger = new Debugger(this, this);
    tgCombo.removeAllItems();
    for (AbstractThreadGroup group : debugger.getThreadGroups()) {
        tgCombo.addItem(group);
    }

    AbstractThreadGroup selectedThreadGroup = debugger.getSelectedThreadGroup();
    if (selectedThreadGroup != null) {
        changeComboValue(selectedThreadGroup);
    }

    tgCombo.setEnabled(tgCombo.getItemCount() > 0);
    start.setEnabled(tgCombo.getItemCount() > 0);
    start.requestFocus();
    clearListeners();
}
 
Example #2
Source File: WeightedSwitchControllerGui.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(TestElement element) {
    // from model to GUI
    super.configure(element);
    log.debug("Props: " + this.isShowing() + " " + isVisible() + " " + isEnabled() + " " + isFocusOwner());
    GuiPackage gp = GuiPackage.getInstance();

    if (gp != null && element instanceof WeightedSwitchController) {
        WeightedSwitchController wsc = (WeightedSwitchController) element;
        CollectionProperty oldData = wsc.getData();

        grid.getModel().clearData();
        isRandomChoiceCheckBox.setSelected(wsc.isRandomChoice());
        if (isShowing()) {
            fillGridFromTree(wsc, oldData);
        } else {
            JMeterPluginsUtils.collectionPropertyToTableModelRows(oldData, grid.getModel());
        }
    }
}
 
Example #3
Source File: DebuggerDialogTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void testGui() throws Exception {
    if (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
        return;
    }
    String actions = ActionRouter.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    String renderers = RenderAsHTML.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    JMeterUtils.setProperty("search_paths", actions + ";" + renderers);
    TestProvider prov = new TestProvider();
    JMeterTreeModel mdl = prov.getTreeModel();
    JMeterTreeListener a = new JMeterTreeListener();
    a.setActionHandler(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            log.debug("Action " + actionEvent);
        }
    });
    a.setModel(mdl);
    GuiPackage.getInstance(a, mdl);

    DebuggerDialog obj = new DebuggerDialogMock(prov.getTreeModel());
    obj.componentShown(null);
    obj.started();
    obj.statusRefresh(JMeterContextService.getContext());
    obj.frozenAt(new SamplerDebug());
    obj.continuing();
    obj.stopped();
    obj.componentHidden(null);
}
 
Example #4
Source File: ThreadCountsAccessor.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private static void refreshUI() {
    long ts = System.currentTimeMillis();
    if (ts - lastUpdate < 1000) {
        return; // throttle down updates
    }

    lastUpdate = ts;
    GuiPackage gp = GuiPackage.getInstance();
    if (gp != null) {// check there is a GUI
        gp.getMainFrame().updateCounts();
    }
}
 
Example #5
Source File: MergeResultsGui.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private boolean loadFilesFromTable(CorrectedResultCollector crc) {
    for (int row = 0; row < tableModel.getRowCount(); row++) {
        startTimeRef = 0;
        crc.setFilename(String.valueOf(tableModel.getValueAt(row,
                INPUT_FILE_NAME)));
        if (crc.getFilename().isEmpty()) {
            GuiPackage.showErrorMessage(
                    "Error merging results files - could not open file [row: "
                            + row + ";filename: " + collector.getFilename()
                            + "]", "Input file error");
            return false;
        }
        crc.setStartOffset(String.valueOf(tableModel.getValueAt(row,
                OFFSET_START)));
        crc.setEndOffset(String.valueOf(tableModel.getValueAt(row,
                OFFSET_END)));
        crc.setIncludeLabels(String.valueOf(tableModel.getValueAt(row,
                INCLUDE_LABEL)));
        crc.setExcludeLabels(String.valueOf(tableModel.getValueAt(row,
                EXCLUDE_LABEL)));
        crc.setEnabledIncludeRegex(Boolean.valueOf(String
                .valueOf((tableModel.getValueAt(row, REGEX_INCLUDE)))));
        crc.setEnabledExcludeRegex(Boolean.valueOf(String
                .valueOf((tableModel.getValueAt(row, REGEX_EXCLUDE)))));
        crc.setPrefixLabel(String.valueOf((tableModel.getValueAt(row,
                PREFIX_LABEL))));
        setUpFiltering(crc);
        crc.loadExistingFile();
    }
    return true;
}
 
Example #6
Source File: HttpSimpleTableControl.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public void stopHttpSimpleTable() {
    if (server != null) {
        server.stopServer();
        GuiPackage instance = GuiPackage.getInstance();
        if (instance != null) {
            instance.unregister(server);
        }
        server = null;
    }
}
 
Example #7
Source File: HttpSimpleTableControl.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public void startHttpSimpleTable() throws IOException {
    log.info("Creating HTTP Simple Table Server...");
    log.info("Port=" + getPort());
    log.info("Dataset directory=" + getDataDir());
    log.info("Timestamp=" + getTimestamp());
    log.info("STS Version=" + HttpSimpleTableServer.STS_VERSION);
    server = new HttpSimpleTableServer(getPort(), getTimestamp(),
            getDataDir());
    server.start();
    GuiPackage instance = GuiPackage.getInstance();
    if (instance != null) {
        instance.register(server);
    }
}
 
Example #8
Source File: BrowseAction.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = getFileChooser();
    if (chooser != null) {
        if(GuiPackage.getInstance() != null) {
            int returnVal = chooser.showOpenDialog(GuiPackage.getInstance().getMainFrame());
            if(returnVal == JFileChooser.APPROVE_OPTION) {
               control.setText(chooser.getSelectedFile().getPath());
            }
            lastPath = chooser.getCurrentDirectory().getPath();
        }
    }
}
 
Example #9
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void clearRowsFromCompositeModels(String vizualizerName) {
    GuiPackage gui = GuiPackage.getInstance();
    if (gui == null) {
        log.debug("No GUI Package present, ignored removing from composite");
        return;
    }
    JMeterTreeModel testTree = gui.getTreeModel();

    for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
        //System.out.println("obj");
        CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
        compositeResultCollector.getCompositeModel().clearRows(vizualizerName);
    }
}
 
Example #10
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void addRowToCompositeModels(String rowName, AbstractGraphRow row) {
    GuiPackage gui = GuiPackage.getInstance();
    if (gui == null) {
        log.debug("No GUI Package present, ignored adding to composite");
        return;
    }

    JMeterTreeModel testTree = gui.getTreeModel();

    for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
        CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
        compositeResultCollector.getCompositeModel().addRow(rowName, row);
    }
}
 
Example #11
Source File: GraphPanel.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private void addGraphTab() {
    ImageIcon graphIcon = createImageIcon("/kg/apc/jmeter/img/graph.png");
    graphPanelObject = new GraphPanelChart(GuiPackage.getInstance() != null);
    graphPanelObject.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
    JGraphPanel graphTab = new JGraphPanel();
    graphTab.add(graphPanelObject, BorderLayout.CENTER);
    addTab("Chart", graphIcon, graphTab, "View chart");
}
 
Example #12
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private synchronized void displayElementGui(TestElement wrpElm) {
        GuiPackage gui = GuiPackage.getInstance();
        if (gui != null) {
            JMeterGUIComponent egui = gui.getGui(wrpElm);
            egui.configure(wrpElm);
            egui.modifyTestElement(wrpElm);

            elementContainer.removeAll();
            if (egui instanceof Component) {
//                egui.setEnabled(false);
                elementContainer.add((Component) egui, BorderLayout.CENTER);
            }
            elementContainer.updateUI();
        }
    }
 
Example #13
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void clearListeners() {
    GuiPackage guiPackage = GuiPackage.getInstance();
    for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
        JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
        if (guiComp instanceof Clearable){
            Clearable item = (Clearable) guiComp;
            try {
                item.clearData();
            } catch (Exception ex) {
                log.error("Can't clear: {} {}", node, guiComp, ex);
            }
        }
    }
}
 
Example #14
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public void componentHidden(ComponentEvent e) {
    log.debug("Closing dialog");

    debugger.stop();
    if (GuiPackage.getInstance() != null) {
        GuiPackage.getInstance().setDirty(savedDirty);
    }
    clearListeners();
    clearStatusPane();
}
 
Example #15
Source File: DebuggerMenuItem.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void addToolbarIcon() {
    GuiPackage instance = GuiPackage.getInstance();
    if (instance != null) {
        final MainFrame mf = instance.getMainFrame();
        final ComponentFinder<JMeterToolBar> finder = new ComponentFinder<>(JMeterToolBar.class);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JMeterToolBar toolbar = null;
                while (toolbar == null) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        log.debug("Did not add btn to toolbar", e);
                    }
                    log.debug("Searching for toolbar");
                    toolbar = finder.findComponentIn(mf);
                }

                int pos = 21;
                Component toolbarButton = getToolbarButton();
                toolbarButton.setSize(toolbar.getComponent(pos).getSize());
                toolbar.add(toolbarButton, pos);
            }
        });
    }
}
 
Example #16
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private AbstractThreadGroup getSelectedThreadGroup(AbstractThreadGroup[] grps) {
    JMeterTreeNode currentElement = GuiPackage.getInstance().getCurrentNode();
    if (currentElement != null) {
        SearchParentClass<AbstractThreadGroup> searcher = new SearchParentClass(currentElement, AbstractThreadGroup.class);
        treeProvider.getTestTree().traverse(searcher);
        return searcher.hasResults() ? searcher.getSearchResults().get(0) : grps[0];
    }
    return grps[0];
}
 
Example #17
Source File: WeightedSwitchControllerGui.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private void fillGridFromTree(WeightedSwitchController wsc, CollectionProperty oldData) {
    JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
    JMeterTreeNode root = (JMeterTreeNode) treeModel.getRoot();

    Map<JMeterTreeNode, Boolean> childItems = getChildItems(root, wsc);
    for (JMeterTreeNode node : childItems.keySet()) {
        String w = "100";
        JMeterProperty row = getRowByName(node.getTestElement().getName(), oldData);
        if (row != null) {
            w = ((CollectionProperty) row).get(1).getStringValue();
        }
        grid.getModel().addRow(new String[]{node.getTestElement().getName(), w, childItems.get(node).toString()});
    }
}
 
Example #18
Source File: DebuggerDialogTest.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Test
public void displayGUI() throws InterruptedException, IOException, IllegalUserActionException {
    if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
        TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");
        JMeterTreeModel mdl = prov.getTreeModel();
        JMeterTreeListener a = new JMeterTreeListener();
        a.setActionHandler(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                log.debug("Action " + actionEvent);
            }
        });
        a.setModel(mdl);

        GuiPackage.getInstance(a, mdl);
        String actions = ActionRouter.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        String renderers = RenderAsHTML.class.getProtectionDomain().getCodeSource().getLocation().getFile();
        JMeterUtils.setProperty("search_paths", actions + ";" + renderers);
        MainFrame mf = new MainFrame(mdl, a); // does important stuff inside
        ComponentFinder<JMeterToolBar> finder = new ComponentFinder<>(JMeterToolBar.class);
        JMeterToolBar tb = finder.findComponentIn(mf);
        tb.add(new JButton("test"));

        new TimeFunction();
        long now = System.currentTimeMillis();
        JMeterUtils.setProperty("START.MS", Long.toString(now));
        Date today = new Date(now);
        JMeterUtils.setProperty("START.YMD", new SimpleDateFormat("yyyyMMdd").format(today));
        JMeterUtils.setProperty("START.HMS", new SimpleDateFormat("HHmmss").format(today));

        DebuggerDialogMock frame = new DebuggerDialogMock(mdl);

        frame.setPreferredSize(new Dimension(800, 600));
        frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        while (frame.isVisible()) {
            Thread.sleep(1000);
        }
    }
}
 
Example #19
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 4 votes vote down vote up
@Override
public HashTree getTestTree() {
    GuiPackage gui = GuiPackage.getInstance();
    return gui.getTreeModel().getTestPlan();
}
 
Example #20
Source File: ClassPropertyEditor.java    From pepper-box with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent) {

    //Get class from input text field
    String className = this.textField.getText();

    //Get list of class properties
    List<FieldExpressionMapping> attributeList = new ArrayList<>();
    try {

        //Load class and get fields using reflection
        Class loadedClass = Class.forName(className);

        Field fields[] = loadedClass.getDeclaredFields();

        for (Field field : fields) {

            field.setAccessible(true);

            FieldExpressionMapping expressionMapping = new FieldExpressionMapping();
            expressionMapping.setFieldName(field.getName());
            expressionMapping.setFieldExpression(PropsKeys.IGNORE);

            attributeList.add(expressionMapping);
        }

        //Get current test GUI component
        TestBeanGUI testBeanGUI = (TestBeanGUI) GuiPackage.getInstance().getCurrentGui();
        Field customizer = TestBeanGUI.class.getDeclaredField(PropsKeys.CUSTOMIZER);
        customizer.setAccessible(true);


        //From TestBeanGUI retrieve Bean Customizer as it includes all editors like ClassPropertyEditor, TableEditor
        GenericTestBeanCustomizer testBeanCustomizer = (GenericTestBeanCustomizer) customizer.get(testBeanGUI);
        Field editors = GenericTestBeanCustomizer.class.getDeclaredField(PropsKeys.EDITORS);
        editors.setAccessible(true);

        //Retrieve TableEditor and set all fields with default values to it
        PropertyEditor propertyEditors[] = (PropertyEditor[]) editors.get(testBeanCustomizer);
        for (PropertyEditor propertyEditor : propertyEditors){
            if (propertyEditor instanceof TableEditor){
                propertyEditor.setValue(attributeList);
            }
        }

    } catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException e) {
        JOptionPane.showMessageDialog(null, "Failed to load class properties : " + e.getMessage(), "ERROR: Failed to load class properties!" , JOptionPane.ERROR_MESSAGE);
        LOGGER.log(Level.SEVERE, "Failed to load class properties", e);
    }

}
 
Example #21
Source File: PerfMonGui.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private Component createConnectionsPanel() {
    JPanel panel = new JPanel(new BorderLayout(5, 5));
    panel.setBorder(BorderFactory.createTitledBorder("Servers to Monitor (ServerAgent must be started, see help)"));
    panel.setPreferredSize(new Dimension(150, 150));

    JScrollPane scroll = new JScrollPane(createGrid());
    scroll.setPreferredSize(scroll.getMinimumSize());
    panel.add(scroll, BorderLayout.CENTER);
    panel.add(new ButtonPanelAddCopyRemove(grid, tableModel, defaultValues), BorderLayout.SOUTH);

    List<String> items = new LinkedList<>(metrics);
    // add metrics from new agent
    items.add("TCP");
    items.add("JMX");
    items.add("EXEC");
    items.add("TAIL");
    JComboBox metricTypesBox = new JComboBox(items.toArray());
    grid.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(metricTypesBox));

    final JTextField wizEditor = new JTextField();
    wizEditor.setBorder(null);
    JButton wiz = new JButton("...");
    if (!GraphicsEnvironment.isHeadless()) {
        wiz.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Frame parent = GuiPackage.getInstance().getMainFrame();
                String type = grid.getValueAt(grid.getSelectedRow(), 2).toString();

                JPerfmonParamsPanel dlgContent = new JPerfmonParamsPanel(type, wizEditor);
                dlgContent.setMinWidth(400);
                JDialog dlg = DialogFactory.getJDialogInstance(parent, "PerfMon [" + type + "] Parameters Helper",
                        true, dlgContent, "/kg/apc/jmeter/vizualizers/wand.png");

                DialogFactory.centerDialog(parent, dlg);

                dlg.setVisible(true);
            }
        });
    }
    wiz.setMargin(new Insets(0, 6, 5, 6));
    GuiBuilderHelper.strechItemToComponent(wizEditor, wiz);
    ComponentBorder bd = new ComponentBorder(wiz);

    bd.install(wizEditor);

    grid.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(wizEditor));
    grid.getTableHeader().setReorderingAllowed(false);

    return panel;
}