KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > LogicalPackageAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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;
12
13 import org.eclipse.core.resources.mapping.ResourceMapping;
14
15 import org.eclipse.core.runtime.IAdapterFactory;
16
17
18 import org.eclipse.search.ui.ISearchPageScoreComputer;
19
20 import org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping;
21
22 import org.eclipse.jdt.internal.ui.browsing.LogicalPackage;
23 import org.eclipse.jdt.internal.ui.search.JavaSearchPageScoreComputer;
24 import org.eclipse.jdt.internal.ui.search.SearchUtil;
25
26 /**
27  * Implements basic UI support for LogicalPackage.
28  */

29 public class LogicalPackageAdapterFactory implements IAdapterFactory {
30     
31     private static Class JavaDoc[] PROPERTIES= new Class JavaDoc[] {
32         ResourceMapping.class
33     };
34
35     // Must be Object to allow lazy loading
36
private Object JavaDoc fSearchPageScoreComputer;
37     
38     public Class JavaDoc[] getAdapterList() {
39         updateLazyLoadedAdapters();
40         return PROPERTIES;
41     }
42     
43     public Object JavaDoc getAdapter(Object JavaDoc element, Class JavaDoc key) {
44         updateLazyLoadedAdapters();
45         
46         if (fSearchPageScoreComputer != null && ISearchPageScoreComputer.class.equals(key)) {
47             return fSearchPageScoreComputer;
48         } else if (ResourceMapping.class.equals(key)) {
49             if (!(element instanceof LogicalPackage))
50                 return null;
51             return JavaElementResourceMapping.create((LogicalPackage)element);
52         }
53         return null;
54     }
55     
56     private void updateLazyLoadedAdapters() {
57         if (fSearchPageScoreComputer == null && SearchUtil.isSearchPlugInActivated())
58             createSearchPageScoreComputer();
59     }
60
61     private void createSearchPageScoreComputer() {
62         fSearchPageScoreComputer= new JavaSearchPageScoreComputer();
63         PROPERTIES= new Class JavaDoc[] {
64             ISearchPageScoreComputer.class,
65             ResourceMapping.class
66         };
67     }
68 }
69
Popular Tags