1 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 P_PAGE_ID = "pageId"; 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 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"); for (int i = 0; i < elements.length; i++) { 45 IConfigurationElement element = elements[i]; 46 if (element.getName().equals("page")) { String att = element.getAttribute("class"); if (att != null 49 && att.equals("org.eclipse.ui.intro.universal.ExtensionFactory:welcomeCustomization")) { return element; 51 } 52 } 53 } 54 return null; 55 } 56 57 private void run(String 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 pageId) { 67 if (element == null) 68 return null; 69 String id = element.getAttribute("id"); String label = element.getAttribute("name"); String className = "org.eclipse.ui.internal.intro.shared.WelcomeCustomizationPreferencePage"; 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 |