View Javadoc

1   /*
2    * $Id: DumpOnt.java,v 1.6 2005/07/07 19:02:42 jlerner Exp $
3    * Created on Apr 28, 2004
4    *
5    * Copyright (c) 1999-2004, BBN Technologies, LLC.
6    * All rights reserved.
7    * http://www.daml.org/legal/opensource/bbn_license.html
8    */
9   
10  package com.bbn.swede.library.dumpont;
11  
12  import org.daml.rdf.dumpont.core.Class;
13  import org.daml.rdf.dumpont.core.Ontology;
14  import org.daml.rdf.dumpont.core.OntologyReader;
15  import org.daml.rdf.dumpont.core.Property;
16  import org.eclipse.jface.util.IPropertyChangeListener;
17  import org.eclipse.jface.util.PropertyChangeEvent;
18  import org.eclipse.jface.viewers.DoubleClickEvent;
19  import org.eclipse.jface.viewers.IDoubleClickListener;
20  import org.eclipse.jface.viewers.ISelection;
21  import org.eclipse.jface.viewers.IStructuredSelection;
22  import org.eclipse.jface.viewers.TreeViewer;
23  import org.eclipse.swt.widgets.Composite;
24  import org.eclipse.ui.IEditorInput;
25  import org.eclipse.ui.IEditorSite;
26  import org.eclipse.ui.ISelectionListener;
27  import org.eclipse.ui.IWorkbenchPage;
28  import org.eclipse.ui.IWorkbenchPart;
29  import org.eclipse.ui.PartInitException;
30  
31  import com.bbn.swede.core.OWLCore;
32  import com.bbn.swede.core.dom.OASTEvent;
33  import com.bbn.swede.editor.OWLEditor;
34  import com.bbn.swede.editor.OWLEditorInput;
35  import com.bbn.swede.editor.OWLVisualEditor;
36  
37  /***
38   * Wraps DumpOnt as a visualization page for the multi-page OWL editor.  It
39   * populates a JFace TreeViewer with a class and property hierarchy generated
40   * by the dumpont core.
41   * @author Dmoore
42   * @author jlerner
43   * @author rblace
44   */
45  public class DumpOnt extends OWLVisualEditor
46     implements IDoubleClickListener, IPropertyChangeListener, ISelectionListener
47  {
48     /***
49      * The tree control that displays the DumpOnt results.
50      */
51     protected TreeViewer _treeViewer;
52     /***
53      * The input for the OWL editor.
54      */
55     protected IEditorInput _editorInput;
56  
57     /*
58      *  (non-Javadoc)
59      * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
60      */
61     public void init(IEditorSite site, IEditorInput input)
62        throws PartInitException
63     {
64        super.init(site, input);
65        _editorInput = input;
66     }
67  
68     /* (non-Javadoc)
69      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
70      */
71     public void createPartControl(Composite parent)
72     {
73        _treeViewer = new TreeViewer(parent);
74        _treeViewer.setLabelProvider(new DumpOntLabelProvider());
75        _treeViewer.setContentProvider(new DumpOntContentProvider());
76        _treeViewer.setUseHashlookup(true);
77        _treeViewer.addDoubleClickListener(this);
78        getSite().setSelectionProvider(_treeViewer);
79        getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(
80           (ISelectionListener)this);
81  
82     }
83  
84     /***
85      * Adapts the Jena model associated with the editor's file into dumpont's
86      * representation of an ontology.
87      * @return An org.daml.rdf.dumpont.core.Ontology containing the document's
88      *         class and property hierarchies
89      */
90     private Ontology parseInput()
91     {
92        OntologyReader or = OntologyReader.newReader();
93        Ontology ont = null;
94        com.hp.hpl.jena.rdf.model.Model model = 
95           ((OWLEditorInput) _editorInput).getModel();
96  
97        ont = or.parseOntology(model, ((OWLEditorInput) _editorInput).getOAST().getBaseURI());
98        return ont;
99     }
100 
101 
102    /* (non-Javadoc)
103     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
104     */
105    public void propertyChange(PropertyChangeEvent event)
106    {
107    }
108 
109    /* (non-Javadoc)
110     * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
111     */
112    public void doubleClick(DoubleClickEvent event)
113    {
114       IStructuredSelection sel = (IStructuredSelection) event.getSelection();
115       if (sel.size() != 1)
116       {
117          return;
118       }
119       Object elem = sel.getFirstElement();
120       IWorkbenchPage page = this.getSite().getPage();
121       if (elem instanceof Class)
122       {
123          Class klass = (Class)elem;
124          ((OWLEditor)page.getActiveEditor()).goToURI(klass.getNode().getURI());
125       }
126       else if (elem instanceof Property)
127       {
128          Property prop = (Property)elem;
129          ((OWLEditor)page.getActiveEditor()).goToURI(prop.getNode().getURI());
130       }
131 
132    }
133 
134    /* (non-Javadoc)
135     * @see org.eclipse.ui.ISelectionListener#selectionChanged(
136     *       org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
137     */
138    public void selectionChanged(IWorkbenchPart part, ISelection selection)
139    {
140    }
141 
142    /* (non-Javadoc)
143     * @see com.bbn.swede.editor.IVisualizationPage#activate()
144     */
145    public void populate()
146    {
147       Ontology ont = parseInput();
148       _treeViewer.setInput(ont);
149       _treeViewer.expandAll();
150    }
151 
152    public void oastChanged(OASTEvent event)
153    {
154       //Only update as changes come in if this page is visible
155       if (isActivePage())
156       {
157          OWLCore.trace(DumpOntPlugin.getID(), "Repopulating DumpOnt...", false);
158          populate();
159       }
160    }
161 
162    public void setFocus()
163    {
164       super.setFocus();
165       populate();
166    }
167 
168 }