Let's create our own PDU that will be based on DefaultPdu. It will add one String and one integer parameter.
/**
* Example PDU based on default pdu.
* <p>Contains the following metadata:</p>
* <ul>
* <li>string param,</li>
* <li>integer param.</li>
* </ul>
*/
@Getter
@Setter
public class ExamplePdu extends DefaultPdu {
private String stringParam;
private int integerParam;
public ExamplePdu(
Proxy proxy,
Connection connection,
PduDestination destination,
byte[] buffer,
int size,
String stringParam,
int integerParam) {
super(proxy, connection, destination, buffer, size);
this.stringParam = stringParam;
this.integerParam = integerParam;
}
public ExamplePdu(
Proxy proxy,
Connection connection,
PduDestination destination,
byte[] buffer,
int size,
Charset charset,
Set<String> tags,
String stringParam,
int integerParam) {
super(proxy, connection, destination, buffer, size, charset, tags);
this.stringParam = stringParam;
this.integerParam = integerParam;
}
@Override
public PDU copy() {
var pdu = new ExamplePdu(proxy, connection, destination, buffer, size, stringParam, integerParam);
pdu.setCharset(charset);
pdu.addTags(tags);
pdu.setLastInterceptor(pdu.getLastInterceptor());
return pdu;
}
}
And now, let's create metadata editor (for our string and integer values):
/**
* Example metadata pane for configuring metadata of example PDU:
* <ul>
* <li>string param,</li>
* <li>integer param.</li>
* </ul>
*/
public class ExamplePduMetadataPane extends PduMetadataPane {
@FXML
private TextField stringInput;
@FXML
private TextField integerInput;
public ExamplePduMetadataPane() throws IOException {
super("/fxml/ExamplePduMetadataPane.fxml");
}
@Override
public Optional<PDU> createPdu(
Proxy proxy,
Connection connection,
PduDestination destination,
byte[] buffer,
int size,
Charset charset,
Set<String> tags) {
return Optional.of(new ExamplePdu(
proxy,
connection,
destination,
buffer,
size,
charset,
tags,
stringInput.getText(),
Integer.parseInt(integerInput.getText())
));
}
@Override
public void setPdu(PDU pdu) {
var examplePdu = (ExamplePdu) pdu;
stringInput.setText(examplePdu.getStringParam());
integerInput.setText(String.valueOf(examplePdu.getIntegerParam()));
}
@Override
public void clear() {
stringInput.clear();
integerInput.clear();
}
@Override
public boolean isValid() {
return true;
}
}
It is up to you how you make your medatada editor look, here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>
<fx:root xmlns:fx="http://javafx.com/fxml/1" prefHeight="69.0" prefWidth="249.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/11.0.1">
<children>
<Label layoutX="7.0" layoutY="13.0" styleClass="input-label" text="String:" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="13.0"/>
<TextField fx:id="stringInput" layoutX="90.0" layoutY="2.0" text="" AnchorPane.leftAnchor="85.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"/>
<Label layoutX="10.0" layoutY="43.0" styleClass="input-label" text="Integer:" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="43.0"/>
<TextField fx:id="integerInput" layoutX="85.0" layoutY="39.0" prefHeight="25.0" prefWidth="154.0" text="1" AnchorPane.leftAnchor="85.0" AnchorPane.rightAnchor="10.0"/>
</children>
</fx:root>
We will use our Pdu and Metadata Pane in the following chapters.