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.List;
21
22 import olr.rdf.Model;
23
24 /***
25 * @version $Id: ModelViewer.java,v 1.13 2004/08/03 16:01:15 roku Exp $
26 */
27 public abstract class ModelViewer {
28 private final String root;
29
30 ModelViewer(Model model, String root, String title) {
31 this.title = "";
32 this.model = null;
33 expanded = false;
34 modelRows = new ArrayList();
35 this.model = model;
36 this.root = root;
37 this.title = title;
38 model.getStatementPool().addParsedNamespaceURI(model.getNamespace(), title);
39 initializeModelRows();
40 }
41
42 protected final String getRoot() {
43 return this.root;
44 }
45
46 public Model getModel() {
47 return model;
48 }
49
50 public String getNamespace() {
51 return getModel().getNamespace();
52 }
53
54 public String getTitle() {
55 return title;
56 }
57
58 public String getResource(int rowNr) {
59 if (rowNr >= 0 && rowNr < modelRows.size())
60 return ((ModelViewerRow) modelRows.get(rowNr)).getResource();
61 else
62 return null;
63 }
64
65 public void expand() {
66 expanded = !expanded;
67 initializeModelRows();
68 }
69
70 public boolean isExpanded() {
71 return expanded;
72 }
73
74 public void expandResource(int rowNr) {
75 if (rowNr < 0 || rowNr >= modelRows.size())
76 return;
77 final ModelViewerRow row = (ModelViewerRow) modelRows.get(rowNr);
78 if (row.isPredicate())
79 return;
80 if (row.isExpanded()) {
81 int i = rowNr + 1;
82 do {
83 if (i >= modelRows.size())
84 break;
85 ModelViewerRow subrow = (ModelViewerRow) modelRows.get(i);
86 if (subrow.getIndent() <= row.getIndent())
87 break;
88 modelRows.remove(i);
89 } while (true);
90 } else {
91 addSubitems(rowNr);
92 }
93 row.expand();
94 }
95
96 public void updateResource(String resource) {
97 if (resource == null)
98 return;
99 for (int i = modelRows.size() - 1; i >= 0; i--) {
100 ModelViewerRow row = (ModelViewerRow) modelRows.get(i);
101 if (row.isExpanded() && resource.equals(row.getResource())) {
102 expandResource(i);
103 expandResource(i);
104 }
105 }
106
107 }
108
109 public boolean isExpanded(int rowNr) {
110 if (rowNr < 0 || rowNr >= modelRows.size())
111 return false;
112 else
113 return ((ModelViewerRow) modelRows.get(rowNr)).isExpanded();
114 }
115
116 public List getModelRows() {
117 return modelRows;
118 }
119
120 public void expandAllResource(int rowNr) {
121 if (rowNr < 0 || rowNr >= modelRows.size())
122 return;
123 ModelViewerRow row = (ModelViewerRow) modelRows.get(rowNr);
124 if (row.isPredicate())
125 return;
126 if (!row.isExpanded()) {
127 addSubitems(rowNr);
128 row.expand();
129 }
130 }
131
132 protected abstract void initializeModelRows();
133
134 protected abstract void addSubitems(int i);
135
136 public abstract boolean checkSub(int rowNr);
137
138 protected String title;
139
140 protected Model model;
141
142 protected boolean expanded;
143
144 protected List modelRows;
145 }