<commit_before>package com.canoo.cog.ui.welcome;

/*
 * #%L
 * code-of-gotham
 * %%
 * Copyright (C) 2015 Canoo Engineering AG
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


import java.util.List;

import com.canoo.cog.solver.CityNode;
import com.canoo.cog.solver.Solver;
import com.canoo.cog.solver.SolverMaximusHaeckius;
import com.canoo.cog.solver.SonarToStrategyConerter;
import com.canoo.cog.sonar.SonarException;
import com.canoo.cog.sonar.SonarService;
import com.canoo.cog.sonar.model.CityModel;
import com.canoo.cog.sonar.model.SonarProject;
import com.canoo.cog.ui.city.CityStage;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;

import static javafx.scene.control.Alert.AlertType;

class WelcomeController {

    // Property Keys
    private static final String COG_PROXY_KEY = "cogProxy";
    private static final String COG_SONAR_HOST_KEY = "cogSonarHost";

    // Alert Messages
    public static final String PROXY_FORM_ERROR_HEADER = "Proxy is not well formed.";
    public static final String PROXY_FORM_ERROR_CONTENT = "The proxy %s does not have the appropriate format {hostname}:{port}.";
    public static final String PROJECT_LIST_EMPTY_HEAER = "Project list is empty.";
    public static final String PROJECT_LIST_EMPTY_CONTENT = "The project list retrieved from %s does not return any projects.";
    public static final String PROJECTS_LOAD_ERROR_HEADER = "Could not load Projects.";
    public static final String PROJECTS_LOAD_ERROR_CONTENT = "An error occurred when communicating with %s. The server does not seem to be reachable.";
    public static final String CITY_BUILD_ERROR_HEADER = "The city could not be built.";
    public static final String CITY_BUILD_ERROR_CONTENT = "An Exception occurred when getting the city information from the sonar server %s";

    @FXML
    private TextField sonarHostname;

    @FXML
    private TextField proxy;

    @FXML
    private PasswordField passwordTextField;

    @FXML
    private TextField usernameField;

    @FXML
    private Button loadButton;

    @FXML
    private Button startButton;

    @FXML
    private TableView projectTable;

    @FXML
    private TableColumn keyColumn;

    @FXML
    private TableColumn nameColumn;

    @FXML
    private TableColumn versionColumn;

    @FXML
    private ProgressIndicator progressIndicator;

    @FXML
    private Label progressText;

    private SonarService sonarService;
    private List<SonarProject> projects;
    private boolean isCityLoading;
    private BooleanBinding isDataOrCityLoading;

    WelcomeController(SonarService sonarService) {
        this.sonarService = sonarService;
    }

    public void init() {
        // Set server values
        setConfiguredServerValues();

        //Initialize Is Loading Property
        isCityLoading = false;
        isDataOrCityLoading = new BooleanBinding() {
            @Override
            protected boolean computeValue() {
                return isCityLoading;
            }
        };

        // Bind progress indicator
        progressIndicator.visibleProperty().bind(isDataOrCityLoading);
        progressText.visibleProperty().bind(isDataOrCityLoading);

        // Enter event that triggers project load
        addLoadProjectsOnEnterEvent(sonarHostname);
        addLoadProjectsOnEnterEvent(proxy);
        addLoadProjectsOnEnterEvent(usernameField);
        addLoadProjectsOnEnterEvent(passwordTextField);

        // Bind disable property to is city loading
        projectTable.disableProperty().bind(isDataOrCityLoading);
        sonarHostname.disableProperty().bind(isDataOrCityLoading);
        proxy.disableProperty().bind(isDataOrCityLoading);
        usernameField.disableProperty().bind(isDataOrCityLoading);
        passwordTextField.disableProperty().bind(isDataOrCityLoading);

        // Initialize the projects table
        keyColumn.setCellValueFactory(new PropertyValueFactory<SonarProject, String>("key"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<SonarProject, String>("name"));
        versionColumn.setCellValueFactory(new PropertyValueFactory<SonarProject, String>("version"));
        projectTable.setRowFactory(tv -> {
            TableRow<String> row = new TableRow<>();
            row.setOnMouseClicked(event -> {
                if (event.getClickCount() == 2 && (!row.isEmpty())) {
                    loadCodeCity();
                }
            });
            return row;
        });

        // Initialize the buttons
        loadButton.setOnMouseClicked(event -> loadProjects());
        loadButton.disableProperty().bind(Bindings.or(sonarHostname.textProperty().isEmpty(), isDataOrCityLoading));
        startButton.setOnMouseClicked(event -> loadCodeCity());
        startButton.disableProperty().bind(isDataOrCityLoading);
        Platform.runLater(startButton::requestFocus);
    }

    private void addLoadProjectsOnEnterEvent(TextField sonarHostname) {<commit_msg>bind code of gotham start building button to index of chosen element in project table<commit_after>package com.canoo.cog.ui.welcome;

/*
 * #%L
 * code-of-gotham
 * %%
 * Copyright (C) 2015 Canoo Engineering AG
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


import java.util.List;

import com.canoo.cog.solver.CityNode;
import com.canoo.cog.solver.Solver;
import com.canoo.cog.solver.SolverMaximusHaeckius;
import com.canoo.cog.solver.SonarToStrategyConerter;
import com.canoo.cog.sonar.SonarException;
import com.canoo.cog.sonar.SonarService;
import com.canoo.cog.sonar.model.CityModel;
import com.canoo.cog.sonar.model.SonarProject;
import com.canoo.cog.ui.city.CityStage;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;

import static javafx.scene.control.Alert.AlertType;

class WelcomeController {

    // Property Keys
    private static final String COG_PROXY_KEY = "cogProxy";
    private static final String COG_SONAR_HOST_KEY = "cogSonarHost";

    // Alert Messages
    public static final String PROXY_FORM_ERROR_HEADER = "Proxy is not well formed.";
    public static final String PROXY_FORM_ERROR_CONTENT = "The proxy %s does not have the appropriate format {hostname}:{port}.";
    public static final String PROJECT_LIST_EMPTY_HEAER = "Project list is empty.";
    public static final String PROJECT_LIST_EMPTY_CONTENT = "The project list retrieved from %s does not return any projects.";
    public static final String PROJECTS_LOAD_ERROR_HEADER = "Could not load Projects.";
    public static final String PROJECTS_LOAD_ERROR_CONTENT = "An error occurred when communicating with %s. The server does not seem to be reachable.";
    public static final String CITY_BUILD_ERROR_HEADER = "The city could not be built.";
    public static final String CITY_BUILD_ERROR_CONTENT = "An Exception occurred when getting the city information from the sonar server %s";

    @FXML
    private TextField sonarHostname;

    @FXML
    private TextField proxy;

    @FXML
    private PasswordField passwordTextField;

    @FXML
    private TextField usernameField;

    @FXML
    private Button loadButton;

    @FXML
    private Button startButton;

    @FXML
    private TableView projectTable;

    @FXML
    private TableColumn keyColumn;

    @FXML
    private TableColumn nameColumn;

    @FXML
    private TableColumn versionColumn;

    @FXML
    private ProgressIndicator progressIndicator;

    @FXML
    private Label progressText;

    private SonarService sonarService;
    private List<SonarProject> projects;
    private boolean isCityLoading;
    private BooleanBinding isDataOrCityLoading;

    WelcomeController(SonarService sonarService) {
        this.sonarService = sonarService;
    }

    public void init() {
        // Set server values
        setConfiguredServerValues();

        //Initialize Is Loading Property
        isCityLoading = false;
        isDataOrCityLoading = new BooleanBinding() {
            @Override
            protected boolean computeValue() {
                return isCityLoading;
            }
        };

        // Bind progress indicator
        progressIndicator.visibleProperty().bind(isDataOrCityLoading);
        progressText.visibleProperty().bind(isDataOrCityLoading);

        // Enter event that triggers project load
        addLoadProjectsOnEnterEvent(sonarHostname);
        addLoadProjectsOnEnterEvent(proxy);
        addLoadProjectsOnEnterEvent(usernameField);
        addLoadProjectsOnEnterEvent(passwordTextField);

        // Bind disable property to is city loading
        projectTable.disableProperty().bind(isDataOrCityLoading);
        sonarHostname.disableProperty().bind(isDataOrCityLoading);
        proxy.disableProperty().bind(isDataOrCityLoading);
        usernameField.disableProperty().bind(isDataOrCityLoading);
        passwordTextField.disableProperty().bind(isDataOrCityLoading);

        // Initialize the projects table
        keyColumn.setCellValueFactory(new PropertyValueFactory<SonarProject, String>("key"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<SonarProject, String>("name"));
        versionColumn.setCellValueFactory(new PropertyValueFactory<SonarProject, String>("version"));
        projectTable.setRowFactory(tv -> {
            TableRow<String> row = new TableRow<>();
            row.setOnMouseClicked(event -> {
                if (event.getClickCount() == 2 && (!row.isEmpty())) {
                    loadCodeCity();
                }
            });
            return row;
        });

        // Initialize the buttons
        loadButton.setOnMouseClicked(event -> loadProjects());
        loadButton.disableProperty().bind(Bindings.or(sonarHostname.textProperty().isEmpty(), isDataOrCityLoading));
        startButton.setOnMouseClicked(event -> loadCodeCity());
        startButton.disableProperty().bind(Bindings.or(isDataOrCityLoading, projectTable.getSelectionModel().selectedIndexProperty().lessThan(0)));
        Platform.runLater(startButton::requestFocus);
    }

    private void addLoadProjectsOnEnterEvent(TextField sonarHostname) {
{'fraction_non_alphanumeric': 0.08368098159509202, 'fraction_numerical': 0.0015541922290388548, 'mean_word_length': 3.624054462934947, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '256032', 'n_tokens_mistral': 3404, 'n_tokens_neox': 3289, 'n_words': 863}