Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
28e88325
Commit
28e88325
authored
Jan 25, 2018
by
Piotr Gawron
Browse files
color schema can include model name
parent
d8f01ce2
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java
View file @
28e88325
...
...
@@ -10,6 +10,7 @@ import java.util.Map;
import
org.apache.log4j.Logger
;
import
lcsb.mapviewer.common.Pair
;
import
lcsb.mapviewer.common.comparator.StringComparator
;
import
lcsb.mapviewer.common.exception.NotImplementedException
;
import
lcsb.mapviewer.model.graphics.ArrowTypeData
;
import
lcsb.mapviewer.model.map.BioEntity
;
...
...
@@ -20,6 +21,7 @@ import lcsb.mapviewer.model.map.compartment.Compartment;
import
lcsb.mapviewer.model.map.layout.ColorSchema
;
import
lcsb.mapviewer.model.map.layout.InvalidColorSchemaException
;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.map.model.ModelData
;
import
lcsb.mapviewer.model.map.model.ModelSubmodelConnection
;
import
lcsb.mapviewer.model.map.reaction.AbstractNode
;
import
lcsb.mapviewer.model.map.reaction.Product
;
...
...
@@ -60,6 +62,8 @@ public class ColorModelCommand extends ModelCommand {
*/
private
ElementUtils
eu
=
new
ElementUtils
();
private
StringComparator
stringComparator
=
new
StringComparator
();
/**
* Default constructor.
*
...
...
@@ -125,6 +129,9 @@ public class ColorModelCommand extends ModelCommand {
if
(
schema
.
getName
()
!=
null
)
{
return
false
;
}
if
(!
modelMatch
(
reaction
.
getModelData
(),
schema
))
{
return
false
;
}
if
(
schema
.
getReactionIdentifier
()
!=
null
&&
schema
.
getReactionIdentifier
().
equalsIgnoreCase
(
reaction
.
getIdReaction
()))
{
...
...
@@ -150,6 +157,19 @@ public class ColorModelCommand extends ModelCommand {
return
false
;
}
private
boolean
modelMatch
(
ModelData
model
,
ColorSchema
schema
)
{
if
(
schema
.
getModelName
()
!=
null
&&
!
schema
.
getModelName
().
isEmpty
())
{
if
(
model
==
null
)
{
logger
.
warn
(
"Model of element is null..."
);
return
false
;
}
if
(
stringComparator
.
compare
(
model
.
getName
(),
schema
.
getModelName
())
!=
0
)
{
return
false
;
}
}
return
true
;
}
/**
* Applies color schema into the {@link Element}.
*
...
...
@@ -181,6 +201,9 @@ public class ColorModelCommand extends ModelCommand {
*/
protected
boolean
match
(
Element
element
,
ColorSchema
schema
)
{
if
(
element
instanceof
Species
)
{
if
(!
modelMatch
(
element
.
getModelData
(),
schema
))
{
return
false
;
}
if
(
schema
.
getName
()
!=
null
)
{
if
(!
element
.
getName
().
equalsIgnoreCase
(
schema
.
getName
()))
{
return
false
;
...
...
model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java
View file @
28e88325
...
...
@@ -362,4 +362,94 @@ public class ColorModelCommandTest extends CommandTestFunctions {
}
@Test
public
void
testReactionColoringWithModelNotMatching
()
throws
Exception
{
try
{
Model
model
=
getModelForFile
(
"testFiles/reactions_to_color.xml"
,
false
);
ColorSchema
schema
=
new
GenericColorSchema
();
schema
.
setReactionIdentifier
(
"re4"
);
schema
.
setName
(
null
);
schema
.
setModelName
(
model
.
getName
()
+
"XXX"
);
Collection
<
ColorSchema
>
schemas
=
new
ArrayList
<>();
schemas
.
add
(
schema
);
ColorModelCommand
factory
=
new
ColorModelCommand
(
model
,
schemas
,
colorExtractor
);
Map
<
Object
,
ColorSchema
>
map
=
factory
.
getModifiedElements
();
assertEquals
(
0
,
map
.
values
().
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testReactionColoringWithModelMatch
()
throws
Exception
{
try
{
Model
model
=
getModelForFile
(
"testFiles/reactions_to_color.xml"
,
false
);
ColorSchema
schema
=
new
GenericColorSchema
();
schema
.
setReactionIdentifier
(
"re4"
);
schema
.
setName
(
null
);
schema
.
setModelName
(
model
.
getName
());
Collection
<
ColorSchema
>
schemas
=
new
ArrayList
<>();
schemas
.
add
(
schema
);
ColorModelCommand
factory
=
new
ColorModelCommand
(
model
,
schemas
,
colorExtractor
);
Map
<
Object
,
ColorSchema
>
map
=
factory
.
getModifiedElements
();
assertEquals
(
1
,
map
.
values
().
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testAliasColoringWithModelNotMatching
()
throws
Exception
{
try
{
Model
model
=
getModelForFile
(
"testFiles/sample.xml"
,
false
);
ColorSchema
schema
=
new
GenericColorSchema
();
schema
.
setName
(
"CNC"
);
schema
.
setModelName
(
model
.
getName
()
+
"XXX"
);
Collection
<
ColorSchema
>
schemas
=
new
ArrayList
<>();
schemas
.
add
(
schema
);
ColorModelCommand
factory
=
new
ColorModelCommand
(
model
,
schemas
,
colorExtractor
);
Map
<
Object
,
ColorSchema
>
map
=
factory
.
getModifiedElements
();
assertEquals
(
0
,
map
.
values
().
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
@Test
public
void
testAliasColoringWithModelMatch
()
throws
Exception
{
try
{
Model
model
=
getModelForFile
(
"testFiles/sample.xml"
,
false
);
ColorSchema
schema
=
new
GenericColorSchema
();
schema
.
setName
(
"CNC"
);
schema
.
setModelName
(
model
.
getName
());
Collection
<
ColorSchema
>
schemas
=
new
ArrayList
<>();
schemas
.
add
(
schema
);
ColorModelCommand
factory
=
new
ColorModelCommand
(
model
,
schemas
,
colorExtractor
);
Map
<
Object
,
ColorSchema
>
map
=
factory
.
getModifiedElements
();
assertEquals
(
1
,
map
.
values
().
size
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
}
model/src/main/java/lcsb/mapviewer/model/map/layout/ColorSchema.java
View file @
28e88325
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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