Search in sources :

Example 6 with ShortcutCreationDTO

use of org.phoenicis.library.dto.ShortcutCreationDTO in project POL-POM-5 by PhoenicisOrg.

the class LibraryController method createShortcut.

/**
 * creates a new shortcut
 * @param shortcutCreationDTO DTO describing the new shortcut
 */
private void createShortcut(ShortcutCreationDTO shortcutCreationDTO) {
    // get container
    // TODO: smarter way using container manager
    final String executablePath = shortcutCreationDTO.getExecutable().getAbsolutePath();
    final String pathInContainers = executablePath.replace(containersPath, "");
    final String[] split = pathInContainers.split("/");
    final String engineContainer = split[0];
    final String engine = (Character.toUpperCase(engineContainer.charAt(0)) + engineContainer.substring(1)).replace("prefix", "");
    final String container = split[1];
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + engine + "\", \"Shortcuts\", \"" + engine + "\"]);", ignored -> interactiveScriptSession.eval("new " + engine + "Shortcut()", output -> {
        final ScriptObjectMirror shortcutObject = (ScriptObjectMirror) output;
        shortcutObject.callMember("name", shortcutCreationDTO.getName());
        shortcutObject.callMember("category", shortcutCreationDTO.getCategory());
        shortcutObject.callMember("description", shortcutCreationDTO.getDescription());
        shortcutObject.callMember("miniature", shortcutCreationDTO.getMiniature());
        shortcutObject.callMember("search", shortcutCreationDTO.getExecutable().getName());
        shortcutObject.callMember("prefix", container);
        shortcutObject.callMember("create");
    }, e -> this.showErrorMessage(e, tr("Error while creating shortcut"))), e -> this.showErrorMessage(e, tr("Error while creating shortcut")));
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) LibraryView(org.phoenicis.javafx.views.mainwindow.library.LibraryView) RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) ShortcutCreationDTO(org.phoenicis.library.dto.ShortcutCreationDTO) RepositoryManager(org.phoenicis.repository.RepositoryManager) ConsoleController(org.phoenicis.javafx.controller.library.console.ConsoleController) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ShortcutRunner(org.phoenicis.library.ShortcutRunner) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ConfirmMessage(org.phoenicis.javafx.views.common.ConfirmMessage) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 7 with ShortcutCreationDTO

use of org.phoenicis.library.dto.ShortcutCreationDTO in project POL-POM-5 by PlayOnLinux.

the class ShortcutCreationPanelSkin method initialise.

/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final GridPane gridPane = new GridPane();
    gridPane.getStyleClass().add("shortcut-information-grid");
    ColumnConstraints labelConstraints = new ColumnConstraintsWithPercentage(30);
    ColumnConstraints valueConstraints = new ColumnConstraintsWithPercentage(70);
    gridPane.getColumnConstraints().addAll(labelConstraints, valueConstraints);
    // add name input
    final TextField name = addName(gridPane);
    final Tooltip nameErrorTooltip = new Tooltip(tr("Please specify a name!"));
    // add category input
    final TextField category = addCategory(gridPane);
    final Tooltip categoryErrorTooltip = new Tooltip(tr("Please specify a category!"));
    // add description input
    final TextArea description = addDescription(gridPane);
    // add miniature input
    final TextField miniature = addMiniature(gridPane);
    final Tooltip miniatureErrorTooltip = new Tooltip(tr("Please specify a valid miniature!"));
    // add executable input
    final TextField executable = addExecutable(gridPane);
    final Tooltip executableErrorTooltip = new Tooltip(tr("Please specify a valid executable!"));
    // add create button
    final Button createButton = new Button(tr("Create"));
    createButton.setOnMouseClicked(event -> {
        boolean error = false;
        if (StringUtils.isEmpty(name.getText())) {
            name.pseudoClassStateChanged(errorClass, true);
            name.setTooltip(nameErrorTooltip);
            error = true;
        }
        if (StringUtils.isEmpty(category.getText())) {
            category.pseudoClassStateChanged(errorClass, true);
            category.setTooltip(categoryErrorTooltip);
            error = true;
        }
        URI miniatureUri = null;
        // but if a miniature is given, it must exist
        if (StringUtils.isNotEmpty(miniature.getText())) {
            File miniatureFile = new File(miniature.getText());
            if (miniatureFile.exists()) {
                miniatureUri = miniatureFile.toURI();
            } else {
                miniature.pseudoClassStateChanged(errorClass, true);
                miniature.setTooltip(miniatureErrorTooltip);
                error = true;
            }
        }
        File executableFile = new File(executable.getText());
        if (!executableFile.exists()) {
            executable.pseudoClassStateChanged(errorClass, true);
            executable.setTooltip(executableErrorTooltip);
            error = true;
        }
        if (!error) {
            final ShortcutCreationDTO newShortcut = new ShortcutCreationDTO.Builder().withName(name.getText()).withCategory(category.getText()).withDescription(description.getText()).withMiniature(miniatureUri).withExecutable(executableFile).build();
            getControl().getOnCreateShortcut().accept(newShortcut);
        }
    });
    final VBox container = new VBox(gridPane, createButton);
    container.getStyleClass().addAll("library-details-panel-content", "create-shortcut-panel-content");
    getChildren().setAll(container);
}
Also used : ShortcutCreationDTO(org.phoenicis.library.dto.ShortcutCreationDTO) URI(java.net.URI) ColumnConstraintsWithPercentage(org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage) File(java.io.File)

Example 8 with ShortcutCreationDTO

use of org.phoenicis.library.dto.ShortcutCreationDTO 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)

Aggregations

ShortcutCreationDTO (org.phoenicis.library.dto.ShortcutCreationDTO)8 File (java.io.File)4 URI (java.net.URI)4 Collections (java.util.Collections)4 Platform (javafx.application.Platform)4 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)4 ConsoleController (org.phoenicis.javafx.controller.library.console.ConsoleController)4 ColumnConstraintsWithPercentage (org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage)4 ShortcutManager (org.phoenicis.library.ShortcutManager)4 ShortcutRunner (org.phoenicis.library.ShortcutRunner)4 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)4 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)4 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 List (java.util.List)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 StringProperty (javafx.beans.property.StringProperty)2 FXCollections (javafx.collections.FXCollections)2