KickJava   Java API By Example, From Geeks To Geeks.

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


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.IStatus;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.ui.IWorkbenchPropertyPage;
18 import org.eclipse.ui.internal.WorkbenchMessages;
19 import org.eclipse.ui.internal.misc.StatusUtil;
20 import org.eclipse.ui.internal.preferences.WorkbenchPreferenceExtensionNode;
21 import org.eclipse.ui.statushandlers.StatusManager;
22
23 /**
24  * Property page node allows us to achieve presence in the property page dialog
25  * without loading the page itself, thus loading the contributing plugin.
26  * Only when the user selects the page will it be loaded.
27  */

28 public class PropertyPageNode extends WorkbenchPreferenceExtensionNode {
29     private RegistryPageContributor contributor;
30
31     private IWorkbenchPropertyPage page;
32
33     private Image icon;
34
35     private Object JavaDoc element;
36
37     /**
38      * Create a new instance of the receiver.
39      * @param contributor
40      * @param element
41      */

42     public PropertyPageNode(RegistryPageContributor contributor,
43             Object JavaDoc element) {
44         super(contributor.getPageId(), contributor.getConfigurationElement());
45         this.contributor = contributor;
46         this.element = element;
47     }
48
49     /**
50      * Creates the preference page this node stands for. If the page is null,
51      * it will be created by loading the class. If loading fails,
52      * empty filler page will be created instead.
53      */

54     public void createPage() {
55         try {
56             page = contributor.createPage(element);
57         } catch (CoreException e) {
58             // Just inform the user about the error. The details are
59
// written to the log by now.
60
IStatus errStatus = StatusUtil.newStatus(e.getStatus(), WorkbenchMessages.PropertyPageNode_errorMessage);
61             StatusManager.getManager().handle(errStatus, StatusManager.SHOW);
62             page = new EmptyPropertyPage();
63         }
64         setPage(page);
65     }
66
67     /** (non-Javadoc)
68      * Method declared on IPreferenceNode.
69      */

70     public void disposeResources() {
71
72         if (page != null) {
73             page.dispose();
74             page = null;
75         }
76         if (icon != null) {
77             icon.dispose();
78             icon = null;
79         }
80     }
81
82     /**
83      * Returns page icon, if defined.
84      */

85     public Image getLabelImage() {
86         if (icon == null) {
87             ImageDescriptor desc = contributor.getPageIcon();
88             if (desc != null) {
89                 icon = desc.createImage();
90             }
91         }
92         return icon;
93     }
94
95     /**
96      * Returns page label as defined in the registry.
97      */

98     public String JavaDoc getLabelText() {
99         return contributor.getPageName();
100     }
101 }
102
Popular Tags