View Javadoc

1   /*
2    *  Copyright 2004 University of Hannover
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package olr.viewer;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import olr.rdf.Attribute;
25  import olr.rdf.Model;
26  import olr.rdf.Resource;
27  import olr.rdf.util.SortedStringList;
28  
29  /***
30   * @version $Id: InstanceFileViewer.java,v 1.11 2004/08/03 12:27:14 roku Exp $
31   */
32  public final class InstanceFileViewer extends ModelViewer {
33  
34      public InstanceFileViewer(Model model, String title) {
35          super(model, null, title);
36      }
37  
38      protected void initializeModelRows() {
39          super.modelRows = new ArrayList();
40          if (!super.expanded)
41              return;
42          Collection resources = new SortedStringList(super.model.getSubjects());
43          for (Iterator it = resources.iterator(); it.hasNext(); super.modelRows
44                  .add(new ModelViewerRow(this, it.next().toString(), 0)))
45              ;
46      }
47  
48      protected void addSubitems(int rowNr) {
49          ModelViewerRow row = (ModelViewerRow) super.modelRows.get(rowNr);
50          Resource resElement = getModel().getStatementPool().getResource(row.getResource());
51          if (resElement != null && resElement.getNS().equals(getModel().getNamespace())) {
52              int level = row.getIndent();
53              int n = 0;
54              String lastPredicate = "";
55              List attributes = resElement.getAttributes();
56              for (Iterator it = attributes.iterator(); it.hasNext();) {
57                  Attribute attribute = (Attribute) it.next();
58                  String predicate = attribute.getPredicate();
59                  if (!lastPredicate.equals(predicate))
60                      super.modelRows.add(rowNr + 1 + n++, new ModelViewerRow(this, predicate,
61                              level + 1));
62                  super.modelRows.add(rowNr + 1 + n++, new ModelViewerRow(this,
63                          attribute.getObject(), level + 2));
64                  lastPredicate = predicate;
65              }
66  
67          }
68      }
69  
70      public boolean checkSub(int rowNr) {
71          ModelViewerRow row = (ModelViewerRow) super.modelRows.get(rowNr);
72          row.setSub(false);
73          Resource resElement = getModel().getStatementPool().getResource(row.getResource());
74          if (resElement != null && resElement.getNS().equals(getModel().getNamespace())) {
75  
76              List attributes = resElement.getAttributes();
77              for (Iterator it = attributes.iterator(); it.hasNext();) {
78                  row.setSub(true);
79              }
80  
81          }
82          return row.isExpandable();
83      }
84  }