/* * Copyright (c) 2006, 2007 Borland Software Corporation * * 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: * Dmitry Stadnik (Borland) - initial API and implementation */ package org.eclipse.gmf.examples.design2d.providers; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.examples.design2d.part.DesignVisualIDRegistry; import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; import org.eclipse.gmf.runtime.common.core.service.IOperation; import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation; import org.eclipse.gmf.runtime.common.ui.services.parser.IParser; import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter; import org.eclipse.gmf.runtime.notation.View; /** * @generated */ public class DesignParserProvider extends AbstractProvider implements IParserProvider { /** * @generated */ protected IParser getParser(int visualID) { switch (visualID) { } return null; } /** * @generated */ public IParser getParser(IAdaptable hint) { String vid = (String) hint.getAdapter(String.class); if (vid != null) { return getParser(DesignVisualIDRegistry.getVisualID(vid)); } View view = (View) hint.getAdapter(View.class); if (view != null) { return getParser(DesignVisualIDRegistry.getVisualID(view)); } return null; } /** * @generated */ public boolean provides(IOperation operation) { if (operation instanceof GetParserOperation) { IAdaptable hint = ((GetParserOperation) operation).getHint(); if (DesignElementTypes.getElement(hint) == null) { return false; } return getParser(hint) != null; } return false; } /** * @generated */ public static class HintAdapter extends ParserHintAdapter { /** * @generated */ private final IElementType elementType; /** * @generated */ public HintAdapter(IElementType type, EObject object, String parserHint) { super(object, parserHint); assert type != null; elementType = type; } /** * @generated */ public Object getAdapter(Class adapter) { if (IElementType.class.equals(adapter)) { return elementType; } return super.getAdapter(adapter); } } }