Skip to content

Commit

Permalink
Added port preference for OMERO server instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylern committed Feb 20, 2024
1 parent e5cde2e commit 5180531
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 77 deletions.
32 changes: 32 additions & 0 deletions src/main/java/qupath/ext/omero/core/ClientsPreferencesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class ClientsPreferencesManager {
"omero_ext.ice_address",
""
);
private static final StringProperty icePortPreference = PathPrefs.createPersistentPreference(
"omero_ext.ice_port",
""
);
private static final ObservableList<URI> uris;
private static final ObservableList<URI> urisImmutable;

Expand Down Expand Up @@ -81,6 +85,7 @@ public static void clearAllPreferences() {
msPixelBufferPortPreference.set("");
webJpegQualityPreference.set("");
iceAddressPreference.set("");
icePortPreference.set("");
}

/**
Expand Down Expand Up @@ -228,6 +233,33 @@ public static void setIceAddress(URI serverURI, String iceAddress) {
setProperty(iceAddressPreference, serverURI, iceAddress);
}

/**
* Get the saved port of the OMERO (Ice) server corresponding to the provided URI of web server.
*
* @param serverURI the URI of the OMERO web server to whose OMERO (Ice) server port should be retrieved
* @return the OMERO (Ice) server port, or an empty optional if not found
*/
public static Optional<Integer> getIcePort(URI serverURI) {
return getProperty(icePortPreference, serverURI).map(property -> {
try {
return Integer.parseInt(property);
} catch (NumberFormatException e) {
logger.warn(String.format("Could not convert saved ice port %s to an integer", property), e);
return null;
}
});
}

/**
* Set the saved OMERO (Ice) server port corresponding to the provided URI of web server.
*
* @param serverURI the URI of the OMERO web server to whose OMERO (Ice) server port should be set
* @param icePort the OMERO (Ice) server port
*/
public static void setIcePort(URI serverURI, int icePort) {
setProperty(icePortPreference, serverURI, String.valueOf(icePort));
}

private static synchronized void setServerListPreference() {
Gson gson = new Gson();
ClientsPreferencesManager.serverListPreference.set(gson.toJson(uris));
Expand Down
41 changes: 39 additions & 2 deletions src/main/java/qupath/ext/omero/core/pixelapis/ice/IceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public class IceAPI implements PixelAPI {
private static final Logger logger = LoggerFactory.getLogger(IceAPI.class);
static final String NAME = "Ice";
private static final String ADDRESS_PARAMETER = "--serverAddress";
private static final String PORT_PARAMETER = "--serverPort";
private static boolean gatewayAvailable;
private final ApisHandler apisHandler;
private final boolean isAuthenticated;
private final String sessionUuid;
private final StringProperty serverAddress;
private final IntegerProperty serverPort;

static {
try {
Expand Down Expand Up @@ -60,6 +62,9 @@ public IceAPI(ApisHandler apisHandler, boolean isAuthenticated, @Nullable String
this.serverAddress = new SimpleStringProperty(
ClientsPreferencesManager.getIceAddress(apisHandler.getWebServerURI()).orElse("")
);
this.serverPort = new SimpleIntegerProperty(
ClientsPreferencesManager.getIcePort(apisHandler.getWebServerURI()).orElse(0)
);
}

@Override
Expand All @@ -69,7 +74,10 @@ public String getName() {

@Override
public String[] getArgs() {
return new String[] {ADDRESS_PARAMETER, serverAddress.get()};
return new String[] {
ADDRESS_PARAMETER, serverAddress.get(),
PORT_PARAMETER, String.valueOf(serverPort.get())
};
}

@Override
Expand All @@ -78,6 +86,13 @@ public void setParametersFromArgs(String... args) {
if (args[i].equals(ADDRESS_PARAMETER)) {
setServerAddress(args[i+1]);
}
if (args[i].equals(PORT_PARAMETER)) {
try {
setServerPort(Integer.parseInt(args[i + 1]));
} catch (NumberFormatException e) {
logger.warn(String.format("Can't convert %s to integer", args[i+1]), e);
}
}
}
}

Expand Down Expand Up @@ -128,7 +143,7 @@ public PixelAPIReader createReader(long id, ImageServerMetadata metadata) throws
sessionUuid,
sessionUuid,
serverAddress.get(),
apisHandler.getServerPort() //TODO: change
serverPort.get()
)
),
id,
Expand Down Expand Up @@ -176,4 +191,26 @@ public void setServerAddress(String serverAddress) {
serverAddress
);
}

/**
* @return the port used to communicate with the OMERO server.
* This property may be updated from any thread
*/
public ReadOnlyIntegerProperty getServerPort() {
return serverPort;
}

/**
* Set the port used to communicate with the OMERO server.
*
* @param serverPort the port of the OMERO server
*/
public void setServerPort(int serverPort) {
this.serverPort.set(serverPort);

ClientsPreferencesManager.setIcePort(
apisHandler.getWebServerURI(),
serverPort
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.util.ResourceBundle;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;

/**
Expand All @@ -35,6 +36,8 @@ public class Settings extends Stage {
private TextField webJpegQuality;
@FXML
private TextField omeroAddress;
@FXML
private TextField omeroPort;

/**
* Creates the settings window.
Expand Down Expand Up @@ -72,19 +75,19 @@ private void onApplyClicked(ActionEvent ignoredEvent) {
private void initUI(Stage ownerWindow) throws IOException {
UiUtilities.loadFXML(this, Settings.class.getResource("settings.fxml"));

TextFormatter<String> integerFormatter = new TextFormatter<>(change ->
Pattern.matches("^\\d*$", change.getControlNewText()) ? change : null
);
msPixelBufferAPIPort.setTextFormatter(integerFormatter);
UnaryOperator<TextFormatter.Change> integerFilter = change ->
Pattern.matches("^\\d*$", change.getControlNewText()) ? change : null;
msPixelBufferAPIPort.setTextFormatter(new TextFormatter<>(integerFilter));
omeroPort.setTextFormatter(new TextFormatter<>(integerFilter));

TextFormatter<String> floatFormatter = new TextFormatter<>(change ->
Pattern.matches("^\\d*\\.?\\d*$", change.getControlNewText()) ? change : null
);
webJpegQuality.setTextFormatter(floatFormatter);
UnaryOperator<TextFormatter.Change> floatFilter = change ->
Pattern.matches("^\\d*\\.?\\d*$", change.getControlNewText()) ? change : null;
webJpegQuality.setTextFormatter(new TextFormatter<>(floatFilter));

msPixelBufferAPIPort.setText(String.valueOf(msPixelBufferAPI.getPort().get()));
webJpegQuality.setText(String.valueOf(webAPI.getJpegQuality().get()));
omeroAddress.setText(iceAPI.getServerAddress().get());
omeroPort.setText(String.valueOf(iceAPI.getServerPort().get()));

initOwner(ownerWindow);
show();
Expand All @@ -100,18 +103,23 @@ private void setUpListeners() {
iceAPI.getServerAddress().addListener((p, o, n) -> Platform.runLater(() ->
omeroAddress.setText(n)
));
iceAPI.getServerPort().addListener((p, o, n) -> Platform.runLater(() ->
omeroPort.setText(String.valueOf(n))
));
}

private boolean save() {
try {
msPixelBufferAPI.setPort(Integer.parseInt(msPixelBufferAPIPort.getText()), false);
webAPI.setJpegQuality(Float.parseFloat(webJpegQuality.getText()));
iceAPI.setServerAddress(omeroAddress.getText());
iceAPI.setServerPort(Integer.parseInt(omeroPort.getText()));

// Reset the texts, as the user input may have had incorrect values and been ignored
msPixelBufferAPIPort.setText(String.valueOf(msPixelBufferAPI.getPort().get()));
webJpegQuality.setText(String.valueOf(webAPI.getJpegQuality().get()));
omeroAddress.setText(iceAPI.getServerAddress().get());
omeroPort.setText(String.valueOf(iceAPI.getServerPort().get()));

Dialogs.showInfoNotification(
resources.getString("Browser.ServerBrowser.Settings.saved"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,122 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.stage.Stage?>

<fx:root title="%Browser.ServerBrowser.Settings.title" type="Stage" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<scene>
<Scene>
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
<Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.mxPixelBufferAPIPort">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.mxPixelBufferAPIPortDescription" />
</tooltip>
</Label>
<TextField fx:id="msPixelBufferAPIPort" GridPane.columnIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.mxPixelBufferAPIPortDescription" />
</tooltip>
</TextField>
<Label layoutX="25.0" layoutY="25.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.webJpegQuality" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.webJpegQualityDescription" />
</tooltip>
</Label>
<TextField fx:id="webJpegQuality" layoutX="564.0" layoutY="27.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.webJpegQualityDescription" />
</tooltip>
</TextField>
<Label text="%Browser.ServerBrowser.Settings.omeroServerAddress" GridPane.rowIndex="2">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.omeroServerAddressDescription" />
</tooltip>
</Label>
<TextField fx:id="omeroAddress" GridPane.columnIndex="1" GridPane.rowIndex="2">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.omeroServerAddressDescription" />
</tooltip>
</TextField>
<HBox alignment="CENTER_RIGHT" spacing="10.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="3">
<Button mnemonicParsing="false" onAction="#onOKClicked" text="%Browser.ServerBrowser.Settings.ok" />
<Button mnemonicParsing="false" onAction="#onCancelClicked" text="%Browser.ServerBrowser.Settings.cancel" />
<Button mnemonicParsing="false" onAction="#onApplyClicked" text="%Browser.ServerBrowser.Settings.apply" />
</HBox>
</GridPane>
<Scene stylesheets="@../../../../styles.css">
<VBox>
<VBox>
<children>
<Label styleClass="title" text="%Browser.ServerBrowser.Settings.webAPI" />
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
<children>
<Label layoutX="25.0" layoutY="25.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.webAPIJpegQuality">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.webAPIJpegQualityDescription" />
</tooltip>
</Label>
<TextField fx:id="webJpegQuality" layoutX="564.0" layoutY="27.0" GridPane.columnIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.webAPIJpegQualityDescription" />
</tooltip>
</TextField>
</children>
</GridPane>
</children>
</VBox>
<VBox>
<children>
<Label styleClass="title" text="%Browser.ServerBrowser.Settings.iceAPI" />
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
<children>
<Label text="%Browser.ServerBrowser.Settings.iceAPIServerAddress">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerAddressDescription" />
</tooltip>
</Label>
<TextField fx:id="omeroAddress" GridPane.columnIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerAddressDescription" />
</tooltip>
</TextField>
<Label text="%Browser.ServerBrowser.Settings.iceAPIServerPort" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerPortDescription" />
</tooltip>
</Label>
<TextField fx:id="omeroPort" GridPane.columnIndex="1" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerPortDescription" />
</tooltip>
</TextField>
</children>
</GridPane>
</children>
</VBox>
<VBox>
<children>
<Label styleClass="title" text="%Browser.ServerBrowser.Settings.msPixelBufferAPI" />
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
<children>
<Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.msPixelBufferAPIPort">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.msPixelBufferAPIPortDescription" />
</tooltip>
</Label>
<TextField fx:id="msPixelBufferAPIPort" GridPane.columnIndex="1">
<tooltip>
<Tooltip text="%Browser.ServerBrowser.Settings.msPixelBufferAPIPortDescription" />
</tooltip>
</TextField>
</children>
</GridPane>
</children>
</VBox>
<HBox alignment="CENTER_RIGHT" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#onOKClicked" text="%Browser.ServerBrowser.Settings.ok" />
<Button mnemonicParsing="false" onAction="#onCancelClicked" text="%Browser.ServerBrowser.Settings.cancel" />
<Button mnemonicParsing="false" onAction="#onApplyClicked" text="%Browser.ServerBrowser.Settings.apply" />
</children>
</HBox>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</Scene>
</scene>
</fx:root>
Loading

0 comments on commit 5180531

Please sign in to comment.