Mercurial > hg > ismi-richfaces
diff src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/AliasEntityList.java @ 112:59f26a5ef2b3
AliasListenerObject adds aliases to ListenerObject. Change all forms to enable ALIAS for (historical) PLACE fields. Remove REPOSITORY from event forms.
author | casties |
---|---|
date | Tue, 13 Dec 2016 19:04:45 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/AliasEntityList.java Tue Dec 13 19:04:45 2016 +0100 @@ -0,0 +1,72 @@ +package de.mpiwg.itgroup.ismi.util.guiComponents; + +import java.util.HashMap; +import java.util.List; + +import org.mpi.openmind.repository.bo.Attribute; +import org.mpi.openmind.repository.bo.Entity; + +import de.mpiwg.itgroup.ismi.auxObjects.AliasListenerObject; + +/** + * EntityList that also takes ALIASes related to the Entities. + * + * @author casties + * + */ +public class AliasEntityList extends EntityList { + + private static final long serialVersionUID = 6671675804993282617L; + + protected String aliasRelName; + protected String entityClass; + + /** + * EntityList that searches in Entity Attributes and also in ALIASes connected by a given Relation. + * + * Uses relation ALIAS - aliasRelName -> ENTITY (usually "is_alias_name_of"). + * + * @param oc + * @param attName + * @param alistRelName + * @param useCalendar + */ + public AliasEntityList(String oc, String attName, String aliasRelName, boolean useCalendar) { + this.aliasRelName = aliasRelName; + this.entityClass = oc; + this.lo = new AliasListenerObject(oc, attName, aliasRelName); + this.useCalendar = useCalendar; + this.calendarMap = new HashMap<Long, Calendar>(); + } + + /* (non-Javadoc) + * @see de.mpiwg.itgroup.ismi.util.guiComponents.EntityList#add(org.mpi.openmind.repository.bo.Entity, org.mpi.openmind.repository.bo.Attribute) + */ + @Override + public void add(Entity e, Attribute calendarAtt) { + // check if we add an alias + if (e.getObjectClass().equals(ALIAS)) { + // get original object + List<Entity> ents = getWrapper().getTargetsForSourceRelation(e, aliasRelName, entityClass, 1); + Entity ent = ents.get(0); + if (entities.contains(ent)) { + // original is in the List -- remove it + super.remove(ent.getId()); + } + } else { + // get alias + List<Entity> ents = getWrapper().getSourcesForTargetRelation(e, aliasRelName, ALIAS, 0); + if (!ents.isEmpty()) { + for (Entity ent : ents) { + if (entities.contains(ent)) { + // alias is in the List -- leave it + return; + } + } + } + } + super.add(e, calendarAtt); + } + + +}