View Javadoc

1   /*
2    * $Id: OWLLabelProvider.java,v 1.17 2005/06/01 17:38:35 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.IResource;
11  import org.eclipse.jdt.ui.JavaUI;
12  import org.eclipse.jface.viewers.LabelProvider;
13  import org.eclipse.swt.graphics.Image;
14  import org.eclipse.ui.ide.IDE;
15  import org.eclipse.ui.internal.SharedImages;
16  import org.eclipse.ui.model.WorkbenchLabelProvider;
17  
18  import com.bbn.swede.core.IOWLClass;
19  import com.bbn.swede.core.IOWLDocument;
20  import com.bbn.swede.core.IOWLElement;
21  import com.bbn.swede.core.IOWLExternalDocument;
22  import com.bbn.swede.core.IOWLFolder;
23  import com.bbn.swede.core.IOWLLibrary;
24  import com.bbn.swede.core.IOWLProject;
25  import com.bbn.swede.core.IOWLProperty;
26  
27  
28  /***
29   * <p>Supplies text and icons for OWL elements, as well as  standard icons for 
30   * ordinary Eclipse resources.</p>
31   * 
32   * <p>This class introduces a dependency with the org.eclipse.jdt.ui plug-in
33   * to use the standard Eclipse library image for SWeDE libraries.</p>
34   * 
35   * @author jlerner
36   * @author aperezlo
37   */
38  public class OWLLabelProvider extends LabelProvider
39  {
40     private WorkbenchLabelProvider _workbenchLabelProvider = new WorkbenchLabelProvider();
41     /*
42      *  (non-Javadoc)
43      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
44      */
45     public Image getImage(Object element)
46     {
47        SharedImages images = new SharedImages();
48        if (element instanceof IOWLProject)
49        {
50           if (((IOWLProject)element).getProject().isOpen())
51           {
52              return OWLImages.getSharedImage(OWLImages.IMG_OWLPROJ_OBJ);
53           }
54           else
55           {
56              return images.getImage(IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED);
57           }
58        }
59           
60        if (element instanceof IOWLFolder)
61        {
62           return OWLImages.getSharedImage(OWLImages.IMG_OWLFOLD_OBJ);
63        }
64        if (element instanceof IOWLExternalDocument)
65        {
66           return OWLImages.getSharedImage(OWLImages.IMG_OWL_EXT_OBJ);
67        }
68        if (element instanceof IOWLDocument)
69        {
70           return OWLImages.getSharedImage(OWLImages.IMG_OWL_OBJ);
71        }
72        if (element instanceof IOWLClass)
73        {
74           return OWLImages.getSharedImage(OWLImages.IMG_CLASS_OBJ);
75        }
76        if (element instanceof IOWLProperty)
77        {
78           return OWLImages.getSharedImage(OWLImages.IMG_PROP_OBJ);
79        }
80        if(element instanceof IOWLLibrary)
81        {
82           return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_LIBRARY);
83        }
84  
85  
86        return _workbenchLabelProvider.getImage(element);
87     }
88  
89     /*
90      *  (non-Javadoc)
91      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
92      */
93     public String getText(Object element)
94     {
95        // shouldn't ever return this, because the content provider should weed them out...
96        String toReturn = "Anonymous";   
97        if (element instanceof IOWLElement)
98        {
99           if(element instanceof IOWLProperty)
100          {
101             if(!((IOWLProperty)element).isAnonymous())
102             {
103                toReturn = ((IOWLElement) element).getElementName();
104             }
105          }
106          else if(element instanceof IOWLClass)
107          {
108             if(!((IOWLClass)element).isAnonymous())
109             {
110                toReturn = ((IOWLElement) element).getElementName();
111             }
112          }
113          else 
114          {
115             toReturn = ((IOWLElement) element).getElementName();
116          }
117       }
118       else if (element instanceof IResource)
119       {
120          toReturn = ((IResource) element).getName();
121       }
122       return toReturn;
123    }
124 
125    /* (non-Javadoc)
126     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
127     */
128    public void dispose()
129    {
130 
131    }
132 
133 }