View Javadoc

1   /*
2    * $Id: OWLSorter.java,v 1.6 2004/09/20 15:31:34 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   package com.bbn.swede.ui;
9   
10  import org.eclipse.core.resources.IFolder;
11  import org.eclipse.jface.viewers.ViewerSorter;
12  
13  import com.bbn.swede.core.IOWLClass;
14  import com.bbn.swede.core.IOWLDocument;
15  import com.bbn.swede.core.IOWLFolder;
16  import com.bbn.swede.core.IOWLProperty;
17  
18  
19  /***
20   * Provides custom categorizations for sorting OWL elements.
21   * 
22   * The default sorting behavior for ViewerSorter is to do a primary sort based
23   * on category number and a secondary sort using case-insensitive comparisons
24   * of element labels, so defining categories is sufficient for OWL sorting.
25   * @author jlerner
26   */
27  public class OWLSorter extends ViewerSorter
28  {
29     /*
30      *  (non-Javadoc)
31      * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
32      */
33     public int category(Object element)
34     {
35        if (element instanceof IOWLFolder)
36        {
37           return 0;
38        }
39        if (element instanceof IFolder)
40        {
41           return 1;
42        }
43        if (element instanceof IOWLDocument)
44        {
45           return 2;
46        }
47        if (element instanceof IOWLClass || element instanceof IOWLProperty)
48        {
49           return 3;
50        }
51        return 4;
52     }
53  
54  }