View Javadoc
1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.ui.views.navigator;
26  
27  import org.omwg.ontology.Concept;
28  
29  import java.util.Set;
30  
31  /***
32   * An extension of <code>WSMOContentProvider</code> which enables the visualization
33   * of attributes as descendants of the representation of their containing concept.
34   *
35   * @author not attributable
36   * @version $Revision: 1.3 $ $Date: 2006/01/09 12:51:14 $
37   */
38  
39  public class AttributesContentProvider extends WSMOContentProvider {
40  
41      public AttributesContentProvider() {
42          super(CONCEPT_MASK | ONTOLOGY_MASK | ATTRIBUTE_MASK);
43      }
44  
45      public Object[] getChildren(Object parentElement) {
46          Object[] result = super.getChildren(parentElement);
47          if (parentElement instanceof Concept) {
48              Set attrs = ((Concept)parentElement).listAttributes();
49              if (attrs.size() > 0) {
50                  if (result == null || result.length == 0) {
51                      return attrs.toArray();
52                  }
53                  Object[] newResult = new Object[result.length + attrs.size()];
54                  System.arraycopy(result, 0, newResult, 0, result.length);
55                  System.arraycopy(attrs.toArray(), 0, newResult, result.length, attrs.size());
56                  return newResult;
57              }
58          }
59          return result;
60      }
61      
62      public boolean hasChildren(Object element) {
63          if (element instanceof Concept) {
64              if (((Concept)element).listAttributes().size() > 0) {
65                  return true;
66              }
67          }
68          return super.hasChildren(element);
69      }
70  }
71  
72  /*
73   * $Log: AttributesContentProvider.java,v $
74   * Revision 1.3  2006/01/09 12:51:14  alex_simov
75   * Copyright message in header updated
76   *
77   * Revision 1.2  2005/07/29 15:08:03  alex_simov
78   * added javadoc: class description, footer
79   *
80   *
81   */