View Javadoc

1   /*
2    * $Id: URIExplorer.java,v 1.48 2005/06/01 20:45:38 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   
9   package com.bbn.swede.view.uriexplorer.ui;
10  
11  import java.net.URL;
12  import java.util.ArrayList;
13  import java.util.Iterator;
14  
15  import org.eclipse.core.resources.ICommand;
16  import org.eclipse.core.resources.IContainer;
17  import org.eclipse.core.resources.IFile;
18  import org.eclipse.core.resources.IFolder;
19  import org.eclipse.core.resources.IProject;
20  import org.eclipse.core.resources.IProjectDescription;
21  import org.eclipse.core.resources.IResource;
22  import org.eclipse.core.resources.IResourceChangeEvent;
23  import org.eclipse.core.resources.IResourceChangeListener;
24  import org.eclipse.core.resources.IResourceDelta;
25  import org.eclipse.core.resources.IWorkspace;
26  import org.eclipse.core.resources.IWorkspaceRoot;
27  import org.eclipse.core.resources.ResourcesPlugin;
28  import org.eclipse.core.runtime.CoreException;
29  import org.eclipse.core.runtime.IAdaptable;
30  import org.eclipse.jface.action.Action;
31  import org.eclipse.jface.action.IAction;
32  import org.eclipse.jface.action.IMenuListener;
33  import org.eclipse.jface.action.IMenuManager;
34  import org.eclipse.jface.action.MenuManager;
35  import org.eclipse.jface.action.Separator;
36  import org.eclipse.jface.dialogs.MessageDialog;
37  import org.eclipse.jface.resource.ImageDescriptor;
38  import org.eclipse.jface.viewers.DecoratingLabelProvider;
39  import org.eclipse.jface.viewers.DoubleClickEvent;
40  import org.eclipse.jface.viewers.IDoubleClickListener;
41  import org.eclipse.jface.viewers.ISelection;
42  import org.eclipse.jface.viewers.ISelectionChangedListener;
43  import org.eclipse.jface.viewers.IStructuredSelection;
44  import org.eclipse.jface.viewers.ITreeViewerListener;
45  import org.eclipse.jface.viewers.SelectionChangedEvent;
46  import org.eclipse.jface.viewers.StructuredSelection;
47  import org.eclipse.jface.viewers.TreeExpansionEvent;
48  import org.eclipse.jface.viewers.TreeViewer;
49  import org.eclipse.swt.dnd.Clipboard;
50  import org.eclipse.swt.widgets.Composite;
51  import org.eclipse.swt.widgets.Menu;
52  import org.eclipse.swt.widgets.Shell;
53  import org.eclipse.ui.IActionBars;
54  import org.eclipse.ui.IMemento;
55  import org.eclipse.ui.IViewSite;
56  import org.eclipse.ui.IWorkbenchActionConstants;
57  import org.eclipse.ui.IWorkbenchPage;
58  import org.eclipse.ui.IWorkbenchWindow;
59  import org.eclipse.ui.PartInitException;
60  import org.eclipse.ui.PlatformUI;
61  import org.eclipse.ui.actions.ActionFactory;
62  import org.eclipse.ui.actions.CloseResourceAction;
63  import org.eclipse.ui.actions.CopyResourceAction;
64  import org.eclipse.ui.actions.DeleteResourceAction;
65  import org.eclipse.ui.actions.NewWizardMenu;
66  import org.eclipse.ui.actions.RefreshAction;
67  import org.eclipse.ui.dialogs.PropertyDialogAction;
68  import org.eclipse.ui.ide.IDE;
69  import org.eclipse.ui.ide.IDEActionFactory;
70  import org.eclipse.ui.part.ISetSelectionTarget;
71  import org.eclipse.ui.part.ViewPart;
72  import org.eclipse.ui.views.navigator.ResourceNavigatorActionGroup;
73  import org.osgi.framework.Bundle;
74  
75  import com.bbn.swede.core.IOWLClass;
76  import com.bbn.swede.core.IOWLDocument;
77  import com.bbn.swede.core.IOWLElement;
78  import com.bbn.swede.core.IOWLFolder;
79  import com.bbn.swede.core.IOWLLibrary;
80  import com.bbn.swede.core.IOWLModel;
81  import com.bbn.swede.core.IOWLProject;
82  import com.bbn.swede.core.IOWLProperty;
83  import com.bbn.swede.core.OWLCore;
84  import com.bbn.swede.core.OWLDocumentInfo;
85  import com.bbn.swede.core.OWLNature;
86  import com.bbn.swede.core.dom.IOASTChangeListener;
87  import com.bbn.swede.core.dom.IOWLAbstractSyntaxTree;
88  import com.bbn.swede.core.dom.OASTEvent;
89  import com.bbn.swede.core.resources.SWResourceManager;
90  import com.bbn.swede.editor.OWLEditor;
91  import com.bbn.swede.tools.ToolsPlugin;
92  import com.bbn.swede.ui.OWLLabelProvider;
93  import com.bbn.swede.ui.OWLSorter;
94  import com.bbn.swede.view.ViewPlugin;
95  import com.bbn.swede.view.uriexplorer.core.URIExplorerContentProvider;
96  import com.hp.hpl.jena.rdf.model.Resource;
97  
98  /***
99   * A Semantic Web-oriented view of the eclipse workspace.  URI Explorer allows 
100  * the user to access various semantic web features via context menu
101  * and drill down into OWL documents to see a list of the classes and 
102  * properties it contains.
103  * @author jlerner
104  * @author tself
105  */
106 public class URIExplorer
107    extends ViewPart
108    implements IDoubleClickListener, IMenuListener, ISelectionChangedListener, 
109               ISetSelectionTarget, ITreeViewerListener
110 {
111    private static final String TAG_EXPANSION_STATE = "TAG_EXPANSION_STATE";
112    private static final String TAG_EXPANDED_ELEMENT = "TAG_EXPANDED_ELEMENT";
113    private static final String TAG_PATH = "TAG_PATH";
114    /***
115     * The main tree view for URI explorer.
116     */
117    protected TreeViewer _tree;
118    private ResourceNavigatorActionGroup _actionGroup;
119    private IAction _actionDelete;
120    private IAction _actionCopy;
121    private IAction _actionPaste;
122    private IAction _actionRefresh;
123    private IAction _actionProperties;
124    private IAction _actionLibraryRefresh;
125    private IAction _actionClose;
126    private IAction _actionImport;
127    private IAction _actionExport;
128    private IAction _actionCloseProject;
129    private IAction _actionOpenProject;
130    private IAction _actionMigrateProject;
131    
132    private ViewChangeListener _viewUpdater;
133 
134    private IMemento _memento;
135 
136    private URIExplorerContentProvider _content;
137    
138    private IWorkbenchWindow _window;
139    
140    /*
141     *  (non-Javadoc)
142     * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
143     */
144    public void createPartControl(Composite parent)
145    {
146       IWorkspace workspace = ResourcesPlugin.getWorkspace();
147       IWorkspaceRoot wsroot = workspace.getRoot();
148       try
149       {
150          _content = new URIExplorerContentProvider();
151          _tree = new TreeViewer(parent);
152          _tree.setContentProvider(_content);
153          _tree.setLabelProvider(new DecoratingLabelProvider(new OWLLabelProvider(), new URIExplorerLabelDecorator()));
154          _tree.setSorter(new OWLSorter());
155          IOWLModel model = SWResourceManager.getModel();
156          _tree.setInput(model);
157          _tree.addSelectionChangedListener(this);
158          _tree.addTreeListener(this);
159          //Adding this listener after requesting the model ensures that
160          //URI explorer gets notified of workspace changes after the
161          //OWL model has already had a chance to update itself
162          _viewUpdater = new ViewChangeListener();
163          workspace.addResourceChangeListener(_viewUpdater);
164          _tree.addDoubleClickListener(this);
165          getViewSite().setSelectionProvider(_tree);
166       }
167       finally
168       {
169       }
170       // add context menu
171       initContextMenu();
172       restoreState(_memento);
173    }
174    
175    /***
176     * Creates standard actions (copy, delete, open/close project, etc.) for 
177     * the context menu.
178     */
179    private void initActions()
180    {
181       IWorkbenchWindow window = getViewSite().getWorkbenchWindow();
182       Shell shell = this.getViewSite().getWorkbenchWindow().getShell();
183       Clipboard clipboard = new Clipboard(shell.getDisplay());
184       IActionBars bars = getViewSite().getActionBars();
185 
186       _actionDelete = ActionFactory.DELETE.create(window);
187       IAction handler = new DeleteResourceAction(shell);
188       _tree.addSelectionChangedListener((ISelectionChangedListener)handler);
189       bars.setGlobalActionHandler(ActionFactory.DELETE.getId(), handler);
190 
191       //TODO: make the copy action behave like it does in Package Explorer
192       //TODO: add a paste action so that doing the above doesn't render Copy useless
193       handler = new CopyResourceAction(shell);
194       _tree.addSelectionChangedListener((ISelectionChangedListener) handler);
195       _actionCopy = ActionFactory.COPY.create(window);
196       bars.setGlobalActionHandler(ActionFactory.COPY.getId(), handler);
197       
198       handler = new RefreshAction(shell);
199       _actionRefresh = ActionFactory.REFRESH.create(window);
200       Bundle bundle = ViewPlugin.getPlugin().getBundle();
201       URL url = bundle.getEntry("/icons/refresh.gif");
202       _actionRefresh.setImageDescriptor(ImageDescriptor.createFromURL(url)); //$NON-NLS-1$ 
203       bars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), handler);
204 
205       _actionClose = new CloseResourceAction(shell);
206       _tree.addSelectionChangedListener((ISelectionChangedListener) _actionClose);
207 
208 
209       _actionProperties = ActionFactory.PROPERTIES.create(window);
210 
211       bars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(),
212          new PropertyDialogAction(getViewSite().getShell(), getViewSite()
213             .getSelectionProvider()));
214       
215       _actionImport = ActionFactory.IMPORT.create(window);
216       _actionExport = ActionFactory.EXPORT.create(window);
217 
218 //      _actionLibraryRefresh = new LibraryRefreshAction("Refresh");
219 //      _tree.addSelectionChangedListener((ISelectionChangedListener) _actionLibraryRefresh);
220       
221       handler = new CloseResourceAction(shell);
222       _tree.addSelectionChangedListener(
223          (ISelectionChangedListener) handler);
224       _actionCloseProject = IDEActionFactory.CLOSE_PROJECT.create(window);
225       bars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), handler);
226       handler = new OpenProjectAction();
227       _actionOpenProject = IDEActionFactory.OPEN_PROJECT.create(window);
228       bars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), handler);
229       
230       _actionMigrateProject = new MigrateProjectAction();
231       
232       
233    }
234    
235    /*
236     *  (non-Javadoc)
237     * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(
238     *       org.eclipse.jface.viewers.SelectionChangedEvent)
239     */
240    public void selectionChanged(SelectionChangedEvent e)
241    {
242    }
243    
244    /***
245     * Initializes the context menu.  No actions are added to the menu until
246     * it is actually shown.
247     * @see #menuAboutToShow(IMenuManager)
248     */
249    protected void initContextMenu()
250    {
251       MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
252       menuMgr.setRemoveAllWhenShown(true);
253       menuMgr.addMenuListener(this);
254       Menu menu = menuMgr.createContextMenu(_tree.getControl());
255       _tree.getControl().setMenu(menu);
256       getSite().registerContextMenu(menuMgr, _tree);
257       initActions();
258    }
259    
260    /*
261     *  (non-Javadoc)
262     * @see org.eclipse.ui.IViewPart#saveState(org.eclipse.ui.IMemento)
263     */
264    public void saveState(IMemento memento)
265    {
266       Object element = null;
267       IResource res = null;
268       Object[] expandedElements = _tree.getVisibleExpandedElements();
269       if (expandedElements.length > 0)
270       {
271          IMemento expandedMem = memento.createChild(TAG_EXPANSION_STATE);
272          for (int i = 0; i < expandedElements.length; i++)
273          {
274             IMemento elementMem = expandedMem.createChild(TAG_EXPANDED_ELEMENT);
275             element = expandedElements[i];
276             if (element instanceof IResource)
277             {
278                res = (IResource) element;
279             }
280             else if (element instanceof IOWLElement)
281             {
282                res = ((IOWLElement) element).getResource();
283             }
284             elementMem.putString(TAG_PATH, res.getFullPath().toString());
285          }
286       }
287    }
288 
289    /***
290     * Restores the view's state from a memento.
291     * @param memento A memento containing the view state
292     */
293    public void restoreState(IMemento memento)
294    {
295       if (memento == null)
296       {
297          return;
298       }
299       IOWLModel model = SWResourceManager.getModel();
300       IContainer container = ResourcesPlugin.getWorkspace().getRoot();
301       IMemento childMem = memento.getChild(TAG_EXPANSION_STATE);
302       if (childMem != null)
303       {
304          ArrayList elements = new ArrayList();
305          IMemento[] elementMem = childMem.getChildren(TAG_EXPANDED_ELEMENT);
306          for (int i = 0; i < elementMem.length; i++)
307          {
308             IOWLElement owlElem = null;
309             Object element =
310                container.findMember(elementMem[i].getString(TAG_PATH));
311             owlElem = model.getCorrespondingElement((IResource) element);
312             if (owlElem != null)
313             {
314                elements.add(owlElem);
315             }
316             else
317             {
318                if(element != null)
319                {
320                   elements.add(element);
321                }
322             }
323          }
324          _tree.setExpandedElements(elements.toArray());
325          
326          //Make sure we're listening for changes to any already-expanded documents
327          Iterator it = elements.iterator();
328          while (it.hasNext())
329          {
330             Object o = it.next();
331             if (o instanceof IOWLDocument)
332             {
333                IOWLDocument doc = (IOWLDocument)o;
334                IOWLAbstractSyntaxTree oast = doc.getDocumentInfo().getOAST();
335                oast.addOASTChangeListener(_viewUpdater);
336             }
337          }
338       }
339    }
340    
341    /*
342     *  (non-Javadoc)
343     * @see org.eclipse.ui.IWorkbenchPart#setFocus()
344     */
345    public void setFocus()
346    {
347 
348    }
349 
350    /*
351     *  (non-Javadoc)
352     * @see org.eclipse.ui.IWorkbenchPart#dispose()
353     */
354    public void dispose()
355    {
356       super.dispose();
357       //ResourcesPlugin.getWorkspace().removeResourceChangeListener(_resourceChangeListener);
358    }
359 
360    /*
361     *  (non-Javadoc)
362     * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
363     */
364    public void doubleClick(DoubleClickEvent event)
365    {
366       IStructuredSelection sel = (IStructuredSelection) event.getSelection();
367       Iterator it = sel.iterator();
368       while (it.hasNext())
369       {
370          Object element = it.next();
371          if (element instanceof IOWLProject
372             || element instanceof IOWLFolder
373             || element instanceof IFolder)
374          {
375             this._tree.expandToLevel(element, 1);
376          }
377          if (element instanceof IFile)
378          {
379             IWorkbenchPage page = _window.getPages()[0];
380             try
381             {
382                IDE.openEditor(page, (IFile) element, true);
383             }
384             catch (PartInitException e)
385             {
386                OWLCore.logError(
387                   ViewPlugin.getID(),
388                   "Error initializing editor",
389                   e);
390             }
391          }
392          if (element instanceof IOWLDocument
393             || element instanceof IOWLClass
394             || element instanceof IOWLProperty)
395          {
396             IWorkbenchPage page = _window.getPages()[0];
397             IOWLElement elem = (IOWLElement) element;
398             IResource res = elem.getResource();
399             try
400             {
401                if(elem.isReadOnly() || ((elem.getParent() != null) && (elem.getParent().isReadOnly())))
402                {
403                   MessageDialog.openWarning(getViewSite().getShell(),
404                      "Read-only", "Cannot open '" + elem.getElementName()
405                         + "' in the editor because it is read-only.");
406                }
407                else
408                {
409                   if (res instanceof IFile)
410                   {
411                      IDE.openEditor(page, (IFile) res, true);
412                   }
413                   if (!(element instanceof IOWLDocument))
414                   {
415                      OWLEditor ed = (OWLEditor) page.getActiveEditor();
416                      IOWLDocument doc =
417                         (IOWLDocument) ((IOWLElement) element).getParent();
418                      OWLDocumentInfo docInfo = doc.getDocumentInfo();
419                      Resource resource = null;
420                      if (element instanceof IOWLClass)
421                      {
422                         IOWLClass oc = (IOWLClass) element;
423                         resource = oc.getJenaResource();
424                      }
425                      else if (element instanceof IOWLProperty)
426                      {
427                         IOWLProperty op = (IOWLProperty) element;
428                         resource = op.getJenaProperty();
429                      }
430                      if (resource != null)
431                      {
432                         IOWLAbstractSyntaxTree tree = docInfo.getOAST();
433                         ed.goToResource(resource);
434                      }
435                   }
436                }
437             }
438             catch (PartInitException e)
439             {
440                OWLCore.logError(
441                   ViewPlugin.getID(),
442                   "Error initializing OWL editor",
443                   e);
444             }
445          }
446       }
447    }
448    
449    /***
450     * Called to populate the context menu immediately before it is displayed.
451     * @param menu The context menu to populate with actions
452     */
453    public void menuAboutToShow(IMenuManager menu)
454    {
455       boolean bAllProjects = false;
456       boolean bAllOpenProjects = false;
457       boolean bAllClosedProjects = false;
458       boolean bAllDocuments = false;
459       boolean bAllMigrateableProjects = false;
460       boolean bLibrarySelected = false;
461       boolean bAllLibrariesSelected = false;
462       
463       IStructuredSelection selection = null;
464       if (_tree.getSelection() instanceof IStructuredSelection)
465       {
466          selection = (IStructuredSelection)_tree.getSelection();
467       }
468                
469       if (selection != null)
470       {
471          if (selection.size() >= 1)
472          {
473             bAllOpenProjects = true;
474             bAllClosedProjects = true;
475             bAllProjects = true;
476             bAllDocuments = true;
477             bAllMigrateableProjects = true;
478             bAllLibrariesSelected = true;
479             
480             
481             Iterator it = selection.iterator();
482             while (it.hasNext())
483             {
484                Object obj = (Object) it.next();
485                if(obj instanceof IOWLLibrary)
486                {
487                   bLibrarySelected = true;
488                }
489                else
490                {
491                   bAllLibrariesSelected = false;
492                }
493                if (!(obj instanceof IProject) && !(obj instanceof IOWLProject))
494                {
495                   bAllProjects = false;
496                }
497                if (!(obj instanceof IOWLDocument))
498                {
499                   bAllDocuments = false;
500                }
501                if (obj instanceof IAdaptable
502                   && ((IAdaptable) obj).getAdapter(IProject.class) != null)
503                {
504                   IProject p =
505                      (IProject) ((IAdaptable) obj).getAdapter(IProject.class);
506                   if (p.isOpen())
507                   {
508                      bAllClosedProjects = false;
509                   }
510                   else
511                   {
512                      bAllOpenProjects = false;
513                   }
514                }
515                if(!bAllOpenProjects || !(obj instanceof IOWLProject) || isMigrated((IOWLProject) obj))
516                {
517                   bAllMigrateableProjects = false;
518                }
519                
520             }
521             
522          }
523       }
524 
525       MenuManager newMenu = new MenuManager("New");
526       menu.add(newMenu);
527       new NewWizardMenu(newMenu, getSite().getWorkbenchWindow(), false);
528       menu.add(new Separator());
529 
530       menu.add(_actionCopy);
531 //      menu.add(pasteAction);
532      
533       
534       if(bLibrarySelected)
535       {
536          _actionDelete.setEnabled(false);
537       }
538       else
539       {
540          _actionDelete.setEnabled(true);
541          getViewSite().getActionBars().setGlobalActionHandler(
542             ActionFactory.REFRESH.getId(),
543             new RefreshAction(getViewSite().getShell()));
544          _actionRefresh.setEnabled(true);
545 
546       }
547       
548       menu.add(_actionDelete);
549       menu.add(new Separator());
550 
551       menu.add(_actionImport);
552       menu.add(_actionExport);
553       menu.add(new Separator());
554 
555       if(bLibrarySelected)
556       {
557          if(!bAllLibrariesSelected)
558          {
559             menu.add(_actionRefresh);
560             _actionRefresh.setEnabled(false);
561          }
562          else
563          {
564             _actionRefresh.setEnabled(true);
565 //            menu.add(_actionLibraryRefresh);
566          }
567       }
568       else
569       {
570          menu.add(_actionRefresh);
571       }
572       
573       if (bAllProjects)
574       {
575          if (bAllClosedProjects)
576          {
577             menu.add(_actionOpenProject);
578             //this shouldnt be neccessary, but it wont always show an active menuitem otherwise
579             _actionOpenProject.setEnabled(true);
580          }
581          else if (bAllOpenProjects)
582          {
583             menu.add(_actionCloseProject);
584             _actionCloseProject.setEnabled(true);
585          }
586       }
587       menu.add(new Separator("odeadditions"));
588 
589       if(bAllMigrateableProjects && bAllOpenProjects)
590       {
591          menu.add(_actionMigrateProject);
592       }
593          
594       if (bAllDocuments && selection.size() == 1)
595       {
596          menu.add(ToolsPlugin.getToolsPlugin().getCodeGeneratorMenu());
597       }
598 
599       menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
600       menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end"));
601       menu.add(_actionProperties);
602    }
603 
604    /***
605     * Checks the project to see if it has been migrated.  Currently, this means
606     * checking for the syntax_builder and the config_builder.
607     * 
608     * @param owlProject The project to check for migration status
609     * @return boolean <code>true</code> if the project is up to date,
610     *                 <code>false</code> if it must be migrated.
611     */
612    private boolean isMigrated(IOWLProject owlProject)
613    {  
614       return hasBuilder(owlProject, OWLCore.SYNTAX_BUILDER) && hasBuilder(owlProject, OWLCore.CONFIG_BUILDER);
615    }
616    
617    /***
618     * Checks a project to see if it has a builderassociated with it.
619     * @param owlProject The project to check
620     * @param builder ID of the builder to check for
621     * @return boolean <code>true</code> if <code>project</code> has the 
622     *                 specified builder, <code>false</code> if not.
623     */
624    private boolean hasBuilder(IOWLProject owlProject, String builder)
625    {     
626       IProject project = owlProject.getProject();
627       IProjectDescription desc = null;
628       try
629       {
630          desc = project.getDescription();
631       }
632       catch(CoreException e)
633       {
634          OWLCore.trace("URIExplorer", "Failed to get the Project Description.", true);
635       }      
636       ICommand[] commands = desc.getBuildSpec();
637       
638       boolean hasBuilder = false;      
639       for(int i = 0; (i < commands.length) && (!hasBuilder); i++)
640       {
641          if(commands[i].getBuilderName().equals(builder))
642          {
643             hasBuilder = true;
644          }
645       }
646             
647       if(hasBuilder)
648       {
649          return true;                  
650       }
651       return false;
652    }
653 
654    /*
655     *  (non-Javadoc)
656     * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
657     */
658    public void init(IViewSite site, IMemento memento) throws PartInitException
659    {
660       super.init(site, memento);
661       _window = site.getWorkbenchWindow();
662       _memento = memento;
663    }
664    /***
665     * Change Listener for adding/removing objects from tree.
666     */
667    class ViewChangeListener implements IResourceChangeListener, IOASTChangeListener
668    {
669       /*
670        *  (non-Javadoc)
671        * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(
672        *       org.eclipse.core.resources.IResourceChangeEvent)
673        */
674       public void resourceChanged(IResourceChangeEvent e)
675       {
676          IResourceDelta delta = e.getDelta();
677          if (delta == null)
678          {
679             return;
680          }
681          if(!_tree.getControl().isDisposed())
682          {
683             _tree.getControl().getDisplay().asyncExec(new Runnable()
684             {
685                public void run()
686                {
687                   if(!_tree.getControl().isDisposed())
688                   {
689                      _tree.refresh(false);
690                   }
691                }
692             });
693          }
694       }
695 
696       /* (non-Javadoc)
697        * @see com.bbn.swede.core.dom.IOASTChangeListener#oastChanged(com.bbn.swede.core.dom.OASTEvent)
698        */
699       public void oastChanged(OASTEvent event)
700       {
701          IOWLAbstractSyntaxTree oast = event.getOWLAbstractSyntaxTree();
702          final IOWLDocument doc = oast.getRoot().getOWLDocument();
703          if(!_tree.getControl().isDisposed())
704          {
705             _tree.getControl().getDisplay().asyncExec(new Runnable()
706             {
707                public void run()
708                {
709                   if(!_tree.getControl().isDisposed()
710                      && _tree.getExpandedState(doc))
711                   {
712                      _tree.refresh(false);
713                   }
714                }
715             });
716          }
717       }
718    }
719 
720    /***
721     * Action for reopening a closed project.
722     * @author tself
723     */
724    class OpenProjectAction extends Action
725    {
726       /***
727        * Default constructor.
728        *
729        */
730       public OpenProjectAction()
731       {
732          super("Open Project");
733       }
734       /* (non-Javadoc)
735        * @see org.eclipse.jface.action.Action#run()
736        */
737       public void run()
738       {
739          ISelection sel =
740             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
741          if (sel instanceof IStructuredSelection)
742          {
743             IStructuredSelection selection = (IStructuredSelection) sel;
744             Iterator it = selection.iterator();
745             while (it.hasNext())
746             {
747                Object o = it.next();
748                IProject p = null;
749                if (o instanceof IAdaptable
750                   && (p = (IProject) ((IAdaptable) o).getAdapter(IProject.class))
751                      != null)
752                {
753                   try
754                   {
755                      p.open(null);
756                   }
757                   catch (CoreException ce)
758                   {
759                      OWLCore.trace(
760                         "URIExplorer",
761                         "Error opening project",
762                         true);
763                   }
764                }
765             }
766          }
767       }
768    }
769    
770    /***
771     * Action for migrating projects to the current version of SWeDE.
772     * @author reblace
773     */
774    class MigrateProjectAction extends Action
775    {
776       /***
777        * Creates a migrate project action.
778        */
779       public MigrateProjectAction()
780       {
781          super("Migrate to SWeDE 2.0");
782       }
783       /* (non-Javadoc)
784        * @see org.eclipse.jface.action.Action#run()
785        */
786       public void run()
787       {
788          OWLCore.trace("URIExplorer", "Running the MigrateAction.", false);
789          
790          ISelection sel =
791             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
792          if (sel instanceof IStructuredSelection)
793          {
794             IStructuredSelection selection = (IStructuredSelection) sel;
795             Iterator it = selection.iterator();
796             while (it.hasNext())
797             {
798                Object o = it.next();
799 
800                try
801                {
802                   if(!hasBuilder((IOWLProject)o, OWLCore.SYNTAX_BUILDER))
803                   {
804                      OWLNature.addOWLSyntaxBuilder(((IOWLProject)o).getProject());
805                   }
806                   if(!hasBuilder((IOWLProject)o, OWLCore.CONFIG_BUILDER))
807                   {
808                      OWLNature.addSWProjectInfoBuilder(((IOWLProject)o).getProject());
809                   }
810                }
811                catch (CoreException ce)
812                {
813                   OWLCore.trace(
814                      "URIExplorer",
815                      "Error Migrating Project",
816                      true);
817                }               
818             }
819          }
820       }
821    }
822 
823    /* (non-Javadoc)
824     * @see org.eclipse.ui.part.ISetSelectionTarget#selectReveal(org.eclipse.jface.viewers.ISelection)
825     */
826    public void selectReveal(ISelection selection)
827    {
828       if(selection instanceof IStructuredSelection)
829       {
830          IStructuredSelection sel = (IStructuredSelection)selection;
831          ArrayList al = new ArrayList();
832          Iterator it = sel.iterator();
833          while (it.hasNext())
834          {
835             Object o = it.next();
836             if (o instanceof IOWLElement)
837             {
838                al.add(o);
839             }
840             if(o instanceof IAdaptable)
841             {
842                IAdaptable adapter = (IAdaptable)o;
843                IResource resource = (IResource)adapter.getAdapter(IResource.class);
844                IOWLElement elem = SWResourceManager.getModel().getCorrespondingElement(resource);
845                if (elem != null)
846                {
847                   al.add(elem);
848                }
849                else
850                {
851                   al.add(resource);
852                }
853             }
854          }
855          
856          if (al.size() == 0)
857          {
858             //Don't bother clearing the current selection if there's nothing
859             //new to set it to
860             return;
861          }
862          
863          _tree.setSelection(new StructuredSelection(al), true);
864       }
865    }
866 
867    /* (non-Javadoc)
868     * @see org.eclipse.jface.viewers.ITreeViewerListener#treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent)
869     */
870    public void treeCollapsed(TreeExpansionEvent event)
871    {
872       if (event.getElement() instanceof IOWLDocument)
873       {
874          IOWLDocument doc = (IOWLDocument)event.getElement();
875          IOWLAbstractSyntaxTree oast = doc.getDocumentInfo().getOAST();
876          oast.removeOASTChangeListener(_viewUpdater);
877       }
878    }
879 
880    /* (non-Javadoc)
881     * @see org.eclipse.jface.viewers.ITreeViewerListener#treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent)
882     */
883    public void treeExpanded(TreeExpansionEvent event)
884    {
885       if (event.getElement() instanceof IOWLDocument)
886       {
887          IOWLDocument doc = (IOWLDocument)event.getElement();
888          IOWLAbstractSyntaxTree oast = doc.getDocumentInfo().getOAST();
889          oast.addOASTChangeListener(_viewUpdater);
890       }
891    }
892 
893    
894    
895 }