package org.eclipse.gmf.tooling.examples.affixednode.diagram.part;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tooling.examples.affixednode.AffixedNodePackage;
import org.eclipse.gmf.tooling.examples.affixednode.Canvas;
import org.eclipse.gmf.tooling.examples.affixednode.diagram.edit.parts.BundleEditPart;
import org.eclipse.gmf.tooling.examples.affixednode.diagram.edit.parts.BundleNameEditPart;
import org.eclipse.gmf.tooling.examples.affixednode.diagram.edit.parts.CanvasEditPart;
import org.eclipse.gmf.tooling.examples.affixednode.diagram.edit.parts.CommunicationEditPart;
import org.eclipse.gmf.tooling.examples.affixednode.diagram.edit.parts.IncomingCommunicatorEditPart;
import org.eclipse.gmf.tooling.examples.affixednode.diagram.edit.parts.OutcomingCommunicatorEditPart;
import org.eclipse.gmf.tooling.runtime.structure.DiagramStructure;
/**
* This registry is used to determine which type of visual object should be
* created for the corresponding Diagram, Node, ChildNode or Link represented
* by a domain model object.
*
* @generated
*/
public class AffixednodeVisualIDRegistry {
/**
* @generated
*/
private static final String DEBUG_KEY = "org.eclipse.gmf.tooling.examples.affixednode.diagram/debug/visualID"; //$NON-NLS-1$
/**
* @generated
*/
public static int getVisualID(View view) {
if (view instanceof Diagram) {
if (CanvasEditPart.MODEL_ID.equals(view.getType())) {
return CanvasEditPart.VISUAL_ID;
} else {
return -1;
}
}
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getVisualID(view.getType());
}
/**
* @generated
*/
public static String getModelID(View view) {
View diagram = view.getDiagram();
while (view != diagram) {
EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
if (annotation != null) {
return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
}
view = (View) view.eContainer();
}
return diagram != null ? diagram.getType() : null;
}
/**
* @generated
*/
public static int getVisualID(String type) {
try {
return Integer.parseInt(type);
} catch (NumberFormatException e) {
if (Boolean.TRUE.toString().equalsIgnoreCase(Platform.getDebugOption(DEBUG_KEY))) {
AffixednodeDiagramEditorPlugin.getInstance().logError("Unable to parse view type as a visualID number: " + type);
}
}
return -1;
}
/**
* @generated
*/
public static String getType(int visualID) {
return Integer.toString(visualID);
}
/**
* @generated
*/
public static int getDiagramVisualID(EObject domainElement) {
if (domainElement == null) {
return -1;
}
if (AffixedNodePackage.eINSTANCE.getCanvas().isSuperTypeOf(domainElement.eClass()) && isDiagram((Canvas) domainElement)) {
return CanvasEditPart.VISUAL_ID;
}
return -1;
}
/**
* @generated
*/
public static int getNodeVisualID(View containerView, EObject domainElement) {
if (domainElement == null) {
return -1;
}
String containerModelID = org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getModelID(containerView);
if (!CanvasEditPart.MODEL_ID.equals(containerModelID)) {
return -1;
}
int containerVisualID;
if (CanvasEditPart.MODEL_ID.equals(containerModelID)) {
containerVisualID = org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getVisualID(containerView);
} else {
if (containerView instanceof Diagram) {
containerVisualID = CanvasEditPart.VISUAL_ID;
} else {
return -1;
}
}
switch (containerVisualID) {
case CanvasEditPart.VISUAL_ID:
if (AffixedNodePackage.eINSTANCE.getBundle().isSuperTypeOf(domainElement.eClass())) {
return BundleEditPart.VISUAL_ID;
}
break;
case BundleEditPart.VISUAL_ID:
if (AffixedNodePackage.eINSTANCE.getIncomingCommunicator().isSuperTypeOf(domainElement.eClass())) {
return IncomingCommunicatorEditPart.VISUAL_ID;
}
if (AffixedNodePackage.eINSTANCE.getOutcomingCommunicator().isSuperTypeOf(domainElement.eClass())) {
return OutcomingCommunicatorEditPart.VISUAL_ID;
}
break;
}
return -1;
}
/**
* @generated
*/
public static boolean canCreateNode(View containerView, int nodeVisualID) {
String containerModelID = org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getModelID(containerView);
if (!CanvasEditPart.MODEL_ID.equals(containerModelID)) {
return false;
}
int containerVisualID;
if (CanvasEditPart.MODEL_ID.equals(containerModelID)) {
containerVisualID = org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getVisualID(containerView);
} else {
if (containerView instanceof Diagram) {
containerVisualID = CanvasEditPart.VISUAL_ID;
} else {
return false;
}
}
switch (containerVisualID) {
case CanvasEditPart.VISUAL_ID:
if (BundleEditPart.VISUAL_ID == nodeVisualID) {
return true;
}
break;
case BundleEditPart.VISUAL_ID:
if (BundleNameEditPart.VISUAL_ID == nodeVisualID) {
return true;
}
if (IncomingCommunicatorEditPart.VISUAL_ID == nodeVisualID) {
return true;
}
if (OutcomingCommunicatorEditPart.VISUAL_ID == nodeVisualID) {
return true;
}
break;
}
return false;
}
/**
* @generated
*/
public static int getLinkWithClassVisualID(EObject domainElement) {
if (domainElement == null) {
return -1;
}
if (AffixedNodePackage.eINSTANCE.getCommunication().isSuperTypeOf(domainElement.eClass())) {
return CommunicationEditPart.VISUAL_ID;
}
return -1;
}
/**
* User can change implementation of this method to handle some specific
* situations not covered by default logic.
*
* @generated
*/
private static boolean isDiagram(Canvas element) {
return true;
}
/**
* @generated
*/
public static boolean checkNodeVisualID(View containerView, EObject domainElement, int candidate) {
if (candidate == -1) {
//unrecognized id is always bad
return false;
}
int basic = getNodeVisualID(containerView, domainElement);
return basic == candidate;
}
/**
* @generated
*/
public static boolean isCompartmentVisualID(int visualID) {
return false;
}
/**
* @generated
*/
public static boolean isSemanticLeafVisualID(int visualID) {
switch (visualID) {
case CanvasEditPart.VISUAL_ID:
return false;
case IncomingCommunicatorEditPart.VISUAL_ID:
case OutcomingCommunicatorEditPart.VISUAL_ID:
return true;
default:
break;
}
return false;
}
/**
* @generated
*/
public static final DiagramStructure TYPED_INSTANCE = new DiagramStructure() {
/**
* @generated
*/
@Override
public int getVisualID(View view) {
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getVisualID(view);
}
/**
* @generated
*/
@Override
public String getModelID(View view) {
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getModelID(view);
}
/**
* @generated
*/
@Override
public int getNodeVisualID(View containerView, EObject domainElement) {
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.getNodeVisualID(containerView, domainElement);
}
/**
* @generated
*/
@Override
public boolean checkNodeVisualID(View containerView, EObject domainElement, int candidate) {
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.checkNodeVisualID(containerView, domainElement, candidate);
}
/**
* @generated
*/
@Override
public boolean isCompartmentVisualID(int visualID) {
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.isCompartmentVisualID(visualID);
}
/**
* @generated
*/
@Override
public boolean isSemanticLeafVisualID(int visualID) {
return org.eclipse.gmf.tooling.examples.affixednode.diagram.part.AffixednodeVisualIDRegistry.isSemanticLeafVisualID(visualID);
}
};
}