KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > properties > PropertySheet


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.views.properties;
12
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.ISaveablePart;
16 import org.eclipse.ui.ISelectionListener;
17 import org.eclipse.ui.IViewSite;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.internal.views.ViewsPlugin;
22 import org.eclipse.ui.part.IContributedContentsView;
23 import org.eclipse.ui.part.IPage;
24 import org.eclipse.ui.part.IPageBookViewPage;
25 import org.eclipse.ui.part.PageBook;
26 import org.eclipse.ui.part.PageBookView;
27
28 /**
29  * Main class for the Property Sheet View.
30  * <p>
31  * This standard view has id <code>"org.eclipse.ui.views.PropertySheet"</code>.
32  * </p>
33  * <p>
34  * Note that property <it>sheets</it> and property sheet pages are not the
35  * same thing as property <it>dialogs</it> and their property pages (the property
36  * pages extension point is for contributing property pages to property dialogs).
37  * Within the property sheet view, all pages are <code>IPropertySheetPage</code>s.
38  * </p>
39  * <p>
40  * Property sheet pages are discovered by the property sheet view automatically
41  * when a part is first activated. The property sheet view asks the active part
42  * for its property sheet page; this is done by invoking
43  * <code>getAdapter(IPropertySheetPage.class)</code> on the part. If the part
44  * returns a page, the property sheet view then creates the controls for that
45  * property sheet page (using <code>createControl</code>), and adds the page to
46  * the property sheet view. Whenever this part becomes active, its corresponding
47  * property sheet page is shown in the property sheet view (which may or may not
48  * be visible at the time). A part's property sheet page is discarded when the
49  * part closes. The property sheet view has a default page (an instance of
50  * <code>PropertySheetPage</code>) which services all parts without a property
51  * sheet page of their own.
52  * </p>
53  * <p>
54  * The workbench will automatically instantiates this class when a Property
55  * Sheet view is needed for a workbench window. This class is not intended
56  * to be instantiated or subclassed by clients.
57  * </p>
58  *
59  * @see IPropertySheetPage
60  * @see PropertySheetPage
61  */

62 public class PropertySheet extends PageBookView implements ISelectionListener {
63     /**
64      * No longer used but preserved to avoid api change
65      */

66     public static final String JavaDoc HELP_CONTEXT_PROPERTY_SHEET_VIEW = IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW;
67
68     /**
69      * The initial selection when the property sheet opens
70      */

71     private ISelection bootstrapSelection;
72
73     /**
74      * Creates a property sheet view.
75      */

76     public PropertySheet() {
77         super();
78     }
79
80     /* (non-Javadoc)
81      * Method declared on PageBookView.
82      * Returns the default property sheet page.
83      */

84     protected IPage createDefaultPage(PageBook book) {
85         PropertySheetPage page = new PropertySheetPage();
86         initPage(page);
87         page.createControl(book);
88         return page;
89     }
90
91     /**
92      * The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code>
93      * method creates a <code>PageBook</code> control with its default page showing.
94      */

95     public void createPartControl(Composite parent) {
96         super.createPartControl(parent);
97         getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem()
98                 .setHelp(getPageBook(),
99                         IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
100     }
101
102     /* (non-Javadoc)
103      * Method declared on IWorkbenchPart.
104      */

105     public void dispose() {
106         // run super.
107
super.dispose();
108
109         // remove ourselves as a selection listener
110
getSite().getPage().removeSelectionListener(this);
111     }
112
113     /* (non-Javadoc)
114      * Method declared on PageBookView.
115      */

116     protected PageRec doCreatePage(IWorkbenchPart part) {
117         // Try to get a custom property sheet page.
118
IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part,
119                 IPropertySheetPage.class, false);
120         if (page != null) {
121             if (page instanceof IPageBookViewPage) {
122                 initPage((IPageBookViewPage) page);
123             }
124             page.createControl(getPageBook());
125             return new PageRec(part, page);
126         }
127
128         // Use the default page
129
return null;
130     }
131
132     /* (non-Javadoc)
133      * Method declared on PageBookView.
134      */

135     protected void doDestroyPage(IWorkbenchPart part, PageRec rec) {
136         IPropertySheetPage page = (IPropertySheetPage) rec.page;
137         page.dispose();
138         rec.dispose();
139     }
140
141     /* (non-Javadoc)
142      * Method declared on PageBookView.
143      * Returns the active part on the same workbench page as this property
144      * sheet view.
145      */

146     protected IWorkbenchPart getBootstrapPart() {
147         IWorkbenchPage page = getSite().getPage();
148         if (page != null) {
149             bootstrapSelection = page.getSelection();
150             return page.getActivePart();
151         }
152         return null;
153     }
154
155     /* (non-Javadoc)
156      * Method declared on IViewPart.
157      */

158     public void init(IViewSite site) throws PartInitException {
159         site.getPage().addSelectionListener(this);
160         super.init(site);
161     }
162
163     /* (non-Javadoc)
164      * Method declared on PageBookView.
165      * The property sheet may show properties for any view other than this view.
166      */

167     protected boolean isImportant(IWorkbenchPart part) {
168         return part != this;
169     }
170
171     /**
172      * The <code>PropertySheet</code> implementation of this <code>IPartListener</code>
173      * method first sees if the active part is an <code>IContributedContentsView</code>
174      * adapter and if so, asks it for its contributing part.
175      */

176     public void partActivated(IWorkbenchPart part) {
177         // Look for a declaratively-contributed adapter - including not yet loaded adapter factories.
178
// See bug 86362 [PropertiesView] Can not access AdapterFactory, when plugin is not loaded.
179
IContributedContentsView view = (IContributedContentsView) ViewsPlugin.getAdapter(part,
180                 IContributedContentsView.class, true);
181         IWorkbenchPart source = null;
182         if (view != null) {
183             source = view.getContributingPart();
184         }
185         if (source != null) {
186             super.partActivated(source);
187         } else {
188             super.partActivated(part);
189         }
190
191         // When the view is first opened, pass the selection to the page
192
if (bootstrapSelection != null) {
193             IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
194             if (page != null) {
195                 page.selectionChanged(part, bootstrapSelection);
196             }
197             bootstrapSelection = null;
198         }
199     }
200
201     /* (non-Javadoc)
202      * Method declared on ISelectionListener.
203      * Notify the current page that the selection has changed.
204      */

205     public void selectionChanged(IWorkbenchPart part, ISelection sel) {
206         // we ignore our own selection or null selection
207
if (part == this || sel == null) {
208             return;
209         }
210
211         // pass the selection to the page
212
IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
213         if (page != null) {
214             page.selectionChanged(part, sel);
215         }
216     }
217     
218     /**
219      * The <code>PropertySheet</code> implementation of this
220      * <code>PageBookView</code> method handles the <code>ISaveablePart</code>
221      * adapter case by calling <code>getSaveablePart()</code>.
222      *
223      * @since 3.2
224      */

225     protected Object JavaDoc getViewAdapter(Class JavaDoc key) {
226         if (ISaveablePart.class.equals(key)) {
227             return getSaveablePart();
228         }
229         return super.getViewAdapter(key);
230     }
231
232     /**
233      * Returns an <code>ISaveablePart</code> that delegates to the source part
234      * for the current page if it implements <code>ISaveablePart</code>, or
235      * <code>null</code> otherwise.
236      *
237      * @return an <code>ISaveablePart</code> or <code>null</code>
238      * @since 3.2
239      */

240     protected ISaveablePart getSaveablePart() {
241         IWorkbenchPart part = getCurrentContributingPart();
242         if (part instanceof ISaveablePart) {
243             return (ISaveablePart) part;
244         }
245         return null;
246     }
247 }
248
Popular Tags