KickJava   Java API By Example, From Geeks To Geeks.

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


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.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Item;
17 import org.eclipse.swt.widgets.Widget;
18
19 import org.eclipse.jface.viewers.ViewerFilter;
20
21 import org.eclipse.jdt.core.IPackageFragment;
22 import org.eclipse.jdt.core.JavaModelException;
23
24 import org.eclipse.jdt.internal.ui.JavaPlugin;
25 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
26 import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer;
27
28 /**
29  * Special problem tree viewer to handle logical packages.
30  */

31 public class PackagesViewTreeViewer extends ProblemTreeViewer implements IPackagesViewViewer{
32
33     public PackagesViewTreeViewer(Composite parent, int style) {
34         super(parent, style);
35         ColoredViewersManager.install(this);
36     }
37
38     /*
39      * @see org.eclipse.jface.viewers.StructuredViewer#mapElement(java.lang.Object, org.eclipse.swt.widgets.Widget)
40      */

41     public void mapElement(Object JavaDoc element, Widget item) {
42         if (element instanceof LogicalPackage && item instanceof Item) {
43             LogicalPackage cp= (LogicalPackage) element;
44             IPackageFragment[] fragments= cp.getFragments();
45             for (int i= 0; i < fragments.length; i++) {
46                 IPackageFragment fragment= fragments[i];
47                 fResourceToItemsMapper.addToMap(fragment, (Item) item);
48             }
49         }
50         super.mapElement(element, item);
51     }
52
53     /*
54      * @see org.eclipse.jface.viewers.StructuredViewer#unmapElement(java.lang.Object, org.eclipse.swt.widgets.Widget)
55      */

56     public void unmapElement(Object JavaDoc element, Widget item) {
57
58         if (element instanceof LogicalPackage && item instanceof Item) {
59             LogicalPackage cp= (LogicalPackage) element;
60             IPackageFragment[] fragments= cp.getFragments();
61             for (int i= 0; i < fragments.length; i++) {
62                 IPackageFragment fragment= fragments[i];
63                 fResourceToItemsMapper.removeFromMap((Object JavaDoc)fragment, (Item)item);
64             }
65         }
66         super.unmapElement(element, item);
67     }
68     
69     /* (non-Javadoc)
70      * @see org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer#isFiltered(java.lang.Object, java.lang.Object, org.eclipse.jface.viewers.ViewerFilter[])
71      */

72     protected boolean isFiltered(Object JavaDoc object, Object JavaDoc parent, ViewerFilter[] filters) {
73         boolean res= super.isFiltered(object, parent, filters);
74         if (res && isEssential(object)) {
75             return false;
76         }
77         return res;
78     }
79
80     private boolean isEssential(Object JavaDoc object) {
81         try {
82             if (object instanceof IPackageFragment) {
83                 IPackageFragment fragment = (IPackageFragment) object;
84                 if (!fragment.isDefaultPackage() && fragment.hasSubpackages()) {
85                     return hasFilteredChildren(fragment);
86                 }
87             } else if (object instanceof LogicalPackage) {
88                 LogicalPackage logicalPackage= (LogicalPackage) object;
89                 if (!logicalPackage.isDefaultPackage() && logicalPackage.hasSubpackages()) {
90                     return !hasFilteredChildren(object);
91                 }
92             }
93         } catch (JavaModelException e) {
94             JavaPlugin.log(e);
95         }
96         return false;
97     }
98
99     // --------- see: IPackagesViewViewer ----------
100

101     public Widget doFindItem(Object JavaDoc element) {
102         return super.doFindItem(element);
103     }
104
105     public Widget doFindInputItem(Object JavaDoc element) {
106         return super.doFindInputItem(element);
107     }
108
109     public List JavaDoc getSelectionFromWidget() {
110         return super.getSelectionFromWidget();
111     }
112
113     public void doUpdateItem(Widget item, Object JavaDoc element, boolean fullMap){
114         super.doUpdateItem(item, element, fullMap);
115     }
116
117     public void internalRefresh(Object JavaDoc element){
118         super.internalRefresh(element);
119     }
120
121     public void setSelectionToWidget(List JavaDoc l, boolean reveal){
122         super.setSelectionToWidget(l, reveal);
123     }
124 }
125
Popular Tags