p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / propertysheet / namerelations / wizard / NameRelationWizardModel.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.propertysheet.namerelations.wizard;
11
12 import java.beans.PropertyChangeListener;
13 import java.beans.PropertyChangeSupport;
14 import java.util.List;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.model.name.NameRelationship;
19 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
20 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21 import eu.etaxonomy.cdm.model.name.ZoologicalName;
22 import eu.etaxonomy.taxeditor.model.CdmUtil;
23
24 /**
25 * @author p.ciardelli
26 * @created 05.06.2008
27 * @version 1.0
28 */
29 public class NameRelationWizardModel {
30 private static final Logger logger = Logger
31 .getLogger(NameRelationWizardModel.class);
32
33 protected static final String RELATEDNAME = "relatedname";
34 protected static final String RELATIONTYPE = "relationtype";
35
36 private TaxonNameBase baseName;
37 private TaxonNameBase relatedName;
38 private TaxonNameBase fromName;
39 private TaxonNameBase toName;
40 private NameRelationshipType type;
41 private boolean isZoological = false;
42
43 // Stores pre-existing relation, if any exists
44 private NameRelationship nameRelationship;
45 // List of the base name's relations
46 private List<NameRelationship> nameRelationsList;
47
48 private PropertyChangeSupport propertyChangeSupport;
49
50
51 public NameRelationWizardModel(TaxonNameBase baseName) {
52 this.baseName = baseName;
53 if (baseName instanceof ZoologicalName) {
54 isZoological = true;
55 }
56 this.propertyChangeSupport = new PropertyChangeSupport(this);
57 }
58
59 private void firePropertyChange(String propertyName, Object oldValue,
60 Object newValue) {
61 propertyChangeSupport.firePropertyChange(propertyName, oldValue,
62 newValue);
63 }
64
65 public void addPropertyChangeListener(String propertyName,
66 PropertyChangeListener listener) {
67 propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
68 }
69
70 public void addPropertyChangeListener(PropertyChangeListener listener) {
71 propertyChangeSupport.addPropertyChangeListener(listener);
72 }
73
74 public TaxonNameBase getBaseName() {
75 return baseName;
76 }
77
78 public void setBaseName(TaxonNameBase baseName) {
79 this.baseName = baseName;
80 }
81
82 public TaxonNameBase getRelatedName() {
83 return relatedName;
84 }
85
86 public void setRelatedName(TaxonNameBase relatedName) {
87 this.relatedName = relatedName;
88 firePropertyChange(RELATEDNAME, null, relatedName);
89 }
90
91 public TaxonNameBase getFromName() {
92 return fromName;
93 }
94
95 public void setFromName(TaxonNameBase fromName) {
96 this.fromName = fromName;
97 logger.warn("Setting from name: " + CdmUtil.getDisplayName(fromName));
98 }
99
100 public TaxonNameBase getToName() {
101 return toName;
102 }
103
104 public void setToName(TaxonNameBase toName) {
105 this.toName = toName;
106 logger.warn("Setting to name: " + CdmUtil.getDisplayName(toName));
107 }
108
109 public NameRelationshipType getType() {
110 return type;
111 }
112
113 public void setType(NameRelationshipType type) {
114 this.type = type;
115 firePropertyChange(RELATIONTYPE, null, type);
116 }
117
118 public void setRelation(NameRelationship nameRelationship) {
119 this.nameRelationship = nameRelationship;
120 }
121
122 public NameRelationship getRelation() {
123 return nameRelationship;
124 }
125
126 public void setNameRelationsList(List<NameRelationship> nameRelationsList) {
127 this.nameRelationsList = nameRelationsList;
128 }
129
130 public List<NameRelationship> getNameRelationsList() {
131 return nameRelationsList;
132 }
133
134 public boolean isZoological() {
135 return isZoological;
136 }
137 }