Search in sources :

Example 16 with ContainerDTO

use of org.phoenicis.containers.dto.ContainerDTO in project phoenicis by PhoenicisOrg.

the class WinePrefixContainerController method runInContainer.

public void runInContainer(ContainerDTO container, String command, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new " + container.getEngine() + "()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("prefix", container.getName());
        wine.callMember("run", command);
        wine.callMember("wait");
        doneCallback.run();
    }, errorCallback), errorCallback);
}
Also used : Consumer(java.util.function.Consumer) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 17 with ContainerDTO

use of org.phoenicis.containers.dto.ContainerDTO in project POL-POM-5 by PlayOnLinux.

the class ContainerVerbsPanelSkin method createVerbManagementButtons.

/**
 * Creates a container with the buttons for the verb selection management. These buttons consist of:
 * - a button to install all selected verbs
 * - a button to clear/reset the selection
 *
 * @param verbs The {@link GridPane} containing the visual verb installation components
 * @return A container with the buttons for the verb selection management
 */
private HBox createVerbManagementButtons(final GridPane verbs) {
    final Button installButton = new Button(tr("Install selected"));
    installButton.disableProperty().bind(getControl().lockVerbsProperty());
    installButton.setOnAction(event -> {
        getControl().setLockVerbs(true);
        final ContainerDTO container = getControl().getContainer();
        // find the ids of all selected verbs
        final List<ScriptDTO> installationVerbs = verbs.getChildren().stream().filter(element -> element instanceof CheckBox && ((CheckBox) element).isSelected()).map(GridPane::getRowIndex).map(getControl().getVerbScripts()::get).collect(Collectors.toList());
        final List<String> verbNames = installationVerbs.stream().map(ScriptDTO::getScriptName).collect(Collectors.toList());
        final ListConfirmDialog confirmDialog = ListConfirmDialog.builder().withTitle(tr("Install Verbs")).withMessage(tr("Are you sure you want to install the following Verbs:")).withConfirmItems(verbNames).withOwner(getControl().getScene().getWindow()).withYesCallback(() -> {
            final List<String> verbIds = installationVerbs.stream().map(ScriptDTO::getId).collect(Collectors.toList());
            // install the selected verbs
            getControl().getVerbsManager().installVerbs(container.getEngine().toLowerCase(), container.getName(), verbIds, () -> getControl().setLockVerbs(false), e -> Platform.runLater(() -> {
                final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error installing Verbs")).withException(e).build();
                errorDialog.showAndWait();
            }));
        }).build();
        confirmDialog.showAndCallback();
        // after the dialog has been closed unlock the verb buttons
        getControl().setLockVerbs(false);
    });
    final Button clearButton = new Button(tr("Clear selection"));
    clearButton.disableProperty().bind(getControl().lockVerbsProperty());
    clearButton.setOnAction(event -> verbs.getChildren().stream().filter(element -> element instanceof CheckBox).map(element -> (CheckBox) element).forEach(verbCheckBox -> verbCheckBox.setSelected(false)));
    return new HBox(installButton, clearButton);
}
Also used : Button(javafx.scene.control.Button) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label) ContainerVerbsPanel(org.phoenicis.javafx.components.container.control.ContainerVerbsPanel) CheckBox(javafx.scene.control.CheckBox) ListConfirmDialog(org.phoenicis.javafx.dialogs.ListConfirmDialog) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Observable(javafx.beans.Observable) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) Priority(javafx.scene.layout.Priority) List(java.util.List) ScrollPane(javafx.scene.control.ScrollPane) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) GridPane(javafx.scene.layout.GridPane) SkinBase(org.phoenicis.javafx.components.common.skin.SkinBase) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ListConfirmDialog(org.phoenicis.javafx.dialogs.ListConfirmDialog) HBox(javafx.scene.layout.HBox) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) GridPane(javafx.scene.layout.GridPane) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Button(javafx.scene.control.Button) CheckBox(javafx.scene.control.CheckBox) List(java.util.List)

Example 18 with ContainerDTO

use of org.phoenicis.containers.dto.ContainerDTO 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 19 with ContainerDTO

use of org.phoenicis.containers.dto.ContainerDTO in project POL-POM-5 by PlayOnLinux.

the class ContainersFeaturePanelSkin method updateEngineTools.

/**
 * Applies the engine tools belonging to the currently selected container to the given
 * {@link ContainerInformationPanel}
 *
 * @param containerInformationPanel The information panel showing the details for the currently selected container
 */
private void updateEngineTools(final ContainerInformationPanel containerInformationPanel) {
    final ObservableMap<String, ApplicationDTO> engineTools = getControl().getEngineTools();
    final ContainerDTO container = containerInformationPanel.getContainer();
    if (container != null && engineTools.containsKey(container.getEngine().toLowerCase())) {
        containerInformationPanel.setEngineTools(engineTools.get(container.getEngine().toLowerCase()));
    } else {
        containerInformationPanel.setEngineTools(null);
    }
}
Also used : ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO)

Example 20 with ContainerDTO

use of org.phoenicis.containers.dto.ContainerDTO in project POL-POM-5 by PlayOnLinux.

the class ContainersFeaturePanelSkin method createContent.

/**
 * {@inheritDoc}
 */
@Override
public ObjectExpression<Node> createContent() {
    /*
         * initialize the container lists by:
         * 1. sorting the containers by their name
         * 2. filtering the containers
         */
    final FilteredList<ContainerDTO> filteredContainers = ConcatenatedList.create(new MappedList<>(getControl().getCategories().sorted(Comparator.comparing(ContainerCategoryDTO::getName)), ContainerCategoryDTO::getContainers)).sorted(Comparator.comparing(ContainerDTO::getName)).filtered(getControl().getFilter()::filter);
    filteredContainers.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty()));
    final ObservableList<ListWidgetElement<ContainerDTO>> listWidgetEntries = new MappedList<>(filteredContainers, ListWidgetElement::create);
    final CombinedListWidget<ContainerDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
    // bind direction: controller property -> skin property
    getControl().selectedContainerProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            combinedListWidget.select(newValue);
        } else {
            combinedListWidget.deselect();
        }
    });
    // bind direction: skin property -> controller properties
    combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final ContainerDTO selectedItem = newValue.getItem();
            getControl().setSelectedContainer(selectedItem);
            getControl().setOpenedDetailsPanel(new ContainerInformation(selectedItem));
        } else {
            getControl().setSelectedContainer(null);
            getControl().setOpenedDetailsPanel(new None());
        }
    });
    return new SimpleObjectProperty<>(combinedListWidget);
}
Also used : MappedList(org.phoenicis.javafx.collections.MappedList) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ContainerInformation(org.phoenicis.javafx.components.container.panelstates.ContainerInformation) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) None(org.phoenicis.javafx.components.common.panelstates.None)

Aggregations

ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)21 File (java.io.File)12 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 ContainerCategoryDTO (org.phoenicis.containers.dto.ContainerCategoryDTO)11 ArrayList (java.util.ArrayList)10 ConfigFile (org.phoenicis.tools.config.ConfigFile)10 List (java.util.List)9 Consumer (java.util.function.Consumer)8 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 IOException (java.io.IOException)7 Collectors (java.util.stream.Collectors)7 TypeReference (com.fasterxml.jackson.core.type.TypeReference)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Collections (java.util.Collections)6 Map (java.util.Map)6 ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)6 Safe (org.phoenicis.configuration.security.Safe)6 LibraryManager (org.phoenicis.library.LibraryManager)6