1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package olr.viewer;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import olr.rdf.AbstractStatementPool;
24 import olr.rdf.Attribute;
25 import olr.rdf.Model;
26 import olr.rdf.OLR3Definitions;
27 import olr.rdf.Resource;
28
29 /***
30 * @version $Id: CourseViewer.java,v 1.17 2004/08/03 12:47:49 roku Exp $
31 */
32 public final class CourseViewer extends ModelViewer {
33
34 private final boolean isAuthor;
35
36 /***
37 * Initializes an instance of this class.
38 * @param model
39 * @param root
40 * @param title
41 * @param isAuthor
42 */
43 public CourseViewer(Model model, String root, String title, boolean isAuthor) {
44 super(model, root, title);
45 this.isAuthor = isAuthor;
46 }
47
48 private boolean isAuthor() {
49 return this.isAuthor;
50 }
51
52 public boolean isExpanded() {
53 return true;
54 }
55
56 protected void initializeModelRows() {
57 super.modelRows = new ArrayList();
58 if (getRoot() != null) {
59 super.modelRows.add(new CourseViewerRow(this, getRoot(), 0));
60 } else {
61 Resource courseClass = super.model.getStatementPool().getResource(
62 OLR3Definitions.OLR3_ROOT);
63 if (AbstractStatementPool.isClass(courseClass)) {
64 for (Iterator it = courseClass.getInstance().iterator(); it.hasNext(); super.modelRows
65 .add(new CourseViewerRow(this, it.next().toString(), 0)))
66 ;
67 }
68 }
69 for (int i = getModelRows().size() - 1; i >= 0; i--)
70 expandResource(i);
71
72 }
73
74 protected void addSubitems(int rowNr) {
75 CourseViewerRow row = (CourseViewerRow) super.modelRows.get(rowNr);
76 Resource subjectObj = getModel().getStatementPool().getResource(row.getResource());
77 if (subjectObj != null && super.model.getSubjects().contains(subjectObj.getType())) {
78 int level = row.getIndent();
79 int n = 0;
80 String lastPredicate = "";
81 List attributes;
82 if (isAuthor())
83 attributes = subjectObj.getAttributes();
84 else
85 attributes = (new SequenceAttributes(subjectObj.getAttributes())).getAttributes();
86 Iterator it = attributes.iterator();
87 do {
88 if (!it.hasNext())
89 break;
90 Attribute attribute = (Attribute) it.next();
91 String predicate = attribute.getPredicate();
92 String object = attribute.getObject();
93 Resource objectObj = getModel().getStatementPool().getResource(object);
94 if (super.model.getSubjects().contains(predicate) && objectObj != null
95 && super.model.getSubjects().contains(objectObj.getType())) {
96 if (!lastPredicate.equals(predicate))
97 super.modelRows.add(rowNr + 1 + n++, new CourseViewerRow(this, predicate,
98 level + 1, true));
99 super.modelRows.add(rowNr + 1 + n++, new CourseViewerRow(this, object,
100 level + 2));
101 lastPredicate = predicate;
102 }
103 } while (true);
104 }
105 }
106
107 public boolean checkSub(int rowNr) {
108 CourseViewerRow row = (CourseViewerRow) super.modelRows.get(rowNr);
109 Resource subjectObj = getModel().getStatementPool().getResource(row.getResource());
110 row.setSub(false);
111 if (subjectObj != null && super.model.getSubjects().contains(subjectObj.getType())) {
112
113 List attributes;
114 if (isAuthor())
115 attributes = subjectObj.getAttributes();
116 else
117 attributes = (new SequenceAttributes(subjectObj.getAttributes())).getAttributes();
118 Iterator it = attributes.iterator();
119 do {
120 if (!it.hasNext())
121 break;
122 Attribute attribute = (Attribute) it.next();
123 String predicate = attribute.getPredicate();
124 String object = attribute.getObject();
125 Resource objectObj = getModel().getStatementPool().getResource(object);
126 if (super.model.getSubjects().contains(predicate) && objectObj != null
127 && super.model.getSubjects().contains(objectObj.getType())) {
128 row.setSub(true);
129 }
130 } while (true);
131 }
132 return row.isExpandable();
133 }
134 }