KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > navigator > PipelinedViewerUpdate


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.ui.navigator;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.LinkedHashSet JavaDoc;
16 import java.util.Map JavaDoc;
17 import java.util.Set JavaDoc;
18
19 import org.eclipse.jface.viewers.AbstractTreeViewer;
20
21 /**
22  *
23  * A pipelined viewer update should map requests to refresh or update elements
24  * in the viewer to their correct, modified structure. Clients use
25  * {@link PipelinedViewerUpdate} as the input and return type from intercept
26  * methods on {@link IPipelinedTreeContentProvider}.
27  *
28  * <p>
29  * Clients should use the viewer update to describe how the request from the
30  * upstream extension (see {@link IPipelinedTreeContentProvider} for more
31  * information on <i>upstream</i> extensions) should be reshaped when applied
32  * to the tree. A request from an upstream extension to refresh a given element
33  * could result in multiple refresh requests from downstream extensions.
34  * Therefore, the refresh targets are modeled as a set.
35  * </p>
36  * <p>
37  * Initially, this set will contain the original element that was passed to the
38  * refresh requests. Clients may squash the refresh by clearing the set, change
39  * the original target by removing the current element and adding a new target,
40  * or expand the refresh by adding more elements to the set.
41  * </p>
42  * <p>
43  * A pipelined extension may receive a {@link PipelinedViewerUpdate} as the
44  * result of a call to {@link AbstractTreeViewer#refresh()}-methods or
45  * {@link AbstractTreeViewer#update(Object, String[])}-methods. The
46  * <code>properties</code> field is only applicable for <code>update()</code>
47  * calls and the <code>updateLabels</code> field is only applicable for
48  * <code>refresh()</code> calls.
49  * </p>
50  *
51  * @since 3.2
52  *
53  */

54 public final class PipelinedViewerUpdate {
55
56     private static final String JavaDoc[] NO_PROPERTIES = new String JavaDoc[0];
57
58     private final Set JavaDoc refreshTargets = new LinkedHashSet JavaDoc();
59
60     private boolean updateLabels = false;
61
62     private Map JavaDoc properties;
63
64     /**
65      * Properties allow optimization for <code>update</code> calls.
66      *
67      * @param aTarget
68      * The target which may have specific properties associated with
69      * it for an optimized refresh.
70      *
71      * @return Returns the properties for the given target. If no properties are
72      * specified, then an empty array is returned. <b>null</b> will
73      * never be returned.
74      */

75     public final String JavaDoc[] getProperties(Object JavaDoc aTarget) {
76         if (properties != null && properties.containsKey(aTarget)) {
77             String JavaDoc[] props = (String JavaDoc[]) properties.get(aTarget);
78             return props != null ? props : NO_PROPERTIES;
79         }
80         return NO_PROPERTIES;
81     }
82
83     /**
84      *
85      * Properties allow optimization for <code>update</code> calls.
86      *
87      * @param aTarget
88      * The target of the properties.
89      * @param theProperties
90      * The properties to pass along to the <code>update</code>
91      * call.
92      * @see AbstractTreeViewer#update(Object, String[])
93      */

94     public final void setProperties(Object JavaDoc aTarget, String JavaDoc[] theProperties) {
95         if (theProperties != null && theProperties.length > 0) {
96             if (properties == null) {
97                 properties = new HashMap JavaDoc();
98             }
99             properties.put(aTarget, theProperties);
100
101         } else {
102             properties.remove(aTarget);
103         }
104
105         if (properties.size() == 0) {
106             properties = null;
107         }
108
109     }
110
111     /**
112      * @return Returns the current set of refresh targets. Clients may add or
113      * remove directly to or from this set.
114      */

115     public final Set JavaDoc getRefreshTargets() {
116         return refreshTargets;
117     }
118
119     /**
120      * @return Returns the true if the labels should also be updated during the
121      * <code>refresh</code>.
122      */

123     public final boolean isUpdateLabels() {
124         return updateLabels;
125     }
126
127     /**
128      * @param toUpdateLabels
129      * True indicates that calls to <code>refresh</code> should
130      * force the update of the labels in addition to refreshing the
131      * structure.
132      */

133     public final void setUpdateLabels(boolean toUpdateLabels) {
134         updateLabels = toUpdateLabels;
135     }
136
137 }
138
Popular Tags