| package org.eclipse.stem.ui.grapheditor.adapters; |
| |
| /******************************************************************************* |
| * Copyright (c) 2008 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 |
| *******************************************************************************/ |
| |
| import org.eclipse.core.runtime.Platform; |
| import org.eclipse.emf.edit.provider.DelegatingWrapperItemProvider; |
| import org.eclipse.stem.core.common.Identifiable; |
| import org.eclipse.stem.core.graph.Displayable; |
| import org.eclipse.stem.core.model.DisplayableCanonical; |
| import org.eclipse.stem.jobs.adapters.identifiable.IdentifiableAdapterFactory; |
| |
| /** |
| * This class is an {@link IdentifiableAdapterFactory} that adapts |
| * {@link DelegatingWrapperItemProvider}s to {@link Displayable}s. |
| */ |
| public class DelegatingWrapperItemProviderDisplayableCanonicalAdapterFactory extends |
| IdentifiableAdapterFactory { |
| |
| /** |
| * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, |
| * java.lang.Class) |
| */ |
| public Object getAdapter(Object adaptableObject, Class adapterType) { |
| DisplayableCanonical retValue = null; |
| |
| // It it what we're looking for? |
| if (adaptableObject instanceof DelegatingWrapperItemProvider |
| && adapterType.equals(DisplayableCanonical.class)) { |
| // Yes |
| final DelegatingWrapperItemProvider dwip = (DelegatingWrapperItemProvider) adaptableObject; |
| // Is this an Identifiable? |
| if (dwip.getValue() instanceof Identifiable) { |
| // Yes |
| // ...and is it Modifiable? |
| if (dwip.getValue() instanceof DisplayableCanonical) { |
| // Yes |
| retValue = (DisplayableCanonical) dwip.getValue(); |
| } |
| // else NO |
| } // if Identifiable |
| else { |
| // No |
| // Keep adapting... |
| retValue = (DisplayableCanonical) Platform.getAdapterManager() |
| .getAdapter(dwip.getValue(), DisplayableCanonical.class); |
| } |
| } // if |
| return retValue; |
| } // getAdapter |
| } // DelegatingWrapperItemProviderModifiableAdapterFactory |