KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.jdt.internal.ui;
12
13
14 import org.eclipse.core.runtime.IAdapterFactory;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.ui.part.FileEditorInput;
20
21 import org.eclipse.jdt.core.IJavaElement;
22 import org.eclipse.jdt.core.JavaCore;
23
24 public class ResourceAdapterFactory implements IAdapterFactory {
25
26     private static Class JavaDoc[] PROPERTIES= new Class JavaDoc[] {
27         IJavaElement.class
28     };
29         
30     public Class JavaDoc[] getAdapterList() {
31         return PROPERTIES;
32     }
33     
34     public Object JavaDoc getAdapter(Object JavaDoc element, Class JavaDoc key) {
35         if (IJavaElement.class.equals(key)) {
36             
37             // Performance optimization, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133141
38
if (element instanceof IFile) {
39                 IJavaElement je= JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(new FileEditorInput((IFile)element));
40                 if (je != null)
41                     return je;
42             }
43             
44             return JavaCore.create((IResource)element);
45         }
46         return null;
47     }
48 }
49
Popular Tags