View Javadoc

1   /*
2    * Created on Mar 12, 2005. Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the "License"); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.editor.wizards.document;
13  import java.util.Set;
14  import org.eclipse.swt.widgets.Composite;
15  import org.eclipse.swt.widgets.Control;
16  import sk.uniba.euromath.document.NamespaceManager;
17  import sk.uniba.euromath.editor.lang.Messages;
18  import sk.uniba.euromath.editor.widgets.IModifyListener;
19  import sk.uniba.euromath.editor.widgets.NewPrefixesQuery;
20  import sk.uniba.euromath.editor.widgets.ValidityMessages;
21  import sk.uniba.euromath.editor.wizards.BaseWizardPage;
22  /***
23   * Queries for new prefixes.
24   * @author Martin Vysny
25   */
26  public class NewPrefixesQueryWizardPage extends BaseWizardPage {
27  	/***
28  	 * The widget. Do not modify.
29  	 */
30  	public NewPrefixesQuery npq;
31  	/***
32  	 * Constructor.
33  	 * @param namespaces get prefixes for these namespaces.
34  	 * @param nsManager current namespace manager. New prefixes are not
35  	 * registered here, new manager is created instead.
36  	 */
37  	public NewPrefixesQueryWizardPage(Set<String> namespaces,
38  			NamespaceManager nsManager) {
39  		super(
40  				"NewPrefixesQuery", Messages.getString("SELECT_NEW_PREFIXES"), null); //$NON-NLS-1$ //$NON-NLS-2$
41  		this.namespaces = namespaces;
42  		this.nsManager = nsManager;
43  	}
44  	/***
45  	 * Get prefixes for these namespaces.
46  	 */
47  	protected final Set<String> namespaces;
48  	/***
49  	 * Current namespace manager. New prefixes are not registered here, new
50  	 * manager is created instead.
51  	 */
52  	protected final NamespaceManager nsManager;
53  	/*
54  	 * (non-Javadoc)
55  	 * @see sk.uniba.euromath.editor.wizards.BaseWizardPage#handleCreateControl(org.eclipse.swt.widgets.Composite)
56  	 */
57  	@Override
58  	public Control handleCreateControl(Composite parent) {
59  		npq = new NewPrefixesQuery(parent, namespaces, nsManager);
60  		npq.addModifyListener(new IModifyListener() {
61  			public void dataModified() {
62  				validatePage();
63  			}
64  		});
65  		validatePage();
66  		return npq.getComposite();
67  	}
68  	/***
69  	 * Validates the page and shows appropriate error message if necessary.
70  	 */
71  	protected void validatePage() {
72  		npq.getPrefixes();
73  		ValidityMessages messages = npq.getMessages();
74  		setMessages(messages);
75  	}
76  	/*
77  	 * (non-Javadoc)
78  	 * @see sk.uniba.euromath.editor.wizards.BaseWizardPage#handleDispose()
79  	 */
80  	@Override
81  	public void handleDispose() {
82  		// do nothing
83  	}
84  }