org.eclipse.core.runtime.IAdapterManager Java Examples
The following examples show how to use
org.eclipse.core.runtime.IAdapterManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdapterUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Returns an instance of the adaptable object with type of adapterType, or * null if the given object could not be adapted to that type. See * {@link IAdapterManager#getAdapter(Object, Class)}. */ @SuppressWarnings("unchecked") public static <T> T getAdapter(Object adaptable, Class<? extends T> adapterType) { /* * Try a simple instanceof check. This also safeguards against a misuse of * getAdapter. For example, ISelection is adaptable (there is a * SelectionAdapterFactory), so the user may incorrectly try adapting it to * IStructuredSelection. However, in this case, the implementation of * SelectionAdapterFactory would return null. */ if (adapterType.isInstance(adaptable)) { return (T) adaptable; } IAdapterManager adapterManager = Platform.getAdapterManager(); assert (adapterManager != null); return (T) adapterManager.getAdapter(adaptable, adapterType); }
Example #2
Source File: ArrayUtils.java From saros with GNU General Public License v2.0 | 6 votes |
/** * Tries to adapt each object to the given class. * * @param objects objects that are tried to adapted * @param clazz class to adapt each object to * @param adapterManager the adapterManager that is used to adapt the objects * @return all objects that were adapted or <code>null</code> if the object array is <code>null * </code> */ public static <T> List<T> getAdaptableObjects( Object[] objects, Class<? extends T> clazz, IAdapterManager adapterManager) { if (objects == null) return null; Set<T> adaptableObjects = new HashSet<T>(objects.length); for (Object object : objects) { T adaptedObject = adapterManager.getAdapter(object, clazz); if (adaptedObject != null && !adaptableObjects.contains(adaptedObject)) { adaptableObjects.add(adaptedObject); } } return new ArrayList<T>(adaptableObjects); }
Example #3
Source File: ArrayUtilsTest.java From saros with GNU General Public License v2.0 | 6 votes |
@Before public void createMock() { adapterManager = EasyMock.createMock(IAdapterManager.class); EasyMock.expect( adapterManager.getAdapter(EasyMock.anyObject(), EasyMock.anyObject(Class.class))) .andAnswer( new IAnswer<Object>() { @Override public Object answer() throws Throwable { return EasyMock.getCurrentArguments()[0]; } }) .anyTimes(); EasyMock.replay(adapterManager); }
Example #4
Source File: Spec.java From tlaplus with MIT License | 5 votes |
/** * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public <T> T getAdapter(Class<T> adapter) { // lookup the IAdapterManager service final IAdapterManager manager = Platform.getAdapterManager(); // forward the request to IAdapterManager service return manager.getAdapter(this, adapter); }
Example #5
Source File: SVNAdapterFactories.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void startup(IProgressMonitor monitor) throws CoreException { IAdapterManager mgr = Platform.getAdapterManager(); // adapterFactory to translate IResource to ISVNResource localResourceAdapterFactory = new LocalResourceAdapterFactory(); mgr.registerAdapters(localResourceAdapterFactory,IResource.class); }
Example #6
Source File: ReportExamplesView.java From birt with Eclipse Public License 1.0 | 5 votes |
private void registerActions( ) { final IActionBars actionBars = getViewSite( ).getActionBars( ); IToolBarManager toolbarManager = actionBars.getToolBarManager( ); exportAction = new ExportSampleReportAction( instance ); toolbarManager.add( exportAction ); toolbarManager.add( new Separator( ) ); Object adapter = null; int status = Platform.getAdapterManager( ).queryAdapter( this, IAction.class.getName( ) ); if ( status == IAdapterManager.LOADED ) { adapter = Platform.getAdapterManager( ).getAdapter( this, IAction.class ); } else if ( status == IAdapterManager.NOT_LOADED ) { // Cause the plug-in loading first adapter = Platform.getAdapterManager( ).loadAdapter( this, IAction.class.getName( ) ); } if ( adapter != null ) { importAction = ( (IOpenSampleReportAction) adapter ); importAction.setMainComposite( instance ); toolbarManager.add( (Action) importAction ); } actionBars.updateActionBars( ); }
Example #7
Source File: Platform.java From birt with Eclipse Public License 1.0 | 5 votes |
public static IAdapterManager getAdapterManager( ) { if ( platform != null ) { return platform.getAdapterManager( ); } return null; }
Example #8
Source File: SVNAdapterFactories.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public void shutdown(IProgressMonitor monitor) throws CoreException { IAdapterManager mgr = Platform.getAdapterManager(); mgr.unregisterAdapters(localResourceAdapterFactory); localResourceAdapterFactory = null; }
Example #9
Source File: ChartReportItemUtil.java From birt with Eclipse Public License 1.0 | 4 votes |
public static <T> T getAdapter( Object adaptable, Class<T> adapterClass ) { IAdapterManager adapterManager = org.eclipse.birt.core.framework.Platform.getAdapterManager( ); return adapterClass.cast( adapterManager.loadAdapter( adaptable, adapterClass.getName( ) ) ); }
Example #10
Source File: ServicePlatform.java From birt with Eclipse Public License 1.0 | 4 votes |
public IAdapterManager getAdapterManager( ) { return AdapterManager.getDefault( ); }
Example #11
Source File: EclipsePlatform.java From birt with Eclipse Public License 1.0 | 4 votes |
public IAdapterManager getAdapterManager( ) { return Platform.getAdapterManager( ); }
Example #12
Source File: ChartUtil.java From birt with Eclipse Public License 1.0 | 3 votes |
/** * Gets adapter from extension point. * * @param <T> * @param adaptable * @param type * @return adapter class * @since 2.5.1 */ public static <T> T getAdapter( Object adaptable, Class<T> type ) { // use BIRT platform as the Eclipse platform may throws exception if the // OSGi is not started IAdapterManager adapterManager = org.eclipse.birt.core.framework.Platform.getAdapterManager( ); return type.cast( adapterManager.loadAdapter( adaptable, type.getName( ) ) ); }
Example #13
Source File: IPlatform.java From birt with Eclipse Public License 1.0 | votes |
IAdapterManager getAdapterManager( );