2 * Copyright (c) 2002-2004 Roberto Gonzalez Rocha and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Roberto Gonzalez Rocha - Initial version
10 * Igor Malinin - refactoring, minor changes
12 * $Id: XMLPreferenceInitializer.java,v 1.3 2006-10-21 23:14:13 pombredanne Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.preferences;
16 /*import java.io.InputStream;
17 import java.util.Enumeration;
18 import java.util.PropertyResourceBundle;
20 import net.sourceforge.phpdt.core.JavaCore;
21 import net.sourceforge.phpdt.ui.PreferenceConstants;
22 import net.sourceforge.phpeclipse.ui.IPreferenceConstants;
24 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
25 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
26 import net.sourceforge.phpeclipse.ui.WebUI;
27 import net.sourceforge.phpeclipse.ui.preferences.ITextStylePreferences;
28 //import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
29 import net.sourceforge.phpeclipse.xml.ui.text.IXMLSyntaxConstants;
31 //import org.eclipse.core.runtime.Path;
32 import org.eclipse.core.runtime.Platform;
33 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
34 import org.eclipse.jface.preference.IPreferenceStore;
35 import org.eclipse.jface.preference.PreferenceConverter;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.graphics.RGB;
38 import org.eclipse.swt.widgets.Display;
39 import org.eclipse.ui.texteditor.AbstractTextEditor;
42 * @author Igor Malinin
44 public class XMLPreferenceInitializer extends AbstractPreferenceInitializer implements IPreferenceConstants {
46 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
48 public void initializeDefaultPreferences() {
49 final IPreferenceStore store = /*XMLPlugin*/WebUI.getDefault()
50 .getPreferenceStore();
51 final Display display = Display.getDefault();
53 // TODO: ChainedPreferenceStore does not work for preferences preview
55 display.syncExec(new Runnable() {
57 PreferenceConverter.setDefault(store,
58 AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, display
59 .getSystemColor(SWT.COLOR_LIST_FOREGROUND)
65 AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT,
68 display.syncExec(new Runnable() {
70 PreferenceConverter.setDefault(store,
71 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, display
72 .getSystemColor(SWT.COLOR_LIST_BACKGROUND)
78 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT,
81 // end of common preferences
83 setDefault(store, IXMLSyntaxConstants.XML_DEFAULT, "0,0,0",
84 ITextStylePreferences.STYLE_NORMAL);
86 setDefault(store, IXMLSyntaxConstants.XML_TAG, "127,0,127",
87 ITextStylePreferences.STYLE_NORMAL);
89 setDefault(store, IXMLSyntaxConstants.XML_ATT_NAME, "0,127,0",
90 ITextStylePreferences.STYLE_NORMAL);
92 setDefault(store, IXMLSyntaxConstants.XML_ATT_VALUE, "0,0,255",
93 ITextStylePreferences.STYLE_NORMAL);
95 setDefault(store, IXMLSyntaxConstants.XML_ENTITY, "127,127,0",
96 ITextStylePreferences.STYLE_NORMAL);
98 setDefault(store, IXMLSyntaxConstants.XML_CDATA, "127,127,0",
99 ITextStylePreferences.STYLE_NORMAL);
101 setDefault(store, IXMLSyntaxConstants.XML_PI, "127,127,127",
102 ITextStylePreferences.STYLE_BOLD);
104 setDefault(store, IXMLSyntaxConstants.XML_COMMENT, "127,0,0",
105 ITextStylePreferences.STYLE_NORMAL);
107 setDefault(store, IXMLSyntaxConstants.XML_DECL, "127,0,127",
108 ITextStylePreferences.STYLE_BOLD);
110 setDefault(store, IXMLSyntaxConstants.XML_SMARTY, "255,0,127",
111 ITextStylePreferences.STYLE_BOLD);
113 setDefault(store, IXMLSyntaxConstants.DTD_CONDITIONAL, "127,127,0",
114 ITextStylePreferences.STYLE_BOLD);
116 String operatingSystem = Platform.getOS();
117 // maxosx, linux, solaris, win32,...
119 /*InputStream is = getDefault()
121 new Path("prefs/default_" + operatingSystem
123 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(
125 Enumeration e = resourceBundle.getKeys();
127 while (e.hasMoreElements()) {
128 key = (String) e.nextElement();
129 store.setDefault(key, resourceBundle.getString(key));
131 } catch (Exception e) {
132 // no default properties found
133 if (operatingSystem.equals(Platform.OS_WIN32)) {
134 // store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
135 // store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php
137 // store.setDefault(MYSQL_RUN_PREF,
138 // "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
139 // store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
140 // store.setDefault(XAMPP_START_PREF,
141 // "c:\\xampp\\xampp_start.exe");
142 // store.setDefault(XAMPP_STOP_PREF,
143 // "c:\\xampp\\xampp_stop.exe");
145 // ETC_HOSTS_PATH_PREF,
146 // "c:\\windows\\system32\\drivers\\etc\\hosts");
148 // store.setDefault(PHP_RUN_PREF, "/apache/php/php");
149 // store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f
151 // store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
152 // store.setDefault(APACHE_RUN_PREF, "/apache/apache");
153 // store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
154 // store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
156 // store.setDefault(MYSQL_PREF, "--standalone");
157 // store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot
159 // store.setDefault(APACHE_STOP_PREF, "-k shutdown");
160 // store.setDefault(APACHE_RESTART_PREF, "-k restart");
161 // store.setDefault(MYSQL_START_BACKGROUND, "true");
162 // store.setDefault(APACHE_START_BACKGROUND, "true");
163 // store.setDefault(APACHE_STOP_BACKGROUND, "true");
164 // store.setDefault(APACHE_RESTART_BACKGROUND, "true");
166 store.setDefault(PHP_USERDEF_XMLFILE, "");
167 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
168 PreferenceConverter.setDefault(store, PHP_KEYWORD,
169 PHPColorProvider.KEYWORD);
170 PreferenceConverter.setDefault(store, PHP_VARIABLE,
171 PHPColorProvider.VARIABLE);
172 PreferenceConverter.setDefault(store, PHP_VARIABLE_DOLLAR,
173 PHPColorProvider.VARIABLE);
174 /*PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
175 PHPColorProvider.FUNCTION_NAME);*/
177 setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME,
178 ITextStylePreferences.STYLE_BOLD);
180 PreferenceConverter.setDefault(store, PHP_CONSTANT,
181 PHPColorProvider.CONSTANT);
182 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
183 PreferenceConverter.setDefault(store, PHP_DEFAULT,
184 PHPColorProvider.DEFAULT);
185 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
186 PHPColorProvider.PHPDOC_KEYWORD);
188 PreferenceConverter.setDefault(store, PHPDOC_TAG,
189 PHPColorProvider.PHPDOC_TAG);
190 PreferenceConverter.setDefault(store, PHPDOC_LINK,
191 PHPColorProvider.PHPDOC_LINK);
192 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
193 PHPColorProvider.PHPDOC_DEFAULT);
195 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
196 new RGB(127, 0, 85));
197 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
198 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
200 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR,
202 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
203 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
205 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR,
207 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
208 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
211 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
212 new RGB(127, 0, 85));
213 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
214 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
216 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR,
218 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
219 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
221 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR,
223 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
224 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
226 // this will initialize the static fields in the syntaxrdr class
228 JavaCore.initializeDefaultPluginPreferences();
229 PreferenceConstants.initializeDefaultValues(store);
232 private static void setDefault(IPreferenceStore store, String constant,
233 String color, String style) {
234 store.setDefault(constant + ITextStylePreferences.SUFFIX_FOREGROUND,
236 store.setDefault(constant + ITextStylePreferences.SUFFIX_STYLE, style);