Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008 Chase Technology Ltd - http://www.chasetechnology.co.uk |
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 |
* Doug Satchwell (Chase Technology Ltd) - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.wst.sse.ui.internal; |
12 |
|
13 |
import org.eclipse.core.runtime.IAdapterFactory; |
14 |
import org.eclipse.jface.resource.ImageDescriptor; |
15 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
16 |
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; |
17 |
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; |
18 |
import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; |
19 |
|
20 |
public class NodeNotifierWorkbenchAdapterFactory implements IAdapterFactory |
21 |
{ |
22 |
private static final Class[] LIST = new Class[]{IWorkbenchAdapter.class}; |
23 |
private final IWorkbenchAdapter adapter = new IWorkbenchAdapter(){ |
24 |
|
25 |
protected IJFaceNodeAdapter getJFaceNodeAdapter(Object adaptable) |
26 |
{ |
27 |
if (adaptable instanceof INodeNotifier) |
28 |
{ |
29 |
INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class); |
30 |
if (adapter instanceof IJFaceNodeAdapter) |
31 |
return (IJFaceNodeAdapter) adapter; |
32 |
} |
33 |
return null; |
34 |
} |
35 |
|
36 |
public Object[] getChildren(Object o) |
37 |
{ |
38 |
IJFaceNodeAdapter adapter = getJFaceNodeAdapter(o); |
39 |
if (adapter != null) |
40 |
return adapter.getChildren(o); |
41 |
return new Object[0]; |
42 |
} |
43 |
|
44 |
public ImageDescriptor getImageDescriptor(Object object) |
45 |
{ |
46 |
return ImageDescriptor.createFromImage(getJFaceNodeAdapter(object).getLabelImage(object)); |
47 |
} |
48 |
|
49 |
public String getLabel(Object o) |
50 |
{ |
51 |
return getJFaceNodeAdapter(o).getLabelText(o); |
52 |
} |
53 |
|
54 |
public Object getParent(Object o) |
55 |
{ |
56 |
IJFaceNodeAdapter adapter = getJFaceNodeAdapter(o); |
57 |
if (adapter != null) |
58 |
return adapter.getParent(o); |
59 |
return null; |
60 |
} |
61 |
}; |
62 |
|
63 |
public Object getAdapter(Object adaptableObject, Class adapterType) |
64 |
{ |
65 |
return adapter; |
66 |
} |
67 |
|
68 |
public Class[] getAdapterList() |
69 |
{ |
70 |
return LIST; |
71 |
} |
72 |
} |