1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.gene.gui.widgets;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionAdapter;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.layout.RowLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import sk.baka.ikslibs.beans.XMLSerializeBean;
20 import sk.uniba.euromath.editor.widgets.AbstractUserInputWidget;
21 import sk.uniba.euromath.editor.widgets.ValidityMessages;
22 import sk.uniba.euromath.gene.lang.Messages;
23 /***
24 * Queries the DOM Level 3 Load/Save export parameters. Useful when serializing
25 * XML document.
26 * @author Martin Vysny
27 */
28 public class XMLSerializerPropertiesWidget extends AbstractUserInputWidget {
29 /***
30 * All controls are placed here.
31 */
32 protected final Composite c;
33 /***
34 * Creates an instance of the object, with default values.
35 * @param parent the parent composite.
36 */
37 public XMLSerializerPropertiesWidget(Composite parent) {
38 super();
39 c = new Composite(parent, SWT.NONE);
40
41 RowLayout shellLayout = new RowLayout();
42 shellLayout.type = SWT.VERTICAL;
43 shellLayout.fill = true;
44 c.setLayout(shellLayout);
45 canonicalForm = new Button(c, SWT.CHECK);
46 canonicalForm.setText(Messages.getString("CANONICAL_FORM"));
47 canonicalForm.setToolTipText(Messages.getString("CANONICAL_FORM_HINT"));
48 canonicalForm.addSelectionListener(new SelectionAdapter() {
49
50
51
52 @Override
53 public void widgetSelected(SelectionEvent e) {
54 model.setCanonicalForm(canonicalForm.getSelection());
55 enableControls();
56 fireDataModified();
57 }
58 });
59 discardDefaultContent = new Button(c, SWT.CHECK);
60 discardDefaultContent.setText(Messages.getString("DISCARD_DEFAULTS"));
61 discardDefaultContent.setToolTipText(Messages.getString("DISCARD_DEFAULTS_HINT"));
62 discardDefaultContent.addSelectionListener(new SelectionAdapter() {
63
64
65
66 @Override
67 public void widgetSelected(SelectionEvent e) {
68 model.setDiscardDefaultContent(discardDefaultContent.getSelection());
69 fireDataModified();
70 }
71 });
72 formatPrettyPrint = new Button(c, SWT.CHECK);
73 formatPrettyPrint.setText(Messages.getString("PRETTY_PRINT"));
74 formatPrettyPrint.setToolTipText(Messages.getString("PRETTY_PRINT_HINT"));
75 formatPrettyPrint.addSelectionListener(new SelectionAdapter() {
76
77
78
79 @Override
80 public void widgetSelected(SelectionEvent e) {
81 model.setFormatPrettyPrint(formatPrettyPrint.getSelection());
82 fireDataModified();
83 }
84 });
85 xmlDeclaration = new Button(c, SWT.CHECK);
86 xmlDeclaration.setText(Messages.getString("XML_DECLARATION"));
87 xmlDeclaration.setToolTipText(Messages.getString("XML_DECLARATION_HINT"));
88 xmlDeclaration.addSelectionListener(new SelectionAdapter() {
89
90
91
92 @Override
93 public void widgetSelected(SelectionEvent e) {
94 model.setXmlDeclaration(xmlDeclaration.getSelection());
95 fireDataModified();
96 }
97 });
98 cdataSections = new Button(c, SWT.CHECK);
99 cdataSections.setText(Messages.getString("KEEP_CDATA"));
100 cdataSections.setToolTipText(Messages.getString("KEEP_CDATA_HINT"));
101 cdataSections.addSelectionListener(new SelectionAdapter() {
102
103
104
105 @Override
106 public void widgetSelected(SelectionEvent e) {
107 model.setCdataSections(cdataSections.getSelection());
108 fireDataModified();
109 }
110 });
111 comments = new Button(c, SWT.CHECK);
112 comments.setText(Messages.getString("KEEP_COMMENTS"));
113 comments.setToolTipText(Messages.getString("KEEP_COMMENTS_HINT"));
114 comments.addSelectionListener(new SelectionAdapter() {
115
116
117
118 @Override
119 public void widgetSelected(SelectionEvent e) {
120 model.setComments(comments.getSelection());
121 fireDataModified();
122 }
123 });
124 elementContentWhitespace = new Button(c, SWT.CHECK);
125 elementContentWhitespace.setText(Messages.getString("KEEP_WHITESPACES"));
126 elementContentWhitespace.setToolTipText(Messages.getString("KEEP_WHITESPACES_HINT"));
127 elementContentWhitespace.addSelectionListener(new SelectionAdapter() {
128
129
130
131 @Override
132 public void widgetSelected(SelectionEvent e) {
133 model.setElementContentWhitespace(elementContentWhitespace.getSelection());
134 fireDataModified();
135 }
136 });
137 entities = new Button(c, SWT.CHECK);
138 entities.setText(Messages.getString("KEEP_ENTITIES"));
139 entities.setToolTipText(Messages.getString("KEEP_ENTITIES_HINT"));
140 entities.addSelectionListener(new SelectionAdapter() {
141
142
143
144 @Override
145 public void widgetSelected(SelectionEvent e) {
146 model.setEntities(entities.getSelection());
147 fireDataModified();
148 }
149 });
150 }
151 private final Button canonicalForm;
152 private final Button discardDefaultContent;
153 private final Button formatPrettyPrint;
154 private final Button xmlDeclaration;
155 private final Button cdataSections;
156 private final Button comments;
157 private final Button elementContentWhitespace;
158 private final Button entities;
159 /***
160 * Refreshes the controls.
161 */
162 private void enableControls() {
163 boolean enable = !model.isCanonicalForm();
164 discardDefaultContent.setEnabled(enable);
165 formatPrettyPrint.setEnabled(enable);
166 xmlDeclaration.setEnabled(enable);
167 cdataSections.setEnabled(enable);
168 elementContentWhitespace.setEnabled(enable);
169 entities.setEnabled(enable);
170 if (!enable) {
171 discardDefaultContent.setSelection(false);
172 formatPrettyPrint.setSelection(false);
173 xmlDeclaration.setSelection(false);
174 cdataSections.setSelection(false);
175 elementContentWhitespace.setSelection(true);
176 entities.setSelection(false);
177 }
178 }
179 /***
180 * Underlying model.
181 */
182 private XMLSerializeBean model=new XMLSerializeBean();
183
184
185
186
187 public Composite getComposite() {
188 return c;
189 }
190
191
192
193
194 public ValidityMessages getMessages() {
195
196 return null;
197 }
198
199
200
201 public Object getState() {
202 return model;
203 }
204
205
206
207 public Class< ? > getStateClass() {
208 return XMLSerializeBean.class;
209 }
210
211
212
213 public void setState(Object model) {
214 this.model=(XMLSerializeBean)model;
215 if(!canonicalForm.isDisposed())canonicalForm.setSelection(this.model.isCanonicalForm());
216 if(!discardDefaultContent.isDisposed())discardDefaultContent.setSelection(this.model.isDiscardDefaultContent());
217 if(!formatPrettyPrint.isDisposed())formatPrettyPrint.setSelection(this.model.isFormatPrettyPrint());
218 if(!xmlDeclaration.isDisposed())xmlDeclaration.setSelection(this.model.isXmlDeclaration());
219 if(!cdataSections.isDisposed())cdataSections.setSelection(this.model.isCdataSections());
220 if(!comments.isDisposed())comments.setSelection(this.model.isComments());
221 if(!elementContentWhitespace.isDisposed())elementContentWhitespace.setSelection(this.model.isElementContentWhitespace());
222 if(!entities.isDisposed())entities.setSelection(this.model.isEntities());
223 enableControls();
224 }
225
226 }