KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Item;
18 import org.eclipse.swt.widgets.Widget;
19
20 import org.eclipse.jdt.core.IPackageFragment;
21
22 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
23 import org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer;
24
25 /**
26  * Special problem table viewer to handle logical packages.
27  */

28 class PackagesViewTableViewer extends ProblemTableViewer implements IPackagesViewViewer {
29
30     public PackagesViewTableViewer(Composite parent, int style) {
31         super(parent, style);
32         ColoredViewersManager.install(this);
33     }
34
35     public void mapElement(Object JavaDoc element, Widget item) {
36         if (element instanceof LogicalPackage && item instanceof Item) {
37             LogicalPackage cp= (LogicalPackage) element;
38             IPackageFragment[] fragments= cp.getFragments();
39             for (int i= 0; i < fragments.length; i++) {
40                 IPackageFragment fragment= fragments[i];
41                 fResourceToItemsMapper.addToMap(fragment, (Item)item);
42             }
43         }
44         super.mapElement(element, item);
45     }
46
47     public void unmapElement(Object JavaDoc element, Widget item) {
48         if (element instanceof LogicalPackage && item instanceof Item) {
49             LogicalPackage cp= (LogicalPackage) element;
50             IPackageFragment[] fragments= cp.getFragments();
51             for (int i= 0; i < fragments.length; i++) {
52                 IPackageFragment fragment= fragments[i];
53                 fResourceToItemsMapper.removeFromMap(fragment, (Item)item);
54             }
55         }
56         super.unmapElement(element, item);
57     }
58
59     /*
60      * @see org.eclipse.jface.viewers.StructuredViewer#getFilteredChildren(java.
61      * lang.Object)
62      */

63     protected Object JavaDoc[] getFilteredChildren(Object JavaDoc parent) {
64
65         Object JavaDoc[] result= getRawChildren(parent);
66         List JavaDoc list= new ArrayList JavaDoc();
67         if (result != null) {
68             Object JavaDoc[] toBeFiltered= new Object JavaDoc[1];
69             for (int i= 0; i < result.length; i++) {
70                 Object JavaDoc object= result[i];
71                 if(object instanceof LogicalPackage) {
72                     if(selectLogicalPackage((LogicalPackage)object))
73                         list.add(object);
74                 } else {
75                     toBeFiltered[0]= object;
76                     if (filter(toBeFiltered).length == 1)
77                         list.add(object);
78                 }
79             }
80         }
81         return list.toArray();
82     }
83
84     private boolean selectLogicalPackage(LogicalPackage logicalPackage) {
85         return filter(logicalPackage.getFragments()).length > 0;
86     }
87
88     // --------- see: IPackagesViewViewer ----------
89

90     public Widget doFindItem(Object JavaDoc element){
91         return super.doFindItem(element);
92     }
93
94     public Widget doFindInputItem(Object JavaDoc element){
95         return super.doFindInputItem(element);
96     }
97
98     public List JavaDoc getSelectionFromWidget(){
99         return super.getSelectionFromWidget();
100     }
101
102     public void doUpdateItem(Widget item, Object JavaDoc element, boolean fullMap){
103         super.doUpdateItem(item, element, fullMap);
104     }
105
106     public void internalRefresh(Object JavaDoc element){
107         super.internalRefresh(element);
108     }
109
110     public void setSelectionToWidget(List JavaDoc l, boolean reveal){
111         super.setSelectionToWidget(l, reveal);
112     }
113 }
114
Popular Tags