View Javadoc

1   /*
2    * Created on Mar 18, 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.List;
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.document.XMLAccess;
18  import sk.uniba.euromath.document.schema.InsertList;
19  import sk.uniba.euromath.document.schema.plug.IValueRule;
20  import sk.uniba.euromath.editor.lang.Messages;
21  import sk.uniba.euromath.editor.widgets.IModifyListener;
22  import sk.uniba.euromath.editor.widgets.InsertListChooser;
23  import sk.uniba.euromath.editor.widgets.ValidityMessages;
24  import sk.uniba.euromath.editor.wizards.BaseWizardPage;
25  /***
26   * Allows the user to choose between multiple insertlists, and to choose the
27   * name of each element. These user settings are returned. Alternatively, user
28   * may choose to enter some text if it is permitted by the rule.
29   * @author Martin Vysny
30   */
31  public class InsertListChooserWizardPage extends BaseWizardPage {
32  	/***
33  	 * The widget.
34  	 */
35  	private InsertListChooser ilc = null;
36  	/***
37  	 * Returns the widget.
38  	 * @return underlying widget.
39  	 */
40  	public InsertListChooser getWidget() {
41  		return ilc;
42  	}
43  	/***
44  	 * The constructor.
45  	 * @param xmlAccess the XML Access instance.
46  	 * @param insertLists the list of choosable insertlists.
47  	 * @param nsManager the map of namespace>prefix mapping. It will not get
48  	 * modified. If <code>null</code> then manager from <code>xmlAccess</code>
49  	 * will be used.
50  	 * @param parentName the displayable qname of the parent. It is only
51  	 * displayed in a window as a text - it is not used in other way.
52  	 * @param textRule if not <code>null</code> then it is possible to choose
53  	 * a text value also. This value must comply this rule.
54  	 * @param title optional title. If <code>null</code> then default one is
55  	 * used.
56  	 */
57  	public InsertListChooserWizardPage(XMLAccess xmlAccess,
58  			List<InsertList> insertLists, NamespaceManager nsManager,
59  			String parentName, IValueRule textRule, String title) {
60  		super("InsertListChooser", //$NON-NLS-1$
61  				title == null ? Messages.getString("SELECT_NODE_NAMELIST") : title, null); //$NON-NLS-1$
62  		this.xmlAccess = xmlAccess;
63  		this.insertLists = insertLists;
64  		this.nsManager = nsManager;
65  		this.parentName = parentName;
66  		this.textRule = textRule;
67  	}
68  	/***
69  	 * The XML Access instance.
70  	 */
71  	protected final XMLAccess xmlAccess;
72  	/***
73  	 * Insertlists.
74  	 */
75  	protected final List<InsertList> insertLists;
76  	/***
77  	 * User may choose to enter text contents of an element instead.
78  	 */
79  	protected final IValueRule textRule;
80  	/***
81  	 * The displayable qname of the parent. It is only displayed in a window as
82  	 * a text - it is not used in other way.
83  	 */
84  	protected final String parentName;
85  	/***
86  	 * Current namespace manager.
87  	 */
88  	protected final NamespaceManager nsManager;
89  	/*
90  	 * (non-Javadoc)
91  	 * @see sk.uniba.euromath.editor.wizards.BaseWizardPage#handleCreateControl(org.eclipse.swt.widgets.Composite)
92  	 */
93  	@Override
94  	protected Control handleCreateControl(Composite parent) {
95  		ilc = new InsertListChooser(parent, xmlAccess, insertLists, nsManager,
96  				parentName, textRule);
97  		ilc.addModifyListener(new IModifyListener() {
98  			public void dataModified() {
99  				validatePage();
100 			}
101 		});
102 		validatePage();
103 		return ilc.getComposite();
104 	}
105 	/***
106 	 * Validates the page and shows appropriate error message if necessary.
107 	 */
108 	protected void validatePage() {
109 		// collect all error messages
110 		int i = ilc.getSelected();
111 		if (i == -2)
112 			ilc.getText();
113 		else if (i >= 0)
114 			ilc.getInsertListNames();
115 		// show messages
116 		ValidityMessages messages = ilc.getMessages();
117 		assert (i != -1) || (messages.error != null);
118 		setMessages(messages);
119 	}
120 	/*
121 	 * (non-Javadoc)
122 	 * @see sk.uniba.euromath.editor.wizards.BaseWizardPage#handleDispose()
123 	 */
124 	@Override
125 	public void handleDispose() {
126 		// do nothing.
127 	}
128 }