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: 5b2028ef36e903b3861131c415699238f728ec77 (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
/*******************************************************************************
 * Copyright (c) 2001, 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
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.dtd.ui.internal;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier;
import org.eclipse.wst.dtd.ui.style.IStyleConstantsDTD;
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.preferences.PreferenceKeyGenerator;
import org.eclipse.wst.sse.ui.preferences.ui.ColorHelper;

/**
 * The main plugin class to be used in the desktop.
 */
public class DTDUIPlugin extends AbstractUIPlugin {
	//The shared instance.
	private static DTDUIPlugin plugin;

	/**
	 * Returns the shared instance.
	 */
	public static DTDUIPlugin getDefault() {
		return plugin;
	}

	/**
	 * Returns the string from the plugin's resource bundle, or 'key' if not
	 * found.
	 */
	public static String getResourceString(String key) {
		ResourceBundle bundle = DTDUIPlugin.getDefault()
				.getResourceBundle();
		try {
			if (bundle != null)
				return bundle.getString(key);
			else
				return key;
		} catch (MissingResourceException e) {
			return key;
		}
	}

	/**
	 * Returns the workspace instance.
	 */
	public static IWorkspace getWorkspace() {
		return ResourcesPlugin.getWorkspace();
	}

	//Resource bundle.
	private ResourceBundle resourceBundle;

	/**
	 * The constructor.
	 */
	public DTDUIPlugin() {
		super();
		plugin = this;
		try {
			//resourceBundle =
			// ResourceBundle.getBundle("org.eclipse.wst.dtd.ui.DTDPluginResources");
			resourceBundle = Platform.getResourceBundle(Platform
					.getBundle("org.eclipse.wst.dtd.ui"));
		} catch (MissingResourceException x) {
			resourceBundle = null;
		}

		// Force a call to initialize default preferences since
		// initializeDefaultPreferences is only called if *this* plugin's
		// preference store is accessed
		initializeDefaultDTDPreferences(SSEUIPlugin.getDefault()
				.getPreferenceStore());

	}

	/**
	 * Returns the plugin's resource bundle,
	 */
	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}

	private void initializeDefaultDTDPreferences(IPreferenceStore store) {
		String ctId = IContentTypeIdentifier.ContentTypeID_DTD;

		// DTD Style Preferences
		String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$
		String styleValue = ColorHelper.getColorString(0, 0, 0)
				+ NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_DEFAULT, ctId), styleValue); //black

		styleValue = ColorHelper.getColorString(63, 63, 191) + NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_TAG, ctId), styleValue); // blue
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_TAGNAME, ctId), styleValue); // blue

		styleValue = ColorHelper.getColorString(127, 127, 127)
				+ NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_COMMENT, ctId), styleValue); // grey

		styleValue = ColorHelper.getColorString(128, 0, 0) + NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_KEYWORD, ctId), styleValue); // dark
		// red

		styleValue = ColorHelper.getColorString(63, 159, 95) + NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_STRING, ctId), styleValue); //green

		styleValue = ColorHelper.getColorString(191, 95, 95) + NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_DATA, ctId), styleValue); // light
		// red

		styleValue = ColorHelper.getColorString(128, 0, 0) + NOBACKGROUNDBOLD;
		store.setDefault(PreferenceKeyGenerator.generateKey(
				IStyleConstantsDTD.DTD_SYMBOL, ctId), styleValue); // dark
		// red
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPluginPreferences()
	 */
	protected void initializeDefaultPreferences(IPreferenceStore store) {
		// ignore this preference store
		// use EditorPlugin preference store
		IPreferenceStore editorStore = SSEUIPlugin.getDefault().getPreferenceStore();
		initializeDefaultDTDPreferences(editorStore);
	}
}

Back to the top