Search in sources :

Example 1 with WorkerStateEvent

use of javafx.concurrent.WorkerStateEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class MainViewController method initializeInlineComponent.

/**
     * Initialize in-line built component
     */
private void initializeInlineComponent() {
    updateBtn.setGraphic(new ImageView(new Image("/icons/apply.png")));
    newProfileBtn.setGraphic(new ImageView(new Image("/icons/add_profile.png")));
    stopUpdateBtn.setGraphic(new ImageView(new Image("/icons/stop_update.png")));
    devicesTreeArrowContainer.setImage(leftArrow);
    // mapped profiles enabling with property
    profileListBox.disableProperty().bind(disableProfileProperty);
    newProfileBtn.disableProperty().bind(disableProfileProperty);
    profileDetailLabel.disableProperty().bind(disableProfileProperty);
    profileListBox.getItems().clear();
    profileListBox.setItems(FXCollections.observableArrayList(getProfilesNameList()));
    profileListBox.valueProperty().addListener(new UpdateProfileListener<>(profileListBox.getSelectionModel()));
    updateProfileListProperty.bind(ProfileManager.getInstance().getUpdatedProperty());
    updateProfileListProperty.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
        List<String> profiles = getProfilesNameList();
        profileListBox.setItems(FXCollections.observableArrayList(profiles));
        if (!profiles.contains(currentSelectedProfile)) {
            tableView.reset();
            profileDetailContainer.setVisible(false);
        }
    });
    tableView = new PacketTableView(230, this, true);
    profileTableViewContainer.getChildren().add(tableView);
    serverStatusIcon.setImage(new Image("/icons/offline.png"));
    // initialize right click menu
    rightClickPortMenu = new ContextMenu();
    addMenuItem(rightClickPortMenu, "Acquire", ContextMenuClickType.ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Force Acquire", ContextMenuClickType.FORCE_ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Release Acquire", ContextMenuClickType.RELEASE_ACQUIRE, false);
    rightClickProfileMenu = new ContextMenu();
    addMenuItem(rightClickProfileMenu, "Play", ContextMenuClickType.PLAY, false);
    addMenuItem(rightClickProfileMenu, "Pause", ContextMenuClickType.PAUSE, false);
    addMenuItem(rightClickProfileMenu, "Stop", ContextMenuClickType.STOP, false);
    rightClickGlobalMenu = new ContextMenu();
    addMenuItem(rightClickGlobalMenu, "Release All Ports", ContextMenuClickType.RELEASE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Acquire All Ports", ContextMenuClickType.ACQUIRE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Force Acquire All Ports", ContextMenuClickType.FORCE_ACQUIRE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Re-Acquire my Ports", ContextMenuClickType.ACQUIRE_MY_PORT, false);
    // initialize multiplexer
    multiplierView = new MultiplierView(this);
    multiplierOptionContainer.getChildren().add(multiplierView);
    notificationPanel = new NotificationPanel();
    notificationPanel.setNotificationMsg(DISABLED_MULTIPLIER_MSG);
    notificationPanelHolder.getChildren().add(notificationPanel);
    // add close
    TrexApp.getPrimaryStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            // handle aplpication close
            DialogManager.getInstance().closeAll();
            handleAppClose();
        }
    });
    TrexApp.getPrimaryStage().setOnShown(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            TrexApp.getPrimaryStage().focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue && tableView.isStreamEditingWindowOpen()) {
                    tableView.setStreamEditingWindowOpen(false);
                    streamTableUpdated();
                }
            });
        }
    });
    TrexApp.getPrimaryStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            System.exit(0);
        }
    });
    logContainer.getChildren().add(LogsController.getInstance().getView());
    consoleLogContainer.getChildren().add(LogsController.getInstance().getConsoleLogView());
    // initialize countdown service
    countdownService = new CountdownService();
    countdownService.setPeriod(Duration.seconds(Constants.REFRESH_ONE_INTERVAL_SECONDS));
    countdownService.setRestartOnFailure(false);
    countdownService.setOnSucceeded((WorkerStateEvent event) -> {
        int count = (int) event.getSource().getValue();
        countdownValue.setText(String.valueOf(count) + " Sec");
        if (count == 0) {
            doUpdateAssignedProfile(getSelectedPortIndex());
        }
    });
    devicesTree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            handleTreeItemSelectionChanged();
        }
    });
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) Image(javafx.scene.image.Image) NotificationPanel(com.exalttech.trex.ui.components.NotificationPanel) CountdownService(com.exalttech.trex.ui.views.services.CountdownService) WindowEvent(javafx.stage.WindowEvent) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) ChangeListener(javafx.beans.value.ChangeListener) JsonObject(com.google.gson.JsonObject) ImageView(javafx.scene.image.ImageView)

Aggregations

NotificationPanel (com.exalttech.trex.ui.components.NotificationPanel)1 CountdownService (com.exalttech.trex.ui.views.services.CountdownService)1 JsonObject (com.google.gson.JsonObject)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 WorkerStateEvent (javafx.concurrent.WorkerStateEvent)1 Image (javafx.scene.image.Image)1 ImageView (javafx.scene.image.ImageView)1 WindowEvent (javafx.stage.WindowEvent)1