diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/cell/WebApiRemoteCell.java b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/cell/WebApiRemoteCell.java new file mode 100644 index 0000000000000000000000000000000000000000..b8b421e5b45bb2a36e9b6a8101fef0b624b18b5c --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/cell/WebApiRemoteCell.java @@ -0,0 +1,17 @@ +package de.tobias.playpad.plugin.api.cell; + +import de.tobias.playpad.plugin.api.settings.WebApiRemoteSettings; +import javafx.scene.control.ListCell; + +public class WebApiRemoteCell extends ListCell<WebApiRemoteSettings> { + + @Override + protected void updateItem(WebApiRemoteSettings item, boolean empty) { + super.updateItem(item, empty); + if (!empty) { + setText(item.getName()); + } else { + setText(""); + } + } +} diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/settings/WebApiRemoteSettings.java b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/settings/WebApiRemoteSettings.java index 40c5d72a58f347ea412c09cf76fc155305c6fd9b..33cdde7e4c18c795db90c56fb9ca526bd8b87b88 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/settings/WebApiRemoteSettings.java +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/settings/WebApiRemoteSettings.java @@ -5,7 +5,11 @@ import de.tobias.playpad.Displayable; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import java.util.UUID; + public class WebApiRemoteSettings implements Displayable { + @Key + private UUID id = UUID.randomUUID(); @Key private String name; @Key @@ -13,6 +17,10 @@ public class WebApiRemoteSettings implements Displayable { @Key private int port; + public UUID getId() { + return id; + } + public String getName() { return name; } diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItem.java b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItem.java index 87371e602d3959f7f8ec55281a32e40fe8d0a50a..88da46fe8b406b2fd74ac2faed131c5d9930a4fc 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItem.java +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItem.java @@ -1,17 +1,43 @@ package de.tobias.playpad.plugin.api.trigger; +import de.thecodelabs.utils.list.UniqList; import de.tobias.playpad.pad.Pad; +import de.tobias.playpad.pad.PadStatus; import de.tobias.playpad.profile.Profile; import de.tobias.playpad.project.Project; import de.tobias.playpad.tigger.TriggerItem; import de.tobias.playpad.viewcontroller.main.IMainViewController; +import org.dom4j.Element; + +import java.util.List; +import java.util.UUID; public class RemoteTriggerItem extends TriggerItem { private final String type; + private UUID serverId; + private List<UUID> uuids; + private PadStatus newStatus; + public RemoteTriggerItem(String type) { this.type = type; + + this.newStatus = PadStatus.PLAY; + this.uuids = new UniqList<>(); + } + + public List<UUID> getCarts() { + return uuids; + } + + public PadStatus getNewStatus() { + return newStatus; + } + + public void setNewStatus(PadStatus newStatus) { + if (newStatus == PadStatus.PLAY || newStatus == PadStatus.PAUSE || newStatus == PadStatus.STOP) + this.newStatus = newStatus; } @Override @@ -26,6 +52,52 @@ public class RemoteTriggerItem extends TriggerItem { @Override public TriggerItem copy() { - return null; + RemoteTriggerItem clone = new RemoteTriggerItem(getType()); + + clone.uuids = new UniqList<>(); + clone.uuids.addAll(uuids); + clone.newStatus = newStatus; + + return clone; + } + + private static final String SERVER_ELEMENT = "Server"; + private static final String CART_ELEMENT = "Cart"; + private static final String STATUS_ATTR = "Status"; + + @Override + public void load(Element element) { + super.load(element); + + if (element.attributeValue(SERVER_ELEMENT) != null) + setServerId(UUID.fromString(element.attributeValue(SERVER_ELEMENT))); + + if (element.attributeValue(STATUS_ATTR) != null) + setNewStatus(PadStatus.valueOf(element.attributeValue(STATUS_ATTR))); + + for (Element cartElement : element.elements(CART_ELEMENT)) { + uuids.add(UUID.fromString(cartElement.getStringValue())); + } + } + + @Override + public void save(Element element) { + super.save(element); + + element.addAttribute(SERVER_ELEMENT, serverId.toString()); + element.addAttribute(STATUS_ATTR, newStatus.name()); + + for (UUID cart : uuids) { + Element cartElement = element.addElement(CART_ELEMENT); + cartElement.addText(String.valueOf(cart)); + } + } + + public UUID getServerId() { + return serverId; + } + + public void setServerId(UUID serverId) { + this.serverId = serverId; } } diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemFactory.java b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemFactory.java index 1e5bb19c7588507111862ccb1f711775ac929170..18d2033f1b812edb83ee29dccd9e6332b02ece51 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemFactory.java +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemFactory.java @@ -19,6 +19,6 @@ public class RemoteTriggerItemFactory extends TriggerItemFactory { @Override public NVC getSettingsController(TriggerItem item, IMainViewController mainViewController) { - return null; + return new RemoteTriggerItemSettingsController((RemoteTriggerItem) item); } } diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemSettingsController.java b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemSettingsController.java index 235f933d5d53612da483b42b0e679312ed24b546..2fe553f0eb486c82216943a4bfce7a5d99390dea 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemSettingsController.java +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/trigger/RemoteTriggerItemSettingsController.java @@ -1,4 +1,84 @@ package de.tobias.playpad.plugin.api.trigger; -public class RemoteTriggerItemSettingsController { +import de.thecodelabs.utils.ui.NVC; +import de.thecodelabs.utils.util.Localization; +import de.tobias.playpad.pad.PadStatus; +import de.tobias.playpad.plugin.api.WebApiPlugin$; +import de.tobias.playpad.plugin.api.cell.WebApiRemoteCell; +import de.tobias.playpad.plugin.api.settings.WebApiRemoteSettings; +import de.tobias.playpad.project.api.IPad; +import de.tobias.playpad.view.main.ProjectPreviewView; +import javafx.application.Platform; +import javafx.beans.InvalidationListener; +import javafx.fxml.FXML; +import javafx.geometry.Insets; +import javafx.scene.control.ComboBox; +import javafx.scene.layout.VBox; + +import java.util.List; +import java.util.stream.Collectors; + +public class RemoteTriggerItemSettingsController extends NVC { + @FXML + private ComboBox<PadStatus> statusComboBox; + @FXML + private ComboBox<WebApiRemoteSettings> remoteComboBox; + + private ProjectPreviewView projectPreviewView; + + private final RemoteTriggerItem item; + + public RemoteTriggerItemSettingsController(RemoteTriggerItem item) { + load("plugin/webapi/view", "RemoteTrigger", Localization.getBundle()); + this.item = item; + + showProjectPreview(); + + statusComboBox.setValue(item.getNewStatus()); + remoteComboBox.setValue(WebApiPlugin$.MODULE$.connections().keySet().stream() + .filter(server -> server.getId().equals(item.getServerId())) + .findFirst() + .orElse(null) + ); + } + + private void showProjectPreview() { + WebApiPlugin$.MODULE$.getConnection(item.getServerId()).ifPresent(client -> { + client.getCurrentProject(project -> { + Platform.runLater(() -> { + // Remove old node from tree + if (projectPreviewView != null) { + ((VBox) getParent()).getChildren().remove(projectPreviewView); + projectPreviewView = null; + } + + final List<? extends IPad> pads = item.getCarts().stream().map(project::getPad).collect(Collectors.toList()); + projectPreviewView = new ProjectPreviewView(project, pads, 0); + projectPreviewView.setPadding(new Insets(0, 0, 0, 164)); + projectPreviewView.selectedProperty().addListener((InvalidationListener) observable -> { + item.getCarts().clear(); + for (IPad pad : projectPreviewView.getSelected()) { + item.getCarts().add(pad.getUuid()); + } + }); + VBox vBox = (VBox) getParent(); + vBox.getChildren().add(projectPreviewView); + }); + }); + }); + } + + @Override + public void init() { + statusComboBox.getItems().setAll(PadStatus.PLAY, PadStatus.PAUSE, PadStatus.STOP); + statusComboBox.valueProperty().addListener((a, b, c) -> item.setNewStatus(c)); + + remoteComboBox.getItems().setAll(WebApiPlugin$.MODULE$.connections().keySet()); + remoteComboBox.setCellFactory(list -> new WebApiRemoteCell()); + remoteComboBox.setButtonCell(new WebApiRemoteCell()); + remoteComboBox.valueProperty().addListener((observable, oldValue, newValue) -> { + item.setServerId(newValue.getId()); + showProjectPreview(); + }); + } } diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/lang/base_de.properties b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/lang/base_de.properties index 74bfbb3a632d77f93e46304ae28a2b2915e4ba38..9c3306049746f4201ed5c1789322928626a7f34e 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/lang/base_de.properties +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/lang/base_de.properties @@ -12,4 +12,8 @@ webapi-settings.remote.port=Port webapi-settings.remote.add=Hinzuf\u00FCgen webapi-settings.remote.remove=L\u00F6schen -Trigger.RemoteCart.Name=Remote Kachel \ No newline at end of file +Trigger.RemoteCart.Name=Remote Kachel + +remotetrigger.label.action=Aktion f\u00FCr Kacheln: +remotetrigger.label.server=PlayWall Instanz +remotetrigger.label.carts=Kacheln: \ No newline at end of file diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/view/RemoteTrigger.fxml b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/view/RemoteTrigger.fxml new file mode 100644 index 0000000000000000000000000000000000000000..967b16dce38d431d497ed3115db7e6f12b4e2d53 --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin/webapi/view/RemoteTrigger.fxml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.control.ComboBox?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.VBox?> +<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0" + xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> + <children> + <HBox spacing="14.0"> + <children> + <Label alignment="BASELINE_RIGHT" maxHeight="1.7976931348623157E308" prefWidth="150.0" + text="%remotetrigger.label.action"/> + <ComboBox fx:id="statusComboBox" prefWidth="150.0"/> + </children> + </HBox> + <HBox spacing="14.0"> + <children> + <Label alignment="BASELINE_RIGHT" maxHeight="1.7976931348623157E308" prefWidth="150.0" + text="%remotetrigger.label.server"/> + <ComboBox fx:id="remoteComboBox" prefWidth="150.0"/> + </children> + </HBox> + </children> +</VBox> diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala index d932311848a8520f29df01aa8738a6bbc2d4196a..e0fb64962a4a9e8b095c51a38a4a2ca51684fde3 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala @@ -18,6 +18,7 @@ import spark.{Request, Response, Spark} import java.nio.file.{Files, Path} import java.util +import java.util.{Optional, UUID} class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { @@ -80,4 +81,8 @@ object WebApiPlugin { def getWebApiSettingsPath: Path = ApplicationUtils.getApplication.getPath(PathType.CONFIGURATION, "webapi.json") var connections: util.Map[WebApiRemoteSettings, PlayPadClient] = new util.HashMap() + + def getConnection(id: UUID): Optional[PlayPadClient] = { + connections.entrySet().stream().filter(entry => entry.getKey.getId == id).findFirst().map(_.getValue) + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 227a5f29d9d20c0678c8f9a3170d7c789d248f70..fa22179ea3da43f353c646bfdb29a7a8cf16cb88 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ <jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version> <spark-core.version>[2.9.3,)</spark-core.version> - <PlayWallWebApiClient.version>1.0.3</PlayWallWebApiClient.version> + <PlayWallWebApiClient.version>1.2.0</PlayWallWebApiClient.version> <jna.version>5.6.0</jna.version>