blob: 395fdedfca49d87d2b685a14c07bf8ba216d2e02 [file] [log] [blame]
nitind958d79a2004-11-23 19:23:00 +00001/*******************************************************************************
amywu923ee602007-04-10 18:32:07 +00002 * Copyright (c) 2004, 2006 IBM Corporation and others.
nitind958d79a2004-11-23 19:23:00 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
amywu923ee602007-04-10 18:32:07 +00007 *
nitind958d79a2004-11-23 19:23:00 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
david_williamsaaadf2b2005-04-11 07:28:31 +000011package org.eclipse.wst.html.ui.internal.contentproperties.ui;
nitind958d79a2004-11-23 19:23:00 +000012
nitind958d79a2004-11-23 19:23:00 +000013import java.util.Map;
14
15import org.eclipse.core.resources.IResource;
16import org.eclipse.swt.SWT;
17import org.eclipse.swt.layout.GridData;
18import org.eclipse.swt.widgets.Label;
19import org.eclipse.swt.widgets.Text;
20import org.eclipse.swt.widgets.Widget;
nitinddb72dcc2005-11-28 21:08:01 +000021import org.eclipse.ui.PlatformUI;
david_williams3a2ab2d2005-04-11 16:32:45 +000022import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
nitind958d79a2004-11-23 19:23:00 +000023import org.eclipse.wst.html.ui.internal.Logger;
24import org.eclipse.wst.html.ui.internal.editor.IHelpContextIds;
david_williams1d37d7a2005-10-21 20:18:39 +000025import org.eclipse.wst.sse.internal.contentproperties.IContentSettings;
david_williamsc54bdb72005-04-13 20:22:44 +000026import org.eclipse.wst.sse.ui.internal.contentproperties.ui.ComboListOnPropertyPage;
27import org.eclipse.wst.sse.ui.internal.contentproperties.ui.ContentSettingsPropertyPage;
nitind958d79a2004-11-23 19:23:00 +000028
amywu3a205672006-02-23 05:05:23 +000029/**
30 * @deprecated Use WebContentSettingsPropertyPage instead
31 */
nitind958d79a2004-11-23 19:23:00 +000032public final class HTMLContentSettingsPropertyPage extends ContentSettingsPropertyPage implements org.eclipse.swt.events.SelectionListener {
33
34
35 private final int N_DOCUMENT_TYPE = 0;
36 private final int N_CSS_PROFILE = 1;
37 private final int N_TARGET_DEVICE = 2;
38
39 private Text publicIdText;
40 private Text systemIdText;
41
42 public HTMLContentSettingsPropertyPage() {
43 super();
44 numberOfCombo = 3;
45 numCols = 2;
46 numRows = 8;
47 combo = new ComboListOnPropertyPage[super.numberOfCombo];
48
49 }
50
51
52
53 protected void createDocumentTypeComboBox() {
54
55 // create description of implecit DOCTYPE
56 Label label = new Label(propertyPage, SWT.LEFT);
david_williams3a2ab2d2005-04-11 16:32:45 +000057 label.setText(HTMLUIMessages.UI_Description_of_role_of_following_DOCTYPE);
nitind958d79a2004-11-23 19:23:00 +000058 GridData data = new GridData();
59 data.horizontalAlignment = GridData.FILL;
60 data.horizontalSpan = numCols;
61 label.setLayoutData(data);
62
63 // create combobox
64 super.combo[N_DOCUMENT_TYPE] = super.createComboBoxOf(DOCUMENT_LABEL);
65 super.combo[this.N_DOCUMENT_TYPE].addSelectionListener(this);
66 // set entry list into Combo
67 ContentSettingsRegistry.setHTMLDocumentTypeRegistryInto(combo[N_DOCUMENT_TYPE]);
68 // create TextField
69 createIDTextField();
70 if (combo[N_DOCUMENT_TYPE].getItemCount() <= 0)
71 return;
72
73 String initValue = contentSettings.getProperty((IResource) super.getElement(), IContentSettings.HTML_DOCUMENT_TYPE);
74 // when either .contentsettings or element doesn't exist
75 // when attribute doesn't exists,getProperty returns empty string.
76 if (initValue == null)
77 initValue = ""; //$NON-NLS-1$
78 // set init selectionItem in Combo
79 super.setSelectionItem(combo[N_DOCUMENT_TYPE], initValue);
80 this.publicIdText.setText(initValue);
81 if (!initValue.equals("")) {//$NON-NLS-1$
82 // toro D210260
83 if (ContentSettingsRegistry.getSystemIdFrom(initValue) != null)
84 this.systemIdText.setText(ContentSettingsRegistry.getSystemIdFrom(initValue));
85 else
86 this.systemIdText.setText("");//$NON-NLS-1$
87 }
88 else
89 this.systemIdText.setText("");//$NON-NLS-1$
90
91 // create separator
92 label = new Label(propertyPage, SWT.SEPARATOR | SWT.HORIZONTAL);
93 data = new GridData();
94 data.horizontalAlignment = GridData.FILL;
95 data.horizontalSpan = numCols;
96 data.verticalSpan = 8;
97 label.setLayoutData(data);
98
99 }
100
101
102
103 protected void createCSSComboBox() {
104 super.combo[N_CSS_PROFILE] = super.createComboBoxOf(CSS_LABEL);
105
106 ContentSettingsRegistry.setCSSMetaModelRegistryInto(combo[N_CSS_PROFILE]);
107 if (combo[N_CSS_PROFILE].getItemCount() <= 0)
108 return;
109 String initValue = contentSettings.getProperty((IResource) super.getElement(), IContentSettings.CSS_PROFILE);
110 // when either .contentsettings or element doesn't exist
111 // when attribute doesn't exists,getProperty returns empty string.
112 if (initValue == null)
113 initValue = ""; //$NON-NLS-1$
114 // set init selectionItem in Combo
115 super.setSelectionItem(combo[N_CSS_PROFILE], initValue);
116 }
117
118
119
120 protected void createDeviceComboBox() {
121 super.combo[N_TARGET_DEVICE] = super.createComboBoxOf(DEVICE_LABEL);
122
123 ContentSettingsRegistry.setDeviceProfileRegistryInto(combo[N_TARGET_DEVICE]);
124 if (combo[N_TARGET_DEVICE].getItemCount() <= 0)
125 return;
126 String initValue = contentSettings.getProperty((IResource) super.getElement(), IContentSettings.DEVICE_PROFILE);
127 // when either .contentsettings or element doesn't exist
128 // when attribute doesn't exists,getProperty returns empty string.
129 if (initValue == null)
130 initValue = ""; //$NON-NLS-1$
131 // set init selectionItem in Combo
132 super.setSelectionItem(combo[N_TARGET_DEVICE], initValue);
133 }
134
135
136 protected void createSettingsPageGUI() {
137 int type = ((IResource) getElement()).getType();
138 switch (type) {
139 case IResource.FILE :
140 // composite = createComposite(propertyPage,numCols,numRows);
141 createDocumentTypeComboBox();
142 createCSSComboBox();
143 createDeviceComboBox();
144 computeMaxWidthHint();
nitinddb72dcc2005-11-28 21:08:01 +0000145 PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyPage, IHelpContextIds.WEB_CONTENT_SETTINGS_HELPID);
nitind958d79a2004-11-23 19:23:00 +0000146 break;
147
148 default :
149 Logger.log(Logger.WARNING, "HTMLContentSettingsPropertyPage is instantiated by resource except FILE");//$NON-NLS-1$
150 break;
151 }
152
153 }
154
155
156
157 protected void putSelectedPropertyInto(Map properties, String valueInCombo, int index) {
158
159 switch (index) {
160 case N_DOCUMENT_TYPE :
161 // doc type
162 properties.put(IContentSettings.HTML_DOCUMENT_TYPE, valueInCombo);
163 break;
164 case N_CSS_PROFILE :
165 // css
166 properties.put(IContentSettings.CSS_PROFILE, valueInCombo);
167 break;
168 case N_TARGET_DEVICE :
169 // device
170 properties.put(IContentSettings.DEVICE_PROFILE, valueInCombo);
171 break;
172 default :
173 Logger.log(Logger.ERROR, "Index is out of range in putSelectedPropertyInto() in class HTMLContentSettingsPropertyPage");//$NON-NLS-1$
174 break;
175 }
176
177 }
178
179 protected void deleteNoneProperty(int index) {
180 switch (index) {
181 case N_DOCUMENT_TYPE :
182 // doc type
183 contentSettings.deleteProperty((IResource) super.getElement(), IContentSettings.HTML_DOCUMENT_TYPE);
184 break;
185 case N_CSS_PROFILE :
186 // css
187 contentSettings.deleteProperty((IResource) super.getElement(), IContentSettings.CSS_PROFILE);
188 break;
189 case N_TARGET_DEVICE :
190 // device
191 contentSettings.deleteProperty((IResource) super.getElement(), IContentSettings.DEVICE_PROFILE);
192 break;
193 default :
194 Logger.log(Logger.ERROR, "Index is out of range in deleteNoneProperty() in class HTMLContentSettingsPropertyPage");//$NON-NLS-1$
195 break;
196 }
197 }
198
199 private void createIDTextField() {
200 // public ID & System ID
201 Label publicLabel = new Label(super.propertyPage, SWT.NONE);
202 GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
203 data.horizontalIndent = 10;
204 publicLabel.setLayoutData(data);
david_williams3a2ab2d2005-04-11 16:32:45 +0000205 publicLabel.setText(HTMLUIMessages.UI_Public_ID);
nitind958d79a2004-11-23 19:23:00 +0000206 publicIdText = new Text(super.propertyPage, SWT.BORDER | SWT.READ_ONLY);
207 data = new GridData();
208
209 publicIdText.setLayoutData(data);
210
211 Label systemLabel = new Label(super.propertyPage, SWT.NONE);
212 data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
213 data.horizontalIndent = 10;
214 systemLabel.setLayoutData(data);
david_williams3a2ab2d2005-04-11 16:32:45 +0000215 systemLabel.setText(HTMLUIMessages.UI_System_ID);
nitind958d79a2004-11-23 19:23:00 +0000216 systemIdText = new Text(super.propertyPage, SWT.BORDER | SWT.READ_ONLY);
217 data = new GridData();
218
219 systemIdText.setLayoutData(data);
220 }
221
222
223
224 private void computeMaxWidthHint() {
225 // maxLengthString was set when HTMLDocumentTypeEntry was set in class ContentSettingsRegistry.
226 String maxLengthString = ContentSettingsRegistry.maxLengthStringInHTMLDocumentTypeRegistry;
227 String backup = this.systemIdText.getText();
228 this.systemIdText.setText(maxLengthString);
229 int maxWidthHint = this.systemIdText.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
230 this.systemIdText.setText(backup);
231
232 if (this.combo[this.N_DOCUMENT_TYPE].getLayoutData() != null)
233 ((GridData) this.combo[this.N_DOCUMENT_TYPE].getLayoutData()).widthHint = maxWidthHint;
234 if (this.publicIdText.getLayoutData() != null)
235 ((GridData) this.publicIdText.getLayoutData()).widthHint = maxWidthHint;
236 if (this.systemIdText.getLayoutData() != null)
237 ((GridData) this.systemIdText.getLayoutData()).widthHint = maxWidthHint;
238 if (this.combo[this.N_CSS_PROFILE].getLayoutData() != null)
239 ((GridData) this.combo[this.N_CSS_PROFILE].getLayoutData()).widthHint = maxWidthHint;
240 if (this.combo[this.N_TARGET_DEVICE].getLayoutData() != null)
241 ((GridData) this.combo[this.N_TARGET_DEVICE].getLayoutData()).widthHint = maxWidthHint;
242
243 }
244
245
246 public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
247 }
248
249 public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
250 Widget source = event.widget;
251
252 if (this.combo[this.N_DOCUMENT_TYPE].equals(source)) {
253 ComboListOnPropertyPage combo = this.combo[this.N_DOCUMENT_TYPE];
254 if (combo.getSelectionIndex() < 0)
255 return;
256 if (!combo.getSelectedValue().equals("")) {//$NON-NLS-1$
257 this.publicIdText.setText(combo.getSelectedValue());
258 if (ContentSettingsRegistry.getSystemIdFrom(combo.getSelectedValue()) != null)
259 this.systemIdText.setText(ContentSettingsRegistry.getSystemIdFrom(combo.getSelectedValue()));
260 else
261 this.systemIdText.setText("");//$NON-NLS-1$
262 }
263 else {
264 this.publicIdText.setText("");//$NON-NLS-1$
265 this.systemIdText.setText(""); //$NON-NLS-1$
266 }
267
268 }
269 }
270
271 protected void performDefaults() {
272 super.performDefaults();
273 this.publicIdText.setText("");//$NON-NLS-1$
274 this.systemIdText.setText(""); //$NON-NLS-1$
275
276 }
277
278
279}
280