use of org.phoenicis.library.dto.ShortcutCreationDTO in project POL-POM-5 by PhoenicisOrg.
the class CreateShortcutPanel method populate.
/**
* populates the panel
*/
public void populate() {
final PseudoClass errorClass = PseudoClass.getPseudoClass("error");
final VBox vBox = new VBox();
GridPane gridPane = new GridPane();
gridPane.getStyleClass().add("grid");
gridPane.getColumnConstraints().addAll(new ColumnConstraintsWithPercentage(30), new ColumnConstraintsWithPercentage(70));
// name
Label nameLabel = new Label(tr("Name:"));
nameLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(nameLabel, VPos.TOP);
gridPane.add(nameLabel, 0, 0);
TextField name = new TextField();
gridPane.add(name, 1, 0);
Tooltip nameErrorTooltip = new Tooltip(tr("Please specify a name!"));
// category
Label categoryLabel = new Label(tr("Category:"));
categoryLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(categoryLabel, VPos.TOP);
gridPane.add(categoryLabel, 0, 1);
TextField category = new TextField();
gridPane.add(category, 1, 1);
Tooltip categoryErrorTooltip = new Tooltip(tr("Please specify a category!"));
// description
Label descriptionLabel = new Label(tr("Description:"));
descriptionLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(descriptionLabel, VPos.TOP);
gridPane.add(descriptionLabel, 0, 2);
TextArea description = new TextArea();
gridPane.add(description, 1, 2);
// miniature
Label miniatureLabel = new Label(tr("Miniature:"));
miniatureLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(miniatureLabel, VPos.TOP);
gridPane.add(miniatureLabel, 0, 3);
TextField miniature = new TextField();
Button openMiniatureBrowser = new Button(tr("Choose"));
openMiniatureBrowser.setOnAction(event -> {
FileChooser chooser = new FileChooser();
chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(tr("Images"), "*.miniature, *.png"));
File newMiniature = chooser.showOpenDialog(null);
miniature.setText(newMiniature.toString());
});
HBox miniatureHbox = new HBox(miniature, openMiniatureBrowser);
HBox.setHgrow(miniature, Priority.ALWAYS);
gridPane.add(miniatureHbox, 1, 3);
Tooltip miniatureErrorTooltip = new Tooltip(tr("Please specify a valid miniature!"));
// executable
Label executableLabel = new Label(tr("Executable:"));
executableLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(executableLabel, VPos.TOP);
gridPane.add(executableLabel, 0, 4);
TextField executable = new TextField();
Button openExecutableBrowser = new Button(tr("Choose"));
openExecutableBrowser.setOnAction(event -> {
FileChooser chooser = new FileChooser();
File newMiniature = chooser.showOpenDialog(null);
executable.setText(newMiniature.toString());
});
HBox executableHbox = new HBox(executable, openExecutableBrowser);
HBox.setHgrow(executable, Priority.ALWAYS);
gridPane.add(executableHbox, 1, 4);
Tooltip executableErrorTooltip = new Tooltip(tr("Please specify a valid executable!"));
Region spacer = new Region();
spacer.getStyleClass().add("detailsButtonSpacer");
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) {
ShortcutCreationDTO newShortcut = new ShortcutCreationDTO.Builder().withName(name.getText()).withCategory(category.getText()).withDescription(description.getText()).withMiniature(miniatureUri).withExecutable(executableFile).build();
this.onCreateShortcut.accept(newShortcut);
}
});
vBox.getChildren().addAll(gridPane, spacer, createButton);
this.setCenter(vBox);
}
use of org.phoenicis.library.dto.ShortcutCreationDTO in project phoenicis 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 phoenicis by PhoenicisOrg.
the class CreateShortcutPanel method populate.
/**
* populates the panel
*/
public void populate() {
final PseudoClass errorClass = PseudoClass.getPseudoClass("error");
final VBox vBox = new VBox();
GridPane gridPane = new GridPane();
gridPane.getStyleClass().add("grid");
gridPane.getColumnConstraints().addAll(new ColumnConstraintsWithPercentage(30), new ColumnConstraintsWithPercentage(70));
// name
Label nameLabel = new Label(tr("Name:"));
nameLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(nameLabel, VPos.TOP);
gridPane.add(nameLabel, 0, 0);
TextField name = new TextField();
gridPane.add(name, 1, 0);
Tooltip nameErrorTooltip = new Tooltip(tr("Please specify a name!"));
// category
Label categoryLabel = new Label(tr("Category:"));
categoryLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(categoryLabel, VPos.TOP);
gridPane.add(categoryLabel, 0, 1);
TextField category = new TextField();
gridPane.add(category, 1, 1);
Tooltip categoryErrorTooltip = new Tooltip(tr("Please specify a category!"));
// description
Label descriptionLabel = new Label(tr("Description:"));
descriptionLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(descriptionLabel, VPos.TOP);
gridPane.add(descriptionLabel, 0, 2);
TextArea description = new TextArea();
gridPane.add(description, 1, 2);
// miniature
Label miniatureLabel = new Label(tr("Miniature:"));
miniatureLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(miniatureLabel, VPos.TOP);
gridPane.add(miniatureLabel, 0, 3);
TextField miniature = new TextField();
Button openMiniatureBrowser = new Button(tr("Choose"));
openMiniatureBrowser.setOnAction(event -> {
FileChooser chooser = new FileChooser();
chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(tr("Images"), "*.miniature, *.png"));
File newMiniature = chooser.showOpenDialog(null);
miniature.setText(newMiniature.toString());
});
HBox miniatureHbox = new HBox(miniature, openMiniatureBrowser);
HBox.setHgrow(miniature, Priority.ALWAYS);
gridPane.add(miniatureHbox, 1, 3);
Tooltip miniatureErrorTooltip = new Tooltip(tr("Please specify a valid miniature!"));
// executable
Label executableLabel = new Label(tr("Executable:"));
executableLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(executableLabel, VPos.TOP);
gridPane.add(executableLabel, 0, 4);
TextField executable = new TextField();
Button openExecutableBrowser = new Button(tr("Choose"));
openExecutableBrowser.setOnAction(event -> {
FileChooser chooser = new FileChooser();
File newMiniature = chooser.showOpenDialog(null);
executable.setText(newMiniature.toString());
});
HBox executableHbox = new HBox(executable, openExecutableBrowser);
HBox.setHgrow(executable, Priority.ALWAYS);
gridPane.add(executableHbox, 1, 4);
Tooltip executableErrorTooltip = new Tooltip(tr("Please specify a valid executable!"));
Region spacer = new Region();
spacer.getStyleClass().add("detailsButtonSpacer");
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) {
ShortcutCreationDTO newShortcut = new ShortcutCreationDTO.Builder().withName(name.getText()).withCategory(category.getText()).withDescription(description.getText()).withMiniature(miniatureUri).withExecutable(executableFile).build();
this.onCreateShortcut.accept(newShortcut);
}
});
vBox.getChildren().addAll(gridPane, spacer, createButton);
this.setCenter(vBox);
}
use of org.phoenicis.library.dto.ShortcutCreationDTO in project POL-POM-5 by PhoenicisOrg.
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();
}));
}
use of org.phoenicis.library.dto.ShortcutCreationDTO in project POL-POM-5 by PhoenicisOrg.
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);
}
Aggregations