KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > universal > CustomizeAction


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.intro.universal;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.preference.IPreferenceNode;
17 import org.eclipse.jface.preference.PreferenceDialog;
18 import org.eclipse.jface.preference.PreferenceManager;
19 import org.eclipse.jface.preference.PreferenceNode;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.internal.intro.impl.IntroPlugin;
22 import org.eclipse.ui.intro.IIntroSite;
23
24
25 public class CustomizeAction extends Action {
26
27     public static final String JavaDoc P_PAGE_ID = "pageId"; //$NON-NLS-1$
28
private IIntroSite site;
29     private IConfigurationElement element;
30     
31     public CustomizeAction(IIntroSite site, IConfigurationElement element) {
32         this.site = site;
33         this.element = element;
34     }
35     
36     public void run() {
37         String JavaDoc pageId = IntroPlugin.getDefault().getIntroModelRoot().getCurrentPageId();
38         run(pageId);
39     }
40
41     public static IConfigurationElement getPageElement() {
42         IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(
43                 "org.eclipse.ui.preferencePages"); //$NON-NLS-1$
44
for (int i = 0; i < elements.length; i++) {
45             IConfigurationElement element = elements[i];
46             if (element.getName().equals("page")) { //$NON-NLS-1$
47
String JavaDoc att = element.getAttribute("class"); //$NON-NLS-1$
48
if (att != null
49                         && att.equals("org.eclipse.ui.intro.universal.ExtensionFactory:welcomeCustomization")) { //$NON-NLS-1$
50
return element;
51                 }
52             }
53         }
54         return null;
55     }
56
57     private void run(String JavaDoc pageId) {
58         PreferenceManager pm = new PreferenceManager();
59         IPreferenceNode node = createPreferenceNode(pageId);
60         pm.addToRoot(node);
61         IWorkbenchWindow window = site.getWorkbenchWindow();
62         PreferenceDialog dialog = new PreferenceDialog(window.getShell(), pm);
63         dialog.open();
64     }
65
66     private IPreferenceNode createPreferenceNode(final String JavaDoc pageId) {
67         if (element == null)
68             return null;
69         String JavaDoc id = element.getAttribute("id"); //$NON-NLS-1$
70
String JavaDoc label = element.getAttribute("name"); //$NON-NLS-1$
71
String JavaDoc className = "org.eclipse.ui.internal.intro.shared.WelcomeCustomizationPreferencePage"; //$NON-NLS-1$
72
if (id == null || label == null || className == null)
73             return null;
74         return new PreferenceNode(id, label, null, className) {
75
76             public void createPage() {
77                 WelcomeCustomizationPreferencePage page = new WelcomeCustomizationPreferencePage();
78                 page.setTitle(getLabelText());
79                 page.setCurrentPage(pageId);
80                 setPage(page);
81             }
82         };
83     }
84 }
Popular Tags