/* * 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.EObject; import org.eclipse.gmf.examples.taipan.port.diagram.edit.parts.BuildingEditPart; import org.eclipse.gmf.examples.taipan.port.diagram.edit.parts.BuildingInfoEditPart; import org.eclipse.gmf.examples.taipan.port.diagram.edit.parts.PortEditPart; import org.eclipse.gmf.examples.taipan.port.diagram.part.TaiPanVisualIDRegistry; import org.eclipse.gmf.examples.taipan.port.diagram.view.factories.BuildingInfoViewFactory; import org.eclipse.gmf.examples.taipan.port.diagram.view.factories.BuildingViewFactory; import org.eclipse.gmf.examples.taipan.port.diagram.view.factories.PortViewFactory; import org.eclipse.gmf.runtime.diagram.core.providers.AbstractViewProvider; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.emf.type.core.IHintedType; import org.eclipse.gmf.runtime.notation.View; /** * @generated */ public class TaiPanViewProvider extends AbstractViewProvider { /** * @generated */ protected Class getDiagramViewClass(IAdaptable semanticAdapter, String diagramKind) { EObject semanticElement = getSemanticElement(semanticAdapter); if (PortEditPart.MODEL_ID.equals(diagramKind) && TaiPanVisualIDRegistry.getDiagramVisualID(semanticElement) != -1) { return PortViewFactory.class; } return null; } /** * @generated */ protected Class getNodeViewClass(IAdaptable semanticAdapter, View containerView, String semanticHint) { if (containerView == null) { return null; } IElementType elementType = getSemanticElementType(semanticAdapter); EObject domainElement = getSemanticElement(semanticAdapter); int visualID; if (semanticHint == null) { // Semantic hint is not specified. Can be a result of call from CanonicalEditPolicy. // In this situation there should be NO elementType, visualID will be determined // by VisualIDRegistry.getNodeVisualID() for domainElement. if (elementType != null || domainElement == null) { return null; } visualID = TaiPanVisualIDRegistry.getNodeVisualID(containerView, domainElement); } else { visualID = TaiPanVisualIDRegistry.getVisualID(semanticHint); if (elementType != null) { // Semantic hint is specified together with element type. // Both parameters should describe exactly the same diagram element. // In addition we check that visualID returned by VisualIDRegistry.getNodeVisualID() for // domainElement (if specified) is the same as in element type. if (!TaiPanElementTypes.isKnownElementType(elementType) || (!(elementType instanceof IHintedType))) { return null; // foreign element type } String elementTypeHint = ((IHintedType) elementType).getSemanticHint(); if (!semanticHint.equals(elementTypeHint)) { return null; // if semantic hint is specified it should be the same as in element type } if (domainElement != null && visualID != TaiPanVisualIDRegistry.getNodeVisualID(containerView, domainElement)) { return null; // visual id for node EClass should match visual id from element type } } else { // Element type is not specified. Domain element should be present (except pure design elements). // This method is called with EObjectAdapter as parameter from: // - ViewService.createNode(View container, EObject eObject, String type, PreferencesHint preferencesHint) // - generated ViewFactory.decorateView() for parent element if (!PortEditPart.MODEL_ID.equals(TaiPanVisualIDRegistry.getModelID(containerView))) { return null; // foreign diagram } switch (visualID) { case BuildingEditPart.VISUAL_ID: if (domainElement == null || visualID != TaiPanVisualIDRegistry.getNodeVisualID(containerView, domainElement)) { return null; // visual id in semantic hint should match visual id for domain element } break; case BuildingInfoEditPart.VISUAL_ID: if (BuildingEditPart.VISUAL_ID != TaiPanVisualIDRegistry.getVisualID(containerView) || containerView.getElement() != domainElement) { return null; // wrong container } break; default: return null; } } } return getNodeViewClass(containerView, visualID); } /** * @generated */ protected Class getNodeViewClass(View containerView, int visualID) { if (containerView == null || !TaiPanVisualIDRegistry.canCreateNode(containerView, visualID)) { return null; } switch (visualID) { case BuildingEditPart.VISUAL_ID: return BuildingViewFactory.class; case BuildingInfoEditPart.VISUAL_ID: return BuildingInfoViewFactory.class; } return null; } /** * @generated */ protected Class getEdgeViewClass(IAdaptable semanticAdapter, View containerView, String semanticHint) { IElementType elementType = getSemanticElementType(semanticAdapter); if (!TaiPanElementTypes.isKnownElementType(elementType) || (!(elementType instanceof IHintedType))) { return null; // foreign element type } String elementTypeHint = ((IHintedType) elementType).getSemanticHint(); if (elementTypeHint == null) { return null; // our hint is visual id and must be specified } if (semanticHint != null && !semanticHint.equals(elementTypeHint)) { return null; // if semantic hint is specified it should be the same as in element type } int visualID = TaiPanVisualIDRegistry.getVisualID(elementTypeHint); EObject domainElement = getSemanticElement(semanticAdapter); if (domainElement != null && visualID != TaiPanVisualIDRegistry.getLinkWithClassVisualID(domainElement)) { return null; // visual id for link EClass should match visual id from element type } return getEdgeViewClass(visualID); } /** * @generated */ protected Class getEdgeViewClass(int visualID) { switch (visualID) { } return null; } /** * @generated */ private IElementType getSemanticElementType(IAdaptable semanticAdapter) { if (semanticAdapter == null) { return null; } return (IElementType) semanticAdapter.getAdapter(IElementType.class); } }