View Javadoc

1   /*
2    * $Id: NewOWLDocumentWizardPage.java,v 1.6 2005/07/11 20:31:07 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.ui.wizards;
11  
12  import java.io.ByteArrayInputStream;
13  import java.io.IOException;
14  import java.io.InputStream;
15  import java.lang.reflect.InvocationTargetException;
16  import java.net.MalformedURLException;
17  import java.net.URL;
18  import java.util.Iterator;
19  
20  import org.eclipse.core.resources.IFile;
21  import org.eclipse.core.resources.IResource;
22  import org.eclipse.core.resources.IResourceStatus;
23  import org.eclipse.core.resources.ResourceAttributes;
24  import org.eclipse.core.resources.ResourcesPlugin;
25  import org.eclipse.core.runtime.CoreException;
26  import org.eclipse.core.runtime.IAdaptable;
27  import org.eclipse.core.runtime.IPath;
28  import org.eclipse.core.runtime.IProgressMonitor;
29  import org.eclipse.core.runtime.OperationCanceledException;
30  import org.eclipse.core.runtime.SubProgressMonitor;
31  import org.eclipse.jface.dialogs.IDialogConstants;
32  import org.eclipse.jface.viewers.IStructuredSelection;
33  import org.eclipse.jface.wizard.WizardPage;
34  import org.eclipse.swt.SWT;
35  import org.eclipse.swt.events.ModifyEvent;
36  import org.eclipse.swt.events.ModifyListener;
37  import org.eclipse.swt.events.SelectionAdapter;
38  import org.eclipse.swt.events.SelectionEvent;
39  import org.eclipse.swt.layout.GridData;
40  import org.eclipse.swt.layout.GridLayout;
41  import org.eclipse.swt.widgets.Button;
42  import org.eclipse.swt.widgets.Composite;
43  import org.eclipse.swt.widgets.Event;
44  import org.eclipse.swt.widgets.Label;
45  import org.eclipse.swt.widgets.Listener;
46  import org.eclipse.swt.widgets.Text;
47  import org.eclipse.ui.PlatformUI;
48  import org.eclipse.ui.actions.WorkspaceModifyOperation;
49  import org.eclipse.ui.dialogs.ContainerGenerator;
50  import org.eclipse.ui.help.IWorkbenchHelpSystem;
51  import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
52  import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
53  import org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup;
54  
55  import com.bbn.swede.core.IOWLDocument;
56  import com.bbn.swede.core.IOWLModel;
57  import com.bbn.swede.core.OWLCore;
58  import com.bbn.swede.core.dom.OASTNode;
59  import com.bbn.swede.core.resources.SWResourceManager;
60  import com.bbn.swede.ui.UIPlugin;
61  import com.hp.hpl.jena.rdf.arp.MalformedURIException;
62  import com.hp.hpl.jena.rdf.arp.URI;
63  /***
64   * Standard main page for a wizard that creates a file resource.
65   * <p>
66   * This page may be used by clients as-is; it may be also be subclassed to suit.
67   * </p>
68   * <p>
69   * Subclasses may override
70   * <ul>
71   *   <li><code>getInitialContents</code></li>
72   *   <li><code>getNewFileLabel</code></li>
73   * </ul>
74   * </p>
75   * <p>
76   * Subclasses may extend
77   * <ul>
78   *   <li><code>handleEvent</code></li>
79   * </ul>
80   * </p>
81   * @author tself
82   */
83  public class NewOWLDocumentWizardPage extends WizardPage implements Listener
84  {
85     /***
86      * Contains initial content added to new OWL documents.
87      */
88     private static final String XML_DECLARATION = "<?xml version='1.0'?>";
89     private static final String[] INITIAL_OWL_CONTENT_ENTITIES =
90     {
91        " <!DOCTYPE uridef[",
92        " <!ENTITY rdf  \"http://www.w3.org/1999/02/22-rdf-syntax-ns\">",
93        " <!ENTITY rdfs \"http://www.w3.org/2000/01/rdf-schema\">",
94        " <!ENTITY owl  \"http://www.w3.org/2002/07/owl\">",
95        "]>",
96     };
97     private static final String[] INITIAL_OWL_CONTENT_START =
98     {
99        "<rdf:RDF",
100       "  xmlns:rdf=\"" + OASTNode.S_RDF_URI + "#\"",
101       "  xmlns:rdfs=\"" + OASTNode.S_RDFS_URI + "#\"", 
102       "  xmlns:owl=\"" + OASTNode.S_OWL_URI + "#\"", 
103       "  xmlns:xsd=\"" + OASTNode.S_XSD_URI + "#\"",
104    };
105    private static final String[] INITIAL_OWL_CONTENT_END = {">", "", "</rdf:RDF>", };
106 
107    private static final int SIZING_CONTAINER_GROUP_HEIGHT = 250;
108    // the current resource selection
109    private IStructuredSelection _currentSelection;
110 
111    // cache of newly-created file
112    private IFile _newFile;
113 
114    // widgets
115    private ResourceAndContainerGroup _resourceGroup;
116    private Text _tfImportURI;
117    private Text _tfXMLBase;
118 
119    // initial value stores
120    private String _sInitialFileName;
121    private IPath _initialContainerFullPath;
122 
123    // import 
124    /***
125     * First time the import group is validated.
126     */
127    private boolean _bFirstImportCheck = true;
128    private boolean _bImportExternal;
129    private URL _importURL;
130    private URI _xmlBaseURI;
131 
132    /***
133     * Creates a new file creation wizard page. If the initial resource selection 
134     * contains exactly one container resource then it will be used as the default
135     * container resource.
136     *
137     * @param pageName the name of the page
138     * @param selection the current resource selection
139     */
140    public NewOWLDocumentWizardPage(
141       String pageName,
142       IStructuredSelection selection)
143    {
144       super(pageName);
145       setPageComplete(false);
146       this._currentSelection = selection;
147    }
148 
149    /*
150     *  (non-Javadoc)
151     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
152     */
153    public void createControl(Composite parent)
154    {
155       initializeDialogUnits(parent);
156       // top level group
157       Composite topLevel = new Composite(parent, SWT.NONE);
158       topLevel.setLayout(new GridLayout());
159       topLevel.setLayoutData(
160          new GridData(
161             GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
162       topLevel.setFont(parent.getFont());
163       IWorkbenchHelpSystem whs = PlatformUI.getWorkbench().getHelpSystem();
164       whs.setHelp(topLevel, IIDEHelpContextIds.NEW_FILE_WIZARD_PAGE);
165 
166       // resource and container group
167       _resourceGroup 
168          = new ResourceAndContainerGroup(
169             topLevel, 
170             this, 
171             getNewFileLabel(), 
172             IDEWorkbenchMessages.WizardNewFileCreationPage_file, 
173             false, 
174             SIZING_CONTAINER_GROUP_HEIGHT); //$NON-NLS-1$
175       _resourceGroup.setAllowExistingResources(false);
176       initialPopulateContainerNameField();
177       if (_sInitialFileName != null)
178       {
179          _resourceGroup.setResource(_sInitialFileName);
180       }
181 
182       // xml:base field
183       addXMLBaseControls(topLevel);
184 
185       // import controls
186       addImportControls(topLevel);
187 
188       validatePage();
189       // Show description on opening
190       setErrorMessage(null);
191       setMessage(null);
192       setControl(topLevel);
193    }
194    private void addXMLBaseControls(Composite parent)
195    {
196 
197       // URL textfield group
198       Composite xmlBaseGroup = new Composite(parent, SWT.NONE);
199       GridLayout layout = new GridLayout();
200       layout.numColumns = 2;
201       layout.marginWidth = 0;
202       xmlBaseGroup.setLayout(layout);
203       xmlBaseGroup.setLayoutData(
204          new GridData(
205             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
206       xmlBaseGroup.setFont(parent.getFont());
207 
208       Label label = new Label(xmlBaseGroup, SWT.NONE);
209       label.setText("XML Base");
210       label.setToolTipText(
211          "Defines the base URI prepended to locally defined objects in this document.");
212       label.setFont(parent.getFont());
213 
214       _tfXMLBase = new Text(xmlBaseGroup, SWT.BORDER);
215       GridData data =
216          new GridData(
217             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
218       data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
219       data.widthHint = 250;
220       _tfXMLBase.setLayoutData(data);
221       _tfXMLBase.setFont(parent.getFont());
222       _tfXMLBase.setEnabled(!_bImportExternal);
223       _tfXMLBase.addModifyListener(new ModifyListener()
224       {
225          public void modifyText(ModifyEvent e)
226          {
227             setPageComplete(validatePage());
228          }
229       });
230    }
231    private void addImportControls(Composite parent)
232    {
233       // Import Checkbox
234       final Button cbImportToggle = new Button(parent, SWT.CHECK);
235       cbImportToggle.setText("Import OWL Document from the web");
236       cbImportToggle.addSelectionListener(new SelectionAdapter()
237       {
238          public void widgetSelected(SelectionEvent se)
239          {
240             _bImportExternal = cbImportToggle.getSelection();
241             _tfImportURI.setEnabled(_bImportExternal);
242             _tfXMLBase.setEnabled(!_bImportExternal);
243             if (!_bImportExternal)
244             {
245                _importURL = null;
246             }
247             validatePage();
248          }
249       });
250 
251       // URL textfield group
252       Composite uriGroup = new Composite(parent, SWT.NONE);
253       GridLayout layout = new GridLayout();
254       layout.numColumns = 2;
255       layout.marginWidth = 0;
256       uriGroup.setLayout(layout);
257       uriGroup.setLayoutData(
258          new GridData(
259             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
260       uriGroup.setFont(parent.getFont());
261 
262       Label label = new Label(uriGroup, SWT.NONE);
263       label.setText("URL");
264       label.setFont(parent.getFont());
265 
266       _tfImportURI = new Text(uriGroup, SWT.BORDER);
267       GridData data =
268          new GridData(
269             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
270       data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
271       data.widthHint = 250;
272       _tfImportURI.setLayoutData(data);
273       _tfImportURI.setFont(parent.getFont());
274       _tfImportURI.setEnabled(_bImportExternal);
275       _tfImportURI.addModifyListener(new ModifyListener()
276       {
277          public void modifyText(ModifyEvent e)
278          {
279             importTextModified();
280             validatePage();
281          }
282       });
283    }
284    
285    /***
286     * Adds a file resource to the OWL model.  Whether it is added as an ordinary
287     * or external document depends on the state of the Import checkbox.
288     * @param file The file resource
289     */
290    protected void addToOWLModel(IFile file)
291    {
292       IOWLDocument doc = null;
293       if (_bImportExternal) // external owl file
294       {
295          doc = SWResourceManager.create(file, _importURL.toString());
296       }
297       else
298       {
299          doc = SWResourceManager.create(file);
300          if (_xmlBaseURI != null)
301          {
302             try
303             {
304                ((IOWLDocument) doc).setURI(_xmlBaseURI.toString());
305             }
306             catch (MalformedURIException use)
307             {
308                // this should not happen since the textfield is self-validating
309             }
310          }
311       }
312       // add to the model
313       IOWLModel model = SWResourceManager.getModel();
314       model.add(doc);
315    }
316    /***
317     * Creates a file resource given the file handle and contents.
318     *
319     * @param fileHandle the file handle to create a file resource with
320     * @param contents the initial contents of the new file resource, or
321     *   <code>null</code> if none (equivalent to an empty stream)
322     * @param monitor the progress monitor to show visual progress with
323     * @exception CoreException if the operation fails
324     */
325    protected void createFile(
326       IFile fileHandle,
327       InputStream contents,
328       IProgressMonitor monitor)
329       throws CoreException
330    {
331       if (contents == null)
332       {
333          contents = new ByteArrayInputStream(new byte[0]);
334       }
335 
336       try
337       {
338          // Create a new file resource in the workspace
339          fileHandle.create(contents, false, monitor);
340          ResourceAttributes ra = fileHandle.getResourceAttributes();
341          ra.setReadOnly(_bImportExternal);
342          fileHandle.setResourceAttributes(ra);
343       }
344       catch (CoreException e)
345       {
346          // If the file already existed locally, just refresh to get contents
347          if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
348          {
349             fileHandle.refreshLocal(IResource.DEPTH_ZERO, null);
350          }
351          else
352          {
353             throw e;
354          }
355       }
356 
357       if (monitor.isCanceled())
358       {
359          throw new OperationCanceledException();
360       }
361    }
362    
363    /***
364     * Creates a file resource handle for the file with the given workspace path.
365     * This method does not create the file resource; this is the responsibility
366     * of <code>createFile</code>.
367     *
368     * @param filePath the path of the file resource to create a handle for
369     * @return the new file resource handle
370     * @see #createFile
371     */
372    protected IFile createFileHandle(IPath filePath)
373    {
374       return ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
375    }
376 
377    /***
378     * Creates a new file resource in the selected container and with the selected
379     * name. Creates any missing resource containers along the path; does nothing if
380     * the container resources already exist.
381     * <p>
382     * In normal usage, this method is invoked after the user has pressed Finish on
383     * the wizard; the enablement of the Finish button implies that all controls on 
384     * on this page currently contain valid values.
385     * </p>
386     * <p>
387     * Note that this page caches the new file once it has been successfully
388     * created; subsequent invocations of this method will answer the same
389     * file resource without attempting to create it again.
390     * </p>
391     * <p>
392     * This method should be called within a workspace modify operation since
393     * it creates resources.
394     * </p>
395     * 
396     * @deprecated As of SWeDE 1.0.2, replaced by 
397     *             {@link #createNewFile(InputStream)}.  Creating the
398     *             input stream externally allows the wizard to recover 
399     *             gracefully and notify the user if the URL is unreachable.
400     *             See also {@link #openStream()}.
401     *
402     * @return the created file resource, or <code>null</code> if the file
403     *    was not created
404     */
405    public IFile createNewFile()
406    {
407       return createNewFile(null);
408    }
409    
410    /***
411     * Creates a new file resource in the selected container and with the selected
412     * name. Creates any missing resource containers along the path; does nothing if
413     * the container resources already exist.
414     * <p>
415     * In normal usage, this method is invoked after the user has pressed Finish on
416     * the wizard; the enablement of the Finish button implies that all controls on 
417     * on this page currently contain valid values.
418     * </p>
419     * <p>
420     * Note that this page caches the new file once it has been successfully
421     * created; subsequent invocations of this method will answer the same
422     * file resource without attempting to create it again.
423     * </p>
424     * <p>
425     * This method should be called within a workspace modify operation since
426     * it creates resources.
427     * </p>
428     * 
429     * @param input An input stream for the external document being imported.
430     *              If no document is being imported, this parameter is ignored
431     *              and may be <code>null</code>.
432     * 
433     * @return the created file resource, or <code>null</code> if the file
434     *    was not created
435     */
436    public IFile createNewFile(InputStream input)
437    {
438       if (_newFile != null)
439       {
440          return _newFile;
441       }
442 
443       // create the new file and cache it if successful
444 
445       final IPath containerPath = _resourceGroup.getContainerFullPath();
446       IPath newFilePath = containerPath.append(_resourceGroup.getResource());
447       final IFile newFileHandle = createFileHandle(newFilePath);
448       final InputStream initialContents = getContents(newFileHandle, input);
449 
450       WorkspaceModifyOperation op = new WorkspaceModifyOperation()
451       {
452          protected void execute(IProgressMonitor monitor)
453             throws CoreException, InterruptedException
454          {
455             try
456             {
457 //               monitor.beginTask(WorkbenchMessages.getString("WizardNewFileCreationPage.progress"), 2000); //$NON-NLS-1$
458                monitor.beginTask(IDEWorkbenchMessages.WizardNewFileCreationPage_progress, 2000); //$NON-NLS-1$
459                ContainerGenerator generator =
460                   new ContainerGenerator(containerPath);
461                generator.generateContainer(
462                   new SubProgressMonitor(monitor, 1000));
463                createFile(
464                   newFileHandle,
465                   initialContents,
466                   new SubProgressMonitor(monitor, 1000));
467                addToOWLModel(newFileHandle);
468             }
469             finally
470             {
471                monitor.done();
472             }
473          }
474       };
475 
476       try
477       {
478          getContainer().run(true, true, op);
479       }
480       catch (InterruptedException e)
481       {
482          return null;
483       }
484       catch (InvocationTargetException e)
485       {
486          OWLCore.logError(UIPlugin.getID(), "Error creating OWL document", e);
487 //         if (e.getTargetException() instanceof CoreException)
488 //         {
489 //            ErrorDialog.openError(getContainer().getShell(),
490 //            // Was Utilities.getFocusShell()
491 //               WorkbenchMessages.getString("WizardNewFileCreationPage.errorTitle"), //$NON-NLS-1$
492 //               null, // no special message
493 //               ((CoreException) e.getTargetException()).getStatus());
494 //         }
495 //         else
496 //         {
497 //            // CoreExceptions are handled above, but unexpected runtime exceptions and errors may still occur.
498 //            WorkbenchPlugin.log(MessageFormat.format(
499 //               "Exception in {0}.getNewFile(): {1}", 
500 //               new Object[] {getClass().getName(), e.getTargetException()})); //$NON-NLS-1$
501 //            MessageDialog.openError(
502 //               getContainer().getShell(), 
503 //               WorkbenchMessages.getString("WizardNewFileCreationPage.internalErrorTitle"), 
504 //               WorkbenchMessages.format("WizardNewFileCreationPage.internalErrorMessage", 
505 //                  new Object[] {e.getTargetException().getMessage()})); //$NON-NLS-2$ //$NON-NLS-1$
506 //         }
507          return null;
508       }
509 
510       _newFile = newFileHandle;
511 
512       return _newFile;
513    }
514    /***
515     * Returns the current full path of the containing resource as entered or 
516     * selected by the user, or its anticipated initial value.
517     *
518     * @return the container's full path, anticipated initial value, 
519     *   or <code>null</code> if no path is known
520     */
521    public IPath getContainerFullPath()
522    {
523       return _resourceGroup.getContainerFullPath();
524    }
525    /***
526     * Returns the current file name as entered by the user, or its anticipated
527     * initial value.
528     *
529     * @return the file name, its anticipated initial value, or <code>null</code>
530     *   if no file name is known
531     */
532    public String getFileName()
533    {
534       if (_resourceGroup == null)
535       {
536          return _sInitialFileName;
537       }
538 
539       return _resourceGroup.getResource();
540    }
541    /***
542     * Returns a stream containing the initial contents to be given to new file resource
543     * instances.  <b>Subclasses</b> may wish to override.  This default implementation
544     * provides no initial contents.
545     *
546     * @return initial contents to be given to new file resource instances
547     */
548    protected InputStream getInitialContents()
549    {
550       return getInitialContents(null, null);
551    }
552    private InputStream getInitialContents(String xmlBase, IFile fileHandle)
553    {
554       String xBase = null;
555       String endln = System.getProperty("line.separator");
556       StringBuffer sb = new StringBuffer();
557       sb.append(XML_DECLARATION + endln);
558       for (int i = 0; i < INITIAL_OWL_CONTENT_START.length; i++)
559       {
560          sb.append(INITIAL_OWL_CONTENT_START[i] + endln);
561       }
562       // add xmlBase if it exists
563       if (xmlBase != null)
564       {
565          xBase = xmlBase;
566       }
567       else if (fileHandle != null) // otherwise use the file handle
568       {
569          xBase = fileHandle.getRawLocation().toFile().toURI().toString();
570       }
571       if (xBase != null)
572       {
573          sb.append("  xml:base=\"" + xBase + "\"" + endln);
574       }
575       for (int i = 0; i < INITIAL_OWL_CONTENT_END.length; i++)
576       {
577          sb.append(INITIAL_OWL_CONTENT_END[i] + endln);
578       }
579       return new ByteArrayInputStream(sb.toString().getBytes());
580    }
581 
582    /***
583     * Returns an input stream for importing an external document.
584     * @return An open input stream to the import URL, or <code>null</code> if
585     *         a document is not being imported.
586     * @throws IOException if the document cannot be opened from the specified
587     *                     import URL
588     */
589    public InputStream openStream() throws IOException
590    {
591       if (!_bImportExternal || _importURL == null)
592       {
593          return null;
594       }
595       return _importURL.openStream();
596    }
597    private InputStream getContents(IFile fileHandle, InputStream input)
598    {
599       if (!_bImportExternal)
600       {
601          return getInitialContents(getXMLBase(), fileHandle);
602       }
603       if (_importURL != null && input == null)
604       {
605          try
606          {
607             input = _importURL.openStream();
608          }
609          catch (IOException ioe)
610          {
611             OWLCore.logWarning(UIPlugin.getID(),
612                "Unable to import external document: " + _importURL.toString(),
613                ioe);
614             return getInitialContents();
615          }
616       }
617       return input;
618    }
619    /***
620     * Returns the label to display in the file name specification visual
621     * component group.
622     * <p>
623     * Subclasses may reimplement.
624     * </p>
625     *
626     * @return the label to display in the file name specification visual
627     *     component group
628     */
629    protected String getNewFileLabel()
630    {
631       return "File Name";
632    }
633    
634    /***
635     * Retrieves the user-provided XML base for the new OWL document.
636     * @return The value from the XML base text box.
637     */
638    protected String getXMLBase()
639    {
640       if (_xmlBaseURI == null)
641       {
642          return null;
643       }
644       return _xmlBaseURI.toString();
645    }
646    /***
647     * The <code>WizardNewFileCreationPage</code> implementation of this 
648     * <code>Listener</code> method handles all events and enablements for controls
649     * on this page. Subclasses may extend.
650     * @param event The event to handle
651     */
652    public void handleEvent(Event event)
653    {
654       setPageComplete(validatePage());
655    }
656    /***
657     * Sets the initial contents of the container name entry field, based upon
658     * either a previously-specified initial value or the ability to determine
659     * such a value.
660     */
661    protected void initialPopulateContainerNameField()
662    {
663       if (_initialContainerFullPath != null)
664       {
665          _resourceGroup.setContainerFullPath(_initialContainerFullPath);
666       }
667       else
668       {
669          Iterator it = _currentSelection.iterator();
670          if (it.hasNext())
671          {
672             Object object = it.next();
673             IResource selectedResource = null;
674             if (object instanceof IResource)
675             {
676                selectedResource = (IResource) object;
677             }
678             else if (object instanceof IAdaptable)
679             {
680                selectedResource =
681                   (IResource) ((IAdaptable) object).getAdapter(IResource.class);
682             }
683             if (selectedResource != null)
684             {
685                if (selectedResource.getType() == IResource.FILE)
686                {
687                   selectedResource = selectedResource.getParent();
688                }
689                if (selectedResource.isAccessible())
690                {
691                   _resourceGroup.setContainerFullPath(
692                      selectedResource.getFullPath());
693                }
694             }
695          }
696       }
697    }
698    /***
699     * Sets the value of this page's container name field, or stores
700     * it for future use if this page's controls do not exist yet.
701     *
702     * @param path the full path to the container
703     */
704    public void setContainerFullPath(IPath path)
705    {
706       if (_resourceGroup == null)
707       {
708          _initialContainerFullPath = path;
709       }
710       else
711       {
712          _resourceGroup.setContainerFullPath(path);
713       }
714    }
715    /***
716     * Sets the value of this page's file name field, or stores
717     * it for future use if this page's controls do not exist yet.
718     *
719     * @param value new file name
720     */
721    public void setFileName(String value)
722    {
723       if (_resourceGroup == null)
724       {
725          _sInitialFileName = value;
726       }
727       else
728       {
729          _resourceGroup.setResource(value);
730       }
731    }
732 
733    /***
734     * Returns whether this page's controls currently all contain valid 
735     * values.
736     *
737     * @return <code>true</code> if all controls are valid, and
738     *   <code>false</code> if at least one is invalid
739     */
740    protected boolean validatePage()
741    {
742       boolean valid = true;
743       boolean warning = false;
744 
745       /*
746        * Validation checks should be performed in order of
747        * highest priority. Each validation section should only
748        * start if valid==true.
749        */
750       // ResourceGroup validation
751       if (!_resourceGroup.areAllValuesValid())
752       {
753          // if blank name then fail silently
754          if (_resourceGroup.getProblemType()
755             == ResourceAndContainerGroup.PROBLEM_RESOURCE_EMPTY
756             || _resourceGroup.getProblemType()
757                == ResourceAndContainerGroup.PROBLEM_CONTAINER_EMPTY)
758          {
759             setMessage(_resourceGroup.getProblemMessage());
760             setErrorMessage(null);
761          }
762          else
763          {
764             setErrorMessage(_resourceGroup.getProblemMessage());
765          }
766          valid = false;
767       }
768       // if we're invalid, go ahead and return
769       if (!valid)
770       {
771          return false;
772       }
773 
774       // check that filename ends with .owl
775       if (!(getFileName().endsWith(".owl")))
776       {
777          setErrorMessage("Filename must end with .owl");
778          valid = false;
779       }
780 
781       // if we're invalid, go ahead and return
782       if (!valid)
783       {
784          return false;
785       }
786 
787       // xmlBase validation
788       if (!_bImportExternal)
789       {
790          if (_tfXMLBase.getText().length() < 1)
791          {
792             setMessage(
793                "No XML Base specified.\nLocal URI (file:...) will be used.",
794                WARNING);
795             setErrorMessage(null);
796             warning = true;
797          }
798          else
799          {
800             // there must be some text. Remove any warning message.
801             setMessage(null);
802             try
803             {
804                _xmlBaseURI = new URI(_tfXMLBase.getText());
805             }
806             catch (MalformedURIException use)
807             {
808                setErrorMessage("Invalid XML Base specified");
809                _xmlBaseURI = null;
810                valid = false;
811             }
812          }
813       }
814 
815       // if we're invalid, go ahead and return
816       if (!valid)
817       {
818          return false;
819       }
820 
821       // Import Controls validation
822       if (_bImportExternal)
823       {
824          try
825          {
826             _importURL = new URL(_tfImportURI.getText());
827          }
828          catch (MalformedURLException mfe)
829          {
830             setErrorMessage("Valid URL required for importing OWL document");
831             valid = false;
832          }
833       }
834 
835       // if we're invalid, go ahead and return
836       if (!valid)
837       {
838          return false;
839       }
840 
841       // if we're here then everything is valid
842       setErrorMessage(null);
843       if (!warning)
844       {
845          setMessage(null);
846       }
847       return true;
848    }
849    private void importTextModified()
850    {
851       URL url = null;
852       try
853       {
854          url = new URL(_tfImportURI.getText());
855       }
856       catch (MalformedURLException mfe)
857       {
858          return;
859       }
860       _resourceGroup.setResource(suggestedFileName(_tfImportURI.getText()));
861    }
862    private String suggestedFileName(String url)
863    {
864       String name = "";
865       name = url.substring(url.lastIndexOf('/') + 1);
866       if (!name.endsWith(".owl") && !name.endsWith(".OWL"))
867       {
868          name += ".owl";
869       }
870       return name;
871    }
872    /*
873     *  (non-Javadoc)
874     * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
875     */
876    public void setVisible(boolean visible)
877    {
878       super.setVisible(visible);
879       if (visible)
880       {
881          _resourceGroup.setFocus();
882       }
883    }
884 }