View Javadoc

1   /*
2    * $Id: OWLVisualEditor.java,v 1.5 2005/07/07 19:01:08 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.editor;
10  
11  import org.eclipse.core.runtime.IProgressMonitor;
12  import org.eclipse.jface.viewers.ISelection;
13  import org.eclipse.jface.viewers.ISelectionChangedListener;
14  import org.eclipse.jface.viewers.ISelectionProvider;
15  import org.eclipse.jface.viewers.StructuredSelection;
16  import org.eclipse.ui.IEditorInput;
17  import org.eclipse.ui.IEditorSite;
18  import org.eclipse.ui.PartInitException;
19  import org.eclipse.ui.part.EditorPart;
20  import org.eclipse.ui.part.MultiPageEditorSite;
21  
22  import com.bbn.swede.core.dom.IOASTChangeListener;
23  import com.bbn.swede.core.dom.IOWLAbstractSyntaxTree;
24  
25  /***
26   * Abstract base class for OWL visual editors.  All extenders of
27   * com.bbn.swede.editors.visualEditor must provide an implementation of this
28   * class.  Visual editors appear as tabs in the OWL editor and are automatically
29   * registered for change notifications with the document's OAST.
30   * @author jlerner
31   */
32  public abstract class OWLVisualEditor extends EditorPart 
33     implements IOASTChangeListener, ISelectionProvider
34  {
35     private OWLEditor _owlEditor;
36     private IOWLAbstractSyntaxTree _oast;
37     
38     /* (non-Javadoc)
39      * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
40      */
41     public void doSave(IProgressMonitor monitor)
42     {
43        _owlEditor.doSave(monitor);
44     }
45  
46     /* (non-Javadoc)
47      * @see org.eclipse.ui.ISaveablePart#doSaveAs()
48      */
49     public void doSaveAs()
50     {
51        _owlEditor.doSaveAs();
52     }
53  
54     /* (non-Javadoc)
55      * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
56      */
57     public void init(IEditorSite site, IEditorInput input)
58        throws PartInitException
59     {
60        setSite(site);
61        setInput(input);
62        
63        MultiPageEditorSite multi = (MultiPageEditorSite)site;
64        _owlEditor = (OWLEditor)multi.getMultiPageEditor();
65        
66        OWLEditorInput oei = (OWLEditorInput)input;
67        _oast = oei.getOAST();
68        _oast.addOASTChangeListener(this);
69     }
70  
71     /* (non-Javadoc)
72      * @see org.eclipse.ui.ISaveablePart#isDirty()
73      */
74     public boolean isDirty()
75     {
76        // the multi-page editor already iterates over the nested editors and
77        // returns true if any one of them is dirty, so returning false for
78        // visual editors is safe because they cause changes to the source editor
79        // which will accurately report its dirtyness.
80        return false;
81     }
82  
83     /* (non-Javadoc)
84      * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
85      */
86     public boolean isSaveAsAllowed()
87     {
88        return _owlEditor.isSaveAsAllowed();
89     }
90  
91     /***
92      * Retrieves the OAST for the editor's document.
93      * @return The document's OAST
94      */
95     public IOWLAbstractSyntaxTree getOAST()
96     {
97        return _oast;
98     }
99  
100    /*
101     *  (non-Javadoc)
102     * @see org.eclipse.ui.IWorkbenchPart#setFocus()
103     */
104    public void setFocus()
105    {
106       getSite().setSelectionProvider(this);
107    }
108 
109    /* (non-Javadoc)
110     * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
111     */   
112    public ISelection getSelection()
113    {
114       //return istructuredselection, get from owleditor    
115       OWLEditorInput input = (OWLEditorInput)getEditorInput();      
116       StructuredSelection selection = null;
117             
118       if(input != null)
119       {
120          selection = new StructuredSelection(input.getDocument());
121       }
122 
123       _owlEditor.getSourceEditor().editorSyncCheck(input);
124       
125       return selection;
126    }
127    
128    /* (non-Javadoc)
129     * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(
130     *       org.eclipse.jface.viewers.ISelectionChangedListener)
131     */
132    public void addSelectionChangedListener(ISelectionChangedListener listener)
133    { 
134    }
135   
136    /* (non-Javadoc)
137     * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(
138     *       org.eclipse.jface.viewers.ISelectionChangedListener)
139     */
140    public void removeSelectionChangedListener(ISelectionChangedListener listener)
141    {      
142    }
143 
144    /* (non-Javadoc)
145     * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
146     */
147    public void setSelection(ISelection selection)
148    {
149    }
150    
151    /***
152     * Indicates whether this editor is the currently active page.  Visual
153     * editors with expensive processing can use this check to suppress
154     * updates while they are not visible.
155     * @return <code>true</code> if this is the active page,
156     *         <code>false</code> if not.
157     */
158    protected boolean isActivePage()
159    {
160       return _owlEditor.isActivePage(this);
161    }
162 }