Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0b896b7f7c4830c62fd8dec7f00431fc237bc5cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.html.ui.preferences.ui;

import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.wst.common.encoding.CommonEncodingPreferenceNames;
import org.eclipse.wst.html.core.HTMLFilesPreferenceNames;
import org.eclipse.wst.html.core.internal.HTMLCorePlugin;
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
import org.eclipse.wst.html.ui.internal.editor.IHelpContextIds;
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.xml.ui.preferences.EncodingSettings;
import org.eclipse.wst.xml.ui.preferences.WorkbenchDefaultEncodingSettings;
import org.eclipse.wst.xml.ui.preferences.XMLFilesPreferencePage;

public class HTMLFilesPreferencePage extends XMLFilesPreferencePage {
	private WorkbenchDefaultEncodingSettings fInputEncodingSettings = null;
	private Text fHtmlext_Field;
	private Button fDoctype_Button;
	private Button fGenerator_Button;

	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.preferences.ui.AbstractPreferencePage#getModelPreferences()
	 */
	protected Preferences getModelPreferences() {
		return HTMLCorePlugin.getDefault().getPluginPreferences();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore()
	 */
	protected IPreferenceStore doGetPreferenceStore() {
		return HTMLUIPlugin.getDefault().getPreferenceStore();
	}

	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.xml.preferences.ui.XMLFilesPreferencePage#doSavePreferenceStore()
	 */
	protected void doSavePreferenceStore() {
		HTMLCorePlugin.getDefault().savePluginPreferences(); // model
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createContents(Composite parent) {
		Composite scrolledComposite = createScrolledComposite(parent);
		createContentsForCreatingOrSavingGroup(scrolledComposite);
		createContentsForCreatingGroup(scrolledComposite);
		createContentsForLoadingGroup(scrolledComposite);
		
		WorkbenchHelp.setHelp(scrolledComposite, IHelpContextIds.HTML_PREFWEBX_FILES_HELPID);
		
		setSize(scrolledComposite);
		loadPreferences();
		
		return scrolledComposite;
	}

	protected void createContentsForLoadingGroup(Composite parent) {
		Group group = createGroup(parent, 1);
		group.setText(HTMLUIPlugin.getResourceString("%HTMLFilesPreferencePage.0")); //$NON-NLS-1$

		fInputEncodingSettings = new WorkbenchDefaultEncodingSettings(group);
	}
	
	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.preferences.ui.AbstractPreferencePage#initializeValues()
	 */
	protected void initializeValues() {
		super.initializeValues();
		initializeValuesForLoadingGroup();
	}
	
	protected void initializeValuesForLoadingGroup() {
		String encoding = getModelPreferences().getString(CommonEncodingPreferenceNames.INPUT_CODESET);
		
		fInputEncodingSettings.setIANATag(encoding);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
	 */
	protected void performDefaults() {
		super.performDefaults();
		performDefaultsForLoadingGroup();
	}
	
	protected void performDefaultsForLoadingGroup() {
		String encoding = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.INPUT_CODESET);

		fInputEncodingSettings.setIANATag(encoding);
	}
	
	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.preferences.ui.AbstractPreferencePage#storeValues()
	 */
	protected void storeValues() {
		super.storeValues();
		storeValuesForLoadingGroup();
	}
	
	protected void storeValuesForLoadingGroup() {
		getModelPreferences().setValue(CommonEncodingPreferenceNames.INPUT_CODESET, fInputEncodingSettings.getIANATag());		
	}
	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.xml.preferences.ui.XMLFilesPreferencePage#createContentsForCreatingGroup(org.eclipse.swt.widgets.Composite)
	 */
	protected void createContentsForCreatingGroup(Composite parent) {
		Group creatingGroup = createGroup(parent, 2);
		creatingGroup.setText(SSEUIPlugin.getResourceString("%Creating_files")); //$NON-NLS-1$

		// Add this suffix..
		createLabel(creatingGroup, HTMLUIPlugin.getResourceString("%HTMLFilesPreferencePage.1"));	//$NON-NLS-1$
		fHtmlext_Field = createTextField(creatingGroup);
		
		// Encoding..
		Label label = createLabel(creatingGroup, SSEUIPlugin.getResourceString("%Encoding_desc")); //$NON-NLS-1$
		((GridData)label.getLayoutData()).horizontalSpan = 2;
		fEncodingSettings = new EncodingSettings(creatingGroup);
		((GridData)fEncodingSettings.getLayoutData()).horizontalSpan = 2;
		
		// Insert DOCTYPE declaration
		fDoctype_Button = createCheckBox(creatingGroup, HTMLUIPlugin.getResourceString("%HTMLFilesPreferencePage.2"));	//$NON-NLS-1$
		((GridData)fDoctype_Button.getLayoutData()).horizontalSpan = 2;
		
		// Insert GENERATOR with META tag
		fGenerator_Button = createCheckBox(creatingGroup, HTMLUIPlugin.getResourceString("%HTMLFilesPreferencePage.3"));	//$NON-NLS-1$
		((GridData)fGenerator_Button.getLayoutData()).horizontalSpan = 2;
	}
	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.xml.preferences.ui.XMLFilesPreferencePage#initializeValuesForCreatingGroup()
	 */
	protected void initializeValuesForCreatingGroup() {
		super.initializeValuesForCreatingGroup();
		
		String defaultSuffix = getModelPreferences().getString(HTMLFilesPreferenceNames.DEFAULT_SUFFIX);
		if (defaultSuffix.length() > 0) {
			fHtmlext_Field.setText(defaultSuffix);
		}
	
		boolean bCheck;
		bCheck = getModelPreferences().getBoolean(HTMLFilesPreferenceNames.GENERATE_DOCUMENT_TYPE);
		fDoctype_Button.setSelection(bCheck);
		
		bCheck = getModelPreferences().getBoolean(HTMLFilesPreferenceNames.GENERATE_GENERATOR);
		fGenerator_Button.setSelection(bCheck);
	}
	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.xml.preferences.ui.XMLFilesPreferencePage#performDefaultsForCreatingGroup()
	 */
	protected void performDefaultsForCreatingGroup() {
		super.performDefaultsForCreatingGroup();

		fHtmlext_Field.setText(getModelPreferences().getDefaultString(HTMLFilesPreferenceNames.DEFAULT_SUFFIX));
		
		fDoctype_Button.setSelection(getModelPreferences().getDefaultBoolean(HTMLFilesPreferenceNames.GENERATE_DOCUMENT_TYPE));
		fGenerator_Button.setSelection(getModelPreferences().getDefaultBoolean(HTMLFilesPreferenceNames.GENERATE_GENERATOR));
	}
	/* (non-Javadoc)
	 * @see com.ibm.sse.editor.xml.preferences.ui.XMLFilesPreferencePage#storeValuesForCreatingGroup()
	 */
	protected void storeValuesForCreatingGroup() {
		super.storeValuesForCreatingGroup();
		
		String str_ext = fHtmlext_Field.getText();	
		getModelPreferences().setValue(HTMLFilesPreferenceNames.DEFAULT_SUFFIX, str_ext); 

		getModelPreferences().setValue(HTMLFilesPreferenceNames.GENERATE_DOCUMENT_TYPE, fDoctype_Button.getSelection());
	
		getModelPreferences().setValue(HTMLFilesPreferenceNames.GENERATE_GENERATOR, fGenerator_Button.getSelection());
	}
}

Back to the top