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.registry;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.core.runtime.IExtensionRegistry;
015: import org.eclipse.ui.PlatformUI;
016: import org.eclipse.ui.internal.WorkbenchPlugin;
017:
018: /**
019: * A strategy to read view extensions from the registry.
020: */
021: public class ViewRegistryReader extends RegistryReader {
022: /**
023: * General view category id
024: */
025: public static String GENERAL_VIEW_ID = "org.eclipse.ui"; //$NON-NLS-1$
026:
027: private ViewRegistry viewRegistry;
028:
029: /**
030: * RegistryViewReader constructor comment.
031: */
032: public ViewRegistryReader() {
033: super ();
034: }
035:
036: /**
037: * Reads the category element.
038: */
039: protected void readCategory(IConfigurationElement element) {
040: try {
041: viewRegistry.add(new Category(element));
042: } catch (CoreException e) {
043: // log an error since its not safe to show a dialog here
044: WorkbenchPlugin.log(
045: "Unable to create view category.", e.getStatus());//$NON-NLS-1$
046: }
047: }
048:
049: /**
050: * readElement method comment.
051: */
052: protected boolean readElement(IConfigurationElement element) {
053: if (element.getName().equals(
054: IWorkbenchRegistryConstants.TAG_VIEW)) {
055: readView(element);
056: return true;
057: }
058: if (element.getName().equals(
059: IWorkbenchRegistryConstants.TAG_CATEGORY)) {
060: readCategory(element);
061: readElementChildren(element);
062: return true;
063: }
064: if (element.getName().equals(
065: IWorkbenchRegistryConstants.TAG_STICKYVIEW)) {
066: readSticky(element);
067: return true;
068: }
069:
070: return false;
071: }
072:
073: /**
074: * Reads the sticky view element.
075: */
076: protected void readSticky(IConfigurationElement element) {
077: try {
078: viewRegistry.add(new StickyViewDescriptor(element));
079: } catch (CoreException e) {
080: // log an error since its not safe to open a dialog here
081: WorkbenchPlugin
082: .log(
083: "Unable to create sticky view descriptor.", e.getStatus());//$NON-NLS-1$
084:
085: }
086: }
087:
088: /**
089: * Reads the view element.
090: */
091: protected void readView(IConfigurationElement element) {
092: try {
093: viewRegistry.add(new ViewDescriptor(element));
094: } catch (CoreException e) {
095: // log an error since its not safe to open a dialog here
096: WorkbenchPlugin.log(
097: "Unable to create view descriptor.", e.getStatus());//$NON-NLS-1$
098: }
099: }
100:
101: /**
102: * Read the view extensions within a registry.
103: * @param in the extension registry
104: * @param out the view registry
105: */
106: public void readViews(IExtensionRegistry in, ViewRegistry out) {
107: // this does not seem to really ever be throwing an the exception
108: viewRegistry = out;
109: readRegistry(in, PlatformUI.PLUGIN_ID,
110: IWorkbenchRegistryConstants.PL_VIEWS);
111: }
112: }
|