KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > FolderLayout


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  * Chris Gross chris.gross@us.ibm.com Bug 107443
11  *******************************************************************************/

12 package org.eclipse.ui.internal;
13
14 import org.eclipse.ui.IFolderLayout;
15 import org.eclipse.ui.PartInitException;
16 import org.eclipse.ui.activities.WorkbenchActivityHelper;
17 import org.eclipse.ui.views.IViewDescriptor;
18
19 /**
20  * This layout is used to define the initial set of views and placeholders
21  * in a folder.
22  * <p>
23  * Views are added to the folder by ID. This id is used to identify
24  * a view descriptor in the view registry, and this descriptor is used to
25  * instantiate the <code>IViewPart</code>.
26  * </p>
27  */

28 public class FolderLayout implements IFolderLayout {
29     private ViewStack folder;
30
31     private PageLayout pageLayout;
32
33     private ViewFactory viewFactory;
34
35     /**
36      * Create an instance of a <code>FolderLayout</code> belonging to a
37      * <code>PageLayout</code>.
38      */

39     public FolderLayout(PageLayout pageLayout, ViewStack folder,
40             ViewFactory viewFactory) {
41         super();
42         this.folder = folder;
43         this.viewFactory = viewFactory;
44         this.pageLayout = pageLayout;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.ui.IPlaceholderFolderLayout#addPlaceholder(java.lang.String)
49      */

50     public void addPlaceholder(String JavaDoc viewId) {
51         if (!pageLayout.checkValidPlaceholderId(viewId)) {
52             return;
53         }
54
55         // Create the placeholder.
56
PartPlaceholder newPart = new PartPlaceholder(viewId);
57         linkPartToPageLayout(viewId, newPart);
58
59         // Add it to the folder layout.
60
folder.add(newPart);
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.ui.IFolderLayout#addView(java.lang.String)
65      */

66     public void addView(String JavaDoc viewId) {
67         if (pageLayout.checkPartInLayout(viewId)) {
68             return;
69         }
70
71         try {
72             IViewDescriptor descriptor = viewFactory.getViewRegistry().find(
73                     ViewFactory.extractPrimaryId(viewId));
74             if (descriptor == null) {
75                 throw new PartInitException("View descriptor not found: " + viewId); //$NON-NLS-1$
76
}
77             if (WorkbenchActivityHelper.filterItem(descriptor)) {
78                 //create a placeholder instead.
79
addPlaceholder(viewId);
80                 LayoutHelper.addViewActivator(pageLayout, viewId);
81             } else {
82
83                 ViewPane newPart = LayoutHelper.createView(pageLayout
84                         .getViewFactory(), viewId);
85                 linkPartToPageLayout(viewId, newPart);
86                 folder.add(newPart);
87             }
88         } catch (PartInitException e) {
89             // cannot safely open the dialog so log the problem
90
WorkbenchPlugin.log(getClass(), "addView(String)", e); //$NON-NLS-1$
91
}
92     }
93
94     /**
95      * Inform the page layout of the new part created
96      * and the folder the part belongs to.
97      */

98     private void linkPartToPageLayout(String JavaDoc viewId, LayoutPart newPart) {
99         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 JavaDoc getProperty(String JavaDoc 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 JavaDoc id, String JavaDoc value) {
116         folder.setProperty(id,value);
117     }
118 }
119
Popular Tags