001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.dialogs;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IStatus;
014: import org.eclipse.jface.resource.ImageDescriptor;
015: import org.eclipse.swt.graphics.Image;
016: import org.eclipse.ui.IWorkbenchPropertyPage;
017: import org.eclipse.ui.internal.WorkbenchMessages;
018: import org.eclipse.ui.internal.misc.StatusUtil;
019: import org.eclipse.ui.internal.preferences.WorkbenchPreferenceExtensionNode;
020: import org.eclipse.ui.statushandlers.StatusManager;
021:
022: /**
023: * Property page node allows us to achieve presence in the property page dialog
024: * without loading the page itself, thus loading the contributing plugin.
025: * Only when the user selects the page will it be loaded.
026: */
027: public class PropertyPageNode extends WorkbenchPreferenceExtensionNode {
028: private RegistryPageContributor contributor;
029:
030: private IWorkbenchPropertyPage page;
031:
032: private Image icon;
033:
034: private Object element;
035:
036: /**
037: * Create a new instance of the receiver.
038: * @param contributor
039: * @param element
040: */
041: public PropertyPageNode(RegistryPageContributor contributor,
042: Object element) {
043: super (contributor.getPageId(), contributor
044: .getConfigurationElement());
045: this .contributor = contributor;
046: this .element = element;
047: }
048:
049: /**
050: * Creates the preference page this node stands for. If the page is null,
051: * it will be created by loading the class. If loading fails,
052: * empty filler page will be created instead.
053: */
054: public void createPage() {
055: try {
056: page = contributor.createPage(element);
057: } catch (CoreException e) {
058: // Just inform the user about the error. The details are
059: // written to the log by now.
060: IStatus errStatus = StatusUtil.newStatus(e.getStatus(),
061: WorkbenchMessages.PropertyPageNode_errorMessage);
062: StatusManager.getManager().handle(errStatus,
063: StatusManager.SHOW);
064: page = new EmptyPropertyPage();
065: }
066: setPage(page);
067: }
068:
069: /** (non-Javadoc)
070: * Method declared on IPreferenceNode.
071: */
072: public void disposeResources() {
073:
074: if (page != null) {
075: page.dispose();
076: page = null;
077: }
078: if (icon != null) {
079: icon.dispose();
080: icon = null;
081: }
082: }
083:
084: /**
085: * Returns page icon, if defined.
086: */
087: public Image getLabelImage() {
088: if (icon == null) {
089: ImageDescriptor desc = contributor.getPageIcon();
090: if (desc != null) {
091: icon = desc.createImage();
092: }
093: }
094: return icon;
095: }
096:
097: /**
098: * Returns page label as defined in the registry.
099: */
100: public String getLabelText() {
101: return contributor.getPageName();
102: }
103: }
|