Search in sources :

Example 16 with ErrorDialog

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

the class ContainerToolsPanelSkin method createToolsContainer.

/**
 * Creates the container for the tool buttons
 *
 * @return The container with the tool buttons
 */
private TilePane createToolsContainer() {
    final TilePane toolsContainer = new TilePane();
    final Button runExecutable = new Button(tr("Run executable"));
    runExecutable.getStyleClass().addAll("toolButton", "runExecutable");
    runExecutable.setOnMouseClicked(event -> {
        getControl().setLockTools(true);
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(tr("Choose executable..."));
        // open in container directory if it exists
        final File containerDir = new File(getControl().getContainer().getPath());
        if (containerDir.canRead()) {
            fileChooser.setInitialDirectory(containerDir);
        }
        final File file = fileChooser.showOpenDialog(getControl().getScene().getWindow());
        if (file != null) {
            final ContainerDTO container = getControl().getContainer();
            final String engineId = container.getEngine().toLowerCase();
            getControl().getEnginesManager().getEngine(engineId, engine -> {
                engine.setWorkingContainer(container.getName());
                engine.run(file.getAbsolutePath(), new String[0], container.getPath(), false, true, new HashMap<>());
                getControl().setLockTools(false);
            }, exception -> Platform.runLater(() -> {
                final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error")).withOwner(getControl().getScene().getWindow()).withException(exception).build();
                errorDialog.showAndWait();
            }));
        } else {
            // unlock if file chooser is closed
            getControl().setLockTools(false);
        }
    });
    toolsContainer.getChildren().add(runExecutable);
    return toolsContainer;
}
Also used : Button(javafx.scene.control.Button) TilePane(javafx.scene.layout.TilePane) FileChooser(javafx.stage.FileChooser) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) File(java.io.File)

Example 17 with ErrorDialog

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

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 18 with ErrorDialog

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

the class LibraryFeaturePanel method createShortcut.

/**
 * Creates a new shortcut
 *
 * @param shortcutCreationDTO DTO describing the new shortcut
 */
public void createShortcut(ShortcutCreationDTO shortcutCreationDTO) {
    // get container
    // TODO: smarter way using container manager
    final String executablePath = shortcutCreationDTO.getExecutable().getAbsolutePath();
    final String pathInContainers = executablePath.replace(getContainersPath(), "");
    final String[] split = pathInContainers.split("/");
    final String engineContainer = split[0];
    final String engine = StringUtils.capitalize(engineContainer).replace("prefix", "");
    // TODO: better way to get engine ID
    final String engineId = engine.toLowerCase();
    final String container = split[1];
    final InteractiveScriptSession interactiveScriptSession = getScriptInterpreter().createInteractiveSession();
    final String scriptInclude = "const Shortcut = include(\"engines." + engineId + ".shortcuts." + engineId + "\");";
    interactiveScriptSession.eval(scriptInclude, ignored -> interactiveScriptSession.eval("new Shortcut()", output -> {
        final Value shortcutObject = (Value) output;
        shortcutObject.invokeMember("name", shortcutCreationDTO.getName());
        shortcutObject.invokeMember("category", shortcutCreationDTO.getCategory());
        shortcutObject.invokeMember("description", shortcutCreationDTO.getDescription());
        shortcutObject.invokeMember("miniature", shortcutCreationDTO.getMiniature());
        shortcutObject.invokeMember("search", shortcutCreationDTO.getExecutable().getName());
        shortcutObject.invokeMember("prefix", container);
        shortcutObject.invokeMember("create");
    }, e -> Platform.runLater(() -> {
        final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error while creating shortcut")).withException(e).withOwner(getScene().getWindow()).build();
        errorDialog.showAndWait();
    })), e -> Platform.runLater(() -> {
        final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error while creating shortcut")).withException(e).withOwner(getScene().getWindow()).build();
        errorDialog.showAndWait();
    }));
}
Also used : FeaturePanel(org.phoenicis.javafx.components.common.control.FeaturePanel) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) StringUtils(org.apache.commons.lang.StringUtils) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) ConsoleController(org.phoenicis.javafx.controller.library.console.ConsoleController) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) None(org.phoenicis.javafx.components.common.panelstates.None) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ObjectProperty(javafx.beans.property.ObjectProperty) Value(org.graalvm.polyglot.Value) ShortcutCreationDTO(org.phoenicis.library.dto.ShortcutCreationDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) LibraryFilter(org.phoenicis.javafx.views.mainwindow.library.LibraryFilter) ShortcutManager(org.phoenicis.library.ShortcutManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ConsoleTab(org.phoenicis.javafx.views.mainwindow.console.ConsoleTab) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) OpenDetailsPanel(org.phoenicis.javafx.components.common.panelstates.OpenDetailsPanel) ShortcutRunner(org.phoenicis.library.ShortcutRunner) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Collections(java.util.Collections) LibraryFeaturePanelSkin(org.phoenicis.javafx.components.library.skin.LibraryFeaturePanelSkin) Value(org.graalvm.polyglot.Value) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 19 with ErrorDialog

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

the class AppsController method showError.

private void showError(Exception e) {
    Platform.runLater(() -> {
        final ErrorDialog errorDialog = ErrorDialog.builder().withOwner(view.getScene().getWindow()).withException(e).withMessage(tr("Connecting to the repository failed.\nPlease check your connection and try again.")).build();
        errorDialog.showAndWait();
    });
}
Also used : ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog)

Example 20 with ErrorDialog

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

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