01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.dialogs;
11:
12: import org.eclipse.core.runtime.CoreException;
13: import org.eclipse.core.runtime.IConfigurationElement;
14: import org.eclipse.core.runtime.IStatus;
15: import org.eclipse.ui.IWorkbenchPreferencePage;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.internal.WorkbenchMessages;
18: import org.eclipse.ui.internal.WorkbenchPlugin;
19: import org.eclipse.ui.internal.misc.StatusUtil;
20: import org.eclipse.ui.internal.preferences.WorkbenchPreferenceExtensionNode;
21: import org.eclipse.ui.internal.registry.CategorizedPageRegistryReader;
22: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
23: import org.eclipse.ui.statushandlers.StatusManager;
24:
25: /**
26: * A proxy for a preference page to avoid creation of preference page just to
27: * show a node in the preference dialog tree.
28: */
29: public class WorkbenchPreferenceNode extends
30: WorkbenchPreferenceExtensionNode {
31:
32: /**
33: * Create a new instance of the receiver.
34: * @param nodeId
35: * @param element
36: */
37: public WorkbenchPreferenceNode(String nodeId,
38: IConfigurationElement element) {
39: super (nodeId, element);
40: }
41:
42: /**
43: * Creates the preference page this node stands for.
44: */
45: public void createPage() {
46: IWorkbenchPreferencePage page;
47: try {
48: page = (IWorkbenchPreferencePage) WorkbenchPlugin
49: .createExtension(getConfigurationElement(),
50: IWorkbenchRegistryConstants.ATT_CLASS);
51: } catch (CoreException e) {
52: // Just inform the user about the error. The details are
53: // written to the log by now.
54: IStatus errStatus = StatusUtil.newStatus(e.getStatus(),
55: WorkbenchMessages.PreferenceNode_errorMessage);
56: StatusManager.getManager().handle(errStatus,
57: StatusManager.SHOW);
58: page = new ErrorPreferencePage();
59: }
60:
61: page.init(PlatformUI.getWorkbench());
62: if (getLabelImage() != null) {
63: page.setImageDescriptor(getImageDescriptor());
64: }
65: page.setTitle(getLabelText());
66: setPage(page);
67: }
68:
69: /**
70: * Return the category name for the node.
71: * @return java.lang.String
72: */
73: public String getCategory() {
74: return getConfigurationElement().getAttribute(
75: CategorizedPageRegistryReader.ATT_CATEGORY);
76: }
77: }
|