Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 62c3379652df08344008a17da64c3ba93977fb14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*****************************************************************************
 * Copyright (c) 2010 LIFL & CEA LIST.
 *
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Cedric Dumoulin (LIFL) cedric.dumoulin@lifl.fr - Initial API and implementation
 *
 *****************************************************************************/

package org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.part.Page;


/**
 * A {@link Page} handling a {@link ViewPart} in a {@link MultiViewPageBookView}.
 * Subclass must create the viewer in their constructor. The constructor take the part as argument.
 * The constructor is called from a subclass of {@link MultiViewPageBookView}.
 * Subclass should also implements the method getControl().
 *
 * @author cedric dumoulin
 *
 */
public abstract class ViewPartPage extends Page implements IAdaptable {


	/**
	 * The wrapped View
	 */
	private IViewPart modelExplorer;

	/**
	 * Constructor.
	 *
	 */
	public ViewPartPage() {
	}

	/**
	 * Init the inner View
	 *
	 * @see org.eclipse.ui.part.Page#init(org.eclipse.ui.part.IPageSite)
	 *
	 * @param pageSite
	 */
	@Override
	public void init(IPageSite pageSite) {
		// Not used.
		super.init(pageSite);
	}

	/**
	 * @param viewPageSite
	 * @param memento
	 * @throws CoreException
	 */
	public void init(IWorkbenchPart part, ViewPageSite viewPageSite, IMemento memento, IConfigurationElement cfig) throws CoreException {

		// Call the original method to record the site
		init(viewPageSite);

		// ask to create the Viewer
		modelExplorer = createViewer(part);

		// Add the extension config if requested by the Viewer
		if (modelExplorer instanceof IExecutableExtension) {
			((IExecutableExtension) modelExplorer).setInitializationData(cfig, null, null);
		}
		// Init the part
		modelExplorer.init(viewPageSite, memento);
	}

	/**
	 * Create the viewer for this page. The Viewer is associated to the specified part.
	 *
	 * @param part
	 *            The part associated to the Viewer.
	 *
	 * @return The Viewer to render in the page.
	 */
	abstract protected IViewPart createViewer(IWorkbenchPart part);

	/**
	 * Subclass must implement this method.
	 *
	 * @see org.eclipse.ui.part.Page#getControl()
	 *
	 * @return
	 */
	@Override
	abstract public Control getControl();

	/**
	 * @see org.eclipse.ui.part.Page#setFocus()
	 *
	 */
	@Override
	public void setFocus() {
		modelExplorer.setFocus();
	}

	/**
	 * Return the associated viewer
	 *
	 * @return
	 */
	public IViewPart getViewer() {
		return modelExplorer;
	}

	/**
	 * Forward to the
	 *
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
	 *
	 * @param adapter
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class adapter) {

		if (modelExplorer instanceof IAdaptable) {
			return ((IAdaptable) modelExplorer).getAdapter(adapter);
		}

		// do nothing
		return null;
	}

	/**
	 * Dispose the page, and its associated viewer.
	 * 
	 * @see org.eclipse.ui.part.Page#dispose()
	 *
	 */
	@Override
	public void dispose() {
		modelExplorer.dispose();
		super.dispose();
		modelExplorer = null;
	}
}

Back to the top