KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > tasklist > DefaultTaskListResourceAdapter


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.ui.views.tasklist;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.IAdaptable;
17
18 /**
19  * The DefaultTaskListResourceAdapter is the default
20  * implementation of the ITaskListResourceAdapter used by the
21  * TaskList for resource adaption.
22  */

23 class DefaultTaskListResourceAdapter implements ITaskListResourceAdapter {
24
25     private static ITaskListResourceAdapter singleton;
26
27     /**
28      * Constructor for DefaultTaskListResourceAdapter.
29      */

30     DefaultTaskListResourceAdapter() {
31         super();
32     }
33
34     /**
35      * Return the default instance used for TaskList adapting.
36      */

37     static ITaskListResourceAdapter getDefault() {
38         if (singleton == null) {
39             singleton = new DefaultTaskListResourceAdapter();
40         }
41         return singleton;
42     }
43
44     /*
45      * @see ITaskListResourceAdapter#getAffectedResource(IAdaptable)
46      */

47     public IResource getAffectedResource(IAdaptable adaptable) {
48
49         IResource resource = (IResource) adaptable.getAdapter(IResource.class);
50         if (resource == null) {
51             return (IFile) adaptable.getAdapter(IFile.class);
52         } else {
53             return resource;
54         }
55
56     }
57
58 }
59
Popular Tags