Skip to content

Commit 8ef0c20

Browse files
Merge pull request #31 from mathieucarbou/improvements
Support re-using previously edited tc-config file when going directly…
2 parents f66da2a + ba69c40 commit 8ef0c20

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private void stopServer(String stripeName, String serverName, Button stopBT) {
483483
private void startServer(String stripeName, String serverName, Button startBT, Button stopBT, Label stateLBL, Label pidLBL) {
484484
File stripeconfig = tcConfigLocationPerStripe.get(stripeName);
485485
if (stripeconfig == null) {
486-
generateXML();
486+
generateXML(false);
487487
stripeconfig = tcConfigLocationPerStripe.get(stripeName);
488488
}
489489

@@ -688,7 +688,7 @@ private void addVoltronConfigControls() {
688688
generateTcConfig.addStyleName("align-bottom");
689689
generateTcConfig.setWidth(100, Unit.PERCENTAGE);
690690
generateTcConfig.addClickListener((Button.ClickListener) event -> {
691-
generateXML();
691+
generateXML(true);
692692
List<String> filenames = tcConfigLocationPerStripe.values().stream().map(File::getName).collect(Collectors.toList());
693693
Notification.show("Configurations saved:", "Location: " + settings.getKitPath() + "\nFiles: " + filenames, Notification.Type.HUMANIZED_MESSAGE);
694694
});
@@ -721,7 +721,7 @@ private void changeTrashButtonStatus(String pathname) {
721721
}
722722
}
723723

724-
private void generateXML() {
724+
private void generateXML(boolean skipConfirmOverwrite) {
725725
boolean ee = kitAwareClassLoaderDelegator.isEEKit();
726726

727727
tcConfigLocationPerStripe.clear();
@@ -848,19 +848,28 @@ private void generateXML() {
848848
sb.append(" </servers>\n\n" +
849849
"</tc-config>");
850850

851-
String xml = sb.toString();
852-
853-
tcConfigXml.setValue(tcConfigXml.getValue() + xml + "\n\n");
854-
855851
String filename = "tc-config-stripe-" + stripeRow + ".xml";
856852
File location = new File(settings.getKitPath(), filename);
857853
tcConfigLocationPerStripe.put("stripe-" + stripeRow, location);
858854

859-
try {
860-
Files.write(location.toPath(), xml.getBytes("UTF-8"));
861-
} catch (IOException e) {
862-
throw new UncheckedIOException(e);
855+
String xml;
856+
if (location.exists() && !skipConfirmOverwrite) {
857+
Notification.show("Config already found: " + location.getName());
858+
try {
859+
xml = new String(Files.readAllBytes(location.toPath()), "UTF-8");
860+
} catch (IOException e) {
861+
throw new UncheckedIOException(e);
862+
}
863+
} else {
864+
xml = sb.toString();
865+
try {
866+
Files.write(location.toPath(), xml.getBytes("UTF-8"));
867+
} catch (IOException e) {
868+
throw new UncheckedIOException(e);
869+
}
863870
}
871+
872+
tcConfigXml.setValue(tcConfigXml.getValue() + xml + "\n\n");
864873
}
865874
}
866875

0 commit comments

Comments
 (0)