Commit 77d16c06 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

sort ScenarioCheckerMessage based on Tabs and then Errors -> Warn

parent a45cb0e3
......@@ -3,20 +3,93 @@ package org.vadere.gui.components.utils;
import org.vadere.gui.components.control.ScenarioCheckerMessageDocumentView;
import org.vadere.simulator.util.AbstractScenarioCheckerMessageFormatter;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerMessageType;
import org.vadere.state.types.ScenarioElementType;
import java.util.Comparator;
import java.util.PriorityQueue;
public class GuiScenarioCheckerMessageFormatter extends AbstractScenarioCheckerMessageFormatter {
final ScenarioCheckerMessageDocumentView view;
boolean currentTypeChanged;
String currTabString;
boolean currTabStringChanged;
public GuiScenarioCheckerMessageFormatter(ScenarioCheckerMessageDocumentView view) {
this.view = view;
currentTypeChanged = false;
currTabStringChanged = false;
currentType = null;
currTabString = null;
}
/**
* Sort messages by tabs based on gui view
* @return
*/
@Override
protected Comparator<ScenarioCheckerMessage> getComparator() {
return ScenarioCheckerMessage::compareOrdinal;
}
@Override
protected boolean isNewType(ScenarioCheckerMessage msg) {
String tabString = getTabName(msg.getMsgType());
if (currTabString == null || !currTabString.equals(tabString)){
currTabString = tabString;
currTabStringChanged = true;
} else {
currTabStringChanged = false;
}
if (currentType == null || !currentType.equals(msg.getMsgType())){
currentType = msg.getMsgType();
currentTypeChanged = true;
} else {
currentTypeChanged = false;
}
return currentTypeChanged || currTabStringChanged;
}
private String getTabName(ScenarioCheckerMessageType type){
String ret="";
switch (type){
case TOPOGRAPHY_ERROR: case TOPOGRAPHY_WARN:
ret = Messages.getString("Tab.Topography.title");
break;
case DATA_PROCESSOR_ERROR: case DATA_PROCESSOR_WARN:
ret = Messages.getString("Tab.OutputProcessors.title");
break;
case MODEL_ATTR_ERROR: case MODEL_ATTR_WARN:
ret = Messages.getString("Tab.Model.title");
break;
case SIMULATION_ATTR_ERROR: case SIMULATION_ATTR_WARN:
ret = Messages.getString("Tab.Simulation.title");
break;
}
return ret;
}
@Override
protected void writeHeader(ScenarioCheckerMessage msg) {
sb.append("<h4>")
.append(Messages.getString(msg.getMsgType().getLocalTypeId()))
.append("</h4>");
if (currTabStringChanged){
if(sb.length() > 0){
sb.append("<br>");
}
sb.append("<h3>")
.append(currTabString)
.append(" Tab")
.append("</h3>");
}
if (currentTypeChanged){
sb.append("<h4>")
.append(Messages.getString(msg.getMsgType().getLocalTypeId()))
.append("</h4>");
}
}
......
package org.vadere.simulator.util;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
public abstract class AbstractScenarioCheckerMessageFormatter implements ScenarioCheckerMessageFormatter{
private ScenarioCheckerMessageType currentType;
protected ScenarioCheckerMessageType currentType;
protected StringBuilder sb;
public AbstractScenarioCheckerMessageFormatter(){
......@@ -30,6 +31,14 @@ public abstract class AbstractScenarioCheckerMessageFormatter implements Scenar
return sb.toString();
}
/**
* default comparator used for PriorityQueue. It sorts messages from Errors to Warnings.
* @return
*/
protected Comparator<ScenarioCheckerMessage> getComparator(){
return ScenarioCheckerMessage::compareTo;
}
protected boolean isNewType(ScenarioCheckerMessage msg){
if (currentType == null || !currentType.equals(msg.getMsgType())){
currentType = msg.getMsgType();
......
......@@ -68,7 +68,7 @@ public class ScenarioCheckerMessage implements Comparable<ScenarioCheckerMessage
return msgTarget != null;
}
private Comparator<ScenarioCheckerMessage> sortByType() {
public Comparator<ScenarioCheckerMessage> sortErrorToWarning() {
return (o1, o2) -> {
if (o1.equals(o2))
return 0;
......@@ -82,13 +82,31 @@ public class ScenarioCheckerMessage implements Comparable<ScenarioCheckerMessage
};
}
private Comparator<ScenarioCheckerMessage> defaultSort() {
return sortByType();
public Comparator<ScenarioCheckerMessage> sortOrdinalOnMessageType() {
return (o1, o2) -> {
if (o1.equals(o2))
return 0;
if (o1.getMsgType().ordinal() > o2.getMsgType().ordinal()) {
return 1;
} else if (o1.getMsgType().ordinal() < o2.getMsgType().ordinal()) {
return -1;
} else {
return sortErrorToWarning().compare(o1, o2);
}
};
}
@Override
public int compareTo(@NotNull ScenarioCheckerMessage o) {
return defaultSort().compare(this, o);
return compareErrorToWarn(o);
}
public int compareOrdinal(@NotNull ScenarioCheckerMessage o){
return sortOrdinalOnMessageType().compare(this, o);
}
public int compareErrorToWarn(@NotNull ScenarioCheckerMessage o){
return sortErrorToWarning().compare(this, o);
}
@Override
......
......@@ -6,14 +6,17 @@ package org.vadere.simulator.util;
*/
public enum ScenarioCheckerMessageType {
TOPOGRAPHY_ERROR("Error",100, "ScenarioChecker.type.topography.error"),
TOPOGRAPHY_WARN("Warning",500, "ScenarioChecker.type.topography.warning"),
SIMULATION_ATTR_ERROR("Error",101, "ScenarioChecker.type.simulation.error"),
SIMULATION_ATTR_WARN("Warning",501, "ScenarioChecker.type.simulation.warning"),
MODEL_ATTR_ERROR("Error",102, "ScenarioChecker.type.model.error"),
MODEL_ATTR_WARN("Warning",502, "ScenarioChecker.type.model.warning"),
DATA_PROCESSOR_ERROR("Error",103, "ScenarioChecker.type.processor.error"),
DATA_PROCESSOR_WARN("Warning",503, "ScenarioChecker.type.processor.warning");
SIMULATION_ATTR_ERROR("Error",100, "ScenarioChecker.type.simulation.error"),
SIMULATION_ATTR_WARN("Warning",500, "ScenarioChecker.type.simulation.warning"),
MODEL_ATTR_ERROR("Error",101, "ScenarioChecker.type.model.error"),
MODEL_ATTR_WARN("Warning",501, "ScenarioChecker.type.model.warning"),
DATA_PROCESSOR_ERROR("Error",102, "ScenarioChecker.type.processor.error"),
DATA_PROCESSOR_WARN("Warning",502, "ScenarioChecker.type.processor.warning"),
TOPOGRAPHY_ERROR("Error",103, "ScenarioChecker.type.topography.error"),
TOPOGRAPHY_WARN("Warning",503, "ScenarioChecker.type.topography.warning");
private static final int ERROR_START = 100;
private static final int WARN_START = 500;
......@@ -22,7 +25,7 @@ public enum ScenarioCheckerMessageType {
private String msgId;
private int id;
ScenarioCheckerMessageType(String type,int id, String msgId) {
ScenarioCheckerMessageType(String type, int id, String msgId) {
this.type = type;
this.id = id;
this.msgId = msgId;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment