001 package nl.cwi.sen1.gui.plugin.data;
002
003 import java.util.Iterator;
004 import java.util.LinkedList;
005 import java.util.List;
006
007 import nl.cwi.sen1.ioapi.types.File;
008 import aterm.ATerm;
009
010 public class Module implements Comparable<Module> {
011 public static final int STATE_NORMAL = 0;
012
013 public static final int STATE_NEW = 1;
014
015 private ATerm _id;
016
017 private String _name;
018
019 private File _file;
020
021 private List<String> _parent;
022
023 private List<String> _child;
024
025 private ListModel<String> childListModel;
026
027 private ListModel<String> parentListModel;
028
029 private int State = STATE_NORMAL;
030
031 public Module(ATerm id, File file, String name) {
032 setId(id);
033 setName(name);
034 setFile(file);
035 initParentList();
036
037 childListModel = new ListModel<String>(_child);
038 parentListModel = new ListModel<String>(_parent);
039 initChildList();
040 }
041
042 public int compareTo(Module module) {
043 return _name.compareTo(module.getName());
044 }
045
046 public ATerm getId() {
047 return _id;
048 }
049
050 public String getName() {
051 return _name;
052 }
053
054 public String getAbbreviation() {
055 return _name.substring(_name.lastIndexOf('/'), -1);
056 }
057
058 private void setId(ATerm id) {
059 _id = id;
060 }
061
062 private void setName(String name) {
063 _name = name;
064 }
065
066 private void setFile(File file) {
067 _file = file;
068 }
069
070 public void addParent(String parent) {
071 _parent.add(parent);
072 parentListModel.elementAdded();
073 }
074
075 private void initParentList() {
076 _parent = new LinkedList<String>();
077 }
078
079 public Iterator<String> fetchParentIterator() {
080 return _parent.iterator();
081 }
082
083 public ListModel<String> fetchParentListModel() {
084 return parentListModel;
085 }
086
087 public void addChild(String child) {
088 _child.add(child);
089 childListModel.elementAdded();
090 }
091
092 private void initChildList() {
093 _child = new LinkedList<String>();
094 childListModel.setList(_child);
095 }
096
097 public List<String> getChildren() {
098 return _child;
099 }
100
101 public List<String> getParents() {
102 return _parent;
103 }
104
105 public Iterator<String> fetchChildIterator() {
106 return _child.iterator();
107 }
108
109 public ListModel<String> fetchChildListModel() {
110 return childListModel;
111 }
112
113 public Object[] fetchChildrenArray() {
114 return _child.toArray();
115 }
116
117 public String toString() {
118 return _name;
119 }
120
121 public int getState() {
122 return State;
123 }
124
125 public void setState(int State) {
126 this.State = State;
127 }
128
129 public File getFile() {
130 return _file;
131 }
132 }