Ejemplo n.º 1
0
  public JLoadTestAssertionsTable(WsdlLoadTest wsdlLoadTest) {
    super(new BorderLayout());
    this.loadTest = wsdlLoadTest;

    loadTest.addLoadTestListener(internalLoadTestListener);

    tableModel = new LoadTestAssertionsTableModel();
    table = new JXTable(tableModel);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    TableColumnModel columnModel = table.getColumnModel();
    columnModel.getColumn(0).setMaxWidth(16);
    columnModel.getColumn(0).setCellRenderer(new IconTableCellRenderer());
    columnModel.getColumn(1).setPreferredWidth(100);
    columnModel.getColumn(2).setPreferredWidth(100);
    columnModel.getColumn(3).setPreferredWidth(200);

    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane, BorderLayout.CENTER);

    table.addMouseListener(
        new MouseAdapter() {

          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() < 2) return;

            int ix = table.getSelectedRow();
            if (ix == -1) return;
            ix = table.convertRowIndexToModel(ix);

            Object obj = loadTest.getAssertionAt(ix);
            if (obj instanceof Configurable) {
              ((Configurable) obj).configure();
            } else Toolkit.getDefaultToolkit().beep();
          }
        });

    add(buildToolbar(), BorderLayout.NORTH);

    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              public void valueChanged(ListSelectionEvent e) {
                int ix = table.getSelectedRow();

                configureAssertionAction.setEnabled(ix >= 0);
                removeAssertionAction.setEnabled(ix >= 0);

                if (ix == -1) return;

                ix = table.convertRowIndexToModel(ix);
                configureAssertionAction.setEnabled(
                    loadTest.getAssertionAt(ix) instanceof Configurable);
              }
            });

    assertionPopup = new JPopupMenu();
    assertionPopup.add(configureAssertionAction);
    assertionPopup.addSeparator();
    assertionPopup.add(addLoadTestAssertionAction);
    assertionPopup.add(removeAssertionAction);

    setComponentPopupMenu(assertionPopup);

    scrollPane.setInheritsPopupMenu(true);
    table.setComponentPopupMenu(assertionPopup);
  }