1
2
3
4
5
6
7
8
9
10
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
55 .getString("SELECT_ATTRIBUTES_FOR_NEW_ELEMENT"), null);
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
80
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
89
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
110
111
112 @Override
113 protected void handleDispose() {
114
115 }
116 }