View Javadoc

1   /*
2    * $Id: NewOWLOntologyWizardPage.java,v 1.3 2005/05/31 21:57:12 jlerner Exp $
3    * Created on May 19, 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 org.eclipse.jface.dialogs.IDialogConstants;
13  import org.eclipse.jface.wizard.WizardPage;
14  import org.eclipse.swt.SWT;
15  import org.eclipse.swt.events.ModifyEvent;
16  import org.eclipse.swt.events.ModifyListener;
17  import org.eclipse.swt.layout.GridData;
18  import org.eclipse.swt.layout.GridLayout;
19  import org.eclipse.swt.widgets.Composite;
20  import org.eclipse.swt.widgets.Label;
21  import org.eclipse.swt.widgets.Text;
22  
23  /***
24   * Wizard page for naming and versioning an Ontology.
25   * @author tself
26   */
27  public class NewOWLOntologyWizardPage extends WizardPage
28  {
29     private String _sTitle;
30     private String _sCreator;
31     private String _sEmail;
32     private String _sVersion;
33     private String _sReleaseDate;
34     private String _sReleaseLevel;
35     private String _sStatus;
36     private String _sComments;
37  
38     private Text _tTitle, _tCreator, _tEmail, _tVersion;
39     private Text _tReleaseDate, _tReleaseLevel, _tStatus;
40     private Text _tComments;
41  
42     /***
43      * Default constructor.
44      */
45     public NewOWLOntologyWizardPage()
46     {
47        super("New OWL Ontology");
48        setDescription("Create a new OWL ontology within an OWL document");
49        setTitle("New OWL Ontology");
50     }
51  
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
54      */
55     public void createControl(Composite parent)
56     {
57        ModifyListener listener = new ModifyListener()
58        {
59           public void modifyText(ModifyEvent e)
60           {
61              validate();
62           }
63        };
64        Composite container = new Composite(parent, SWT.NONE);
65        GridLayout mainLayout = new GridLayout();
66        mainLayout.verticalSpacing = 0;
67        mainLayout.horizontalSpacing = 0;
68        mainLayout.marginWidth = 0;
69        container.setLayout(mainLayout);
70        GridData mainData =
71           new GridData(
72              GridData.VERTICAL_ALIGN_FILL
73                 | GridData.HORIZONTAL_ALIGN_FILL
74                 | GridData.GRAB_VERTICAL);
75        container.setLayoutData(mainData);
76        container.setFont(parent.getFont());
77  
78        // title
79        _tTitle = createTextWithLabel(container, "Title");
80        _tTitle.addModifyListener(listener);
81        // creator and email
82        Composite comp = new Composite(container, SWT.NONE);
83        GridLayout gl = new GridLayout();
84        comp.setLayoutData(
85           new GridData(
86              GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
87        gl.marginHeight = 2;
88        gl.marginWidth = 2;
89        gl.numColumns = 2;
90        comp.setLayout(gl);
91        _tCreator = createTextWithLabel(comp, "Creator");
92        _tCreator.addModifyListener(listener);
93        _tEmail = createTextWithLabel(comp, "Email");
94        _tEmail.addModifyListener(listener);
95        // version and releaseDate
96        comp = new Composite(container, SWT.NONE);
97        gl = new GridLayout();
98        comp.setLayoutData(
99           new GridData(
100             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
101       gl.marginHeight = 2;
102       gl.marginWidth = 2;
103       gl.numColumns = 2;
104       comp.setLayout(gl);
105       _tVersion = createTextWithLabel(comp, "Version");
106       _tVersion.addModifyListener(listener);
107       _tReleaseDate = createTextWithLabel(comp, "Release Date");
108       _tReleaseDate.addModifyListener(listener);
109       // releaseLevel and status
110       comp = new Composite(container, SWT.NONE);
111       gl = new GridLayout();
112       comp.setLayoutData(
113          new GridData(
114             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
115       gl.marginHeight = 2;
116       gl.marginWidth = 2;
117       gl.numColumns = 2;
118       comp.setLayout(gl);
119       _tReleaseLevel = createTextWithLabel(comp, "Release Level");
120       _tReleaseLevel.addModifyListener(listener);
121       _tStatus = createTextWithLabel(comp, "Status");
122       _tStatus.addModifyListener(listener);
123       // comments
124       comp = new Composite(container, SWT.NONE);
125       gl = new GridLayout();
126       comp.setLayoutData(
127          new GridData(
128             GridData.HORIZONTAL_ALIGN_FILL
129                | GridData.GRAB_HORIZONTAL
130                | GridData.VERTICAL_ALIGN_FILL
131                | GridData.GRAB_VERTICAL));
132       gl.marginHeight = 2;
133       gl.marginWidth = 2;
134       comp.setLayout(gl);
135       Label lComments = new Label(comp, SWT.NONE);
136       lComments.setText("Comments");
137       GridData gd =
138          new GridData(
139             GridData.HORIZONTAL_ALIGN_FILL
140                | GridData.GRAB_HORIZONTAL
141                | GridData.VERTICAL_ALIGN_FILL
142                | GridData.GRAB_VERTICAL);
143       _tComments = new Text(comp, SWT.BORDER | SWT.MULTI | SWT.WRAP);
144       _tComments.setLayoutData(gd);
145       _tComments.addModifyListener(listener);
146 
147       setControl(parent);
148       validate();
149    }
150    private Text createTextWithLabel(Composite parent, String label)
151    {
152       Composite comp = new Composite(parent, SWT.NONE);
153       GridData gd = new GridData();
154       gd.grabExcessHorizontalSpace = true;
155       gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_FILL;
156       GridLayout layout = new GridLayout();
157       layout.numColumns = 2;
158       layout.marginWidth = 0;
159       comp.setLayout(layout);
160       comp.setLayoutData(
161          new GridData(
162             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
163       comp.setFont(parent.getFont());
164 
165       Label l = new Label(comp, SWT.NONE);
166       l.setText(label);
167       l.setFont(parent.getFont());
168 
169       Text t = new Text(comp, SWT.BORDER);
170       GridData data =
171          new GridData(
172             GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
173       data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
174       data.widthHint = 100;
175       t.setLayoutData(data);
176       t.setFont(parent.getFont());
177       return t;
178    }
179    private Composite createSplitRow(
180       Composite parent,
181       Composite left,
182       Composite right)
183    {
184       Composite comp = new Composite(parent, SWT.NONE);
185       GridLayout gl = new GridLayout();
186       gl.numColumns = 2;
187       comp.setLayout(gl);
188       return comp;
189    }
190 
191    private void validate()
192    {
193       boolean valid = true;
194       boolean warning = false;
195 
196       /*
197        * Validation checks should be performed in order of
198        * highest priority. Each validation section should only
199        * start if valid==true.
200        */
201 
202       // title validation
203       if (_tTitle.getText().length() < 1)
204       {
205          setErrorMessage("Title must be specified");
206          _sTitle = null;
207          valid = false;
208       }
209 
210       // if we're invalid, go ahead and return
211       if (!valid)
212       {
213          setPageComplete(valid);
214          return;
215       }
216 
217       // email validation
218       if (_tEmail.getText() != null
219          && _tEmail.getText().length() > 0
220          && !(valid = isValidEmail(_tEmail.getText())))
221       {
222          setErrorMessage("Invalid email address");
223          _sEmail = null;
224       }
225 
226       // if we're invalid, go ahead and return
227       if (!valid)
228       {
229          setPageComplete(valid);
230          return;
231       }
232 
233       // releaseDate validation
234       if (_tReleaseDate.getText() != null
235          && _tReleaseDate.getText().length() > 0
236          && !(valid = isValidDate(_tReleaseDate.getText())))
237       {
238          setErrorMessage("Invalid email address");
239          _sReleaseDate = null;
240       }
241 
242       // if we're invalid, go ahead and return
243       if (!valid)
244       {
245          setPageComplete(valid);
246          return;
247       }
248 
249       // if we're here then everything is valid
250       setErrorMessage(null);
251       if (!warning)
252       {
253          setMessage(null);
254       }
255 
256       _sEmail = _tEmail.getText();
257       _sTitle = _tTitle.getText();
258       _sCreator = _tCreator.getText();
259       _sVersion = _tVersion.getText();
260       _sReleaseDate = _tReleaseDate.getText();
261       _sReleaseLevel = _tReleaseLevel.getText();
262       _sStatus = _tStatus.getText();
263       _sComments = _tComments.getText();
264       setPageComplete(valid);
265    }
266    private boolean isValidEmail(String email)
267    {
268       return true;
269    }
270    private boolean isValidDate(String date)
271    {
272       return true;
273    }
274 
275    /***
276     * Retrieves the user-defined comments for the Ontology.
277     * @return The contents of the Comments text box.
278     */
279    public String getComments()
280    {
281       return (_sComments.length() > 0 ? _sComments : null);
282    }
283 
284    /***
285     * Retrieves the user-defined creator for the Ontology.
286     * @return The contents of the Creator text box.
287     */
288    public String getCreator()
289    {
290       return _sCreator.length() > 0 ? _sCreator : null;
291    }
292 
293    /***
294     * Retrieves the user-defined e-mail address for the Ontology.
295     * @return The contents of the E-mail text box.
296     */
297    public String getEmail()
298    {
299       return _sEmail.length() > 0 ? _sEmail : null;
300    }
301 
302    /***
303     * Retrieves the user-defined release date for the Ontology.
304     * @return The contents of the Release Date text box.
305     */
306    public String getReleaseDate()
307    {
308       return _sReleaseDate.length() > 0 ? _sReleaseDate : null;
309    }
310 
311    /***
312     * Retrieves the user-defined release level for the Ontology.
313     * @return The contents of the Release Level text box.
314     */
315    public String getReleaseLevel()
316    {
317       return _sReleaseLevel.length() > 0 ? _sReleaseLevel : null;
318    }
319 
320    /***
321     * Retrieves the user-defined status for the Ontology.
322     * @return The contents of the Status text box.
323     */
324    public String getStatus()
325    {
326       return _sStatus.length() > 0 ? _sStatus : null;
327    }
328 
329    /***
330     * Retrieves the user-defined title for the Ontology.
331     * @return The contents of the Title text box.
332     */
333    public String getOntologyTitle()
334    {
335       return _sTitle.length() > 0 ? _sTitle : null;
336    }
337 
338    /***
339     * Retrieves the user-defined version for the Ontology.
340     * @return The contents of the Version text box.
341     */
342    public String getVersion()
343    {
344       return _sVersion.length() > 0 ? _sVersion : null;
345    }
346 
347    /***
348     * Sets the release date field of the wizard page.
349     * @param string The release date to set.
350     */
351    public void setReleaseDate(String string)
352    {
353       _tReleaseDate.setText(string);
354    }
355 }