Commit 28e88325 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

color schema can include model name

parent d8f01ce2
......@@ -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;
......
......@@ -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;
}
}
}
Markdown is supported
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