1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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.utils.ui.workbench;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.ui.IElementFactory;
16 import org.eclipse.ui.IMemento;
17 import org.eclipse.ui.PlatformUI;
20 * @author Tuukka Lehtonen
22 public final class IAdaptableUtils {
24 public static IAdaptable getAdaptable(String factoryId, IMemento memento) {
25 IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryId);
28 return factory.createElement(memento);
31 @SuppressWarnings("unchecked")
32 public static <T> T adapt(String factoryId, IMemento memento, Class<T> clazz) {
33 IAdaptable adaptable = getAdaptable(factoryId, memento);
34 if (adaptable == null)
36 return (T) adaptable.getAdapter(clazz);