Commit d45c3603 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

position is passed properly to the model

parent 2a51de93
......@@ -143,6 +143,7 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> {
complex.addSpecies(result);
}
}
species.updateModelElementAfterLayoutAdded(result);
return result;
}
......
package lcsb.mapviewer.converter.model.celldesigner.species;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
......
......@@ -8,6 +8,7 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerAntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Species;
/**
* Class representing CellDesigner {@link AntisenseRna}.
......@@ -31,7 +32,7 @@ public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna>
/**
* List of antisense rna regions (some rna sequences) in this object.
*/
private List<CellDesignerAntisenseRnaRegion> regions = new ArrayList<CellDesignerAntisenseRnaRegion>();
private List<CellDesignerAntisenseRnaRegion> regions = new ArrayList<>();
/**
* Constructor that copies the data from species given in the argument.
......@@ -66,7 +67,7 @@ public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna>
}
/**
* Addd antisense rna region (part of rna sequence that has some meaning) to the
* Add antisense rna region (part of rna sequence that has some meaning) to the
* object. If the region with given id exists then the data of this region is
* copied to the one that is already in the {@link CellDesignerAntisenseRna}.
*
......@@ -140,10 +141,14 @@ public class CellDesignerAntisenseRna extends CellDesignerSpecies<AntisenseRna>
public AntisenseRna createModelElement(String aliasId) {
AntisenseRna result = new AntisenseRna(aliasId);
super.setModelObjectFields(result);
return result;
}
@Override
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerAntisenseRnaRegion region : regions) {
result.addRegion(region.createAntisenseRegionAlias(result));
((AntisenseRna) element).addRegion(region.createAntisenseRegionAlias(element));
}
return result;
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.compartment.Compartment;
/**
* Class representing CellDesigner {@link Compartment}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerCompartment extends CellDesignerElement<Compartment> implements Comparable<CellDesignerCompartment> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerCompartment.class);
/**
* Identifier of the compartment. Unique in the model
*/
private String compartmentId = "";
/**
* List of agregated elements.
*/
private Set<CellDesignerElement<?>> elements = new HashSet<>();
/**
* Default constructor with identifier given as a parameter.
*
* @param id
* identifier of the compartment
*/
public CellDesignerCompartment(String id) {
compartmentId = id;
setName(id);
}
/**
* Default constructor.
*/
public CellDesignerCompartment() {
super();
}
/**
* Constructor that initialize the data using compartment given as a
* parameter.
*
* @param compartment
* object which is used for data intialization
*/
public CellDesignerCompartment(CellDesignerCompartment compartment) {
super(compartment);
setElementId(compartment.getElementId());
for (CellDesignerElement<?> element : compartment.getElements()) {
addElement(element.copy());
}
}
@Override
public int compareTo(CellDesignerCompartment param) {
if (param == null) {
return -1;
}
if (!compartmentId.equals(param.getElementId())) {
return compartmentId.compareTo(param.getElementId());
}
if (!getName().equals(param.getName())) {
return getName().compareTo(param.getName());
}
return 0;
}
@Override
public boolean equals(Object param) {
if (this == param) {
return true;
}
if (!(param instanceof CellDesignerCompartment)) {
return false;
}
return compareTo((CellDesignerCompartment) param) == 0;
}
@Override
public int hashCode() {
String result = compartmentId + "_" + getName();
return result.hashCode();
}
@Override
public CellDesignerCompartment copy() {
if (this.getClass() != CellDesignerCompartment.class) {
throw new NotImplementedException("this method should be overloaded");
}
return new CellDesignerCompartment(this);
}
@Override
public String getElementId() {
return compartmentId;
}
@Override
public void setElementId(String id) {
this.compartmentId = id;
}
/**
* Adds element.
*
* @param element
* element to add
*/
public void addElement(CellDesignerElement<?> element) {
elements.add(element);
element.setParent(this);
}
/**
*
* @return {@link #elements}
*/
public Set<CellDesignerElement<?>> getElements() {
return elements;
}
@Override
public Compartment createModelElement(String aliasId) {
Compartment result = new Compartment(aliasId);
super.setModelObjectFields(result);
if (elements.size() > 0) {
throw new NotImplementedException();
}
return result;
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.compartment.Compartment;
/**
* Class representing CellDesigner {@link Compartment}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerCompartment extends CellDesignerElement<Compartment>
implements Comparable<CellDesignerCompartment> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerCompartment.class);
/**
* Identifier of the compartment. Unique in the model
*/
private String compartmentId = "";
/**
* List of aggregated elements.
*/
private Set<CellDesignerElement<?>> elements = new HashSet<>();
/**
* Default constructor with identifier given as a parameter.
*
* @param id
* identifier of the compartment
*/
public CellDesignerCompartment(String id) {
compartmentId = id;
setName(id);
}
/**
* Default constructor.
*/
public CellDesignerCompartment() {
super();
}
/**
* Constructor that initialize the data using compartment given as a parameter.
*
* @param compartment
* object which is used for data initialization
*/
public CellDesignerCompartment(CellDesignerCompartment compartment) {
super(compartment);
setElementId(compartment.getElementId());
for (CellDesignerElement<?> element : compartment.getElements()) {
addElement(element.copy());
}
}
@Override
public int compareTo(CellDesignerCompartment param) {
if (param == null) {
return -1;
}
if (!compartmentId.equals(param.getElementId())) {
return compartmentId.compareTo(param.getElementId());
}
if (!getName().equals(param.getName())) {
return getName().compareTo(param.getName());
}
return 0;
}
@Override
public boolean equals(Object param) {
if (this == param) {
return true;
}
if (!(param instanceof CellDesignerCompartment)) {
return false;
}
return compareTo((CellDesignerCompartment) param) == 0;
}
@Override
public int hashCode() {
String result = compartmentId + "_" + getName();
return result.hashCode();
}
@Override
public CellDesignerCompartment copy() {
if (this.getClass() != CellDesignerCompartment.class) {
throw new NotImplementedException("this method should be overloaded");
}
return new CellDesignerCompartment(this);
}
@Override
public String getElementId() {
return compartmentId;
}
@Override
public void setElementId(String id) {
this.compartmentId = id;
}
/**
* Adds element.
*
* @param element
* element to add
*/
public void addElement(CellDesignerElement<?> element) {
elements.add(element);
element.setParent(this);
}
/**
*
* @return {@link #elements}
*/
public Set<CellDesignerElement<?>> getElements() {
return elements;
}
@Override
public Compartment createModelElement(String aliasId) {
Compartment result = new Compartment(aliasId);
super.setModelObjectFields(result);
if (elements.size() > 0) {
throw new NotImplementedException();
}
return result;
}
@Override
public void updateModelElementAfterLayoutAdded(Compartment element) {
}
}
......@@ -14,9 +14,9 @@ import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.species.Element;
/**
* Generic CellDesigner element map. It is a root object in inheritance three for
* every element ({@link CellDesignerSpecies} or {@link CellDesignerCompartment}
* ).
* Generic CellDesigner element map. It is a root object in inheritance three
* for every element ({@link CellDesignerSpecies} or
* {@link CellDesignerCompartment} ).
*
* @param <T>
* type of the {@link Element} in the model that is describe by this
......@@ -26,423 +26,426 @@ import lcsb.mapviewer.model.map.species.Element;
*/
public abstract class CellDesignerElement<T extends Element> implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Maximum length of the valid synonym name.
*/
private static final int MAX_SYNONYM_LENGTH = 255;
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(CellDesignerElement.class);
/**
* Notes describing this element.
*/
private String notes;
/**
* Symbol of the element.
*/
private String symbol;
/**
* Full name of the element.
*/
private String fullName;
/**
* Abbreviation associated with the element.
*/
private String abbreviation;
/**
* Formula associated with the element.
*/
private String formula;
/**
* Short name of the element.
*/
private String name = "";
/**
* Lists of all synonyms used for describing this element.
*/
private List<String> synonyms = new ArrayList<>();
/**
* List of former symbols used to describe this element.
*/
private List<String> formerSymbols = new ArrayList<>();
/**
* Where this element lies on.
*/
private CellDesignerCompartment parent;
/**
* In which complex this element is located.
*/
private CellDesignerComplexSpecies complex;
/**
* Set of miriam annotations for this element.
*/
private Set<MiriamData> miriamData = new HashSet<>();
/**
* Default constructor that initialize the data with the information given in
* the parameter.
*
* @param element
* original object from which data should be initialized
*/
protected CellDesignerElement(CellDesignerElement<?> element) {
this.parent = element.parent;
this.complex = element.complex;
this.notes = element.notes;
this.symbol = element.symbol;
this.fullName = element.fullName;
this.name = element.getName();
this.getSynonyms().addAll(element.getSynonyms());
this.getFormerSymbols().addAll(element.getFormerSymbols());
for (MiriamData md : element.getMiriamData()) {
addMiriamData(new MiriamData(md));
}
this.abbreviation = element.getAbbreviation();
this.formula = element.getFormula();
}
/**
* Default constructor.
*/
protected CellDesignerElement() {
this.notes = "";
}
/**
* Adds set of {@link MiriamData} to the object.
*
* @param miriamData
* objects to be added
*/
public void addMiriamData(Collection<MiriamData> miriamData) {
for (MiriamData md : miriamData) {
addMiriamData(md);
}
}
/**
* Returns identifier of the species.
*
* @return identifier of the species
*/
public abstract String getElementId();
/**
* Adds {@link MiriamData} to the element.
*
* @param md
* object to be added
*/
public void addMiriamData(MiriamData md) {
if (this.miriamData.contains(md)) {
logger.warn("Miriam data (" + md.getDataType() + ": " + md.getResource() + ") for " + getElementId() + " already exists. Ignoring...");
} else {
this.miriamData.add(md);
}
}
/**
* Sets notes about the object.
*
* @param notes
* new notes
*/
public void setNotes(String notes) {
if (notes != null) {
if (notes.contains("</html>")) {
throw new InvalidArgumentException("Notes cannot contain html tags...");
}
}
this.notes = notes;
}
/**
* Makes a copy of the element.
*
* @return copy of the object
*/
public abstract CellDesignerElement<T> copy();
/**
* Adds synonyms to the element.
*
* @param synonyms
* list of synonyms to be added
*/
public void addSynonyms(List<String> synonyms) {
for (String string : synonyms) {
if (string.length() > MAX_SYNONYM_LENGTH) {
String message = " <Synonym too long. Only " + MAX_SYNONYM_LENGTH + " characters are allowed>";
this.getSynonyms().add(string.substring(0, MAX_SYNONYM_LENGTH - message.length()) + message);
} else {
this.getSynonyms().add(string);
}
}
}
/**
* Returns notes about the object.