KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > WorkbenchPreferenceNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.dialogs;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.ui.IWorkbenchPreferencePage;
17 import org.eclipse.ui.PlatformUI;
18 import org.eclipse.ui.internal.WorkbenchMessages;
19 import org.eclipse.ui.internal.WorkbenchPlugin;
20 import org.eclipse.ui.internal.misc.StatusUtil;
21 import org.eclipse.ui.internal.preferences.WorkbenchPreferenceExtensionNode;
22 import org.eclipse.ui.internal.registry.CategorizedPageRegistryReader;
23 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
24 import org.eclipse.ui.statushandlers.StatusManager;
25
26 /**
27  * A proxy for a preference page to avoid creation of preference page just to
28  * show a node in the preference dialog tree.
29  */

30 public class WorkbenchPreferenceNode extends WorkbenchPreferenceExtensionNode {
31
32     /**
33      * Create a new instance of the receiver.
34      * @param nodeId
35      * @param element
36      */

37     public WorkbenchPreferenceNode(String JavaDoc nodeId, IConfigurationElement element) {
38         super(nodeId, element);
39     }
40
41     /**
42      * Creates the preference page this node stands for.
43      */

44     public void createPage() {
45         IWorkbenchPreferencePage page;
46         try {
47             page = (IWorkbenchPreferencePage) WorkbenchPlugin.createExtension(
48                     getConfigurationElement(), IWorkbenchRegistryConstants.ATT_CLASS);
49         } catch (CoreException e) {
50             // Just inform the user about the error. The details are
51
// written to the log by now.
52
IStatus errStatus = StatusUtil.newStatus(e.getStatus(), WorkbenchMessages.PreferenceNode_errorMessage);
53             StatusManager.getManager().handle(errStatus, StatusManager.SHOW);
54             page = new ErrorPreferencePage();
55         }
56
57         page.init(PlatformUI.getWorkbench());
58         if (getLabelImage() != null) {
59             page.setImageDescriptor(getImageDescriptor());
60         }
61         page.setTitle(getLabelText());
62         setPage(page);
63     }
64
65     /**
66      * Return the category name for the node.
67      * @return java.lang.String
68      */

69     public String JavaDoc getCategory() {
70         return getConfigurationElement().getAttribute(
71                 CategorizedPageRegistryReader.ATT_CATEGORY);
72     }
73 }
74
Popular Tags