Skip to main content
summaryrefslogtreecommitdiffstats
blob: f24069c0741d3719e680e52af836a71d107b35d4 (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
/*******************************************************************************
 * Copyright (c) 2005, 2006 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.ui.internal.intro.universal;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.intro.impl.IntroPlugin;
import org.eclipse.ui.intro.IIntroSite;


public class CustomizeAction extends Action {

	public static final String P_PAGE_ID = "pageId"; //$NON-NLS-1$
	private IIntroSite site;
	private IConfigurationElement element;
	
	public CustomizeAction(IIntroSite site, IConfigurationElement element) {
		this.site = site;
		this.element = element;
	}
	
	public void run() {
		String pageId = IntroPlugin.getDefault().getIntroModelRoot().getCurrentPageId();
		run(pageId);
	}

	public static IConfigurationElement getPageElement() {
		IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
				"org.eclipse.ui.preferencePages"); //$NON-NLS-1$
		for (int i = 0; i < elements.length; i++) {
			IConfigurationElement element = elements[i];
			if (element.getName().equals("page")) { //$NON-NLS-1$
				String att = element.getAttribute("class"); //$NON-NLS-1$
				if (att != null
						&& att.equals("org.eclipse.ui.intro.universal.ExtensionFactory:welcomeCustomization")) { //$NON-NLS-1$
					return element;
				}
			}
		}
		return null;
	}

	private void run(String pageId) {
		PreferenceManager pm = new PreferenceManager();
		IPreferenceNode node = createPreferenceNode(pageId);
		pm.addToRoot(node);
		IWorkbenchWindow window = site.getWorkbenchWindow();
		PreferenceDialog dialog = new PreferenceDialog(window.getShell(), pm);
		dialog.open();
	}

	private IPreferenceNode createPreferenceNode(final String pageId) {
		if (element == null)
			return null;
		String id = element.getAttribute("id"); //$NON-NLS-1$
		String label = element.getAttribute("name"); //$NON-NLS-1$
		String className = "org.eclipse.ui.internal.intro.shared.WelcomeCustomizationPreferencePage"; //$NON-NLS-1$
		if (id == null || label == null || className == null)
			return null;
		return new PreferenceNode(id, label, null, className) {

			public void createPage() {
				WelcomeCustomizationPreferencePage page = new WelcomeCustomizationPreferencePage();
		        page.setTitle(getLabelText());
				page.setCurrentPage(pageId);
				setPage(page);
			}
		};
	}
}

Back to the top