01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal.provisional.views.markers;
11:
12: import java.util.Collection;
13: import java.util.HashSet;
14:
15: import org.eclipse.core.resources.IMarker;
16: import org.eclipse.core.runtime.IAdapterFactory;
17: import org.eclipse.jface.viewers.StructuredSelection;
18: import org.eclipse.ui.part.IShowInSource;
19: import org.eclipse.ui.part.ShowInContext;
20:
21: /**
22: * MarkerShowInAdapter is the adapter for ExtendedMarkersViews to get an
23: * IShowInSource.
24: *
25: * @since 3.4
26: *
27: */
28: public class MarkerShowInAdapter implements IAdapterFactory {
29:
30: private static Class[] classes = new Class[] { IShowInSource.class };
31:
32: /*
33: * (non-Javadoc)
34: *
35: * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
36: * java.lang.Class)
37: */
38: public Object getAdapter(Object adaptableObject, Class adapterType) {
39: if (!(adaptableObject instanceof ExtendedMarkersView))
40: return null;
41:
42: final ExtendedMarkersView view = (ExtendedMarkersView) adaptableObject;
43:
44: return new IShowInSource() {
45: public ShowInContext getShowInContext() {
46: IMarker[] markers = view.getSelectedMarkers();
47: Collection resources = new HashSet();
48: for (int i = 0; i < markers.length; i++) {
49: resources.add(markers[i].getResource());
50: }
51: return new ShowInContext(view.getViewerInput(),
52: new StructuredSelection(resources.toArray()));
53: }
54:
55: };
56:
57: }
58:
59: /*
60: * (non-Javadoc)
61: *
62: * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
63: */
64: public Class[] getAdapterList() {
65: return classes;
66: }
67:
68: }
|