blob: 66cbca6d5c2b78286469b733e8bbefd68133063c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 Oracle. 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:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.selection;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IWorkbench;
/**
* Factory to build JPA selection adapters for a {@link IWorkbench}:<ul>
* <li>{@link JpaSelectionManager}
* </ul>
* See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
*
* @see JpaWorkbenchManager
*/
public class WorkbenchAdapterFactory
implements IAdapterFactory
{
private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaSelectionManager.class };
public Class<?>[] getAdapterList() {
return ADAPTER_LIST;
}
public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
if (adaptableObject instanceof IWorkbench) {
return this.getAdapter((IWorkbench) adaptableObject, adapterType);
}
return null;
}
private Object getAdapter(IWorkbench workbench, Class<?> adapterType) {
if (adapterType == JpaSelectionManager.class) {
return this.getJpaSelectionManager(workbench);
}
return null;
}
/**
* Never return <code>null</code>.
*/
private JpaSelectionManager getJpaSelectionManager(IWorkbench workbench) {
return JpaWorkbenchManager.forWorkbench(workbench);
}
}