View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: TemplateGroupTreeEntry.java
13   * Created: 2009-09-17
14   * Author: kpietak
15   * $Id$
16   */
17  
18  package pl.edu.agh.cast.importer.wizard.template;
19  
20  import java.util.ArrayList;
21  import java.util.Collection;
22  
23  import pl.edu.agh.cast.importer.base.template.ImportTemplateGroup;
24  
25  /**
26   * Entry used in TreeViewer as a model. Wraps {@link ImportTemplateGroup}.
27   * 
28   * @author AGH CAST Team
29   */
30  public class TemplateGroupTreeEntry implements ITreeEntry {
31  
32  	private final ImportTemplateGroup element;
33  
34  	private final Collection<TemplateTreeEntry> children;
35  
36  	private final Collection<TemplateGroupTreeEntry> parent;
37  
38  	public TemplateGroupTreeEntry(ImportTemplateGroup element, Collection<TemplateGroupTreeEntry> parent) {
39  		if (element == null || parent == null) {
40  			throw new IllegalArgumentException();
41  		}
42  		this.element = element;
43  		this.parent = parent;
44  		this.children = new ArrayList<TemplateTreeEntry>(element.getTemplates().size());
45  	}
46  
47  	public ImportTemplateGroup getElement() {
48  		return element;
49  	}
50  
51  	public Collection<TemplateTreeEntry> getChildren() {
52  		return children;
53  	}
54  
55  	public Collection<TemplateGroupTreeEntry> getParent() {
56  		return parent;
57  	}
58  
59  	public boolean addChild(TemplateTreeEntry template) {
60  		return children.add(template);
61  	}
62  
63  	public boolean removeChild(TemplateTreeEntry template) {
64  		return children.remove(template);
65  	}
66  
67  	/**
68  	 * {@inheritDoc}
69  	 * 
70  	 * @see pl.edu.agh.cast.importer.wizard.template.ITreeEntry#getText()
71  	 */
72  	@Override
73  	public String getText() {
74  		return element.getName();
75  	}
76  
77  }