1 /*******************************************************************************
2  * Copyright (c) 2011, 2015 Wind River Systems 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  *     Wind River Systems - initial API and implementation
13  *     IBM Corporation - ongoing bug fixes and enhancements
14  *******************************************************************************/
15 package org.eclipse.debug.internal.ui.viewers.model.provisional;
16 
17 import org.eclipse.debug.internal.ui.viewers.model.ILabelUpdateListener;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.ISelectionProvider;
20 import org.eclipse.jface.viewers.TreePath;
21 import org.eclipse.jface.viewers.ViewerFilter;
22 import org.eclipse.jface.viewers.ViewerLabel;
23 import org.eclipse.swt.widgets.Display;
24 
25 /**
26  * Interface of an tree model viewer.  It declares the common methods for the
27  * JFace-based {@link TreeModelViewer} and the UI-less
28  * {@link VirtualTreeModelViewer}.
29  *
30  * @since 3.8
31  */
32 public interface ITreeModelViewer extends ISelectionProvider {
33 
34 	/**
35 	 * Constant indicating that all levels of the tree should be expanded or
36 	 * collapsed.
37 	 *
38 	 * @see #setAutoExpandLevel(int)
39 	 * @see #getAutoExpandLevel()
40 	 */
41 	int ALL_LEVELS = -1;
42 
43 	/**
44 	 * Returns the Display object that this viewer is in.  The
45 	 * display object can be used by clients to access the display thread
46 	 * to call the viewer methods.
47 	 *
48 	 * @return The display.
49 	 */
getDisplay()50 	Display getDisplay();
51 
52 	/**
53 	 * Returns this viewer's presentation context.
54 	 *
55 	 * @return presentation context
56 	 */
getPresentationContext()57 	IPresentationContext getPresentationContext();
58 
59 	/**
60 	 * Returns the current input of this viewer, or <code>null</code>
61 	 * if none. The viewer's input provides the "model" for the viewer's
62 	 * content.
63 	 *
64 	 * @return Input object
65 	 */
getInput()66 	Object getInput();
67 
68 	/**
69 	 * Sets the input of this viewer.  Setting the input resets the
70 	 * viewer's contents and triggers an update starting at the input
71 	 * element.
72 	 *
73 	 * @param object Input element, or <code>null</code> if none.
74 	 */
setInput(Object object)75 	void setInput(Object object);
76 
77 	/**
78 	 * Returns the current selection in viewer.
79 	 *
80 	 * @return selection object
81 	 */
getSelection()82 	@Override ISelection getSelection();
83 
84 	/**
85 	 * Sets a new selection for this viewer and optionally makes it visible.
86 	 * The selection is not set if the model selection policy overrides the
87 	 * attempt to set the selection.
88 	 *
89 	 * @param selection the new selection
90 	 * @param reveal <code>true</code> if the selection is to be made
91 	 *   visible, and <code>false</code> otherwise
92 	 * @param force <code>true</code> if the selection should override the
93 	 *   model selection policy
94 	 */
setSelection(ISelection selection, boolean reveal, boolean force)95 	void setSelection(ISelection selection, boolean reveal, boolean force);
96 
97 	/**
98 	 * Attempts to set the selection for this viewer and optionally makes it visible.
99 	 * The selection is not set if the model selection policy overrides the
100 	 * attempt to set the selection.
101 	 *
102 	 * @param selection the new selection
103 	 * @param reveal whether to make the selection visible after successfully setting
104 	 *  the selection
105 	 * @param force whether to force the selection (override the model selection policy)
106 	 * @return <code>true</code> if the selection was set and <code>false</code> if the
107 	 *  model selection policy overrides the selection attempt
108 	 */
trySelection(ISelection selection, boolean reveal, boolean force)109 	boolean trySelection(ISelection selection, boolean reveal, boolean force);
110 
111 	/**
112 	 * Returns the auto-expand level.
113 	 *
114 	 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
115 	 *         the tree are expanded automatically
116 	 * @see #setAutoExpandLevel
117 	 */
getAutoExpandLevel()118 	int getAutoExpandLevel();
119 
120 	/**
121 	 * Sets the auto-expand level to be used when the input of the viewer is set
122 	 * using {@link #setInput(Object)}. The value 0 means that there is no
123 	 * auto-expand; 1 means that the invisible root element is expanded (since
124 	 * most concrete implementations do not show the root element, there is usually
125 	 * no practical difference between using the values 0 and 1); 2 means that
126 	 * top-level elements are expanded, but not their children; 3 means that
127 	 * top-level elements are expanded, and their children, but not
128 	 * grandchildren; and so on.
129 	 * <p>
130 	 * The value <code>ALL_LEVELS</code> means that all subtrees should be
131 	 * expanded.
132 	 * </p>
133 	 *
134 	 * @param level
135 	 *            non-negative level, or <code>ALL_LEVELS</code> to expand all
136 	 *            levels of the tree
137 	 */
setAutoExpandLevel(int level)138 	void setAutoExpandLevel(int level);
139 
140 	/**
141 	 * Returns the label data for the given element and for the given column,
142 	 * Returns <code>null</code> if the given element is not found or is not
143 	 * materialized in the virtual viewer.  Clients may listen to label update
144 	 * events to be notified when element labels are updated.
145 	 *
146 	 * @param path Path of the element.
147 	 * @param columnId ID of the column for which to return the label data.
148 	 * @return Label object containing the label information.  Can be
149 	 * <code>null</code> if the given element is not found or is not
150 	 * materialized in the virtual viewer.
151 	 */
getElementLabel(TreePath path, String columnId)152 	ViewerLabel getElementLabel(TreePath path, String columnId);
153 
154 	/**
155 	 * Registers the specified listener for view update notifications.
156 	 *
157 	 * @param listener Listener to add
158 	 */
addViewerUpdateListener(IViewerUpdateListener listener)159 	void addViewerUpdateListener(IViewerUpdateListener listener);
160 
161 	/**
162 	 * Removes the specified listener from update notifications.
163 	 *
164 	 * @param listener Listener to remove
165 	 */
removeViewerUpdateListener(IViewerUpdateListener listener)166 	void removeViewerUpdateListener(IViewerUpdateListener listener);
167 
168 	/**
169 	 * Registers the specified listener for state update notifications.
170 	 *
171 	 * @param listener Listener to add
172 	 */
addStateUpdateListener(IStateUpdateListener listener)173 	void addStateUpdateListener(IStateUpdateListener listener);
174 
175 	/**
176 	 * Removes the specified listener from state update notifications.
177 	 *
178 	 * @param listener Listener to remove
179 	 */
removeStateUpdateListener(IStateUpdateListener listener)180 	void removeStateUpdateListener(IStateUpdateListener listener);
181 
182 	/**
183 	 * Registers the specified listener for view label update notifications.
184 	 *
185 	 * @param listener Listener to add
186 	 */
addLabelUpdateListener(ILabelUpdateListener listener)187 	void addLabelUpdateListener(ILabelUpdateListener listener);
188 
189 	/**
190 	 * Removes the specified listener from view label update notifications.
191 	 *
192 	 * @param listener Listener to remove
193 	 */
removeLabelUpdateListener(ILabelUpdateListener listener)194 	void removeLabelUpdateListener(ILabelUpdateListener listener);
195 
196 	/**
197 	 * Registers the given listener for model delta notification.
198 	 * This listener is called immediately after the viewer processes
199 	 * the delta.
200 	 *
201 	 * @param listener Listener to add
202 	 */
addModelChangedListener(IModelChangedListener listener)203 	void addModelChangedListener(IModelChangedListener listener);
204 
205 	/**
206 	 * Removes the given listener from model delta notification.
207 	 *
208 	 * @param listener Listener to remove
209 	 */
removeModelChangedListener(IModelChangedListener listener)210 	void removeModelChangedListener(IModelChangedListener listener);
211 
212 	/**
213 	 * Writes state information into a delta for the sub-tree at the given
214 	 * path.  It adds delta nodes and IModelDelta.EXPAND and IModelDelta.SELECT
215 	 * as it parses the sub-tree.
216 	 *
217 	 * @param path Path where to start saving the state.
218 	 * @param delta The delta where the state is to be saved.
219 	 * @param flagsToSave The flags to preserve during the state save.  The
220 	 * supported flags are <code>IModelDelta.SELECT</code>,
221 	 * <code>IModelDelta.EXPAND</code>, <code>IModelDelta.COLLAPSE</code>.
222 	 * @return Returns whether the state was saved for the given path.  Will
223 	 * return <code>false</code> if an element at the given path cannot
224 	 * be found.
225 	 */
saveElementState(TreePath path, ModelDelta delta, int flagsToSave)226 	boolean saveElementState(TreePath path, ModelDelta delta, int flagsToSave);
227 
228 	/**
229 	 * Causes the viewer to process the given delta as if it came from a
230 	 * model proxy.  This method is intended to be used to restore state
231 	 * saved using {@link #saveElementState(TreePath, ModelDelta, int)}.
232 	 *
233 	 * @param delta Delta to process.
234 	 */
updateViewer(IModelDelta delta)235 	void updateViewer(IModelDelta delta);
236 
237 	/**
238 	 * Triggers an update of the given element and its children.  If
239 	 * multiple instances of the given element are found in the tree,
240 	 * they will all be updated.
241 	 *
242 	 * @param element Element to update.
243 	 */
refresh(Object element)244 	void refresh(Object element);
245 
246 	/**
247 	 * Triggers a full update of all the elements in the tree.
248 	 */
refresh()249 	void refresh();
250 
251 	/**
252 	 * Returns the paths at which the given element is found realized in viewer
253 	 * or an empty array if not found.
254 	 *
255 	 * @param element Element to find.
256 	 * @return Array of paths for given element.
257 	 */
getElementPaths(Object element)258 	TreePath[] getElementPaths(Object element);
259 
260 	/**
261 	 * Returns filters currently configured in viewer.
262 	 *
263 	 * @return filter array in viewer.
264 	 */
getFilters()265 	ViewerFilter[] getFilters();
266 
267 	/**
268 	 * Add a new filter to use in viewer.
269 	 *
270 	 * @param filter Filter to add.
271 	 */
addFilter(ViewerFilter filter)272 	void addFilter(ViewerFilter filter);
273 
274 	/**
275 	 * Sets viewer filters to the filters in array.
276 	 *
277 	 * @param filters New filter array to use.
278 	 */
setFilters(ViewerFilter... filters)279 	void setFilters(ViewerFilter... filters);
280 
281  }
282