Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 433a9bab573c4de444ea114285998c30182c8371 (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
/*******************************************************************************
 * 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.css.ui.preferences;

import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.sse.core.IModelManagerPlugin;
import org.eclipse.wst.sse.ui.preferences.PreferenceManager;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * @deprecated preference management has moved to base preferences
 */
public class CSSPreferenceManager extends PreferenceManager {

	private static CSSPreferenceManager fInstance = null;
	//
	private final static String GROUP_COLOR = "color";//$NON-NLS-1$
	private final static String COLOR_ENABLED = "useColor";//$NON-NLS-1$
	//
	private final static String GROUP_ASSIST = "contentAssist"; //$NON-NLS-1$
	private final static String ASSIST_CATEGORIZE = "categorize"; //$NON-NLS-1$

	protected Document fallbackDocument = null;

	/**
	 *  
	 */
	protected CSSPreferenceManager() {
		super();
	}

	/**
	 *  
	 */
	public Document createDefaultPreferences() {
		Document doc = super.createDefaultPreferences();
		if (doc == null) {
			return doc;
		}

		Node preference = doc.getFirstChild();

		Element color = doc.createElement(GROUP_COLOR);
		setBooleanAttribute(color, COLOR_ENABLED, true);
		preference.appendChild(color);

		Element contentAssist = doc.createElement(GROUP_ASSIST);
		setBooleanAttribute(contentAssist, ASSIST_CATEGORIZE, true);
		preference.appendChild(contentAssist);

		return doc;
	}

	public boolean getContentAssistCategorize() {
		return getBooleanAttribute(getGroupElement(GROUP_ASSIST), ASSIST_CATEGORIZE);
	}

	public void setContentAssistCategorize(boolean categorize) {
		setBooleanAttribute(getGroupElement(GROUP_ASSIST), ASSIST_CATEGORIZE, categorize);
	}

	/**
	 *  
	 */
	protected boolean getBooleanAttribute(Element element, String name) {
		String str = element.getAttribute(name);
		if (str == null || str.length() <= 0) {
			element = getDefaultGroupElement(element.getTagName());
			if (element != null)
				str = element.getAttribute(name);
		}
		return (str == null) ? false : str.equals(Boolean.TRUE.toString());
	}

	/**
	 *  
	 */
	public boolean getColorEnabled() {
		return getBooleanAttribute(getGroupElement(GROUP_COLOR), COLOR_ENABLED);
	}

	/**
	 *  
	 */
	protected String getFilename() {
		if (fileName == null) {
			fileName = Platform.getPlugin(IModelManagerPlugin.ID).getStateLocation().toString() + "/cssprefs.xml";//$NON-NLS-1$
		}
		return fileName;
	}

	/**
	 *  
	 */
	protected Element getGroupElement(String name) {
		Node node = getNamedChild(getRootElement(), name);
		return (node instanceof Element) ? (Element) node : getDefaultGroupElement(name);
	}

	/**
	 *  
	 */
	protected Element getDefaultGroupElement(String name) {
		Node node = getNamedChild(getDefaultRootElement(), name);
		return (node instanceof Element) ? (Element) node : null;
	}

	/**
	 *  
	 */
	protected Node getDefaultRootElement() {
		if (fallbackDocument == null)
			fallbackDocument = createDefaultPreferences();
		return getRootElement(fallbackDocument);
	}

	/**
	 *  
	 */
	public synchronized static CSSPreferenceManager getInstance() {
		if (fInstance == null) {
			fInstance = new CSSPreferenceManager();
		}
		return fInstance;
	}

	/**
	 *  
	 */
	protected int getIntAttribute(Element element, String name) {
		int value = 0;
		try {
			value = Integer.parseInt(element.getAttribute(name));
		} catch (NumberFormatException e) {
			element = getDefaultGroupElement(element.getTagName());
			try {
				value = Integer.parseInt(element.getAttribute(name));
			} catch (NumberFormatException ee) {
			}
		}
		return value;
	}

	/**
	 *  
	 */
	protected String getStringAttribute(Element element, String name) {
		if (element.getAttributeNode(name) == null) {
			element = getDefaultGroupElement(element.getTagName());
		}
		return element.getAttribute(name);
	}

	/**
	 *  
	 */
	protected void setBooleanAttribute(Element element, String name, boolean value) {
		element.setAttribute(name, new Boolean(value).toString());
	}

	/**
	 *  
	 */
	public void setColorEnabled(boolean enabled) {
		setBooleanAttribute(getGroupElement(GROUP_COLOR), COLOR_ENABLED, enabled);
	}

	/**
	 *  
	 */
	protected void setStringAttribute(Element element, String name, String value) {
		element.setAttribute(name, value);
	}

}

Back to the top