Search in sources :

Example 1 with StreamTableButton

use of com.exalttech.trex.ui.views.streamtable.StreamTableButton in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method handle.

/**
 * Handle stream button click event
 *
 * @param event
 */
@Override
public void handle(ActionEvent event) {
    StreamTableButton source = (StreamTableButton) event.getSource();
    handleStreamTableAction(source.getButtonActionType());
}
Also used : StreamTableButton(com.exalttech.trex.ui.views.streamtable.StreamTableButton)

Example 2 with StreamTableButton

use of com.exalttech.trex.ui.views.streamtable.StreamTableButton in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketTableView method buildUI.

/**
 * Build component UI
 */
private void buildUI(boolean addExportToYamlBtn) {
    setTopAnchor(this, 0d);
    setLeftAnchor(this, 0d);
    setBottomAnchor(this, 0d);
    setRightAnchor(this, 0d);
    // build btn bar
    HBox buttonContainer = new HBox();
    buttonContainer.setSpacing(5);
    // add build stream btn
    buildPacketBtn = new StreamTableButton(StreamTableAction.BUILD);
    buildPacketBtn.setId("buildStreamBtn");
    initializeStreamButtons(buildPacketBtn, false);
    buttonContainer.getChildren().add(buildPacketBtn);
    editPacketBtn = new StreamTableButton(StreamTableAction.EDIT);
    editPacketBtn.setId("editStreanBtn");
    initializeStreamButtons(editPacketBtn, true);
    buttonContainer.getChildren().add(editPacketBtn);
    duplicatePacketBtn = new StreamTableButton(StreamTableAction.DUPLICATE);
    initializeStreamButtons(duplicatePacketBtn, true);
    buttonContainer.getChildren().add(duplicatePacketBtn);
    deleteButtonBtn = new StreamTableButton(StreamTableAction.DELETE);
    initializeStreamButtons(deleteButtonBtn, true);
    buttonContainer.getChildren().add(deleteButtonBtn);
    importPcapButton = new StreamTableButton(StreamTableAction.IMPORT_PCAP);
    initializeStreamButtons(importPcapButton, false);
    buttonContainer.getChildren().add(importPcapButton);
    exportPcapButton = new StreamTableButton(StreamTableAction.EXPORT_TO_PCAP);
    initializeStreamButtons(exportPcapButton, true);
    buttonContainer.getChildren().add(exportPcapButton);
    if (addExportToYamlBtn) {
        exportToYaml = new StreamTableButton(StreamTableAction.EXPORT_TO_YAML);
        initializeStreamButtons(exportToYaml, false);
        buttonContainer.getChildren().add(exportToYaml);
    }
    getChildren().add(buttonContainer);
    setTopAnchor(buttonContainer, 5d);
    rightClickMenu = new ContextMenu();
    addMenuItem(StreamTableAction.EDIT);
    addMenuItem(StreamTableAction.DUPLICATE);
    addMenuItem(StreamTableAction.DELETE);
    addMenuItem(StreamTableAction.EXPORT_TO_PCAP);
    addMenuItem(StreamTableAction.EXPORT_TO_YAML);
    // add table view
    streamPacketTableView = new TableView<>();
    streamPacketTableView.setId("streamTableView");
    streamPacketTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    streamPacketTableView.setFixedCellSize(32);
    streamPacketTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    streamPacketTableView.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            handleTableRowClick(event);
        }
    });
    streamPacketTableView.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends TableProfileStream> observable, TableProfileStream oldValue, TableProfileStream newValue) -> {
        boolean notSelected = !(newValue != null);
        exportPcapButton.setDisable(notSelected);
        editPacketBtn.setDisable(notSelected);
        duplicatePacketBtn.setDisable(notSelected);
        deleteButtonBtn.setDisable(notSelected);
    });
    streamPacketTableView.addEventFilter(KeyEvent.KEY_RELEASED, (KeyEvent event) -> {
        if (isEditingCell()) {
            return;
        }
        if (copyCombination.match(event)) {
            copiedProfiles = getSelectedProfiles();
        } else if (pasteCombination.match(event) && !copiedProfiles.isEmpty()) {
            handlePasteStreams(copiedProfiles);
        } else if (event.getCode() == KeyCode.DELETE) {
            handleDeletePacket();
        }
    });
    streamPacketTableView.setEditable(true);
    initializeTableColumn();
    // disable table reordering
    streamPacketTableView.widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> source, Number oldWidth, Number newWidth) {
            TableHeaderRow header = (TableHeaderRow) streamPacketTableView.lookup("TableHeaderRow");
            header.reorderingProperty().addListener(new ChangeListener<Boolean>() {

                @Override
                public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                    header.setReordering(false);
                }
            });
        }
    });
    getChildren().add(streamPacketTableView);
    setTopAnchor(streamPacketTableView, 35d);
    setBottomAnchor(streamPacketTableView, 5d);
    setLeftAnchor(streamPacketTableView, 0d);
    setRightAnchor(streamPacketTableView, 0d);
}
Also used : HBox(javafx.scene.layout.HBox) TableHeaderRow(com.sun.javafx.scene.control.skin.TableHeaderRow) TableProfileStream(com.exalttech.trex.ui.views.models.TableProfileStream) ObservableValue(javafx.beans.value.ObservableValue) StreamTableButton(com.exalttech.trex.ui.views.streamtable.StreamTableButton) ChangeListener(javafx.beans.value.ChangeListener)

Aggregations

StreamTableButton (com.exalttech.trex.ui.views.streamtable.StreamTableButton)2 TableProfileStream (com.exalttech.trex.ui.views.models.TableProfileStream)1 TableHeaderRow (com.sun.javafx.scene.control.skin.TableHeaderRow)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 HBox (javafx.scene.layout.HBox)1