intial source from http://www.sf.net/projects/wdte
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / ui / views / preview / BrowserPreview.java
1 /*
2  * Copyright (c) 2004 Christopher Lenz and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API and implementation
10  * 
11  * $Id: BrowserPreview.java,v 1.1 2004-09-02 18:26:31 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.ui.views.preview;
15
16 import net.sourceforge.phpeclipse.ui.internal.WebUIMessages;
17
18 import org.eclipse.ui.IEditorPart;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.IWorkbenchPart;
21 import org.eclipse.ui.part.IPage;
22 import org.eclipse.ui.part.IPageBookViewPage;
23 import org.eclipse.ui.part.MessagePage;
24 import org.eclipse.ui.part.PageBook;
25 import org.eclipse.ui.part.PageBookView;
26
27 /**
28  * 
29  */
30 public class BrowserPreview extends PageBookView {
31
32         /* 
33          * @see PageBookView#createDefaultPage(org.eclipse.ui.part.PageBook)
34          */
35         protected IPage createDefaultPage(PageBook book) {
36                 MessagePage page = new MessagePage();
37                 page.createControl(book);
38                 page.setMessage(WebUIMessages.getString(
39                                 "BrowserPreview.notAvailable")); //$NON-NLS-1$);
40                 return page;
41         }
42
43         /* 
44          * @see PageBookView#doCreatePage(org.eclipse.ui.IWorkbenchPart)
45          */
46         protected PageRec doCreatePage(IWorkbenchPart part) {
47                 // Try to get an outline page.
48                 Object adapter = part.getAdapter(IBrowserPreviewPage.class);
49                 if (adapter instanceof IBrowserPreviewPage) {
50                         IBrowserPreviewPage page = (IBrowserPreviewPage) adapter;
51                         if (page instanceof IPageBookViewPage) {
52                                 initPage((IPageBookViewPage) page);
53                         }
54                         page.createControl(getPageBook());
55                         return new PageRec(part, page);
56                 }
57                 // There is no preview
58                 return null;
59         }
60
61         /* 
62          * @see PageBookView#doDestroyPage(IWorkbenchPart, PageBookView.PageRec)
63          */
64         protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
65                 IBrowserPreviewPage page = (IBrowserPreviewPage) pageRecord.page;
66                 page.dispose();
67                 pageRecord.dispose();
68         }
69
70         /* 
71          * @see PageBookView#getBootstrapPart()
72          */
73         protected IWorkbenchPart getBootstrapPart() {
74                 IWorkbenchPage page = getSite().getPage();
75                 if (page != null) {
76                         return page.getActiveEditor();
77                 }
78                 return null;
79         }
80
81         /* 
82          * @see PageBookView#isImportant(IWorkbenchPart)
83          */
84         protected boolean isImportant(IWorkbenchPart part) {
85                 return (part instanceof IEditorPart);
86         }
87
88 }