Search in sources :

Example 1 with ConfigFormEx

use of example.ConfigFormEx in project selenium_java by sergueik.

the class FlowPaneEx method start.

@Override
public void start(Stage stage) {
    this.stage = stage;
    stage.setTitle("SWET/javaFx");
    stage.setWidth(500);
    stage.setHeight(160);
    scene = new Scene(new Group());
    VBox vbox = new VBox();
    FlowPane flow = new FlowPane();
    flow.setVgap(8);
    flow.setHgap(4);
    flow.setPrefWrapLength(300);
    Button launchButton = new Button();
    Image launchImage = new Image(getClass().getClassLoader().getResourceAsStream("browsers_32.png"));
    launchButton.setGraphic(new ImageView(launchImage));
    launchButton.setTooltip(new Tooltip("Launch browser"));
    // https://examples.javacodegeeks.com/desktop-java/javafx/javafx-concurrency-example/
    launchButton.setOnAction(new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {
            startAsyncTask();
        }
    });
    Button injectButton = new Button();
    Image injectImage = new Image(getClass().getClassLoader().getResourceAsStream("find_32.png"));
    injectButton.setGraphic(new ImageView(injectImage));
    injectButton.setTooltip(new Tooltip("Inject script"));
    injectButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            System.out.println("generate step!");
            for (int i = 0; i < 20; i++) {
                Button stepButton = new Button(String.format("Step %d", i));
                stepButton.setOnAction(new EventHandler<ActionEvent>() {

                    @Override
                    public void handle(ActionEvent event) {
                        // ComplexFormEx
                        Map<String, String> inputData = new HashMap<>();
                        Button button = (Button) event.getTarget();
                        inputData.put("dummy", "42");
                        inputData.put("title", String.format("%s element Locators", button.getText()));
                        Map<String, Map> inputs = new HashMap<>();
                        // TODO: JSON
                        inputs.put("inputs", inputData);
                        scene.setUserData(inputs);
                        logger.info("launching complexFormEx for " + inputData.get("title"));
                        ComplexFormEx complexFormEx = new ComplexFormEx();
                        complexFormEx.setScene(scene);
                        try {
                            complexFormEx.start(new Stage());
                        } catch (Exception e) {
                        }
                    }
                });
                flow.getChildren().add(stepButton);
            }
        }
    });
    Button generateButton = new Button();
    Image generateImage = new Image(getClass().getClassLoader().getResourceAsStream("codegen_32.png"));
    generateButton.setGraphic(new ImageView(generateImage));
    generateButton.setTooltip(new Tooltip("Generate program"));
    Button loadButton = new Button();
    Image loadImage = new Image(getClass().getClassLoader().getResourceAsStream("open_32.png"));
    loadButton.setGraphic(new ImageView(loadImage));
    loadButton.setTooltip(new Tooltip("Load session"));
    loadButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            // https://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm
            FileChooser fileChooser = new FileChooser();
            if (configFilePath != null) {
                logger.info("Loading recording from: " + configFilePath);
                try {
                    fileChooser.setInitialDirectory(new File(configFilePath));
                } catch (IllegalArgumentException e) {
                    logger.info("Exception (ignored): " + e.toString());
                }
            }
            // Set extension filter
            fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("YAML file", "*.yaml"));
            fileChooser.setTitle("Open Recording");
            File file = fileChooser.showOpenDialog(stage);
            if (file != null) {
                logger.info("Load recording: " + file.getPath());
                configFilePath = file.getParent();
                openRecordingFile(file);
            }
        }
    });
    Button testsuiteButton = new Button();
    Image testsuiteImage = new Image(getClass().getClassLoader().getResourceAsStream("excel_gen_32.png"));
    testsuiteButton.setGraphic(new ImageView(testsuiteImage));
    testsuiteButton.setTooltip(new Tooltip("Generate Excel TestSuite"));
    testsuiteButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            // Stage stage = new Stage();
            Map<String, String> inputData = new HashMap<>();
            inputData.put("dummy", "42");
            inputData.put("title", "Step detail");
            Map<String, Map> inputs = new HashMap<>();
            // TODO: JSON
            inputs.put("inputs", inputData);
            scene.setUserData(inputs);
            // See also:
            // http://java-buddy.blogspot.com/2016/06/read-csv-run-in-background-thread-and.html
            TableEditorEx tableEditorEx = new TableEditorEx();
            tableEditorEx.setScene(scene);
            try {
                tableEditorEx.start(new Stage());
            } catch (Exception e) {
            }
        }
    });
    Button saveButton = new Button();
    Image saveImage = new Image(getClass().getClassLoader().getResourceAsStream("save_32.png"));
    saveButton.setGraphic(new ImageView(saveImage));
    saveButton.setTooltip(new Tooltip("Save session"));
    saveButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            try {
                System.err.println("Exercise exception");
                testException();
            } catch (Exception e) {
                Dialog.showThrowable("Exception", "Exception thrown", (Exception) e, /* e.getCause()*/
                stage);
            }
            // save
            // https://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm
            FileChooser fileChooser = new FileChooser();
            if (configFilePath != null) {
                logger.info("Saving recording to: " + configFilePath);
                try {
                    fileChooser.setInitialDirectory(new File(configFilePath));
                } catch (IllegalArgumentException e) {
                    logger.info("Exception (ignored): " + e.toString());
                }
            }
            // Set extension filter
            fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("YAML file", "*.yaml"));
            fileChooser.setTitle("Save Recording");
            File file = fileChooser.showSaveDialog(stage);
        }
    });
    Button configButton = new Button();
    Image configImage = new Image(getClass().getClassLoader().getResourceAsStream("preferences_32.png"));
    configButton.setGraphic(new ImageView(configImage));
    configButton.setTooltip(new Tooltip("Configure"));
    configButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            Stage stage = new Stage();
            ConfigFormEx s = new ConfigFormEx();
            s.start(stage);
        }
    });
    Button quitButton = new Button();
    Image quitImage = new Image(getClass().getClassLoader().getResourceAsStream("quit_32.png"));
    quitButton.setGraphic(new ImageView(quitImage));
    quitButton.setTooltip(new Tooltip("Exit"));
    stage.setOnCloseRequest(e -> {
        e.consume();
        confirmClose();
    });
    quitButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            confirmClose();
        // TODO: refactor
        // does not return
        }
    });
    HBox toolbarHbox = new HBox();
    toolbarHbox.getChildren().addAll(launchButton, injectButton, generateButton, loadButton, testsuiteButton, saveButton, configButton, quitButton);
    statusLabel = new Label();
    statusLabel.setText("Status");
    HBox statusbarHbox = new HBox();
    statusbarHbox.getChildren().addAll(statusLabel);
    HBox.setHgrow(statusLabel, Priority.ALWAYS);
    vbox.getChildren().add(toolbarHbox);
    vbox.getChildren().add(flow);
    vbox.getChildren().add(statusbarHbox);
    VBox.setVgrow(flow, Priority.ALWAYS);
    scene.setRoot(vbox);
    stage.setScene(scene);
    stage.show();
}
Also used : Group(javafx.scene.Group) HBox(javafx.scene.layout.HBox) HashMap(java.util.HashMap) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) EventHandler(javafx.event.EventHandler) Image(javafx.scene.image.Image) Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) FlowPane(javafx.scene.layout.FlowPane) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) ConfigFormEx(example.ConfigFormEx) Tooltip(javafx.scene.control.Tooltip) Scene(javafx.scene.Scene) IOException(java.io.IOException) VBox(javafx.scene.layout.VBox) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

ConfigFormEx (example.ConfigFormEx)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 Group (javafx.scene.Group)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 Tooltip (javafx.scene.control.Tooltip)1 Image (javafx.scene.image.Image)1 ImageView (javafx.scene.image.ImageView)1 FlowPane (javafx.scene.layout.FlowPane)1 HBox (javafx.scene.layout.HBox)1 VBox (javafx.scene.layout.VBox)1 FileChooser (javafx.stage.FileChooser)1 Stage (javafx.stage.Stage)1