Search in sources :

Example 26 with ErrorDialog

use of org.phoenicis.javafx.dialogs.ErrorDialog in project POL-POM-5 by PhoenicisOrg.

the class EngineInformationPanelSkin method createEngineButtons.

/**
 * Creates a new {@link HBox} containing the interaction buttons for selected engine.
 * The interaction buttons consist of:
 * <ul>
 * <li>An install button</li>
 * <li>An uninstall button</li>
 * </ul>
 *
 * @return A new {@link HBox} containing the interaction buttons for the selected engine
 */
private HBox createEngineButtons() {
    // binding to check whether the currently selected engine is installed
    final BooleanBinding engineInstalledProperty = Bindings.createBooleanBinding(() -> {
        final Engine engine = getControl().getEngine();
        final EngineDTO engineDTO = getControl().getEngineDTO();
        if (engine == null || engineDTO == null) {
            return true;
        }
        return engine.isInstalled(engineDTO.getSubCategory(), engineDTO.getVersion());
    }, getControl().engineProperty(), getControl().engineDTOProperty());
    // the engine install button
    final Button installButton = new Button(tr("Install"));
    installButton.disableProperty().bind(engineInstalledProperty);
    installButton.setOnMouseClicked(evt -> {
        try {
            Optional.ofNullable(getControl().getOnEngineInstall()).ifPresent(onEngineInstall -> onEngineInstall.accept(getControl().getEngineDTO()));
        } catch (IllegalArgumentException e) {
            LOGGER.error("Failed to get engine", e);
            final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("An error occurred while installing the engine")).withOwner(getControl().getScene().getWindow()).withException(e).build();
            errorDialog.showAndWait();
        }
    });
    // the engine delete button
    final Button deleteButton = new Button(tr("Delete"));
    deleteButton.disableProperty().bind(Bindings.not(engineInstalledProperty));
    deleteButton.setOnMouseClicked(evt -> {
        try {
            Optional.ofNullable(getControl().getOnEngineDelete()).ifPresent(onEngineDelete -> onEngineDelete.accept(getControl().getEngineDTO()));
        } catch (IllegalArgumentException e) {
            LOGGER.error("Failed to get engine", e);
            final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("An error occurred while deleting the engine")).withOwner(getControl().getScene().getWindow()).withException(e).build();
            errorDialog.showAndWait();
        }
    });
    final HBox buttonBox = new HBox(installButton, deleteButton);
    buttonBox.getStyleClass().add("engineButtons");
    return buttonBox;
}
Also used : HBox(javafx.scene.layout.HBox) BooleanBinding(javafx.beans.binding.BooleanBinding) EngineDTO(org.phoenicis.engines.dto.EngineDTO) Button(javafx.scene.control.Button) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) Engine(org.phoenicis.engines.Engine)

Example 27 with ErrorDialog

use of org.phoenicis.javafx.dialogs.ErrorDialog in project POL-POM-5 by PhoenicisOrg.

the class ApplicationInformationPanelSkin method updateScripts.

/**
 * Refreshes the shown scripts.
 * When this method is called it begins by clearing the <code>scriptGrid</code>.
 * Afterwards this method refills it.
 */
private void updateScripts(final GridPane scriptGrid) {
    scriptGrid.getChildren().clear();
    for (int i = 0; i < filteredScripts.size(); i++) {
        ScriptDTO script = filteredScripts.get(i);
        final Label scriptName = new Label(script.getScriptName());
        GridPane.setHgrow(scriptName, Priority.ALWAYS);
        if (getControl().isShowScriptSource()) {
            final Tooltip tooltip = new Tooltip(tr("Source: {0}", script.getScriptSource()));
            Tooltip.install(scriptName, tooltip);
        }
        final Button installButton = new Button(tr("Install"));
        installButton.setOnMouseClicked(evt -> {
            try {
                installScript(script);
            } catch (IllegalArgumentException e) {
                final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error while trying to download the installer")).withException(e).build();
                errorDialog.showAndWait();
            }
        });
        OperatingSystem curOs = new OperatingSystemFetcher().fetchCurrentOperationSystem();
        Label lTesting = new Label();
        if (script.getTestingOperatingSystems().contains(curOs)) {
            lTesting.getStyleClass().add("testingIcon");
            lTesting.setTooltip(new Tooltip(tr("Testing")));
            lTesting.setMinSize(30, 30);
        }
        Label lCommercial = new Label();
        if (!script.isFree()) {
            lCommercial.getStyleClass().add("commercialIcon");
            lCommercial.setTooltip(new Tooltip(tr("Commercial")));
            lCommercial.setMinSize(30, 30);
        }
        Label lPatch = new Label();
        if (script.isRequiresPatch()) {
            lPatch.getStyleClass().add("patchIcon");
            lPatch.setTooltip(new Tooltip(tr("Patch required")));
            lPatch.setMinSize(30, 30);
        }
        Label lOs = new Label();
        if (!script.getCompatibleOperatingSystems().contains(curOs)) {
            lOs.getStyleClass().add("osIcon");
            lOs.setTooltip(new Tooltip(tr("All Operating Systems")));
            lOs.setMinSize(30, 30);
        }
        Label lSpace = new Label();
        lSpace.setPrefSize(30, 30);
        HBox iconBox = new HBox(lTesting, lCommercial, lPatch, lOs, lSpace);
        scriptGrid.addRow(i, scriptName, iconBox, installButton);
    }
}
Also used : OperatingSystem(org.phoenicis.entities.OperatingSystem) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) OperatingSystemFetcher(org.phoenicis.tools.system.OperatingSystemFetcher) Button(javafx.scene.control.Button) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog)

Example 28 with ErrorDialog

use of org.phoenicis.javafx.dialogs.ErrorDialog in project POL-POM-5 by PhoenicisOrg.

the class ApplicationInformationPanelSkin method installScript.

/**
 * Install the given script
 *
 * @param script The script to be installed
 */
private void installScript(ScriptDTO script) {
    final StringBuilder executeBuilder = new StringBuilder();
    executeBuilder.append(String.format("TYPE_ID=\"%s\";\n", script.getTypeId()));
    executeBuilder.append(String.format("CATEGORY_ID=\"%s\";\n", script.getCategoryId()));
    executeBuilder.append(String.format("APPLICATION_ID=\"%s\";\n", script.getApplicationId()));
    executeBuilder.append(String.format("SCRIPT_ID=\"%s\";\n", script.getId()));
    executeBuilder.append(script.getScript());
    executeBuilder.append("\n");
    getControl().getScriptInterpreter().createInteractiveSession().eval(executeBuilder.toString(), result -> {
        Value installer = (Value) result;
        installer.as(Installer.class).go();
    }, e -> Platform.runLater(() -> {
        // no exception if installation is cancelled
        if (!(e.getCause() instanceof InterruptedException)) {
            final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("The script ended unexpectedly")).withException(e).build();
            errorDialog.showAndWait();
        }
    }));
}
Also used : Installer(org.phoenicis.scripts.Installer) Value(org.graalvm.polyglot.Value) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog)

Aggregations

ErrorDialog (org.phoenicis.javafx.dialogs.ErrorDialog)28 Platform (javafx.application.Platform)8 Button (javafx.scene.control.Button)8 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)8 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)6 JavaFxSettingsManager (org.phoenicis.javafx.settings.JavaFxSettingsManager)6 File (java.io.File)5 SimpleConfirmDialog (org.phoenicis.javafx.dialogs.SimpleConfirmDialog)5 IOException (java.io.IOException)4 Label (javafx.scene.control.Label)4 Tab (javafx.scene.control.Tab)4 EnginesManager (org.phoenicis.engines.EnginesManager)4 List (java.util.List)3 ObjectProperty (javafx.beans.property.ObjectProperty)3 FXCollections (javafx.collections.FXCollections)3 ObservableList (javafx.collections.ObservableList)3 HBox (javafx.scene.layout.HBox)3 Value (org.graalvm.polyglot.Value)3 FeaturePanel (org.phoenicis.javafx.components.common.control.FeaturePanel)3