View Javadoc

1   /*
2    * $Id: RestrictionEditor.java,v 1.11 2005/07/07 17:44:13 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.visualeditors.restriction;
10  
11  import org.eclipse.core.runtime.IProgressMonitor;
12  import org.eclipse.core.runtime.IStatus;
13  import org.eclipse.core.runtime.MultiStatus;
14  import org.eclipse.core.runtime.Status;
15  import org.eclipse.core.runtime.jobs.Job;
16  import org.eclipse.swt.layout.GridData;
17  import org.eclipse.swt.layout.GridLayout;
18  import org.eclipse.swt.widgets.Composite;
19  import org.eclipse.ui.forms.widgets.FormToolkit;
20  import org.eclipse.ui.forms.widgets.ScrolledForm;
21  import org.eclipse.ui.progress.UIJob;
22  
23  import com.bbn.swede.core.dom.OAST;
24  import com.bbn.swede.core.dom.OASTEvent;
25  import com.bbn.swede.editor.EditorPlugin;
26  import com.bbn.swede.editor.OWLVisualEditor;
27  
28  /***
29   * This class implements the visual restriction editor.
30   * 
31   * @author aperezlo
32   */
33  public class RestrictionEditor extends OWLVisualEditor
34  {
35     /***
36      * Index of the class name column.
37      */
38     /*package*/ static final int CLASS_NAME_COLUMN = 0/package-summary.html">class="comment">package*/ static final int CLASS_NAME_COLUMN = 0;
39     /***
40      * Index of the property name column.
41      */
42     /*package*/ static final int PROPERTY_NAME_COLUMN = 1/package-summary.html">class="comment">package*/ static final int PROPERTY_NAME_COLUMN = 1;
43     /***
44      * Index of the restriction type column.
45      */
46     /*package*/ static final int RESTRICTION_TYPE_COLUMN = 2/package-summary.html">class="comment">package*/ static final int RESTRICTION_TYPE_COLUMN = 2;
47     /***
48      * Index of the restriction value column.
49      */
50     /*package*/ static final int RESTRICTION_VALUE_COLUMN = 3/package-summary.html">class="comment">package*/ static final int RESTRICTION_VALUE_COLUMN = 3;
51     /***
52      * Index of the restriction origin column.
53      */
54     /*package*/ static final int RESTRICTION_ORIGIN_COLUMN = 4/package-summary.html">class="comment">package*/ static final int RESTRICTION_ORIGIN_COLUMN = 4;
55     
56     /***
57      * Column name strings.
58      */
59     /* package */static final String[] COLUMN_NAMES_ARRAY =/package-summary/html">class="comment"> package */static final String[] COLUMN_NAMES_ARRAY =/package-summary.html">/* package */static final String[] COLUMN_NAMES_ARRAY =/package-summary.html">class="comment"> package */static final String[] COLUMN_NAMES_ARRAY =
60     {
61        "Class",
62        "Property",
63        "Restriction",
64        "Value",
65        "Inherited From",
66     };
67     
68     
69     private ScrolledForm _form;
70     private RestrictionEditorInspector _detective;
71     private RestrictionEditorTree _tableTree;
72     
73     
74     /***
75      *  Default constructor. 
76      */
77     public RestrictionEditor()
78     {
79        _detective = new RestrictionEditorInspector();
80     }
81     
82     /*
83      *  (non-Javadoc)
84      * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
85      */
86     public void createPartControl(Composite parent)
87     {
88        FormToolkit tool = new FormToolkit(parent.getDisplay());
89        _form = tool.createScrolledForm(parent);
90        _form.setText("Restrictions");
91        _form.getBody().setLayout(new GridLayout());
92        _form.getBody().setLayoutData(new GridData(GridData.FILL_BOTH));
93        createRestrictionTable(_form.getBody(), tool);
94     }
95  
96     /*
97      *  (non-Javadoc)
98      * @see com.bbn.swede.core.dom.IOASTChangeListener#oastChanged(com.bbn.swede.core.dom.OASTEvent)
99      */
100    public void oastChanged(OASTEvent event)
101    {
102       _detective.oastChanged(event);
103    }
104    
105    /***
106     * Initializes the restriction editor table tree.
107     * @param parent The parent control for the table
108     * @param tool The form tool kit
109     */
110    protected void createRestrictionTable(Composite parent, FormToolkit tool)
111    {
112       _tableTree = new RestrictionEditorTree();
113       _tableTree.createComponent(_form, parent, tool, _detective, getOAST());
114    }
115    
116    /*
117     *  (non-Javadoc)
118     * @see org.eclipse.ui.IWorkbenchPart#setFocus()
119     */
120    public void setFocus()
121    {
122       super.setFocus();
123       // if the restriction tree hasn't yet been populated
124       // i want to say - if it isn't sync'd w/ the document, 
125       // but it's difficult to ascertain that
126       if(_tableTree.getInput() == null)
127       {
128          Job initJob = new Job("Restriction Editor Initialization")
129          {
130             public IStatus run(IProgressMonitor progMon)
131             {
132                MultiStatus toReturn = new MultiStatus(EditorPlugin.getID(),
133                   IStatus.OK, "Restriction Editor Initialized", null);
134                ModelLoadJob mlj = new ModelLoadJob(getOAST());
135                try
136                {
137                   progMon.beginTask("Initializing Restriction Editor...", IProgressMonitor.UNKNOWN);
138                   mlj.setUser(true);
139                   mlj.schedule();
140                   mlj.join();
141                   if(mlj.getModel() != null)
142                   {
143                      _detective.setModel(mlj.getModel());
144    //                     getOAST().getJenaModel().register(_detective);
145                   }
146                   toReturn.add(mlj.getResult());
147                   progMon.worked(5);
148                   UIJob uij = (new UIJob("Populating Restriction Editor...")
149                   {
150                      public IStatus runInUIThread(IProgressMonitor monitor)
151                      {
152                         monitor.beginTask("Populating Restrictions...", IProgressMonitor.UNKNOWN);
153                         _tableTree.setInput((OAST) getOAST());
154                         _form.reflow(true);
155                         monitor.done();
156                         return Status.OK_STATUS;
157                      }
158                   });
159                   uij.setUser(true);
160                   uij.schedule(100);
161                   uij.join();
162                   toReturn.add(uij.getResult());
163                   progMon.worked(5);
164                }
165                catch(Exception e)
166                {
167                   //do nothing
168                }
169                finally
170                {
171                   progMon.done();
172                }
173                return toReturn;
174             }
175          };
176 
177          initJob.setUser(true);
178          initJob.schedule();
179             
180             
181 //         try
182 //         {
183 //            // debug!
184 //            FileOutputStream fos = new FileOutputStream("c://jena-out.rdf");
185 //            mlj.getModel().writeAll(fos, null, null);
186 //            fos.flush();
187 //            fos.close();
188 //         }
189 //         catch (Exception e)
190 //         {
191 //            e.printStackTrace();
192 //         }
193 //         
194       }
195       else
196       {
197          try
198          {
199             UIJob uij = (new UIJob("Populating Restriction Editor...")
200             {
201                public IStatus runInUIThread(IProgressMonitor monitor)
202                {
203                   monitor.beginTask("Populating Restrictions...", IProgressMonitor.UNKNOWN);
204                   _detective.getModel().rebind();
205                   _detective.getModel().reset();
206                   _tableTree.setInput((OAST) getOAST());
207                   _tableTree.refresh();
208                   try
209                   {
210                      _form.reflow(true);
211                   }
212                   catch(Exception e)
213                   {
214                      //do nothing
215                   }
216                   finally
217                   {
218                      monitor.done();
219                   }
220                   return Status.OK_STATUS;
221                }
222             });
223             uij.setUser(true);
224             uij.schedule(100);
225    
226 //            _tableTree.refresh();
227 //            _form.reflow(true);
228          }
229          catch(Exception e)
230          {
231             e.printStackTrace();
232          }
233       }
234    }
235    
236 
237    
238     
239    
240    
241 }