mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-23 22:19:13 +00:00
# integrated old course name generation tool in AdminConsole
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
package com.sap.sailing.gwt.ui.adminconsole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
import com.google.gwt.event.dom.client.ChangeHandler;
|
||||
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.IntegerBox;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sailing.gwt.ui.client.DataEntryDialog;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
|
||||
public class CourseNamesGenerationDialog extends DataEntryDialog<List<String>> {
|
||||
|
||||
private static String[] courseLayouts = new String[] { "0,Windward/Leeward", "1,Windward/Leeward",
|
||||
"2,Windward/Leeward", "3,Windward/Leeward", "4,Trapezoid", "5,Trapezoid", "6,Triangle", "7,Triangle",
|
||||
"8,Windward/Leeward" };
|
||||
|
||||
private IntegerBox minRoundsBox;
|
||||
private IntegerBox maxRoundsBox;
|
||||
|
||||
public CourseNamesGenerationDialog(final StringMessages stringMessages,
|
||||
DataEntryDialog.DialogCallback<List<String>> callback) {
|
||||
super(stringMessages.courseNames(), "Yeah do it!", stringMessages.generate(), stringMessages.cancel(),
|
||||
new NamesValidator(stringMessages), callback);
|
||||
minRoundsBox = new IntegerBox();
|
||||
minRoundsBox.setValue(2);
|
||||
maxRoundsBox = new IntegerBox();
|
||||
maxRoundsBox.setValue(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Widget getAdditionalWidget() {
|
||||
final Grid grid = new Grid(2, 2);
|
||||
|
||||
minRoundsBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
validate();
|
||||
}
|
||||
});
|
||||
minRoundsBox.addKeyPressHandler(numbersOnlyHandler);
|
||||
grid.setWidget(0, 0, new Label("Minimum number of rounds:"));
|
||||
grid.setWidget(0, 1, minRoundsBox);
|
||||
|
||||
|
||||
maxRoundsBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
validate();
|
||||
}
|
||||
});
|
||||
maxRoundsBox.addKeyPressHandler(numbersOnlyHandler);
|
||||
grid.setWidget(1, 0, new Label("Maximum number of rounds:"));
|
||||
grid.setWidget(1, 1, maxRoundsBox);
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
minRoundsBox.setFocus(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getResult() {
|
||||
List<String> courseNames = new ArrayList<String>();
|
||||
|
||||
Integer minNumberOfRounds = minRoundsBox.getValue();
|
||||
Integer maxNumberOfRounds = maxRoundsBox.getValue();
|
||||
if (minNumberOfRounds == null || maxNumberOfRounds == null) {
|
||||
return courseNames;
|
||||
}
|
||||
|
||||
for (int layout = 0; layout < courseLayouts.length; layout++) {
|
||||
String[] courseNumberAndName = courseLayouts[layout].split(",");
|
||||
for (int round = minNumberOfRounds; round <= maxNumberOfRounds; round++) {
|
||||
courseNames.add(courseNumberAndName[0] + " " + round + " (" + courseNumberAndName[1] + ")");
|
||||
}
|
||||
}
|
||||
Logger.getLogger("Hallo").log(Level.SEVERE, courseNames.toString());
|
||||
return courseNames;
|
||||
}
|
||||
|
||||
private KeyPressHandler numbersOnlyHandler = new KeyPressHandler() {
|
||||
@Override
|
||||
public void onKeyPress(KeyPressEvent event) {
|
||||
if(!Character.isDigit(event.getCharCode())) {
|
||||
((IntegerBox)event.getSource()).cancelKey();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static class NamesValidator implements Validator<List<String>> {
|
||||
|
||||
private final StringMessages messages;
|
||||
|
||||
public NamesValidator(StringMessages messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMessage(List<String> valueToValidate) {
|
||||
if (valueToValidate.isEmpty()) {
|
||||
return messages.errorWhileAddingSeriesToChart();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
+70
-49
@@ -1,6 +1,7 @@
|
||||
package com.sap.sailing.gwt.ui.adminconsole;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
import com.google.gwt.event.dom.client.ChangeHandler;
|
||||
@@ -19,6 +20,7 @@ import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.sap.sailing.domain.common.CourseDesignerMode;
|
||||
import com.sap.sailing.domain.common.racelog.RacingProcedureType;
|
||||
import com.sap.sailing.gwt.ui.client.DataEntryDialog.DialogCallback;
|
||||
import com.sap.sailing.gwt.ui.client.ErrorReporter;
|
||||
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
@@ -54,7 +56,7 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
|
||||
captionPanel = new CaptionPanel(stringMessages.configuration());
|
||||
VerticalPanel verticalPanel = new VerticalPanel();
|
||||
mainGrid = new Grid(5, 2);
|
||||
mainGrid = new Grid(5, 3);
|
||||
updateButton = new Button(stringMessages.save());
|
||||
updateButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
@@ -105,13 +107,6 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
racingProcedureListBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
int index = racingProcedureListBox.getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
RacingProcedureType type = RacingProcedureType.valueOf(racingProcedureListBox.getValue(index));
|
||||
configuration.defaultRacingProcedureType = type == RacingProcedureType.UNKNOWN ? null : type;
|
||||
} else {
|
||||
configuration.defaultRacingProcedureType = null;
|
||||
}
|
||||
markAsDrity(true);
|
||||
}
|
||||
});
|
||||
@@ -125,13 +120,6 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
designerModeEntryListBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
int index = designerModeEntryListBox.getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
CourseDesignerMode mode = CourseDesignerMode.valueOf(designerModeEntryListBox.getValue(index));
|
||||
configuration.defaultCourseDesignerMode = mode == CourseDesignerMode.UNKNOWN ? null : mode;
|
||||
} else {
|
||||
configuration.defaultCourseDesignerMode = null;
|
||||
}
|
||||
markAsDrity(true);
|
||||
}
|
||||
});
|
||||
@@ -141,16 +129,6 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
|
||||
private void setupCourseAreasBox(int gridRow) {
|
||||
allowedCourseAreasBox = new TextBox();
|
||||
allowedCourseAreasBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
if (allowedCourseAreasBox.getText().isEmpty()) {
|
||||
configuration.allowedCourseAreaNames = null;
|
||||
} else {
|
||||
configuration.allowedCourseAreaNames = Arrays.asList(allowedCourseAreasBox.getText().split(","));
|
||||
}
|
||||
}
|
||||
});
|
||||
allowedCourseAreasBox.addKeyUpHandler(dirtyMarker);
|
||||
if (configuration.allowedCourseAreaNames != null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -169,40 +147,53 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
|
||||
private void setupCourseNameBox(int gridRow) {
|
||||
courseNamesBox = new TextBox();
|
||||
courseNamesBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
if (courseNamesBox.getText().isEmpty()) {
|
||||
configuration.byNameDesignerCourseNames = null;
|
||||
} else {
|
||||
configuration.byNameDesignerCourseNames = Arrays.asList(courseNamesBox.getText().split(","));
|
||||
}
|
||||
}
|
||||
});
|
||||
courseNamesBox.addKeyUpHandler(dirtyMarker);
|
||||
if (configuration.byNameDesignerCourseNames != null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < configuration.byNameDesignerCourseNames.size(); i++) {
|
||||
builder.append(configuration.byNameDesignerCourseNames.get(i));
|
||||
builder.append(',');
|
||||
}
|
||||
courseNamesBox.setText(builder.substring(0, builder.length() - 1));
|
||||
fillCourseNamesBox(configuration.byNameDesignerCourseNames);
|
||||
} else {
|
||||
courseNamesBox.setText("O2,I2");
|
||||
markAsDrity(true);
|
||||
}
|
||||
|
||||
|
||||
Button generateButton = new Button(stringMessages.generate());
|
||||
generateButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
CourseNamesGenerationDialog dialog = new CourseNamesGenerationDialog(stringMessages, new DialogCallback<List<String>>() {
|
||||
@Override
|
||||
public void ok(List<String> courseNames) {
|
||||
fillCourseNamesBox(courseNames);
|
||||
markAsDrity(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() { }
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
mainGrid.setWidget(gridRow, 0, new Label(stringMessages.courseNames()));
|
||||
mainGrid.setWidget(gridRow, 1, courseNamesBox);
|
||||
mainGrid.setWidget(gridRow, 2, generateButton);
|
||||
}
|
||||
|
||||
private void fillCourseNamesBox(List<String> names) {
|
||||
if (names.isEmpty()) {
|
||||
courseNamesBox.setText("");
|
||||
} else {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < names.size(); i++) {
|
||||
builder.append(names.get(i));
|
||||
builder.append(',');
|
||||
}
|
||||
courseNamesBox.setText(builder.substring(0, builder.length() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void setupRecipientBox(int gridRow) {
|
||||
mailRecipientBox = new TextBox();
|
||||
mailRecipientBox.addChangeHandler(new ChangeHandler() {
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
configuration.resultsMailRecipient = mailRecipientBox.getText().isEmpty() ? null : mailRecipientBox.getText();
|
||||
}
|
||||
});
|
||||
mailRecipientBox.addKeyUpHandler(dirtyMarker);
|
||||
if (configuration.resultsMailRecipient != null) {
|
||||
mailRecipientBox.setText(configuration.resultsMailRecipient);
|
||||
@@ -225,12 +216,42 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceConfigurationDTO getResult() {
|
||||
DeviceConfigurationDTO result = new DeviceConfigurationDTO();
|
||||
|
||||
if (!allowedCourseAreasBox.getText().isEmpty()) {
|
||||
result.allowedCourseAreaNames = Arrays.asList(allowedCourseAreasBox.getText().split(","));
|
||||
}
|
||||
|
||||
if (!mailRecipientBox.getText().isEmpty()) {
|
||||
result.resultsMailRecipient = mailRecipientBox.getText().isEmpty() ? null : mailRecipientBox.getText();
|
||||
}
|
||||
|
||||
int index = racingProcedureListBox.getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
RacingProcedureType type = RacingProcedureType.valueOf(racingProcedureListBox.getValue(index));
|
||||
result.defaultRacingProcedureType = type == RacingProcedureType.UNKNOWN ? null : type;
|
||||
}
|
||||
|
||||
index = designerModeEntryListBox.getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
CourseDesignerMode mode = CourseDesignerMode.valueOf(designerModeEntryListBox.getValue(index));
|
||||
result.defaultCourseDesignerMode = mode == CourseDesignerMode.UNKNOWN ? null : mode;
|
||||
}
|
||||
|
||||
if (!courseNamesBox.getText().isEmpty()) {
|
||||
result.byNameDesignerCourseNames = Arrays.asList(courseNamesBox.getText().split(","));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateConfiguration(final SailingServiceAsync sailingService, final ErrorReporter errorReporter) {
|
||||
if (matcher == null || configuration == null) {
|
||||
errorReporter.reportError("Invalid state.");
|
||||
return;
|
||||
}
|
||||
sailingService.createOrUpdateDeviceConfiguration(matcher, configuration,
|
||||
DeviceConfigurationDTO dto = getResult();
|
||||
sailingService.createOrUpdateDeviceConfiguration(matcher, dto,
|
||||
new AsyncCallback<DeviceConfigurationMatcherDTO>() {
|
||||
@Override
|
||||
public void onSuccess(DeviceConfigurationMatcherDTO matcher) {
|
||||
@@ -243,7 +264,7 @@ public class DeviceConfigurationDetailComposite extends Composite {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private KeyUpHandler dirtyMarker = new KeyUpHandler() {
|
||||
@Override
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
|
||||
+1
@@ -842,4 +842,5 @@ public interface StringMessages extends Messages {
|
||||
String courseDesignerMode();
|
||||
String racingProcedure();
|
||||
String courseNames();
|
||||
String generate();
|
||||
}
|
||||
|
||||
+2
-1
@@ -832,4 +832,5 @@ deviceConfiguration=Device Configuration
|
||||
none=None
|
||||
courseDesignerMode=Course Designer
|
||||
racingProcedure=Racing Procedure
|
||||
courseNames=Course Names
|
||||
courseNames=Course Names
|
||||
generate=Generate
|
||||
+2
-1
@@ -828,4 +828,5 @@ deviceConfiguration=Device Configuration
|
||||
none=Keine
|
||||
courseDesignerMode=Kursdesigner
|
||||
racingProcedure=Rennregeln
|
||||
courseNames=Kursnamen
|
||||
courseNames=Kursnamen
|
||||
generate=Generiere
|
||||
+5
-5
@@ -44,6 +44,11 @@ public class DeviceConfigurationJsonDeserializer implements JsonDeserializer<Dev
|
||||
}
|
||||
configuration.setAllowedCourseAreaNames(allowedCourseAreaNames);
|
||||
}
|
||||
|
||||
if (object.containsKey(DeviceConfigurationJsonSerializer.FIELD_RESULTS_RECIPIENT)) {
|
||||
String resultsRecipient = (String) object.get(DeviceConfigurationJsonSerializer.FIELD_RESULTS_RECIPIENT);
|
||||
configuration.setResultsMailRecipient(resultsRecipient);
|
||||
}
|
||||
|
||||
if (object.containsKey(DeviceConfigurationJsonSerializer.FIELD_DEFAULT_RACING_PROCEDURE_TYPE)) {
|
||||
RacingProcedureType type = RacingProcedureType.valueOf(
|
||||
@@ -57,11 +62,6 @@ public class DeviceConfigurationJsonDeserializer implements JsonDeserializer<Dev
|
||||
configuration.setDefaultCourseDesignerMode(mode);
|
||||
}
|
||||
|
||||
if (object.containsKey(DeviceConfigurationJsonSerializer.FIELD_RESULTS_RECIPIENT)) {
|
||||
String resultsRecipient = (String) object.get(DeviceConfigurationJsonSerializer.FIELD_RESULTS_RECIPIENT);
|
||||
configuration.setResultsMailRecipient(resultsRecipient);
|
||||
}
|
||||
|
||||
if (object.containsKey(DeviceConfigurationJsonSerializer.FIELD_BY_VALUE_COURSE_DESIGNER_COURSE_NAMES)) {
|
||||
JSONArray namesArray = Helpers.getNestedArraySafe(object,
|
||||
DeviceConfigurationJsonSerializer.FIELD_BY_VALUE_COURSE_DESIGNER_COURSE_NAMES);
|
||||
|
||||
@@ -227,18 +227,6 @@
|
||||
<string name="generic_load_failure">There was an error loading the requested data:\n\"%s\"\nDo you want to retry?</string>
|
||||
<string name="set_course_layout">Set the course layout</string>
|
||||
|
||||
<string-array name="course_routes">
|
||||
<item>0,Windward/Leeward</item>
|
||||
<item>1,Windward/Leeward</item>
|
||||
<item>2,Windward/Leeward</item>
|
||||
<item>3,Windward/Leeward</item>
|
||||
<item>4,Trapezoid</item>
|
||||
<item>5,Trapezoid</item>
|
||||
<item>6,Triangle</item>
|
||||
<item>7,Triangle</item>
|
||||
<item>8,Windward/Leeward</item>
|
||||
</string-array>
|
||||
|
||||
<string name="loading_failure">Load failure</string>
|
||||
<string name="wind_unknown">(click to set wind)</string>
|
||||
<string name="wind_info" formatted="false">(%s kn, %s)</string>
|
||||
|
||||
Reference in New Issue
Block a user