Search in sources :

Example 1 with EngineSetting

use of org.phoenicis.engines.EngineSetting in project POL-POM-5 by PlayOnLinux.

the class ContainerEngineSettingsPanelSkin method updateEngineSettingsGrid.

/**
 * Updates the engine settings in the given {@link GridPane engineSettingsGrid}
 *
 * @param engineSettingsGrid The GridPane containing the shown engine settings
 */
private void updateEngineSettingsGrid(final GridPane engineSettingsGrid) {
    engineSettingsGrid.getChildren().clear();
    final ContainerDTO container = getControl().getContainer();
    for (EngineSetting engineSetting : getControl().getEngineSettings()) {
        final int row = engineSettingsGrid.getRowCount();
        final Text engineSettingDescription = new Text(engineSetting.getText());
        engineSettingDescription.getStyleClass().add("captionTitle");
        final ObservableList<String> items = FXCollections.observableArrayList(engineSetting.getOptions());
        final ComboBox<String> engineSettingComboBox = new ComboBox<>(items);
        engineSettingComboBox.getStyleClass().add("engine-setting-combo-box");
        engineSettingComboBox.disableProperty().bind(getControl().lockEngineSettingsProperty());
        // if the container is not specified set no default values
        if (container != null) {
            try {
                engineSettingComboBox.setValue(engineSetting.getCurrentOption(container.getName()));
            } catch (Exception e) {
                engineSettingComboBox.getSelectionModel().select(0);
                LOGGER.warn(String.format("Could not fetch current option for engine setting \"%s\", will use default.", engineSetting.getText()));
                LOGGER.debug("Caused by: ", e);
            }
            engineSettingComboBox.valueProperty().addListener((Observable invalidation) -> Platform.runLater(() -> {
                getControl().setLockEngineSettings(true);
                engineSetting.setOption(container.getName(), items.indexOf(engineSettingComboBox.getValue()));
                getControl().setLockEngineSettings(false);
            }));
        }
        engineSettingsGrid.addRow(row, engineSettingDescription, engineSettingComboBox);
    }
}
Also used : EngineSetting(org.phoenicis.engines.EngineSetting) ComboBox(javafx.scene.control.ComboBox) Text(javafx.scene.text.Text) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Observable(javafx.beans.Observable)

Aggregations

Observable (javafx.beans.Observable)1 ComboBox (javafx.scene.control.ComboBox)1 Text (javafx.scene.text.Text)1 ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)1 EngineSetting (org.phoenicis.engines.EngineSetting)1