1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ui;
15 
16 /**
17  * A view is a visual component within a workbench page. It is typically used to
18  * navigate a hierarchy of information (like the workspace), open an editor, or
19  * display properties for the active editor. Modifications made in a view are
20  * saved immediately (in contrast to an editor part, which conforms to a more
21  * elaborate open-save-close lifecycle).
22  * <p>
23  * Only one instance of a particular view type may exist within a workbench
24  * page. This policy is designed to simplify part management for a user.
25  * </p>
26  * <p>
27  * This interface may be implemented directly. For convenience, a base
28  * implementation is defined in <code>ViewPart</code>.
29  * </p>
30  * <p>
31  * A view is added to the workbench in two steps:
32  * </p>
33  * <ol>
34  * <li>A view extension is contributed to the workbench registry. This extension
35  * defines the extension id and extension class.</li>
36  * <li>The view is included in the default layout for a perspective.
37  * Alternatively, the user may open the view from the Perspective menu.</li>
38  * </ol>
39  * <p>
40  * Views implement the <code>IAdaptable</code> interface; extensions are managed
41  * by the platform's adapter manager.
42  * </p>
43  * <p>
44  * As of 3.4, views may optionally adapt to {@link ISizeProvider} if they have a
45  * preferred size. The default presentation will make a best effort to allocate
46  * the preferred size to a view if it is the only part in a stack. If there is
47  * more than one part in the stack, the constraints will be disabled for that
48  * stack. The size constraints are adjusted for the size of the tab and border
49  * trim. Note that this is considered to be a hint to the presentation, and not
50  * all presentations may honor size constraints.
51  * </p>
52  *
53  * @see IWorkbenchPage#showView
54  * @see org.eclipse.ui.part.ViewPart
55  * @see ISizeProvider
56  */
57 public interface IViewPart extends IWorkbenchPart, IPersistable {
58 	/**
59 	 * Returns the site for this view. This method is equivalent to
60 	 * <code>(IViewSite) getSite()</code>.
61 	 * <p>
62 	 * The site can be <code>null</code> while the view is being initialized. After
63 	 * the initialization is complete, this value must be non-<code>null</code> for
64 	 * the remainder of the view's life cycle.
65 	 * </p>
66 	 *
67 	 * @return the view site; this value may be <code>null</code> if the view has
68 	 *         not yet been initialized
69 	 */
getViewSite()70 	IViewSite getViewSite();
71 
72 	/**
73 	 * Initializes this view with the given view site.
74 	 * <p>
75 	 * This method is automatically called by the workbench shortly after the part
76 	 * is instantiated. It marks the start of the views's lifecycle. Clients must
77 	 * not call this method.
78 	 * </p>
79 	 *
80 	 * @param site the view site
81 	 * @exception PartInitException if this view was not initialized successfully
82 	 */
init(IViewSite site)83 	void init(IViewSite site) throws PartInitException;
84 
85 	/**
86 	 * Initializes this view with the given view site. A memento is passed to the
87 	 * view which contains a snapshot of the views state from a previous session.
88 	 * Where possible, the view should try to recreate that state within the part
89 	 * controls.
90 	 * <p>
91 	 * This method is automatically called by the workbench shortly after the part
92 	 * is instantiated. It marks the start of the views's lifecycle. Clients must
93 	 * not call this method.
94 	 * </p>
95 	 *
96 	 * @param site    the view site
97 	 * @param memento the IViewPart state or null if there is no previous saved
98 	 *                state
99 	 * @exception PartInitException if this view was not initialized successfully
100 	 */
init(IViewSite site, IMemento memento)101 	void init(IViewSite site, IMemento memento) throws PartInitException;
102 
103 	/**
104 	 * Saves the object state within a memento.
105 	 *
106 	 * @param memento a memento to receive the object state
107 	 */
108 	@Override
saveState(IMemento memento)109 	void saveState(IMemento memento);
110 }
111