Skip to content

Commit

Permalink
Merge pull request #31 from mathieucarbou/improvements
Browse files Browse the repository at this point in the history
Support re-using previously edited tc-config file when going directly…
  • Loading branch information
mathieucarbou authored Oct 23, 2017
2 parents f66da2a + ba69c40 commit 8ef0c20
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main/java/org/terracotta/tinypounder/TinyPounderMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private void stopServer(String stripeName, String serverName, Button stopBT) {
private void startServer(String stripeName, String serverName, Button startBT, Button stopBT, Label stateLBL, Label pidLBL) {
File stripeconfig = tcConfigLocationPerStripe.get(stripeName);
if (stripeconfig == null) {
generateXML();
generateXML(false);
stripeconfig = tcConfigLocationPerStripe.get(stripeName);
}

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

private void generateXML() {
private void generateXML(boolean skipConfirmOverwrite) {
boolean ee = kitAwareClassLoaderDelegator.isEEKit();

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

String xml = sb.toString();

tcConfigXml.setValue(tcConfigXml.getValue() + xml + "\n\n");

String filename = "tc-config-stripe-" + stripeRow + ".xml";
File location = new File(settings.getKitPath(), filename);
tcConfigLocationPerStripe.put("stripe-" + stripeRow, location);

try {
Files.write(location.toPath(), xml.getBytes("UTF-8"));
} catch (IOException e) {
throw new UncheckedIOException(e);
String xml;
if (location.exists() && !skipConfirmOverwrite) {
Notification.show("Config already found: " + location.getName());
try {
xml = new String(Files.readAllBytes(location.toPath()), "UTF-8");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
xml = sb.toString();
try {
Files.write(location.toPath(), xml.getBytes("UTF-8"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

tcConfigXml.setValue(tcConfigXml.getValue() + xml + "\n\n");
}
}

Expand Down

0 comments on commit 8ef0c20

Please sign in to comment.