Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt226
1 files changed, 226 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt
new file mode 100644
index 000000000..b1abb033a
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt
@@ -0,0 +1,226 @@
+/*
+ * 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:
+ * Alexander Shatalin (Borland) - initial API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+
+«EXTENSION xpt::diagram::Utils»
+
+«DEFINE ViewProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR getDiagram().editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «notationViewProviderClassName» extends org.eclipse.gmf.runtime.diagram.core.providers.AbstractViewProvider {
+ «EXPAND getDiagramViewClass-»
+ «EXPAND getNodeViewClass-»
+ «EXPAND getEdgeViewClass-»
+ «EXPAND getSemanticElementType-»
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE getDiagramViewClass FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getDiagramViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter, String diagramKind) {
+ «REM»When diagram domain element is null only diagram kind is checked«ENDREM-»
+ «EXPAND defineSemanticElement FOR domainDiagramElement-»
+ if («EXPAND xpt::editor::VisualIDRegistry::modelID».equals(diagramKind)«EXPAND checkSemanticElement(self) FOR domainDiagramElement») {
+ return «getNotationViewFactoryQualifiedClassName()».class;
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE defineSemanticElement FOR genmodel::GenClass-»
+org.eclipse.emf.ecore.EObject semanticElement = getSemanticElement(semanticAdapter);
+«ENDDEFINE»
+
+«DEFINE checkSemanticElement(diagram : gmfgen::GenDiagram) FOR genmodel::GenClass» && «EXPAND xpt::editor::VisualIDRegistry::getDiagramVisualIDMethodCall FOR diagram»(semanticElement) != -1«ENDDEFINE»
+
+«DEFINE getNodeViewClass FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getNodeViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter,
+ org.eclipse.gmf.runtime.notation.View containerView, String semanticHint) {
+ if (containerView == null) {
+ return null;
+ }
+ org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = getSemanticElementType(semanticAdapter);
+ org.eclipse.emf.ecore.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 = «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement);
+ } else {
+ visualID = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(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 (!«getElementTypesQualifiedClassName()».isKnownElementType(elementType)
+ || (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) {
+ return null; // foreign element type
+ }
+ String elementTypeHint = ((org.eclipse.gmf.runtime.emf.type.core.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 != «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(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 getElements(self)->select(e | e.elementType <> null)->size() > 0-»
+ if (!«getEditPartQualifiedClassName()».MODEL_ID.equals(«getVisualIDRegistryQualifiedClassName()».getModelID(containerView))) {
+ return null; // foreign diagram
+ }
+ switch (visualID) {
+ «IF ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::NotationType]->size() > 0-»
+ «EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::NotationType]-»
+ break; // pure design element
+ «ENDIF-»
+ «IF ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::MetamodelType]->size() > 0 or ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::SpecializationType]->size() > 0-»
+ «EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::MetamodelType]-»
+ «EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::SpecializationType]-»
+ if (domainElement == null || visualID != «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement)) {
+ return null; // visual id in semantic hint should match visual id for domain element
+ }
+ break;
+ «ENDIF-»
+ «EXPAND checkChildrenVisualIDs FOREACH getElements(self)->select(e | e.elementType <> null)-»
+ default:
+ return null;
+ }
+ «ELSE-»
+ return null;
+ «ENDIF-»
+ }
+ }
+ return getNodeViewClass(containerView, visualID);
+}
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getNodeViewClass(org.eclipse.gmf.runtime.notation.View containerView, int visualID) {
+ if (containerView == null || !«EXPAND xpt::editor::VisualIDRegistry::canCreateNodeMethodCall»(containerView, visualID)) {
+ return null;
+ }
+ switch (visualID) {
+ «EXPAND caseContainerVisualID FOREACH getAllChildContainers()-»
+ «EXPAND caseEntry FOREACH links.labels-»
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE caseVisualID FOR gmfgen::ElementType-»
+ «EXPAND xpt::Common::caseVisualID FOR diagramElement»
+«ENDDEFINE»
+
+«DEFINE checkChildrenVisualIDs FOR gmfgen::GenCommonBase-»
+«ENDDEFINE»
+
+«DEFINE checkChildrenVisualIDs FOR gmfgen::GenNode-»
+ «EXPAND xpt::Common::caseVisualID FOREACH labels-»
+ «EXPAND xpt::Common::caseVisualID FOREACH compartments-»
+ «IF not labels->isEmpty() or not compartments->isEmpty()-»
+if («EXPAND xpt::editor::VisualIDRegistry::visualID» != «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR getDiagram()»(containerView)
+ || containerView.getElement() != domainElement) {
+ return null; // wrong container
+}
+break;
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE checkChildrenVisualIDs FOR gmfgen::GenLink-»
+ «EXPAND xpt::Common::caseVisualID FOREACH labels-»
+ «IF not labels->isEmpty()-»
+if («EXPAND xpt::editor::VisualIDRegistry::visualID» != «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR getDiagram()»(containerView)
+ || containerView.getElement() != domainElement) {
+ return null; // wrong container
+}
+break;
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE caseContainerVisualID FOR gmfgen::GenChildContainer-»
+ «EXPAND caseEntry-»
+«ENDDEFINE»
+
+«DEFINE caseContainerVisualID FOR gmfgen::GenNode-»
+ «EXPAND caseEntry-»
+ «EXPAND caseEntry FOREACH labels-»
+«ENDDEFINE»
+
+«DEFINE caseEntry FOR gmfgen::GenCommonBase-»
+ «EXPAND xpt::Common::caseVisualID» return «getNotationViewFactoryQualifiedClassName()».class;
+«ENDDEFINE»
+
+«DEFINE getEdgeViewClass FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getEdgeViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter,
+ org.eclipse.gmf.runtime.notation.View containerView, String semanticHint) {
+ org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = getSemanticElementType(semanticAdapter);
+ if (!«getElementTypesQualifiedClassName()».isKnownElementType(elementType)
+ || (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) {
+ return null; // foreign element type
+ }
+ String elementTypeHint = ((org.eclipse.gmf.runtime.emf.type.core.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 = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(elementTypeHint);
+ org.eclipse.emf.ecore.EObject domainElement = getSemanticElement(semanticAdapter);
+ if (domainElement != null && visualID != «EXPAND xpt::editor::VisualIDRegistry::getLinkWithClassVisualIDMethodCall»(domainElement)) {
+ return null; // visual id for link EClass should match visual id from element type
+ }
+ return getEdgeViewClass(visualID);
+}
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getEdgeViewClass(int visualID) {
+ switch (visualID) {
+ «EXPAND caseEntry FOREACH links-»
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE getSemanticElementType FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.gmf.runtime.emf.type.core.IElementType getSemanticElementType(
+ org.eclipse.core.runtime.IAdaptable semanticAdapter) {
+ if (semanticAdapter == null) {
+ return null;
+ }
+ return (org.eclipse.gmf.runtime.emf.type.core.IElementType) semanticAdapter.getAdapter(
+ org.eclipse.gmf.runtime.emf.type.core.IElementType.class);
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»

Back to the top