X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FCanvasAdapterFactory.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FCanvasAdapterFactory.java;h=7fb7dc85d4c50ebda884c4b5255b7819a58fe1e5;hp=317966b235bba71a678f05582f4360fa7ec79d5f;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CanvasAdapterFactory.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CanvasAdapterFactory.java index 317966b23..7fb7dc85d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CanvasAdapterFactory.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CanvasAdapterFactory.java @@ -1,54 +1,54 @@ -/******************************************************************************* - * Copyright (c) 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.adapter; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IAdapterFactory; -import org.simantics.g2d.canvas.ICanvasContext; - -/** - * @author Tuukka Lehtonen - */ -public class CanvasAdapterFactory implements IAdapterFactory { - - /** - * Hack for preventing eternal {@link #getAdapter(Object, Class)} recursion - */ - AtomicBoolean adapting = new AtomicBoolean(false); - - @SuppressWarnings("rawtypes") - @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (!adapting.compareAndSet(false, true)) { - return null; - } - try { - if (ICanvasContext.class.equals(adapterType)) { - if (adaptableObject instanceof IAdaptable) { - return ((IAdaptable) adaptableObject).getAdapter(adapterType); - } - } - return null; - } finally { - adapting.set(false); - } - } - - @SuppressWarnings("rawtypes") - @Override - public Class[] getAdapterList() { - return new Class[] { ICanvasContext.class }; - } - -} +/******************************************************************************* + * Copyright (c) 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.adapter; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IAdapterFactory; +import org.simantics.g2d.canvas.ICanvasContext; + +/** + * @author Tuukka Lehtonen + */ +public class CanvasAdapterFactory implements IAdapterFactory { + + /** + * Hack for preventing eternal {@link #getAdapter(Object, Class)} recursion + */ + AtomicBoolean adapting = new AtomicBoolean(false); + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (!adapting.compareAndSet(false, true)) { + return null; + } + try { + if (ICanvasContext.class.equals(adapterType)) { + if (adaptableObject instanceof IAdaptable) { + return ((IAdaptable) adaptableObject).getAdapter(adapterType); + } + } + return null; + } finally { + adapting.set(false); + } + } + + @SuppressWarnings("rawtypes") + @Override + public Class[] getAdapterList() { + return new Class[] { ICanvasContext.class }; + } + +}