Skip to content
Snippets Groups Projects
Commit d62de107 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

#174 - Add settings view for RemoteTriggerItem

parent c1ef2532
No related branches found
No related tags found
No related merge requests found
Showing
with 216 additions and 5 deletions
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("");
}
}
}
...@@ -5,7 +5,11 @@ import de.tobias.playpad.Displayable; ...@@ -5,7 +5,11 @@ import de.tobias.playpad.Displayable;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import java.util.UUID;
public class WebApiRemoteSettings implements Displayable { public class WebApiRemoteSettings implements Displayable {
@Key
private UUID id = UUID.randomUUID();
@Key @Key
private String name; private String name;
@Key @Key
...@@ -13,6 +17,10 @@ public class WebApiRemoteSettings implements Displayable { ...@@ -13,6 +17,10 @@ public class WebApiRemoteSettings implements Displayable {
@Key @Key
private int port; private int port;
public UUID getId() {
return id;
}
public String getName() { public String getName() {
return name; return name;
} }
......
package de.tobias.playpad.plugin.api.trigger; package de.tobias.playpad.plugin.api.trigger;
import de.thecodelabs.utils.list.UniqList;
import de.tobias.playpad.pad.Pad; import de.tobias.playpad.pad.Pad;
import de.tobias.playpad.pad.PadStatus;
import de.tobias.playpad.profile.Profile; import de.tobias.playpad.profile.Profile;
import de.tobias.playpad.project.Project; import de.tobias.playpad.project.Project;
import de.tobias.playpad.tigger.TriggerItem; import de.tobias.playpad.tigger.TriggerItem;
import de.tobias.playpad.viewcontroller.main.IMainViewController; import de.tobias.playpad.viewcontroller.main.IMainViewController;
import org.dom4j.Element;
import java.util.List;
import java.util.UUID;
public class RemoteTriggerItem extends TriggerItem { public class RemoteTriggerItem extends TriggerItem {
private final String type; private final String type;
private UUID serverId;
private List<UUID> uuids;
private PadStatus newStatus;
public RemoteTriggerItem(String type) { public RemoteTriggerItem(String type) {
this.type = 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 @Override
...@@ -26,6 +52,52 @@ public class RemoteTriggerItem extends TriggerItem { ...@@ -26,6 +52,52 @@ public class RemoteTriggerItem extends TriggerItem {
@Override @Override
public TriggerItem copy() { 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;
} }
} }
...@@ -19,6 +19,6 @@ public class RemoteTriggerItemFactory extends TriggerItemFactory { ...@@ -19,6 +19,6 @@ public class RemoteTriggerItemFactory extends TriggerItemFactory {
@Override @Override
public NVC getSettingsController(TriggerItem item, IMainViewController mainViewController) { public NVC getSettingsController(TriggerItem item, IMainViewController mainViewController) {
return null; return new RemoteTriggerItemSettingsController((RemoteTriggerItem) item);
} }
} }
package de.tobias.playpad.plugin.api.trigger; 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();
});
}
} }
...@@ -13,3 +13,7 @@ webapi-settings.remote.add=Hinzuf\u00FCgen ...@@ -13,3 +13,7 @@ webapi-settings.remote.add=Hinzuf\u00FCgen
webapi-settings.remote.remove=L\u00F6schen webapi-settings.remote.remove=L\u00F6schen
Trigger.RemoteCart.Name=Remote Kachel 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
<?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>
...@@ -18,6 +18,7 @@ import spark.{Request, Response, Spark} ...@@ -18,6 +18,7 @@ import spark.{Request, Response, Spark}
import java.nio.file.{Files, Path} import java.nio.file.{Files, Path}
import java.util import java.util
import java.util.{Optional, UUID}
class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { class WebApiPlugin extends PlayPadPluginStub with PluginArtifact {
...@@ -80,4 +81,8 @@ object WebApiPlugin { ...@@ -80,4 +81,8 @@ object WebApiPlugin {
def getWebApiSettingsPath: Path = ApplicationUtils.getApplication.getPath(PathType.CONFIGURATION, "webapi.json") def getWebApiSettingsPath: Path = ApplicationUtils.getApplication.getPath(PathType.CONFIGURATION, "webapi.json")
var connections: util.Map[WebApiRemoteSettings, PlayPadClient] = new util.HashMap() 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
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version> <jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version>
<spark-core.version>[2.9.3,)</spark-core.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> <jna.version>5.6.0</jna.version>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment