blob: 8e3f1067b61f4f577b36f266df6f5948540c4180 [file] [log] [blame]
/*
* Copyright (c) 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.taipan.port.diagram.providers;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.examples.taipan.TaiPanPackage;
import org.eclipse.gmf.examples.taipan.port.diagram.edit.parts.BuildingInfoEditPart;
import org.eclipse.gmf.examples.taipan.port.diagram.parsers.NativeParser;
import org.eclipse.gmf.examples.taipan.port.diagram.part.TaiPanVisualIDRegistry;
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.common.ui.services.parser.ParserService;
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 TaiPanParserProvider extends AbstractProvider implements IParserProvider {
/**
* @generated
*/
private IParser buildingInfo_3001Parser;
/**
* @generated
*/
private IParser getBuildingInfo_3001Parser() {
if (buildingInfo_3001Parser == null) {
EAttribute[] features = new EAttribute[] { TaiPanPackage.eINSTANCE.getBuilding_Info() };
NativeParser parser = new NativeParser(features);
buildingInfo_3001Parser = parser;
}
return buildingInfo_3001Parser;
}
/**
* @generated
*/
protected IParser getParser(int visualID) {
switch (visualID) {
case BuildingInfoEditPart.VISUAL_ID:
return getBuildingInfo_3001Parser();
}
return null;
}
/**
* Utility method that consults ParserService
* @generated
*/
public static IParser getParser(IElementType type, EObject object, String parserHint) {
return ParserService.getInstance().getParser(new HintAdapter(type, object, parserHint));
}
/**
* @generated
*/
public IParser getParser(IAdaptable hint) {
String vid = (String) hint.getAdapter(String.class);
if (vid != null) {
return getParser(TaiPanVisualIDRegistry.getVisualID(vid));
}
View view = (View) hint.getAdapter(View.class);
if (view != null) {
return getParser(TaiPanVisualIDRegistry.getVisualID(view));
}
return null;
}
/**
* @generated
*/
public boolean provides(IOperation operation) {
if (operation instanceof GetParserOperation) {
IAdaptable hint = ((GetParserOperation) operation).getHint();
if (TaiPanElementTypes.getElement(hint) == null) {
return false;
}
return getParser(hint) != null;
}
return false;
}
/**
* @generated
*/
private 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);
}
}
}