1 11 package org.eclipse.help.ui.internal.views; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.help.ui.internal.HelpUIPlugin; 15 import org.eclipse.help.ui.internal.IHelpUIConstants; 16 import org.eclipse.jface.preference.*; 17 18 public class ScopePreferenceManager extends PreferenceManager implements IHelpUIConstants { 19 private ScopeSet set; 20 class SubpagePreferenceNode extends PreferenceNode { 21 private IConfigurationElement config; 22 23 public SubpagePreferenceNode(String id, String label, 24 IConfigurationElement config) { 25 super(id, label, null, null); 26 this.config = config; 27 } 28 public void createPage() { 29 try { 30 Object obj = config.createExecutableExtension(IHelpUIConstants.ATT_CLASS); 31 IPreferencePage page = (IPreferencePage)obj; 32 setPage(page); 33 page.setTitle(getLabelText()); 34 } 35 catch (CoreException e) { 36 HelpUIPlugin.logError("Unable to create executable extension", e); } 38 } 39 } 40 class EnginePreferenceNode extends PreferenceNode { 41 private EngineDescriptor desc; 42 43 public EnginePreferenceNode(EngineDescriptor desc) { 44 super(desc.getId(), desc.getLabel(), desc.getImageDescriptor(), null); 45 this.desc = desc; 46 } 47 public EngineDescriptor getDescriptor() { 48 return desc; 49 } 50 public void createPage() { 51 IPreferencePage page = desc.createRootPage(set.getName()); 52 setPage(page); 53 page.setTitle(desc.getLabel()); 54 page.setImageDescriptor(desc.getImageDescriptor()); 55 page.setDescription(desc.getDescription()); 56 } 57 } 58 61 public ScopePreferenceManager(EngineDescriptorManager descManager, ScopeSet set) { 62 this.set = set; 63 load(descManager.getDescriptors()); 64 } 65 66 private void load(EngineDescriptor [] descriptors) { 67 for (int i=0; i<descriptors.length; i++) { 68 EngineDescriptor desc = descriptors[i]; 69 addNode(desc); 70 IConfigurationElement [] pages = desc.getPages(); 71 for (int j=0; j<pages.length; j++) { 72 String category = pages[i].getAttribute(ATT_CATEGORY); 73 addNode(category, pages[i].getAttribute(ATT_ID), 74 pages[i].getAttribute(ATT_LABEL), 75 pages[i]); 76 } 77 } 78 } 79 public IPreferenceNode addNode(EngineDescriptor desc) { 80 PreferenceNode node = new EnginePreferenceNode(desc); 81 addToRoot(node); 82 return node; 83 } 84 private IPreferenceNode addNode(String category, String id, String name, IConfigurationElement config) { 85 IPreferenceNode parent = find(category); 86 PreferenceNode node = new SubpagePreferenceNode(id, name, config); 87 if (parent!=null) 88 parent.add(node); 89 return node; 90 } 91 } 92 | Popular Tags |