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.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.AttributeListRule;
19  import sk.uniba.euromath.editor.lang.Messages;
20  import sk.uniba.euromath.editor.widgets.CreateAttributeList;
21  import sk.uniba.euromath.editor.widgets.IModifyListener;
22  import sk.uniba.euromath.editor.widgets.ValidityMessages;
23  import sk.uniba.euromath.editor.wizards.BaseWizardPage;
24  /***
25   * Manages the process of creating new attributes into newly created element.
26   * Attributes themselves are not created, their names and values are returned
27   * instead.
28   * @author Martin Vysny
29   */
30  public class CreateAttributeListWizardPage extends BaseWizardPage {
31  	/***
32  	 * The widget.
33  	 */
34  	private CreateAttributeList cal;
35  	/***
36  	 * Returns the widget.
37  	 * @return underlying widget.
38  	 */
39  	public CreateAttributeList getWidget() {
40  		return cal;
41  	}
42  	/***
43  	 * Constructor.
44  	 * @param listRules the list of lists of attribute. Exactly one list will be
45  	 * chosen.
46  	 * @param parentName the name of the parent element. Used only to display
47  	 * the name on the shell.
48  	 * @param xmlAccess the xml document instance.
49  	 * @param currentManager the current manager. It won't get modified.
50  	 */
51  	public CreateAttributeListWizardPage(List<AttributeListRule> listRules,
52  			String parentName, XMLAccess xmlAccess,
53  			NamespaceManager currentManager) {
54  		super("CreateAttributeList", Messages //$NON-NLS-1$
55  				.getString("SELECT_ATTRIBUTES_FOR_NEW_ELEMENT"), null); //$NON-NLS-1$
56  		this.listRules = listRules;
57  		this.parentName = parentName;
58  		this.xmlAccess = xmlAccess;
59  		this.currentManager = currentManager;
60  	}
61  	/***
62  	 * the list of lists of attribute. Exactly one list will be chosen.
63  	 */
64  	public final List<AttributeListRule> listRules;
65  	/***
66  	 * the name of the parent element. Used only to display the name on the
67  	 * shell.
68  	 */
69  	public final String parentName;
70  	/***
71  	 * The document instance.
72  	 */
73  	public final XMLAccess xmlAccess;
74  	/***
75  	 * the current manager. It won't get modified.
76  	 */
77  	public final NamespaceManager currentManager;
78  	/*
79  	 * (non-Javadoc)
80  	 * @see sk.uniba.euromath.editor.wizards.BaseWizardPage#handleCreateControl(org.eclipse.swt.widgets.Composite)
81  	 */
82  	@Override
83  	public Control handleCreateControl(Composite parent) {
84  		cal = new CreateAttributeList(parent, listRules, parentName, xmlAccess,
85  				currentManager);
86  		cal.addModifyListener(new IModifyListener() {
87  			/*
88  			 * (non-Javadoc)
89  			 * @see sk.uniba.euromath.editor.widgets.IModifyListener#dataModified()
90  			 */
91  			public void dataModified() {
92  				validatePage();
93  			}
94  		});
95  		validatePage();
96  		return cal.getComposite();
97  	}
98  	/***
99  	 * Validates the page and shows appropriate error message if necessary.
100 	 * @return <code>true</code> if page is OK.
101 	 */
102 	protected boolean validatePage() {
103 		cal.getNames();
104 		final ValidityMessages messages = cal.getMessages();
105 		setMessages(messages);
106 		return (messages == null) || (messages.error == null);
107 	}
108 	/*
109 	 * (non-Javadoc)
110 	 * @see sk.uniba.euromath.editor.wizards.BaseWizardPage#handleDispose()
111 	 */
112 	@Override
113 	protected void handleDispose() {
114 		// do nothing
115 	}
116 }