Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
77d16c06
Commit
77d16c06
authored
Oct 10, 2018
by
Stefan Schuhbaeck
Browse files
sort ScenarioCheckerMessage based on Tabs and then Errors -> Warn
parent
a45cb0e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
VadereGui/src/org/vadere/gui/components/utils/GuiScenarioCheckerMessageFormatter.java
View file @
77d16c06
...
...
@@ -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>"
);
}
}
...
...
VadereSimulator/src/org/vadere/simulator/util/AbstractScenarioCheckerMessageFormatter.java
View file @
77d16c06
package
org.vadere.simulator.util
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.PriorityQueue
;
public
abstract
class
AbstractScenarioCheckerMessageFormatter
implements
ScenarioCheckerMessageFormatter
{
pr
ivate
ScenarioCheckerMessageType
currentType
;
pr
otected
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
();
...
...
VadereSimulator/src/org/vadere/simulator/util/ScenarioCheckerMessage.java
View file @
77d16c06
...
...
@@ -68,7 +68,7 @@ public class ScenarioCheckerMessage implements Comparable<ScenarioCheckerMessage
return
msgTarget
!=
null
;
}
p
rivate
Comparator
<
ScenarioCheckerMessage
>
sort
ByType
()
{
p
ublic
Comparator
<
ScenarioCheckerMessage
>
sort
ErrorToWarning
()
{
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
...
...
VadereSimulator/src/org/vadere/simulator/util/ScenarioCheckerMessageType.java
View file @
77d16c06
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment