KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > packageview > HierarchicalDecorationContext


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.packageview;
13
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.resources.mapping.ResourceMappingContext;
21 import org.eclipse.core.resources.mapping.ResourceTraversal;
22
23 import org.eclipse.jface.viewers.IDecorationContext;
24
25 import org.eclipse.team.ui.mapping.SynchronizationStateTester;
26
27 import org.eclipse.jdt.core.IJavaElement;
28 import org.eclipse.jdt.core.IPackageFragment;
29
30 import org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping;
31
32 public class HierarchicalDecorationContext implements IDecorationContext {
33     
34     private HierarchicalSynchronizationStateTester fStateTester;
35     public static final HierarchicalDecorationContext CONTEXT= new HierarchicalDecorationContext();
36     
37     private HierarchicalDecorationContext() {
38         fStateTester= new HierarchicalSynchronizationStateTester();
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.jface.viewers.IDecorationContext#getProperties()
43      */

44     public String JavaDoc[] getProperties() {
45         return new String JavaDoc[] { SynchronizationStateTester.PROP_TESTER };
46     }
47
48     /* (non-Javadoc)
49      * @see org.eclipse.jface.viewers.IDecorationContext#getProperty(java.lang.String)
50      */

51     public Object JavaDoc getProperty(String JavaDoc property) {
52         if (property == SynchronizationStateTester.PROP_TESTER) {
53             return fStateTester;
54         }
55         return null;
56     }
57         
58     private static final class HierarchicalSynchronizationStateTester extends SynchronizationStateTester {
59
60         public HierarchicalSynchronizationStateTester() {
61         }
62
63         /* (non-Javadoc)
64          * @see org.eclipse.team.ui.mapping.SynchronizationStateTester#getState(java.lang.Object, int, org.eclipse.core.runtime.IProgressMonitor)
65          */

66         public int getState(Object JavaDoc element, int stateMask, IProgressMonitor monitor) throws CoreException {
67             if (element instanceof JavaElementResourceMapping) {
68                 JavaElementResourceMapping mapping= (JavaElementResourceMapping) element;
69                 IJavaElement javaElement= mapping.getJavaElement();
70                 if (javaElement instanceof IPackageFragment) {
71                     IPackageFragment packageFragment= (IPackageFragment) javaElement;
72                     if (!packageFragment.isDefaultPackage()) {
73                         element= new HierarchicalPackageFragementResourceMapping(packageFragment);
74                     }
75                 }
76             }
77             return super.getState(element, stateMask, monitor);
78         }
79     }
80     
81     private static final class HierarchicalPackageFragementResourceMapping extends JavaElementResourceMapping {
82         private final IPackageFragment fPack;
83         private HierarchicalPackageFragementResourceMapping(IPackageFragment fragment) {
84             Assert.isNotNull(fragment);
85             fPack= fragment;
86         }
87         public Object JavaDoc getModelObject() {
88             return fPack;
89         }
90         public IProject[] getProjects() {
91             return new IProject[] {fPack.getJavaProject().getProject() };
92         }
93         public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
94             return new ResourceTraversal[] {
95                 new ResourceTraversal(new IResource[] {fPack.getResource()}, IResource.DEPTH_INFINITE, 0)
96             };
97         }
98     }
99 }
100
Popular Tags