KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > browsing > PackageViewerWrapper


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.jdt.internal.ui.browsing;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.ListenerList;
17
18 import org.eclipse.swt.events.HelpListener;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Item;
21 import org.eclipse.swt.widgets.Widget;
22
23 import org.eclipse.jface.viewers.IBaseLabelProvider;
24 import org.eclipse.jface.viewers.IContentProvider;
25 import org.eclipse.jface.viewers.IDoubleClickListener;
26 import org.eclipse.jface.viewers.IOpenListener;
27 import org.eclipse.jface.viewers.ISelection;
28 import org.eclipse.jface.viewers.ISelectionChangedListener;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.jface.viewers.StructuredSelection;
31 import org.eclipse.jface.viewers.StructuredViewer;
32 import org.eclipse.jface.viewers.ViewerComparator;
33 import org.eclipse.jface.viewers.ViewerFilter;
34 import org.eclipse.jface.viewers.ViewerSorter;
35
36 import org.eclipse.jdt.core.IPackageFragment;
37
38 /**
39  * Wrapper who transfers listeners and filters and to which clients
40  * can refer.
41  *
42  * @deprecated needs to be replaced by a manager who handles transfer of listeners and filters
43  */

44 class PackageViewerWrapper extends StructuredViewer {
45
46     private StructuredViewer fViewer;
47     private ListenerList fListenerList;
48     private ListenerList fSelectionChangedListenerList;
49     private ListenerList fPostSelectionChangedListenerList;
50
51     public PackageViewerWrapper() {
52         fListenerList= new ListenerList(ListenerList.IDENTITY);
53         fPostSelectionChangedListenerList= new ListenerList(ListenerList.IDENTITY);
54         fSelectionChangedListenerList= new ListenerList(ListenerList.IDENTITY);
55     }
56
57     public void setViewer(StructuredViewer viewer) {
58         Assert.isNotNull(viewer);
59
60         StructuredViewer oldViewer= fViewer;
61         fViewer= viewer;
62
63         if (fViewer.getContentProvider() != null)
64             super.setContentProvider(fViewer.getContentProvider());
65         transferFilters(oldViewer);
66         transferListeners();
67     }
68
69     StructuredViewer getViewer(){
70         return fViewer;
71     }
72
73     private void transferFilters(StructuredViewer oldViewer) {
74         //set filters
75
if (oldViewer != null) {
76             ViewerFilter[] filters= oldViewer.getFilters();
77             for (int i= 0; i < filters.length; i++) {
78                 ViewerFilter filter= filters[i];
79                 fViewer.addFilter(filter);
80             }
81         }
82     }
83
84     private void transferListeners() {
85
86         Object JavaDoc[] listeners= fPostSelectionChangedListenerList.getListeners();
87         for (int i= 0; i < listeners.length; i++) {
88             Object JavaDoc object= listeners[i];
89             ISelectionChangedListener listener= (ISelectionChangedListener)object;
90             fViewer.addPostSelectionChangedListener(listener);
91         }
92
93         listeners= fSelectionChangedListenerList.getListeners();
94         for (int i= 0; i < listeners.length; i++) {
95             Object JavaDoc object= listeners[i];
96             ISelectionChangedListener listener= (ISelectionChangedListener)object;
97             fViewer.addSelectionChangedListener(listener);
98         }
99
100         // Add all other listeners
101
listeners= fListenerList.getListeners();
102         for (int i= 0; i < listeners.length; i++) {
103             Object JavaDoc object= listeners[i];
104
105             if (object instanceof IOpenListener) {
106                 IOpenListener listener= (IOpenListener) object;
107                 addOpenListener(listener);
108             } else if (object instanceof HelpListener) {
109                 HelpListener listener= (HelpListener) object;
110                 addHelpListener(listener);
111             } else if (object instanceof IDoubleClickListener) {
112                 IDoubleClickListener listener= (IDoubleClickListener) object;
113                 addDoubleClickListener(listener);
114             }
115         }
116     }
117
118     public void setSelection(ISelection selection, boolean reveal) {
119         if (selection instanceof IStructuredSelection) {
120             IStructuredSelection sel= (IStructuredSelection) selection;
121
122             //try and give the two a common super class
123
IContentProvider provider= getContentProvider();
124             if (provider instanceof LogicalPackagesProvider) {
125                 LogicalPackagesProvider fprovider= (LogicalPackagesProvider) provider;
126
127                 Object JavaDoc object= sel.getFirstElement();
128                 if (object instanceof IPackageFragment) {
129                     IPackageFragment pkgFragment= (IPackageFragment)object;
130                     LogicalPackage logicalPkg= fprovider.findLogicalPackage(pkgFragment);
131                     if (logicalPkg != null)
132                         object= logicalPkg;
133                     else
134                         object= pkgFragment;
135                 }
136                 if (object != null)
137                     fViewer.setSelection(new StructuredSelection(object), reveal);
138                 else
139                     fViewer.setSelection(StructuredSelection.EMPTY, reveal);
140             }
141         } else
142             fViewer.setSelection(selection, reveal);
143     }
144
145     public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
146         fPostSelectionChangedListenerList.add(listener);
147         fViewer.addPostSelectionChangedListener(listener);
148     }
149
150     public void addSelectionChangedListener(ISelectionChangedListener listener) {
151         fSelectionChangedListenerList.add(listener);
152         fViewer.addSelectionChangedListener(listener);
153     }
154
155     public void addDoubleClickListener(IDoubleClickListener listener) {
156         fViewer.addDoubleClickListener(listener);
157         fListenerList.add(listener);
158     }
159
160     public void addOpenListener(IOpenListener listener) {
161         fViewer.addOpenListener(listener);
162         fListenerList.add(listener);
163     }
164
165     public void addHelpListener(HelpListener listener) {
166         fViewer.addHelpListener(listener);
167         fListenerList.add(listener);
168     }
169
170     public void removeSelectionChangedListener(ISelectionChangedListener listener) {
171         fViewer.removeSelectionChangedListener(listener);
172         fSelectionChangedListenerList.remove(listener);
173     }
174
175     public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
176         fViewer.removePostSelectionChangedListener(listener);
177         fPostSelectionChangedListenerList.remove(listener);
178     }
179
180     public void removeHelpListener(HelpListener listener) {
181         fListenerList.remove(listener);
182         fViewer.removeHelpListener(listener);
183     }
184
185     public void removeDoubleClickListener(IDoubleClickListener listener) {
186         fViewer.removeDoubleClickListener(listener);
187         fListenerList.remove(listener);
188     }
189
190     public void removeOpenListener(IOpenListener listener) {
191         fViewer.removeOpenListener(listener);
192         fListenerList.remove(listener);
193     }
194
195     // --------- simply delegate to wrapped viewer ---------
196
public Control getControl() {
197         return fViewer.getControl();
198     }
199
200     public void addFilter(ViewerFilter filter) {
201         fViewer.addFilter(filter);
202     }
203     
204     public void setFilters(ViewerFilter[] filters) {
205         fViewer.setFilters(filters);
206     }
207
208     public void refresh() {
209         fViewer.refresh();
210     }
211
212     public void removeFilter(ViewerFilter filter) {
213         fViewer.removeFilter(filter);
214     }
215
216     public ISelection getSelection() {
217         return fViewer.getSelection();
218     }
219
220     public void refresh(boolean updateLabels) {
221         fViewer.refresh(updateLabels);
222     }
223
224     public void refresh(Object JavaDoc element, boolean updateLabels) {
225         fViewer.refresh(element, updateLabels);
226     }
227
228     public void refresh(Object JavaDoc element) {
229         fViewer.refresh(element);
230     }
231
232     public void resetFilters() {
233         fViewer.resetFilters();
234     }
235
236     public void reveal(Object JavaDoc element) {
237         fViewer.reveal(element);
238     }
239
240     public void setContentProvider(IContentProvider contentProvider) {
241         fViewer.setContentProvider(contentProvider);
242     }
243
244     public void setSorter(ViewerSorter sorter) {
245         fViewer.setSorter(sorter);
246     }
247     
248     public void setComparator(ViewerComparator comparator) {
249         fViewer.setComparator(comparator);
250     }
251     
252     public void setUseHashlookup(boolean enable) {
253         fViewer.setUseHashlookup(enable);
254     }
255
256     public Widget testFindItem(Object JavaDoc element) {
257         return fViewer.testFindItem(element);
258     }
259
260     public void update(Object JavaDoc element, String JavaDoc[] properties) {
261         fViewer.update(element, properties);
262     }
263
264     public void update(Object JavaDoc[] elements, String JavaDoc[] properties) {
265         fViewer.update(elements, properties);
266     }
267
268     public IContentProvider getContentProvider() {
269         return fViewer.getContentProvider();
270     }
271
272     public Object JavaDoc getInput() {
273         return fViewer.getInput();
274     }
275
276     public IBaseLabelProvider getLabelProvider() {
277         return fViewer.getLabelProvider();
278     }
279
280     public void setLabelProvider(IBaseLabelProvider labelProvider) {
281         fViewer.setLabelProvider(labelProvider);
282     }
283
284     public Object JavaDoc getData(String JavaDoc key) {
285         return fViewer.getData(key);
286     }
287
288     public Item scrollDown(int x, int y) {
289         return fViewer.scrollDown(x, y);
290     }
291
292     public Item scrollUp(int x, int y) {
293         return fViewer.scrollUp(x, y);
294     }
295
296     public void setData(String JavaDoc key, Object JavaDoc value) {
297         fViewer.setData(key, value);
298     }
299
300     public void setSelection(ISelection selection) {
301         fViewer.setSelection(selection);
302     }
303
304     public boolean equals(Object JavaDoc obj) {
305         return fViewer.equals(obj);
306     }
307
308     public int hashCode() {
309         return fViewer.hashCode();
310     }
311
312     public String JavaDoc toString() {
313         return fViewer.toString();
314     }
315
316     public void setViewerInput(Object JavaDoc input){
317         fViewer.setInput(input);
318     }
319
320     // need to provide implementation for abstract methods
321
protected Widget doFindInputItem(Object JavaDoc element) {
322         return ((IPackagesViewViewer)fViewer).doFindInputItem(element);
323     }
324
325     protected Widget doFindItem(Object JavaDoc element) {
326         return ((IPackagesViewViewer)fViewer).doFindItem(element);
327     }
328
329     protected void doUpdateItem(Widget item, Object JavaDoc element, boolean fullMap) {
330         ((IPackagesViewViewer)fViewer).doUpdateItem(item, element, fullMap);
331     }
332
333     protected List JavaDoc getSelectionFromWidget() {
334         return ((IPackagesViewViewer)fViewer).getSelectionFromWidget();
335     }
336
337     protected void internalRefresh(Object JavaDoc element) {
338         ((IPackagesViewViewer)fViewer).internalRefresh(element);
339     }
340
341     protected void setSelectionToWidget(List JavaDoc l, boolean reveal) {
342         ((IPackagesViewViewer)fViewer).setSelectionToWidget(l, reveal);
343     }
344
345
346 }
347
Popular Tags