nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2004, 2006 IBM Corporation and others. |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 3 | * 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 |
amywu | 923ee60 | 2007-04-10 18:32:07 +0000 | [diff] [blame] | 7 | * |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
david_williams | aaadf2b | 2005-04-11 07:28:31 +0000 | [diff] [blame] | 11 | package org.eclipse.wst.html.ui.internal.contentproperties.ui; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 12 | |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 13 | import java.util.Map; |
| 14 | |
| 15 | import org.eclipse.core.resources.IResource; |
| 16 | import org.eclipse.swt.SWT; |
| 17 | import org.eclipse.swt.layout.GridData; |
| 18 | import org.eclipse.swt.widgets.Label; |
| 19 | import org.eclipse.swt.widgets.Text; |
| 20 | import org.eclipse.swt.widgets.Widget; |
nitind | db72dcc | 2005-11-28 21:08:01 +0000 | [diff] [blame] | 21 | import org.eclipse.ui.PlatformUI; |
david_williams | 3a2ab2d | 2005-04-11 16:32:45 +0000 | [diff] [blame] | 22 | import org.eclipse.wst.html.ui.internal.HTMLUIMessages; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 23 | import org.eclipse.wst.html.ui.internal.Logger; |
| 24 | import org.eclipse.wst.html.ui.internal.editor.IHelpContextIds; |
david_williams | 1d37d7a | 2005-10-21 20:18:39 +0000 | [diff] [blame] | 25 | import org.eclipse.wst.sse.internal.contentproperties.IContentSettings; |
david_williams | c54bdb7 | 2005-04-13 20:22:44 +0000 | [diff] [blame] | 26 | import org.eclipse.wst.sse.ui.internal.contentproperties.ui.ComboListOnPropertyPage; |
| 27 | import org.eclipse.wst.sse.ui.internal.contentproperties.ui.ContentSettingsPropertyPage; |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 28 | |
amywu | 3a20567 | 2006-02-23 05:05:23 +0000 | [diff] [blame] | 29 | /** |
| 30 | * @deprecated Use WebContentSettingsPropertyPage instead |
| 31 | */ |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 32 | public 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_williams | 3a2ab2d | 2005-04-11 16:32:45 +0000 | [diff] [blame] | 57 | label.setText(HTMLUIMessages.UI_Description_of_role_of_following_DOCTYPE); |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 58 | 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(); |
nitind | db72dcc | 2005-11-28 21:08:01 +0000 | [diff] [blame] | 145 | PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyPage, IHelpContextIds.WEB_CONTENT_SETTINGS_HELPID); |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 146 | 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_williams | 3a2ab2d | 2005-04-11 16:32:45 +0000 | [diff] [blame] | 205 | publicLabel.setText(HTMLUIMessages.UI_Public_ID); |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 206 | 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_williams | 3a2ab2d | 2005-04-11 16:32:45 +0000 | [diff] [blame] | 215 | systemLabel.setText(HTMLUIMessages.UI_System_ID); |
nitind | 958d79a | 2004-11-23 19:23:00 +0000 | [diff] [blame] | 216 | 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 | |