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: * Chris Gross chris.gross@us.ibm.com Bug 107443
011: *******************************************************************************/package org.eclipse.ui.internal;
012:
013: import org.eclipse.ui.IFolderLayout;
014: import org.eclipse.ui.PartInitException;
015: import org.eclipse.ui.activities.WorkbenchActivityHelper;
016: import org.eclipse.ui.views.IViewDescriptor;
017:
018: /**
019: * This layout is used to define the initial set of views and placeholders
020: * in a folder.
021: * <p>
022: * Views are added to the folder by ID. This id is used to identify
023: * a view descriptor in the view registry, and this descriptor is used to
024: * instantiate the <code>IViewPart</code>.
025: * </p>
026: */
027: public class FolderLayout implements IFolderLayout {
028: private ViewStack folder;
029:
030: private PageLayout pageLayout;
031:
032: private ViewFactory viewFactory;
033:
034: /**
035: * Create an instance of a <code>FolderLayout</code> belonging to a
036: * <code>PageLayout</code>.
037: */
038: public FolderLayout(PageLayout pageLayout, ViewStack folder,
039: ViewFactory viewFactory) {
040: super ();
041: this .folder = folder;
042: this .viewFactory = viewFactory;
043: this .pageLayout = pageLayout;
044: }
045:
046: /* (non-Javadoc)
047: * @see org.eclipse.ui.IPlaceholderFolderLayout#addPlaceholder(java.lang.String)
048: */
049: public void addPlaceholder(String viewId) {
050: if (!pageLayout.checkValidPlaceholderId(viewId)) {
051: return;
052: }
053:
054: // Create the placeholder.
055: PartPlaceholder newPart = new PartPlaceholder(viewId);
056: linkPartToPageLayout(viewId, newPart);
057:
058: // Add it to the folder layout.
059: folder.add(newPart);
060: }
061:
062: /* (non-Javadoc)
063: * @see org.eclipse.ui.IFolderLayout#addView(java.lang.String)
064: */
065: public void addView(String viewId) {
066: if (pageLayout.checkPartInLayout(viewId)) {
067: return;
068: }
069:
070: try {
071: IViewDescriptor descriptor = viewFactory.getViewRegistry()
072: .find(ViewFactory.extractPrimaryId(viewId));
073: if (descriptor == null) {
074: throw new PartInitException(
075: "View descriptor not found: " + viewId); //$NON-NLS-1$
076: }
077: if (WorkbenchActivityHelper.filterItem(descriptor)) {
078: //create a placeholder instead.
079: addPlaceholder(viewId);
080: LayoutHelper.addViewActivator(pageLayout, viewId);
081: } else {
082:
083: ViewPane newPart = LayoutHelper.createView(pageLayout
084: .getViewFactory(), viewId);
085: linkPartToPageLayout(viewId, newPart);
086: folder.add(newPart);
087: }
088: } catch (PartInitException e) {
089: // cannot safely open the dialog so log the problem
090: WorkbenchPlugin.log(getClass(), "addView(String)", e); //$NON-NLS-1$
091: }
092: }
093:
094: /**
095: * Inform the page layout of the new part created
096: * and the folder the part belongs to.
097: */
098: private void linkPartToPageLayout(String viewId, LayoutPart newPart) {
099: pageLayout.setRefPart(viewId, newPart);
100: pageLayout.setFolderPart(viewId, folder);
101: // force creation of the view layout rec
102: pageLayout.getViewLayoutRec(viewId, true);
103: }
104:
105: /* (non-Javadoc)
106: * @see org.eclipse.ui.IPlaceholderFolderLayout#getProperty(java.lang.String)
107: */
108: public String getProperty(String id) {
109: return folder.getProperty(id);
110: }
111:
112: /* (non-Javadoc)
113: * @see org.eclipse.ui.IPlaceholderFolderLayout#setProperty(java.lang.String, java.lang.String)
114: */
115: public void setProperty(String id, String value) {
116: folder.setProperty(id, value);
117: }
118: }
|