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")));
}
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);
}
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();
}));
}
Aggregations