Skip to content

Commit 5180531

Browse files
committed
Added port preference for OMERO server instance
1 parent e5cde2e commit 5180531

File tree

8 files changed

+276
-77
lines changed

8 files changed

+276
-77
lines changed

src/main/java/qupath/ext/omero/core/ClientsPreferencesManager.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public class ClientsPreferencesManager {
4747
"omero_ext.ice_address",
4848
""
4949
);
50+
private static final StringProperty icePortPreference = PathPrefs.createPersistentPreference(
51+
"omero_ext.ice_port",
52+
""
53+
);
5054
private static final ObservableList<URI> uris;
5155
private static final ObservableList<URI> urisImmutable;
5256

@@ -81,6 +85,7 @@ public static void clearAllPreferences() {
8185
msPixelBufferPortPreference.set("");
8286
webJpegQualityPreference.set("");
8387
iceAddressPreference.set("");
88+
icePortPreference.set("");
8489
}
8590

8691
/**
@@ -228,6 +233,33 @@ public static void setIceAddress(URI serverURI, String iceAddress) {
228233
setProperty(iceAddressPreference, serverURI, iceAddress);
229234
}
230235

236+
/**
237+
* Get the saved port of the OMERO (Ice) server corresponding to the provided URI of web server.
238+
*
239+
* @param serverURI the URI of the OMERO web server to whose OMERO (Ice) server port should be retrieved
240+
* @return the OMERO (Ice) server port, or an empty optional if not found
241+
*/
242+
public static Optional<Integer> getIcePort(URI serverURI) {
243+
return getProperty(icePortPreference, serverURI).map(property -> {
244+
try {
245+
return Integer.parseInt(property);
246+
} catch (NumberFormatException e) {
247+
logger.warn(String.format("Could not convert saved ice port %s to an integer", property), e);
248+
return null;
249+
}
250+
});
251+
}
252+
253+
/**
254+
* Set the saved OMERO (Ice) server port corresponding to the provided URI of web server.
255+
*
256+
* @param serverURI the URI of the OMERO web server to whose OMERO (Ice) server port should be set
257+
* @param icePort the OMERO (Ice) server port
258+
*/
259+
public static void setIcePort(URI serverURI, int icePort) {
260+
setProperty(icePortPreference, serverURI, String.valueOf(icePort));
261+
}
262+
231263
private static synchronized void setServerListPreference() {
232264
Gson gson = new Gson();
233265
ClientsPreferencesManager.serverListPreference.set(gson.toJson(uris));

src/main/java/qupath/ext/omero/core/pixelapis/ice/IceAPI.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public class IceAPI implements PixelAPI {
2727
private static final Logger logger = LoggerFactory.getLogger(IceAPI.class);
2828
static final String NAME = "Ice";
2929
private static final String ADDRESS_PARAMETER = "--serverAddress";
30+
private static final String PORT_PARAMETER = "--serverPort";
3031
private static boolean gatewayAvailable;
3132
private final ApisHandler apisHandler;
3233
private final boolean isAuthenticated;
3334
private final String sessionUuid;
3435
private final StringProperty serverAddress;
36+
private final IntegerProperty serverPort;
3537

3638
static {
3739
try {
@@ -60,6 +62,9 @@ public IceAPI(ApisHandler apisHandler, boolean isAuthenticated, @Nullable String
6062
this.serverAddress = new SimpleStringProperty(
6163
ClientsPreferencesManager.getIceAddress(apisHandler.getWebServerURI()).orElse("")
6264
);
65+
this.serverPort = new SimpleIntegerProperty(
66+
ClientsPreferencesManager.getIcePort(apisHandler.getWebServerURI()).orElse(0)
67+
);
6368
}
6469

6570
@Override
@@ -69,7 +74,10 @@ public String getName() {
6974

7075
@Override
7176
public String[] getArgs() {
72-
return new String[] {ADDRESS_PARAMETER, serverAddress.get()};
77+
return new String[] {
78+
ADDRESS_PARAMETER, serverAddress.get(),
79+
PORT_PARAMETER, String.valueOf(serverPort.get())
80+
};
7381
}
7482

7583
@Override
@@ -78,6 +86,13 @@ public void setParametersFromArgs(String... args) {
7886
if (args[i].equals(ADDRESS_PARAMETER)) {
7987
setServerAddress(args[i+1]);
8088
}
89+
if (args[i].equals(PORT_PARAMETER)) {
90+
try {
91+
setServerPort(Integer.parseInt(args[i + 1]));
92+
} catch (NumberFormatException e) {
93+
logger.warn(String.format("Can't convert %s to integer", args[i+1]), e);
94+
}
95+
}
8196
}
8297
}
8398

@@ -128,7 +143,7 @@ public PixelAPIReader createReader(long id, ImageServerMetadata metadata) throws
128143
sessionUuid,
129144
sessionUuid,
130145
serverAddress.get(),
131-
apisHandler.getServerPort() //TODO: change
146+
serverPort.get()
132147
)
133148
),
134149
id,
@@ -176,4 +191,26 @@ public void setServerAddress(String serverAddress) {
176191
serverAddress
177192
);
178193
}
194+
195+
/**
196+
* @return the port used to communicate with the OMERO server.
197+
* This property may be updated from any thread
198+
*/
199+
public ReadOnlyIntegerProperty getServerPort() {
200+
return serverPort;
201+
}
202+
203+
/**
204+
* Set the port used to communicate with the OMERO server.
205+
*
206+
* @param serverPort the port of the OMERO server
207+
*/
208+
public void setServerPort(int serverPort) {
209+
this.serverPort.set(serverPort);
210+
211+
ClientsPreferencesManager.setIcePort(
212+
apisHandler.getWebServerURI(),
213+
serverPort
214+
);
215+
}
179216
}

src/main/java/qupath/ext/omero/gui/browser/serverbrowser/settings/Settings.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.IOException;
1919
import java.util.ResourceBundle;
20+
import java.util.function.UnaryOperator;
2021
import java.util.regex.Pattern;
2122

2223
/**
@@ -35,6 +36,8 @@ public class Settings extends Stage {
3536
private TextField webJpegQuality;
3637
@FXML
3738
private TextField omeroAddress;
39+
@FXML
40+
private TextField omeroPort;
3841

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

75-
TextFormatter<String> integerFormatter = new TextFormatter<>(change ->
76-
Pattern.matches("^\\d*$", change.getControlNewText()) ? change : null
77-
);
78-
msPixelBufferAPIPort.setTextFormatter(integerFormatter);
78+
UnaryOperator<TextFormatter.Change> integerFilter = change ->
79+
Pattern.matches("^\\d*$", change.getControlNewText()) ? change : null;
80+
msPixelBufferAPIPort.setTextFormatter(new TextFormatter<>(integerFilter));
81+
omeroPort.setTextFormatter(new TextFormatter<>(integerFilter));
7982

80-
TextFormatter<String> floatFormatter = new TextFormatter<>(change ->
81-
Pattern.matches("^\\d*\\.?\\d*$", change.getControlNewText()) ? change : null
82-
);
83-
webJpegQuality.setTextFormatter(floatFormatter);
83+
UnaryOperator<TextFormatter.Change> floatFilter = change ->
84+
Pattern.matches("^\\d*\\.?\\d*$", change.getControlNewText()) ? change : null;
85+
webJpegQuality.setTextFormatter(new TextFormatter<>(floatFilter));
8486

8587
msPixelBufferAPIPort.setText(String.valueOf(msPixelBufferAPI.getPort().get()));
8688
webJpegQuality.setText(String.valueOf(webAPI.getJpegQuality().get()));
8789
omeroAddress.setText(iceAPI.getServerAddress().get());
90+
omeroPort.setText(String.valueOf(iceAPI.getServerPort().get()));
8891

8992
initOwner(ownerWindow);
9093
show();
@@ -100,18 +103,23 @@ private void setUpListeners() {
100103
iceAPI.getServerAddress().addListener((p, o, n) -> Platform.runLater(() ->
101104
omeroAddress.setText(n)
102105
));
106+
iceAPI.getServerPort().addListener((p, o, n) -> Platform.runLater(() ->
107+
omeroPort.setText(String.valueOf(n))
108+
));
103109
}
104110

105111
private boolean save() {
106112
try {
107113
msPixelBufferAPI.setPort(Integer.parseInt(msPixelBufferAPIPort.getText()), false);
108114
webAPI.setJpegQuality(Float.parseFloat(webJpegQuality.getText()));
109115
iceAPI.setServerAddress(omeroAddress.getText());
116+
iceAPI.setServerPort(Integer.parseInt(omeroPort.getText()));
110117

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

116124
Dialogs.showInfoNotification(
117125
resources.getString("Browser.ServerBrowser.Settings.saved"),

src/main/resources/qupath/ext/omero/gui/browser/serverbrowser/settings/settings.fxml

Lines changed: 112 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,122 @@
1010
<?import javafx.scene.layout.GridPane?>
1111
<?import javafx.scene.layout.HBox?>
1212
<?import javafx.scene.layout.RowConstraints?>
13+
<?import javafx.scene.layout.VBox?>
1314
<?import javafx.stage.Stage?>
1415

1516
<fx:root title="%Browser.ServerBrowser.Settings.title" type="Stage" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
1617
<scene>
17-
<Scene>
18-
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
19-
<columnConstraints>
20-
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
21-
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
22-
</columnConstraints>
23-
<rowConstraints>
24-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
25-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
26-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
27-
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
28-
</rowConstraints>
29-
<padding>
30-
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
31-
</padding>
32-
<Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.mxPixelBufferAPIPort">
33-
<tooltip>
34-
<Tooltip text="%Browser.ServerBrowser.Settings.mxPixelBufferAPIPortDescription" />
35-
</tooltip>
36-
</Label>
37-
<TextField fx:id="msPixelBufferAPIPort" GridPane.columnIndex="1">
38-
<tooltip>
39-
<Tooltip text="%Browser.ServerBrowser.Settings.mxPixelBufferAPIPortDescription" />
40-
</tooltip>
41-
</TextField>
42-
<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">
43-
<tooltip>
44-
<Tooltip text="%Browser.ServerBrowser.Settings.webJpegQualityDescription" />
45-
</tooltip>
46-
</Label>
47-
<TextField fx:id="webJpegQuality" layoutX="564.0" layoutY="27.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
48-
<tooltip>
49-
<Tooltip text="%Browser.ServerBrowser.Settings.webJpegQualityDescription" />
50-
</tooltip>
51-
</TextField>
52-
<Label text="%Browser.ServerBrowser.Settings.omeroServerAddress" GridPane.rowIndex="2">
53-
<tooltip>
54-
<Tooltip text="%Browser.ServerBrowser.Settings.omeroServerAddressDescription" />
55-
</tooltip>
56-
</Label>
57-
<TextField fx:id="omeroAddress" GridPane.columnIndex="1" GridPane.rowIndex="2">
58-
<tooltip>
59-
<Tooltip text="%Browser.ServerBrowser.Settings.omeroServerAddressDescription" />
60-
</tooltip>
61-
</TextField>
62-
<HBox alignment="CENTER_RIGHT" spacing="10.0" GridPane.columnSpan="2147483647" GridPane.rowIndex="3">
63-
<Button mnemonicParsing="false" onAction="#onOKClicked" text="%Browser.ServerBrowser.Settings.ok" />
64-
<Button mnemonicParsing="false" onAction="#onCancelClicked" text="%Browser.ServerBrowser.Settings.cancel" />
65-
<Button mnemonicParsing="false" onAction="#onApplyClicked" text="%Browser.ServerBrowser.Settings.apply" />
66-
</HBox>
67-
</GridPane>
18+
<Scene stylesheets="@../../../../styles.css">
19+
<VBox>
20+
<VBox>
21+
<children>
22+
<Label styleClass="title" text="%Browser.ServerBrowser.Settings.webAPI" />
23+
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
24+
<columnConstraints>
25+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
26+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
27+
</columnConstraints>
28+
<rowConstraints>
29+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
30+
</rowConstraints>
31+
<padding>
32+
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
33+
</padding>
34+
<children>
35+
<Label layoutX="25.0" layoutY="25.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.webAPIJpegQuality">
36+
<tooltip>
37+
<Tooltip text="%Browser.ServerBrowser.Settings.webAPIJpegQualityDescription" />
38+
</tooltip>
39+
</Label>
40+
<TextField fx:id="webJpegQuality" layoutX="564.0" layoutY="27.0" GridPane.columnIndex="1">
41+
<tooltip>
42+
<Tooltip text="%Browser.ServerBrowser.Settings.webAPIJpegQualityDescription" />
43+
</tooltip>
44+
</TextField>
45+
</children>
46+
</GridPane>
47+
</children>
48+
</VBox>
49+
<VBox>
50+
<children>
51+
<Label styleClass="title" text="%Browser.ServerBrowser.Settings.iceAPI" />
52+
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
53+
<columnConstraints>
54+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
55+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
56+
</columnConstraints>
57+
<rowConstraints>
58+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
59+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
60+
</rowConstraints>
61+
<padding>
62+
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
63+
</padding>
64+
<children>
65+
<Label text="%Browser.ServerBrowser.Settings.iceAPIServerAddress">
66+
<tooltip>
67+
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerAddressDescription" />
68+
</tooltip>
69+
</Label>
70+
<TextField fx:id="omeroAddress" GridPane.columnIndex="1">
71+
<tooltip>
72+
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerAddressDescription" />
73+
</tooltip>
74+
</TextField>
75+
<Label text="%Browser.ServerBrowser.Settings.iceAPIServerPort" GridPane.rowIndex="1">
76+
<tooltip>
77+
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerPortDescription" />
78+
</tooltip>
79+
</Label>
80+
<TextField fx:id="omeroPort" GridPane.columnIndex="1" GridPane.rowIndex="1">
81+
<tooltip>
82+
<Tooltip text="%Browser.ServerBrowser.Settings.iceAPIServerPortDescription" />
83+
</tooltip>
84+
</TextField>
85+
</children>
86+
</GridPane>
87+
</children>
88+
</VBox>
89+
<VBox>
90+
<children>
91+
<Label styleClass="title" text="%Browser.ServerBrowser.Settings.msPixelBufferAPI" />
92+
<GridPane hgap="5.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" vgap="10.0">
93+
<columnConstraints>
94+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
95+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
96+
</columnConstraints>
97+
<rowConstraints>
98+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
99+
</rowConstraints>
100+
<padding>
101+
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
102+
</padding>
103+
<children>
104+
<Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" text="%Browser.ServerBrowser.Settings.msPixelBufferAPIPort">
105+
<tooltip>
106+
<Tooltip text="%Browser.ServerBrowser.Settings.msPixelBufferAPIPortDescription" />
107+
</tooltip>
108+
</Label>
109+
<TextField fx:id="msPixelBufferAPIPort" GridPane.columnIndex="1">
110+
<tooltip>
111+
<Tooltip text="%Browser.ServerBrowser.Settings.msPixelBufferAPIPortDescription" />
112+
</tooltip>
113+
</TextField>
114+
</children>
115+
</GridPane>
116+
</children>
117+
</VBox>
118+
<HBox alignment="CENTER_RIGHT" spacing="10.0">
119+
<children>
120+
<Button mnemonicParsing="false" onAction="#onOKClicked" text="%Browser.ServerBrowser.Settings.ok" />
121+
<Button mnemonicParsing="false" onAction="#onCancelClicked" text="%Browser.ServerBrowser.Settings.cancel" />
122+
<Button mnemonicParsing="false" onAction="#onApplyClicked" text="%Browser.ServerBrowser.Settings.apply" />
123+
</children>
124+
</HBox>
125+
<padding>
126+
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
127+
</padding>
128+
</VBox>
68129
</Scene>
69130
</scene>
70131
</fx:root>

0 commit comments

Comments
 (0)