| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.eclipse.common.util; |
| 17 | |
|
| 18 | |
import org.eclipse.core.resources.IProject; |
| 19 | |
import org.eclipse.core.resources.IResource; |
| 20 | |
import org.eclipse.core.runtime.IAdaptable; |
| 21 | |
import org.eclipse.ui.texteditor.ITextEditor; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | 0 | public class AdaptableUtil { |
| 28 | |
|
| 29 | |
public static ITextEditor toTextEditor(Object adaptable) { |
| 30 | 0 | ITextEditor result = null; |
| 31 | 0 | if (adaptable instanceof ITextEditor) { |
| 32 | 0 | result = (ITextEditor) adaptable; |
| 33 | 0 | } else if (adaptable instanceof IAdaptable) { |
| 34 | 0 | IAdaptable a = (IAdaptable) adaptable; |
| 35 | 0 | result = (ITextEditor) a.getAdapter(ITextEditor.class); |
| 36 | |
} |
| 37 | 0 | return result; |
| 38 | |
} |
| 39 | |
|
| 40 | |
public static IResource toResource(Object adaptable) { |
| 41 | 0 | IResource result = null; |
| 42 | 0 | if (adaptable instanceof IResource) { |
| 43 | 0 | result = (IResource) adaptable; |
| 44 | 0 | } else if (adaptable instanceof IAdaptable) { |
| 45 | 0 | IAdaptable a = (IAdaptable) adaptable; |
| 46 | 0 | result = (IResource) a.getAdapter(IResource.class); |
| 47 | |
} |
| 48 | 0 | return result; |
| 49 | |
} |
| 50 | |
|
| 51 | |
public static IProject toProject(Object adaptable) { |
| 52 | 0 | IProject result = null; |
| 53 | 0 | if (adaptable instanceof IProject) { |
| 54 | 0 | result = (IProject) adaptable; |
| 55 | 0 | } else if (adaptable instanceof IAdaptable) { |
| 56 | 0 | IAdaptable a = (IAdaptable) adaptable; |
| 57 | 0 | result = (IProject) a.getAdapter(IProject.class); |
| 58 | |
} |
| 59 | 0 | if (result == null) { |
| 60 | 0 | IResource r = toResource(adaptable); |
| 61 | 0 | if (r != null) { |
| 62 | 0 | result = r.getProject(); |
| 63 | |
} |
| 64 | |
} |
| 65 | 0 | return result; |
| 66 | |
} |
| 67 | |
} |