View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics and Informatics, Comenius
3    * University, Bratislava. This file is protected by the Mozilla Public License
4    * version 1.1 (the "License"); you may not use this file except in compliance
5    * with the License. You may obtain a copy of the License at
6    * http://euromath2.sourceforge.net/license.html Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is
8    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9    * KIND, either express or implied. See the License for the specific language
10   * governing permissions and limitations under the License.
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  		// create components and initialize them
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")); //$NON-NLS-1$
47  		canonicalForm.setToolTipText(Messages.getString("CANONICAL_FORM_HINT")); //$NON-NLS-1$
48  		canonicalForm.addSelectionListener(new SelectionAdapter() {
49  			/* (non-Javadoc)
50  			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
61  		discardDefaultContent.setToolTipText(Messages.getString("DISCARD_DEFAULTS_HINT")); //$NON-NLS-1$
62  		discardDefaultContent.addSelectionListener(new SelectionAdapter() {
63  			/* (non-Javadoc)
64  			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
74  		formatPrettyPrint.setToolTipText(Messages.getString("PRETTY_PRINT_HINT")); //$NON-NLS-1$
75  		formatPrettyPrint.addSelectionListener(new SelectionAdapter() {
76  			/* (non-Javadoc)
77  			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
87  		xmlDeclaration.setToolTipText(Messages.getString("XML_DECLARATION_HINT")); //$NON-NLS-1$
88  		xmlDeclaration.addSelectionListener(new SelectionAdapter() {
89  			/* (non-Javadoc)
90  			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
100 		cdataSections.setToolTipText(Messages.getString("KEEP_CDATA_HINT")); //$NON-NLS-1$
101 		cdataSections.addSelectionListener(new SelectionAdapter() {
102 			/* (non-Javadoc)
103 			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
113 		comments.setToolTipText(Messages.getString("KEEP_COMMENTS_HINT")); //$NON-NLS-1$
114 		comments.addSelectionListener(new SelectionAdapter() {
115 			/* (non-Javadoc)
116 			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
126 		elementContentWhitespace.setToolTipText(Messages.getString("KEEP_WHITESPACES_HINT")); //$NON-NLS-1$
127 		elementContentWhitespace.addSelectionListener(new SelectionAdapter() {
128 			/* (non-Javadoc)
129 			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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")); //$NON-NLS-1$
139 		entities.setToolTipText(Messages.getString("KEEP_ENTITIES_HINT")); //$NON-NLS-1$
140 		entities.addSelectionListener(new SelectionAdapter() {
141 			/* (non-Javadoc)
142 			 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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 	 * (non-Javadoc)
185 	 * @see sk.uniba.euromath.editor.widgets.IUserInputWidget#getComposite()
186 	 */
187 	public Composite getComposite() {
188 		return c;
189 	}
190 	/*
191 	 * (non-Javadoc)
192 	 * @see sk.uniba.euromath.editor.widgets.IUserInputWidget#getLastError()
193 	 */
194 	public ValidityMessages getMessages() {
195 		// this form has always valid data. just return null
196 		return null;
197 	}
198 	/* (non-Javadoc)
199 	 * @see sk.uniba.euromath.editor.widgets.IUserInputWidget#getModel()
200 	 */
201 	public Object getState() {
202 		return model;
203 	}
204 	/* (non-Javadoc)
205 	 * @see sk.uniba.euromath.editor.widgets.IUserInputWidget#getModelClass()
206 	 */
207 	public Class< ? > getStateClass() {
208 		return XMLSerializeBean.class;
209 	}
210 	/* (non-Javadoc)
211 	 * @see sk.uniba.euromath.editor.widgets.IUserInputWidget#setModel(java.lang.Object)
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 }