1 /*******************************************************************************
2 * Copyright (c) 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.adapter;
14 import java.util.concurrent.atomic.AtomicBoolean;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IAdapterFactory;
18 import org.simantics.g2d.canvas.ICanvasContext;
21 * @author Tuukka Lehtonen
23 public class CanvasAdapterFactory implements IAdapterFactory {
26 * Hack for preventing eternal {@link #getAdapter(Object, Class)} recursion
28 AtomicBoolean adapting = new AtomicBoolean(false);
30 @SuppressWarnings("rawtypes")
32 public Object getAdapter(Object adaptableObject, Class adapterType) {
33 if (!adapting.compareAndSet(false, true)) {
37 if (ICanvasContext.class.equals(adapterType)) {
38 if (adaptableObject instanceof IAdaptable) {
39 return ((IAdaptable) adaptableObject).getAdapter(adapterType);
48 @SuppressWarnings("rawtypes")
50 public Class[] getAdapterList() {
51 return new Class[] { ICanvasContext.class };