teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model; ingo@346: ingo@945: import org.w3c.dom.Document; ingo@945: import org.w3c.dom.Element; ingo@945: import org.w3c.dom.Node; ingo@945: teichmann@5831: import org.dive4elements.artifactdatabase.state.DefaultFacet; teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5831: import org.dive4elements.artifacts.ArtifactNamespaceContext; teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; felix@6960: import org.dive4elements.river.utils.CompareUtil; felix@1624: felix@1624: /** felix@1624: * Facet with user-supplied theme-control-information (pos in list, felix@1624: * active/disabled etc) attached. felix@1624: */ weinzierl@4255: public class ManagedFacet extends DefaultFacet implements Comparable { ingo@346: felix@1624: /** The uuid of the owner artifact. */ ingo@346: protected String uuid; ingo@346: felix@1624: /** A property that determines the position of this facet. */ ingo@346: protected int position; ingo@346: felix@1624: /** A property that determines if this facet is active or not. */ ingo@346: protected int active; ingo@346: ingo@1715: /** A property that determines if this facet is visible or not. */ ingo@1715: protected int visible; ingo@1715: sascha@1061: public ManagedFacet() { sascha@1061: } ingo@346: weinzierl@4255: public ManagedFacet(String name, int index, String desc, String uuid, weinzierl@4255: int pos, int active, int visible) { aheinecke@6139: this(name, index, desc, uuid, pos, active, visible, null); aheinecke@6139: } aheinecke@6139: aheinecke@6139: public ManagedFacet(String name, int index, String desc, String uuid, aheinecke@6139: int pos, int active, int visible, String boundToOut) { ingo@694: super(index, name, desc); ingo@346: weinzierl@4255: this.uuid = uuid; ingo@346: this.position = pos; weinzierl@4255: this.active = active; weinzierl@4255: this.visible = visible; aheinecke@6139: this.boundToOut = boundToOut; ingo@346: } ingo@346: felix@1721: /** felix@1721: * Sets position (will be merged to position in ThemeList). felix@1721: */ ingo@346: public void setPosition(int pos) { ingo@346: this.position = pos; ingo@346: } ingo@346: ingo@346: public int getPosition() { ingo@346: return position; ingo@346: } ingo@346: ingo@346: public void setActive(int active) { ingo@346: this.active = active; ingo@346: } ingo@346: ingo@346: public int getActive() { ingo@346: return active; ingo@346: } ingo@346: ingo@1715: public void setVisible(int visible) { ingo@1715: this.visible = visible; ingo@1715: } ingo@1715: ingo@1715: public int getVisible() { ingo@1715: return visible; ingo@1715: } ingo@1715: felix@1721: /** felix@1721: * Get uuid of related artifact. teichmann@4736: * felix@1721: * @return uuid of related artifact. felix@1721: */ ingo@346: public String getArtifact() { ingo@346: return uuid; ingo@346: } ingo@945: ingo@945: public Node toXML(Document doc) { weinzierl@4255: ElementCreator ec = new ElementCreator(doc, ingo@945: ArtifactNamespaceContext.NAMESPACE_URI, ingo@945: ArtifactNamespaceContext.NAMESPACE_PREFIX); ingo@945: ingo@945: Element facet = ec.create("theme"); ingo@945: ec.addAttr(facet, "artifact", getArtifact(), true); ingo@945: ec.addAttr(facet, "facet", getName(), true); ingo@945: ec.addAttr(facet, "pos", String.valueOf(getPosition()), true); ingo@945: ec.addAttr(facet, "active", String.valueOf(getActive()), true); ingo@945: ec.addAttr(facet, "index", String.valueOf(getIndex()), true); ingo@945: ec.addAttr(facet, "description", getDescription(), true); ingo@1715: ec.addAttr(facet, "visible", String.valueOf(getVisible()), true); ingo@945: ingo@945: return facet; ingo@945: } sascha@1061: sascha@1061: public void set(ManagedFacet other) { weinzierl@4255: uuid = other.uuid; sascha@1061: position = other.position; weinzierl@4255: active = other.active; sascha@1061: } sascha@1061: sascha@3076: @Override sascha@1061: public Facet deepCopy() { sascha@1061: ManagedFacet copy = new ManagedFacet(); weinzierl@4255: copy.set((DefaultFacet) this); weinzierl@4255: copy.set((ManagedFacet) this); sascha@1061: return copy; sascha@1061: } weinzierl@4255: weinzierl@4255: @Override weinzierl@4255: public int compareTo(Object o) { weinzierl@4255: if (!(o instanceof ManagedFacet)) { weinzierl@4255: return -1; weinzierl@4255: } weinzierl@4255: weinzierl@4255: ManagedFacet other = (ManagedFacet) o; weinzierl@4255: weinzierl@4255: if (position < other.position) { weinzierl@4255: return -1; weinzierl@4255: } weinzierl@4255: else if (position > other.position) { weinzierl@4255: return 1; weinzierl@4255: } weinzierl@4255: else { weinzierl@4255: return 0; weinzierl@4255: } weinzierl@4255: } felix@6960: felix@6960: /** felix@6960: * Returns true if the other is likely the same facet. felix@6960: * This happens if a facet is defined for two outs. felix@6960: */ felix@6960: public boolean isSame(Object other) { felix@6960: if (!(other instanceof ManagedFacet)) { felix@6960: return false; felix@6960: } felix@6960: ManagedFacet otherFacet = (ManagedFacet) other; felix@6960: return this.getVisible() == otherFacet.getVisible() && felix@6960: this.getActive() == otherFacet.getActive() && felix@6960: CompareUtil.areSame(this.getArtifact(), otherFacet.getArtifact()) && felix@6960: this.getIndex() == otherFacet.getIndex() && felix@6960: CompareUtil.areSame(this.getName(), otherFacet.getName()) && felix@6960: CompareUtil.areSame(this.getBoundToOut(), otherFacet.getBoundToOut()) && felix@6960: CompareUtil.areSame(this.getDescription(), otherFacet.getDescription()); felix@6960: // Missing properties are blackboard, data, position. felix@6960: } ingo@346: } ingo@346: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :