From fc9038f0c67b0c890f1f4d73cf70e2b31e57c470 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Tue, 9 Apr 2024 14:52:37 +0200 Subject: [PATCH 01/15] CSSTUDIO-2231 Initial implementation of new flag '-select_settings'. --- .../ui/application/PhoebusApplication.java | 120 +++++++++++++++++- 1 file changed, 113 insertions(+), 7 deletions(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index e2ca5467b4..14e3183b54 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -28,6 +28,8 @@ import java.util.logging.Logger; import java.util.stream.Collectors; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.scene.control.Alert; import javafx.scene.control.Button; @@ -36,6 +38,8 @@ import javafx.scene.control.CheckBox; import javafx.scene.control.CheckMenuItem; import javafx.scene.control.Dialog; +import javafx.scene.control.ListView; +import javafx.scene.control.ListView; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuButton; @@ -44,14 +48,26 @@ import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.ToolBar; import javafx.scene.control.Tooltip; -import javafx.scene.layout.*; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyCodeCombination; +import javafx.scene.input.KeyCombination; +import javafx.scene.input.KeyEvent; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Text; +import javafx.stage.Stage; +import javafx.stage.Window; import org.phoebus.framework.jobs.JobManager; import org.phoebus.framework.jobs.JobMonitor; import org.phoebus.framework.jobs.SubJobMonitor; import org.phoebus.framework.persistence.MementoTree; import org.phoebus.framework.persistence.XMLMementoTree; +import org.phoebus.framework.preferences.PropertyPreferenceLoader; import org.phoebus.framework.spi.AppDescriptor; import org.phoebus.framework.spi.AppResourceDescriptor; import org.phoebus.framework.util.ResourceParser; @@ -85,12 +101,6 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyCodeCombination; -import javafx.scene.input.KeyCombination; -import javafx.scene.input.MouseEvent; -import javafx.stage.Stage; -import javafx.stage.Window; /** * Primary UI for a phoebus application @@ -289,14 +299,110 @@ public void start(final Stage initial_stage) throws Exception { // Show splash screen as soon as possible.. final Splash splash = Preferences.splash ? new Splash(initial_stage) : null; + Platform.setImplicitExit(false); + possiblySelectIniFile(application_parameters); + // .. then read saved state etc. in background job JobManager.schedule("Startup", monitor -> { final JobMonitor splash_monitor = new SplashJobMonitor(monitor, splash); backgroundStartup(splash_monitor, splash); + Platform.setImplicitExit(true); }); } + private void possiblySelectIniFile(CopyOnWriteArrayList application_parameters) { + if (application_parameters.contains("-select_settings")) { + int indexOfFlag = application_parameters.indexOf("-select_settings", 0); + if (indexOfFlag < 0) { + throw new RuntimeException("Error, this should never happen!"); + } + if (application_parameters.size() >= indexOfFlag) { + String iniFilesLocation_String = application_parameters.get(indexOfFlag + 1); + File iniFilesLocation_File = new File(iniFilesLocation_String); + if (iniFilesLocation_File.isDirectory()) { + List iniFilesInDirectory_List = Arrays.stream(iniFilesLocation_File.listFiles()).filter(file -> file.getAbsolutePath().endsWith(".ini")).collect(Collectors.toList()); + ObservableList iniFilesInDirectory_ObservableList = FXCollections.observableArrayList(iniFilesInDirectory_List); + + if (iniFilesInDirectory_List.size() > 0) { + Dialog iniFileSelectionDialog = new Dialog(); + iniFileSelectionDialog.setTitle("Select Phoebus configuration"); + iniFileSelectionDialog.setHeaderText("Select Phoebus configuration"); + iniFileSelectionDialog.setGraphic(null); + + iniFileSelectionDialog.setWidth(500); + iniFileSelectionDialog.setHeight(400); + iniFileSelectionDialog.setResizable(false); + + ListView listView = new ListView(iniFilesInDirectory_ObservableList); + listView.getSelectionModel().select(0); + + Runnable setReturnValueAndCloseDialog = () -> { + File selectedFile = (File) listView.getSelectionModel().getSelectedItem(); + if (selectedFile == null) { + selectedFile = (File) listView.getItems().get(0); + } + iniFileSelectionDialog.setResult(selectedFile); + iniFileSelectionDialog.close(); + }; + listView.setOnKeyPressed(keyEvent -> { + if (keyEvent.getCode() == KeyCode.ENTER) { + setReturnValueAndCloseDialog.run(); + } + }); + + iniFileSelectionDialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE); + Button closeButton = (Button) iniFileSelectionDialog.getDialogPane().lookupButton(ButtonType.CLOSE); + closeButton.setVisible(false); // In JavaFX, a button of type ButtonType.CLOSE must exist so that the "X"-button closes the window. + + Button okButton = new Button("OK"); + okButton.setOnAction(actionEvent -> setReturnValueAndCloseDialog.run()); + okButton.setPrefWidth(500); + + VBox vBox = new VBox(listView, okButton); + iniFileSelectionDialog.getDialogPane().setContent(vBox); + listView.requestFocus(); + + iniFileSelectionDialog.getDialogPane().addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> { + if (keyEvent.getCode() == KeyCode.ESCAPE) { + iniFileSelectionDialog.close(); + keyEvent.consume(); + } + }); + + iniFileSelectionDialog.setOnCloseRequest(dialogEvent -> { + Object currentResult = iniFileSelectionDialog.getResult(); + if (currentResult == null || !(currentResult instanceof File)) { + // Return null when closing the dialog by clicking the "X"-button or the ESC-key. + iniFileSelectionDialog.setResult(null); + } + }); + + Optional maybeSelectedFile = iniFileSelectionDialog.showAndWait(); + if (maybeSelectedFile.isPresent()) { + File selectedFile = maybeSelectedFile.get(); + try { + PropertyPreferenceLoader.load(new FileInputStream(selectedFile)); + } catch (Exception exception) { + logger.log(Level.SEVERE, "Error parsing Phoebus configuration '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage()); + stop(); + } + } else { + // Selecting a configuration was cancelled either by pressing the "X"-button or by pressing the ESC-key. + stop(); + } + } else { + logger.log(Level.SEVERE, "Error during evaluation of the flag '-set_settings': the directory '" + iniFilesLocation_String + "' does not contain any .ini files!"); + stop(); + } + } else { + logger.log(Level.SEVERE, "Error during evaluation of the flag '-set_settings': the argument '" + iniFilesLocation_String + "' is not a directory!"); + stop(); + } + } + } + } + /** * Perform potentially slow startup task off the UI thread * From 032278d29795d645f04dd466c9e3809a68d6a12a Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 10:25:22 +0200 Subject: [PATCH 02/15] CSSTUDIO-2231 Call possiblySelectIniFile() before preferences are initialized. --- .../java/org/phoebus/ui/application/PhoebusApplication.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 14e3183b54..90c54b8db6 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -296,12 +296,12 @@ public void start(final Stage initial_stage) throws Exception { // Save original application parameters application_parameters.addAll(getParameters().getRaw()); + Platform.setImplicitExit(false); + possiblySelectIniFile(application_parameters); // possiblySelectIniFile() be called before preferences are initialized, to ensure that the selected configuration options are applied before old configuration options are loaded. + // Show splash screen as soon as possible.. final Splash splash = Preferences.splash ? new Splash(initial_stage) : null; - Platform.setImplicitExit(false); - possiblySelectIniFile(application_parameters); - // .. then read saved state etc. in background job JobManager.schedule("Startup", monitor -> { From e3d33cfb82810a6fde8eec7d5773c2516a28cd60 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 10:30:40 +0200 Subject: [PATCH 03/15] CSSTUDIO-2231 Disallow the flag '-settings' when the flag '-select_settings' is also present. --- core/launcher/src/main/java/org/phoebus/product/Launcher.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/launcher/src/main/java/org/phoebus/product/Launcher.java b/core/launcher/src/main/java/org/phoebus/product/Launcher.java index 481c9934a7..0d2b182aa2 100644 --- a/core/launcher/src/main/java/org/phoebus/product/Launcher.java +++ b/core/launcher/src/main/java/org/phoebus/product/Launcher.java @@ -96,6 +96,9 @@ else if (cmd.equals("-logging")) } else if (cmd.equals("-settings")) { + if (args.contains("-select_settings")) { + throw new Exception("The flag '-settings' cannot be used in conjunction with the flag '-select_settings'."); + } if (! iter.hasNext()) throw new Exception("Missing -settings file name"); iter.remove(); From 9a608b51a8061de72affa010596ccc363e493d3f Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 10:39:38 +0200 Subject: [PATCH 04/15] CSSTUDIO-2231 Add support for configuration files in XML format. Improve error handling. --- .../ui/application/PhoebusApplication.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 90c54b8db6..d6a983ccfb 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -321,7 +321,7 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para String iniFilesLocation_String = application_parameters.get(indexOfFlag + 1); File iniFilesLocation_File = new File(iniFilesLocation_String); if (iniFilesLocation_File.isDirectory()) { - List iniFilesInDirectory_List = Arrays.stream(iniFilesLocation_File.listFiles()).filter(file -> file.getAbsolutePath().endsWith(".ini")).collect(Collectors.toList()); + List iniFilesInDirectory_List = Arrays.stream(iniFilesLocation_File.listFiles()).filter(file -> file.getAbsolutePath().endsWith(".ini") || file.getAbsolutePath().endsWith(".xml")).collect(Collectors.toList()); ObservableList iniFilesInDirectory_ObservableList = FXCollections.observableArrayList(iniFilesInDirectory_List); if (iniFilesInDirectory_List.size() > 0) { @@ -382,9 +382,20 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para if (maybeSelectedFile.isPresent()) { File selectedFile = maybeSelectedFile.get(); try { - PropertyPreferenceLoader.load(new FileInputStream(selectedFile)); - } catch (Exception exception) { - logger.log(Level.SEVERE, "Error parsing Phoebus configuration '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage()); + FileInputStream selectedFile_FileInputStream = new FileInputStream(selectedFile); + try { + if (selectedFile.getAbsolutePath().endsWith(".xml")) { + java.util.prefs.Preferences.importPreferences(selectedFile_FileInputStream); + } + else { + PropertyPreferenceLoader.load(selectedFile_FileInputStream); + } + } catch (Exception exception) { + logger.log(Level.SEVERE, "Error parsing Phoebus configuration '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage()); + stop(); + } + } catch (FileNotFoundException e) { + logger.log(Level.SEVERE, "Error loading Phoebus configuration '" + selectedFile.getAbsolutePath() + "': File does not exist!"); stop(); } } else { From a15c99ffe6be951faec4ca904138966c27a70972 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 10:44:53 +0200 Subject: [PATCH 05/15] CSSTUDIO-2231 Add support for selecting a configuration by double-clicking on it. --- .../java/org/phoebus/ui/application/PhoebusApplication.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index d6a983ccfb..385c31e226 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -345,6 +345,11 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para iniFileSelectionDialog.setResult(selectedFile); iniFileSelectionDialog.close(); }; + listView.setOnMouseClicked(mouseEvent -> { + if (mouseEvent.getClickCount() == 2) { + setReturnValueAndCloseDialog.run(); + } + }); listView.setOnKeyPressed(keyEvent -> { if (keyEvent.getCode() == KeyCode.ENTER) { setReturnValueAndCloseDialog.run(); From 9094fe5774571492e1a882140e9a24749414e2d5 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 11:08:50 +0200 Subject: [PATCH 06/15] CSSTUDIO-2231 Remove duplicate import statement. --- .../main/java/org/phoebus/ui/application/PhoebusApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 385c31e226..5e1bc1bab6 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -39,7 +39,6 @@ import javafx.scene.control.CheckMenuItem; import javafx.scene.control.Dialog; import javafx.scene.control.ListView; -import javafx.scene.control.ListView; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuButton; From 2d40fe31c4888cd190881e4fa964e28e206bff05 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 11:12:22 +0200 Subject: [PATCH 07/15] CSSTUDIO-2231 Add explanatory comment. --- .../java/org/phoebus/ui/application/PhoebusApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 5e1bc1bab6..824b4d3ed7 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -295,7 +295,7 @@ public void start(final Stage initial_stage) throws Exception { // Save original application parameters application_parameters.addAll(getParameters().getRaw()); - Platform.setImplicitExit(false); + Platform.setImplicitExit(false); // Avoids shutdown of Phoebus when the '-select_settings' option is used after the dialog to select configuration file has been closed. Platform.setImplicitExit(true) is called below to restore the option again. possiblySelectIniFile(application_parameters); // possiblySelectIniFile() be called before preferences are initialized, to ensure that the selected configuration options are applied before old configuration options are loaded. // Show splash screen as soon as possible.. From 5752ddae189c53df669ad04da592c25c58ea8e04 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 11:15:15 +0200 Subject: [PATCH 08/15] CSSTUDIO-2231 Fix grammar. --- .../java/org/phoebus/ui/application/PhoebusApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 824b4d3ed7..15d112eb5d 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -296,7 +296,7 @@ public void start(final Stage initial_stage) throws Exception { application_parameters.addAll(getParameters().getRaw()); Platform.setImplicitExit(false); // Avoids shutdown of Phoebus when the '-select_settings' option is used after the dialog to select configuration file has been closed. Platform.setImplicitExit(true) is called below to restore the option again. - possiblySelectIniFile(application_parameters); // possiblySelectIniFile() be called before preferences are initialized, to ensure that the selected configuration options are applied before old configuration options are loaded. + possiblySelectIniFile(application_parameters); // possiblySelectIniFile() must be called before preferences are initialized, to ensure that the selected configuration options are applied before old configuration options are loaded. // Show splash screen as soon as possible.. final Splash splash = Preferences.splash ? new Splash(initial_stage) : null; From e64f378d7c4eccc8454fa8848bb1a5342c1377a3 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 10 Apr 2024 11:16:41 +0200 Subject: [PATCH 09/15] CSSTUDIO-2231 Fix error message. --- .../java/org/phoebus/ui/application/PhoebusApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 15d112eb5d..03340eb115 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -407,7 +407,7 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para stop(); } } else { - logger.log(Level.SEVERE, "Error during evaluation of the flag '-set_settings': the directory '" + iniFilesLocation_String + "' does not contain any .ini files!"); + logger.log(Level.SEVERE, "Error during evaluation of the flag '-set_settings': the directory '" + iniFilesLocation_String + "' does not contain any .ini or .xml file(s)!"); stop(); } } else { From 2fc606b7d6813c624833c186f39ed82c24d0f6cb Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 11 Apr 2024 11:30:11 +0200 Subject: [PATCH 10/15] Revert "CSSTUDIO-2231 Disallow the flag '-settings' when the flag '-select_settings' is also present." This reverts commit e3d33cfb82810a6fde8eec7d5773c2516a28cd60. --- core/launcher/src/main/java/org/phoebus/product/Launcher.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/launcher/src/main/java/org/phoebus/product/Launcher.java b/core/launcher/src/main/java/org/phoebus/product/Launcher.java index 0d2b182aa2..481c9934a7 100644 --- a/core/launcher/src/main/java/org/phoebus/product/Launcher.java +++ b/core/launcher/src/main/java/org/phoebus/product/Launcher.java @@ -96,9 +96,6 @@ else if (cmd.equals("-logging")) } else if (cmd.equals("-settings")) { - if (args.contains("-select_settings")) { - throw new Exception("The flag '-settings' cannot be used in conjunction with the flag '-select_settings'."); - } if (! iter.hasNext()) throw new Exception("Missing -settings file name"); iter.remove(); From 921f19d671666303358bfc709d3994b01c78d0fb Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 11 Apr 2024 11:30:20 +0200 Subject: [PATCH 11/15] CSSTUDIO-2231 Display error message when an error occurs. --- .../ui/application/PhoebusApplication.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 03340eb115..af54a457b3 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -61,6 +61,7 @@ import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.stage.Window; +import javafx.util.Pair; import org.phoebus.framework.jobs.JobManager; import org.phoebus.framework.jobs.JobMonitor; import org.phoebus.framework.jobs.SubJobMonitor; @@ -311,6 +312,23 @@ public void start(final Stage initial_stage) throws Exception { } private void possiblySelectIniFile(CopyOnWriteArrayList application_parameters) { + + Consumer> displayErrorMessageAndQuit = errorTitleAndErrorMessage -> { + + String errorTitle = errorTitleAndErrorMessage.getKey(); + String errorMessage = errorTitleAndErrorMessage.getValue(); + + logger.log(Level.SEVERE, errorMessage); + + Dialog errorDialog = new Alert(AlertType.ERROR); + errorDialog.setTitle(errorTitle); + errorDialog.setHeaderText(errorTitle); + errorDialog.setContentText(errorMessage + "\n\nPhoebus will quit."); + errorDialog.showAndWait(); + + stop(); + }; + if (application_parameters.contains("-select_settings")) { int indexOfFlag = application_parameters.indexOf("-select_settings", 0); if (indexOfFlag < 0) { @@ -395,24 +413,20 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para PropertyPreferenceLoader.load(selectedFile_FileInputStream); } } catch (Exception exception) { - logger.log(Level.SEVERE, "Error parsing Phoebus configuration '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage()); - stop(); + displayErrorMessageAndQuit.accept(new Pair("Error loading Phoebus configuration", "Error loading Phoebus configuration '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage())); } } catch (FileNotFoundException e) { - logger.log(Level.SEVERE, "Error loading Phoebus configuration '" + selectedFile.getAbsolutePath() + "': File does not exist!"); - stop(); + displayErrorMessageAndQuit.accept(new Pair("Error loading Phoebus configuration", "Error loading Phoebus configuration '" + selectedFile.getAbsolutePath() + "': File does not exist!")); } } else { // Selecting a configuration was cancelled either by pressing the "X"-button or by pressing the ESC-key. stop(); } } else { - logger.log(Level.SEVERE, "Error during evaluation of the flag '-set_settings': the directory '" + iniFilesLocation_String + "' does not contain any .ini or .xml file(s)!"); - stop(); + displayErrorMessageAndQuit.accept(new Pair("Error during evaluation of the flag '-set_settings'", "Error during evaluation of the flag '-set_settings': the directory '" + iniFilesLocation_String + "' does not contain any .ini or .xml file(s)!")); } } else { - logger.log(Level.SEVERE, "Error during evaluation of the flag '-set_settings': the argument '" + iniFilesLocation_String + "' is not a directory!"); - stop(); + displayErrorMessageAndQuit.accept(new Pair("Error during evaluation of the flag '-set_settings'", "Error during evaluation of the flag '-set_settings': the argument '" + iniFilesLocation_String + "' is not a directory!")); } } } From c8e4f293c1a8acf1660f11b56051034cfc230da2 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 11 Apr 2024 11:58:12 +0200 Subject: [PATCH 12/15] CSSTUDIO-2231 Add labels to 'messages.properties'. Fix typo: '-set_settings' -> '-select_settings'. --- .../java/org/phoebus/ui/application/Messages.java | 7 +++++++ .../ui/application/PhoebusApplication.java | 15 ++++++++------- .../phoebus/ui/application/messages.properties | 7 +++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/Messages.java b/core/ui/src/main/java/org/phoebus/ui/application/Messages.java index e9a8cdb981..60c72dab8f 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/Messages.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/Messages.java @@ -40,11 +40,14 @@ public class Messages public static String DockSplitH; public static String DockSplitV; public static String Enjoy; + public static String ErrorDuringEvalutationOfTheFlagSelectSettings; + public static String ErrorLoadingPhoebusConfiguration; public static String Exit; public static String ExitContent; public static String ExitHdr; public static String ExitTitle; public static String File; + public static String FileDoesNotExist; public static String FileExists; public static String FixedTitle; public static String Help; @@ -90,6 +93,7 @@ public class Messages public static String MonitorTaskUi; public static String NamePane; public static String NamePaneHdr; + public static String OK; public static String Open; public static String OpenHdr; public static String OpenTitle; @@ -129,9 +133,12 @@ public class Messages public static String SavingHdr; public static String ScreenshotErrHdr; public static String ScreenshotErrMsg; + public static String SelectPhoebusConfiguration; public static String SelectTab; public static String ShowStatusbar; public static String ShowToolbar; + public static String TheArgumentIsNotADirectory; + public static String TheDirectoryDoesNotContainConfigurationFiles; public static String Time12h; public static String Time1d; public static String Time3d; diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index af54a457b3..3f977cb094 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.lang.ref.WeakReference; import java.net.URI; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -343,8 +344,8 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para if (iniFilesInDirectory_List.size() > 0) { Dialog iniFileSelectionDialog = new Dialog(); - iniFileSelectionDialog.setTitle("Select Phoebus configuration"); - iniFileSelectionDialog.setHeaderText("Select Phoebus configuration"); + iniFileSelectionDialog.setTitle(Messages.SelectPhoebusConfiguration); + iniFileSelectionDialog.setHeaderText(Messages.SelectPhoebusConfiguration); iniFileSelectionDialog.setGraphic(null); iniFileSelectionDialog.setWidth(500); @@ -377,7 +378,7 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para Button closeButton = (Button) iniFileSelectionDialog.getDialogPane().lookupButton(ButtonType.CLOSE); closeButton.setVisible(false); // In JavaFX, a button of type ButtonType.CLOSE must exist so that the "X"-button closes the window. - Button okButton = new Button("OK"); + Button okButton = new Button(Messages.OK); okButton.setOnAction(actionEvent -> setReturnValueAndCloseDialog.run()); okButton.setPrefWidth(500); @@ -413,20 +414,20 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para PropertyPreferenceLoader.load(selectedFile_FileInputStream); } } catch (Exception exception) { - displayErrorMessageAndQuit.accept(new Pair("Error loading Phoebus configuration", "Error loading Phoebus configuration '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage())); + displayErrorMessageAndQuit.accept(new Pair(Messages.ErrorLoadingPhoebusConfiguration, Messages.ErrorLoadingPhoebusConfiguration + " '" + selectedFile.getAbsolutePath() + "': " + exception.getMessage())); } } catch (FileNotFoundException e) { - displayErrorMessageAndQuit.accept(new Pair("Error loading Phoebus configuration", "Error loading Phoebus configuration '" + selectedFile.getAbsolutePath() + "': File does not exist!")); + displayErrorMessageAndQuit.accept(new Pair(Messages.ErrorLoadingPhoebusConfiguration, Messages.ErrorLoadingPhoebusConfiguration + " '" + selectedFile.getAbsolutePath() + "': " + Messages.FileDoesNotExist)); } } else { // Selecting a configuration was cancelled either by pressing the "X"-button or by pressing the ESC-key. stop(); } } else { - displayErrorMessageAndQuit.accept(new Pair("Error during evaluation of the flag '-set_settings'", "Error during evaluation of the flag '-set_settings': the directory '" + iniFilesLocation_String + "' does not contain any .ini or .xml file(s)!")); + displayErrorMessageAndQuit.accept(new Pair(Messages.ErrorDuringEvalutationOfTheFlagSelectSettings, Messages.ErrorDuringEvalutationOfTheFlagSelectSettings + ": " + MessageFormat.format(Messages.TheDirectoryDoesNotContainConfigurationFiles, iniFilesLocation_String))); } } else { - displayErrorMessageAndQuit.accept(new Pair("Error during evaluation of the flag '-set_settings'", "Error during evaluation of the flag '-set_settings': the argument '" + iniFilesLocation_String + "' is not a directory!")); + displayErrorMessageAndQuit.accept(new Pair(Messages.ErrorDuringEvalutationOfTheFlagSelectSettings, Messages.ErrorDuringEvalutationOfTheFlagSelectSettings + ": " + MessageFormat.format(Messages.TheArgumentIsNotADirectory, iniFilesLocation_String))); } } } diff --git a/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties b/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties index 2c9a3c4882..1c41683f3c 100644 --- a/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties +++ b/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties @@ -26,11 +26,14 @@ DockNotSaved= DockSplitH=Split Left/Right DockSplitV=Split Top/Bottom Enjoy=Enjoy CS-Studio! +ErrorDuringEvalutationOfTheFlagSelectSettings="Error during evaluation of the flag '-select_settings'" +ErrorLoadingPhoebusConfiguration=Error loading Phoebus configuration Exit=Exit ExitContent=Closing this window exits the application,\nclosing all other windows.\n ExitHdr=Close main window ExitTitle=Exit File=File +FileDoesNotExist=File does not exist! FileExists=File \"{0}\" already exists. Do you want to overwrite it? FixedTitle=CS-Studio Help=Help @@ -76,6 +79,7 @@ MonitorTaskTabs=Restore tabs MonitorTaskUi=Start UI NamePane=Name Pane NamePaneHdr=Assign a name to this pane.\nSome displays can be configured\nto appear in a named pane. +OK=OK Open=Open... OpenHdr=Select application for opening\n OpenTitle=Open @@ -115,9 +119,12 @@ SavingErr=Error saving SavingHdr=Save error ScreenshotErrHdr=Screenshot error ScreenshotErrMsg=Cannot write screenshot +SelectPhoebusConfiguration=Select Phoebus configuration SelectTab=Select Tab ShowStatusbar=Show Status bar ShowToolbar=Show Toolbar +TheArgumentIsNotADirectory="the argument '{0}' is not a directory!" +TheDirectoryDoesNotContainConfigurationFiles=the directory '{0}' does not contain any .ini or .xml file(s)! Time12h=12 h Time1d=1 day Time3d=3 days From d8c922a7c5c95a50f995d65070650b029690dc8e Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 11 Apr 2024 13:27:21 +0200 Subject: [PATCH 13/15] CSSTUDIO-2231 Fix format strings. --- .../org/phoebus/ui/application/messages.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties b/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties index 1c41683f3c..c144a5a2c3 100644 --- a/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties +++ b/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties @@ -26,7 +26,7 @@ DockNotSaved= DockSplitH=Split Left/Right DockSplitV=Split Top/Bottom Enjoy=Enjoy CS-Studio! -ErrorDuringEvalutationOfTheFlagSelectSettings="Error during evaluation of the flag '-select_settings'" +ErrorDuringEvalutationOfTheFlagSelectSettings=Error during evaluation of the flag '-select_settings' ErrorLoadingPhoebusConfiguration=Error loading Phoebus configuration Exit=Exit ExitContent=Closing this window exits the application,\nclosing all other windows.\n @@ -123,8 +123,8 @@ SelectPhoebusConfiguration=Select Phoebus configuration SelectTab=Select Tab ShowStatusbar=Show Status bar ShowToolbar=Show Toolbar -TheArgumentIsNotADirectory="the argument '{0}' is not a directory!" -TheDirectoryDoesNotContainConfigurationFiles=the directory '{0}' does not contain any .ini or .xml file(s)! +TheArgumentIsNotADirectory=the argument ''{0}'' is not a directory! +TheDirectoryDoesNotContainConfigurationFiles=the directory ''{0}'' does not contain any .ini or .xml file(s)! Time12h=12 h Time1d=1 day Time3d=3 days From bd0f1b45ac417566cb99a81fa59c558f49f25e81 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 11 Apr 2024 13:29:40 +0200 Subject: [PATCH 14/15] CSSTUDIO-2231 Add label to 'messages.properties'. --- core/ui/src/main/java/org/phoebus/ui/application/Messages.java | 1 + .../java/org/phoebus/ui/application/PhoebusApplication.java | 2 +- .../resources/org/phoebus/ui/application/messages.properties | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/Messages.java b/core/ui/src/main/java/org/phoebus/ui/application/Messages.java index 60c72dab8f..22bb252a91 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/Messages.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/Messages.java @@ -98,6 +98,7 @@ public class Messages public static String OpenHdr; public static String OpenTitle; public static String OpenWith; + public static String PhoebusWillQuit; public static String ProgressTitle; public static String PVListAppName; public static String PVListJobName; diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 3f977cb094..210ba67578 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -324,7 +324,7 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para Dialog errorDialog = new Alert(AlertType.ERROR); errorDialog.setTitle(errorTitle); errorDialog.setHeaderText(errorTitle); - errorDialog.setContentText(errorMessage + "\n\nPhoebus will quit."); + errorDialog.setContentText(errorMessage + "\n\n" + Messages.PhoebusWillQuit); errorDialog.showAndWait(); stop(); diff --git a/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties b/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties index c144a5a2c3..3f4b29c0c2 100644 --- a/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties +++ b/core/ui/src/main/resources/org/phoebus/ui/application/messages.properties @@ -84,6 +84,7 @@ Open=Open... OpenHdr=Select application for opening\n OpenTitle=Open OpenWith=Open With... +PhoebusWillQuit=Phoebus will quit. ProgressTitle=CS-Studio PVListAppName=PV List PVListJobName=List PVs From f91543526a016031d94f37a6fc2eaff819117036 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Thu, 11 Apr 2024 13:40:39 +0200 Subject: [PATCH 15/15] CSSTUDIO-2231 Fix off-by-one bug. --- .../java/org/phoebus/ui/application/PhoebusApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java index 210ba67578..cdbd71a08c 100644 --- a/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java +++ b/core/ui/src/main/java/org/phoebus/ui/application/PhoebusApplication.java @@ -335,7 +335,7 @@ private void possiblySelectIniFile(CopyOnWriteArrayList application_para if (indexOfFlag < 0) { throw new RuntimeException("Error, this should never happen!"); } - if (application_parameters.size() >= indexOfFlag) { + if (application_parameters.size() > indexOfFlag) { String iniFilesLocation_String = application_parameters.get(indexOfFlag + 1); File iniFilesLocation_File = new File(iniFilesLocation_String); if (iniFilesLocation_File.isDirectory()) {