KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > views > ScopePreferenceManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.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 JavaDoc id, String JavaDoc label,
24                 IConfigurationElement config) {
25             super(id, label, null, null);
26             this.config = config;
27         }
28         public void createPage() {
29             try {
30                 Object JavaDoc 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); //$NON-NLS-1$
37
}
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     /**
59      *
60      */

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 JavaDoc 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 JavaDoc category, String JavaDoc id, String JavaDoc 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