### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench Index: Eclipse UI/org/eclipse/ui/internal/SelectionAdapterFactory.java =================================================================== RCS file: Eclipse UI/org/eclipse/ui/internal/SelectionAdapterFactory.java diff -N Eclipse UI/org/eclipse/ui/internal/SelectionAdapterFactory.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI/org/eclipse/ui/internal/SelectionAdapterFactory.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal; + +import java.util.Collection; + +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.jface.viewers.IStructuredSelection; + +/** + * Adapts IStructuredSelection instances to Collection instances. + * + * @since 3.3 + */ +public class SelectionAdapterFactory implements IAdapterFactory { + + /** + * The classes we can adapt to. + */ + private static final Class[] CLASSES = new Class[] {Collection.class}; + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) adaptableObject; + if (Collection.class.equals(adapterType)) { + return selection.toList(); + } + } + return null; + } + + public Class[] getAdapterList() { + return CLASSES; + } +} #P org.eclipse.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui/plugin.xml,v retrieving revision 1.380 diff -u -r1.380 plugin.xml --- plugin.xml 13 Mar 2007 16:52:44 -0000 1.380 +++ plugin.xml 14 Mar 2007 19:51:38 -0000 @@ -1557,4 +1557,14 @@ + + + + + + #P org.eclipse.ui.tests Index: Eclipse UI Tests/org/eclipse/ui/tests/adaptable/AdaptableTestSuite.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/adaptable/AdaptableTestSuite.java,v retrieving revision 1.9 diff -u -r1.9 AdaptableTestSuite.java --- Eclipse UI Tests/org/eclipse/ui/tests/adaptable/AdaptableTestSuite.java 15 Jun 2005 18:41:27 -0000 1.9 +++ Eclipse UI Tests/org/eclipse/ui/tests/adaptable/AdaptableTestSuite.java 14 Mar 2007 19:51:39 -0000 @@ -34,6 +34,7 @@ addTest(new TestSuite(AdaptableDecoratorTestCase.class)); addTest(new TestSuite(MarkerImageProviderTest.class)); addTest(new TestSuite(WorkingSetTestCase.class)); + addTest(new TestSuite(SelectionAdapterTest.class)); } } Index: Eclipse UI Tests/org/eclipse/ui/tests/adaptable/SelectionAdapterTest.java =================================================================== RCS file: Eclipse UI Tests/org/eclipse/ui/tests/adaptable/SelectionAdapterTest.java diff -N Eclipse UI Tests/org/eclipse/ui/tests/adaptable/SelectionAdapterTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI Tests/org/eclipse/ui/tests/adaptable/SelectionAdapterTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.tests.adaptable; + +import java.util.Collection; + +import junit.framework.TestCase; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.StructuredSelection; + +/** + * @since 3.3 + * + */ +public class SelectionAdapterTest extends TestCase { + + public void testSelectionAdapter() { + String contents = "foo"; + StructuredSelection selection = new StructuredSelection(contents); + Collection adapted = (Collection) Platform.getAdapterManager().getAdapter(selection, Collection.class); + assertNotNull(adapted); + assertEquals(1, adapted.size()); + assertTrue(adapted.contains(contents)); + } +}