Skip to content

Commit

Permalink
Merge pull request #2765 from ControlSystemStudio/CSSTUDIO-2007
Browse files Browse the repository at this point in the history
CSSTUDIO-2007 Add check for existing instances associated with chosen file path to "Save As..." functionality
  • Loading branch information
abrahamwolk authored Aug 15, 2023
2 parents 0e0125c + fa8c130 commit a6bea69
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public class Messages
public static String SaveAsPrompt;
public static String SaveDlgErrHdr;
public static String SaveDlgHdr;
public static String SaveAsFileAlreadyOpen_content;
public static String SaveAsFileAlreadyOpen_header;
public static String SaveAsFileAlreadyOpen_title;
public static String SaveLayoutAs;
public static String SaveLayoutOfContainingWindowAs;
public static String SaveLayoutWarningApplicationNoSaveFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.stream.Collectors;

import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.stage.Window;
import org.apache.commons.io.FilenameUtils;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.framework.jobs.JobMonitor;
import org.phoebus.framework.jobs.JobRunnable;
Expand Down Expand Up @@ -432,10 +431,38 @@ else if (response == ButtonType.NO)
return false;
}

// Update input
setInput(ResourceParser.getURI(actual_file.get()));
// Save in that file
return save(monitor, getTabPane().getScene().getWindow());
URI newInput = ResourceParser.getURI(actual_file.get());
DockItemWithInput existingInstanceWithInput = DockStage.getDockItemWithInput(newInput);
if (existingInstanceWithInput == null || (input != null && newInput.getPath().equals(input.getPath()))) {
// Update input
setInput(ResourceParser.getURI(actual_file.get()));
// Save in that file
return save(monitor, getTabPane().getScene().getWindow());
}
else {
CompletableFuture<Boolean> waitForDialogToClose = new CompletableFuture<>();
Platform.runLater(() -> {
String filename = FilenameUtils.getName(newInput.getPath());

final Alert dialog = new Alert(AlertType.INFORMATION);
dialog.setTitle(Messages.SaveAsFileAlreadyOpen_title);
String headerText = MessageFormat.format(Messages.SaveAsFileAlreadyOpen_header, filename);
dialog.setHeaderText(headerText);
String contentText = MessageFormat.format(Messages.SaveAsFileAlreadyOpen_content, existingInstanceWithInput.getApplication().getAppDescriptor().getDisplayName(), filename);
dialog.setContentText(contentText);
int width = 550;
int height = 200;
dialog.getDialogPane().setPrefSize(width, height);
dialog.getDialogPane().setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
dialog.setResizable(false);
DialogHelper.positionDialog(dialog, getTabPane(), -width/2, -height/2);
dialog.showAndWait();
waitForDialogToClose.complete(true);
});

waitForDialogToClose.get();
save_as(monitor, getTabPane().getScene().getWindow());
}
}
catch (Exception ex)
{
Expand Down
19 changes: 19 additions & 0 deletions core/ui/src/main/java/org/phoebus/ui/docking/DockStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,25 @@ public static DockItemWithInput getDockItemWithInput(final String application_na
return null;
}

/** Locate DockItemWithInput with input
* @param input Input, must not be <code>null</code>
* @return {@link DockItemWithInput} or <code>null</code> if not found
*/
public static DockItemWithInput getDockItemWithInput(URI input)
{
Objects.requireNonNull(input);
for (Stage stage : getDockStages())
for (DockPane pane : getDockPanes(stage))
for (DockItem tab : pane.getDockItems())
if (tab instanceof DockItemWithInput)
{
DockItemWithInput item = (DockItemWithInput) tab;
if (input.equals(item.getInput()))
return item;
}
return null;
}

/** Locate any 'fixed' {@link DockPane}s and un-fix them
* @param stage Stage where to clear 'fixed' panes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ SaveAsHdr=Use this file extension?
SaveAsPrompt=The file name\n {0}\ndoes not have the suggested file extension\ni.e. {1}.\n\nYes: Save as {2}\nNo: Continue with original name\nCancel: Do not save
SaveDlgErrHdr=Name must only contain alphanumeric characters, space, underscore or '-'.\nEnter a valid layout name.
SaveDlgHdr=Enter a file name to save the layout as.
SaveAsFileAlreadyOpen_content=An instance of {0} associated with {1} is already running in a different tab. A different file path must be chosen for the save operation.
SaveAsFileAlreadyOpen_header=The file {0} is already associated with another tab.
SaveAsFileAlreadyOpen_title=File is already associated with another tab
SaveLayoutAs=Save Layout As...
SaveLayoutOfContainingWindowAs=Save Layout of Containing Window As...
SaveLayoutWarningApplicationNoSaveFile=The following application(s) do not have associated with them save file(s). No save file association(s) will be stored for the application instance(s) in question when proceeding to save the layout. Proceed?\n\nThe application(s) in question are:\n
Expand Down

0 comments on commit a6bea69

Please sign in to comment.