View Javadoc

1   /*
2    *  File: RelationalInterval.java 
3    *  Copyright (c) 2004-2008  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.util.ui.timebars.model;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import de.jaret.util.date.IntervalImpl;
26  
27  /**
28   * Simple implementation of the relational interval based on the standard interval. Handles the relation when a relation
29   * is removed (setting the appropriate field in the relation to <code>null</code>. Does handle
30   * 
31   * @author kliem
32   * @version $Id: RelationalInterval.java 800 2008-12-27 22:27:33Z kliem $
33   */
34  public class RelationalInterval extends IntervalImpl implements IRelationalInterval {
35      /** list of relations. */
36      protected List<IIntervalRelation> _relations = new ArrayList<IIntervalRelation>();
37  
38      /**
39       * {@inheritDoc}
40       */
41      public void addRelation(IIntervalRelation relation) {
42          if (!_relations.contains(relation)) {
43              _relations.add(relation);
44              firePropertyChange(RELATIONS, null, relation);
45          }
46      }
47  
48      /**
49       * {@inheritDoc}
50       */
51      public List<IIntervalRelation> getRelations() {
52          return _relations;
53      }
54  
55      /**
56       * {@inheritDoc}. Removes the reference from the relation.
57       */
58      public void removeRelation(IIntervalRelation relation) {
59          if (_relations.contains(relation)) {
60              _relations.remove(relation);
61              if (relation.getStartInterval() == this) {
62                  relation.setStartInterval(null);
63              }
64              if (relation.getEndInterval() == this) {
65                  relation.setEndInterval(null);
66              }
67              firePropertyChange(RELATIONS, relation, null);
68          }
69      }
70  
71  }