Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.dev.assistants.codegen/src/org/eclipse/papyrus/dev/assistants/codegen/generator/ElementTypeToAssistantRule.xtend')
-rw-r--r--plugins/developer/org.eclipse.papyrus.dev.assistants.codegen/src/org/eclipse/papyrus/dev/assistants/codegen/generator/ElementTypeToAssistantRule.xtend87
1 files changed, 87 insertions, 0 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.dev.assistants.codegen/src/org/eclipse/papyrus/dev/assistants/codegen/generator/ElementTypeToAssistantRule.xtend b/plugins/developer/org.eclipse.papyrus.dev.assistants.codegen/src/org/eclipse/papyrus/dev/assistants/codegen/generator/ElementTypeToAssistantRule.xtend
new file mode 100644
index 00000000000..b53e22c112a
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.dev.assistants.codegen/src/org/eclipse/papyrus/dev/assistants/codegen/generator/ElementTypeToAssistantRule.xtend
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus and others.
+ *
+ * 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.dev.assistants.codegen.generator
+
+import javax.inject.Inject
+import org.eclipse.papyrus.infra.elementtypesconfigurations.ElementTypeConfiguration
+import org.eclipse.papyrus.infra.elementtypesconfigurations.ElementTypeSetConfiguration
+import org.eclipse.papyrus.infra.filters.Filter
+import org.eclipse.papyrus.infra.gmfdiag.assistant.AssistantFactory
+import org.eclipse.papyrus.uml.profile.assistants.generator.FiltersUtil
+import org.eclipse.papyrus.uml.profile.elementtypesconfigurations.generator.UMLElementTypes
+
+/**
+ * Element Type to Assistant transformation rule.
+ */
+class ElementTypeToAssistantRule {
+
+ static extension AssistantFactory assistantFactory = AssistantFactory.eINSTANCE
+
+ @Inject extension UMLElementTypes
+ @Inject extension FiltersUtil
+ @Inject extension ModelingAssistantProviderRule
+
+ def create createPopupAssistant toPopupAssistant(ElementTypeConfiguration type) {
+ elementTypeID = type.identifier
+ ownedFilter = type.createPossibleOwnersFilter().reduce()
+ }
+
+ private def createPossibleOwnersFilter(ElementTypeConfiguration type) {
+ diagramSpecificElementTypes.fold(null) [ Filter filter, elementType |
+ if (elementType.canContainType(type))
+ filter || elementType.toFilter()
+ else
+ filter
+ ]
+ }
+
+ def create createConnectionAssistant toConnectionAssistant(ElementTypeConfiguration type) {
+ elementTypeID = type.identifier
+ ownedSourceFilter = type.createPossibleSourcesFilter().reduce()
+ ownedTargetFilter = type.createPossibleTargetsFilter().reduce()
+ }
+
+ def ElementTypeSetConfiguration owningSet(ElementTypeConfiguration elementType) {
+ elementType.eContainer as ElementTypeSetConfiguration
+ }
+
+ def create createElementTypeFilter toFilter(ElementTypeConfiguration elementType) {
+ elementTypeID = elementType.identifier
+ name = elementType.name
+
+ // Shared with all of the assistants
+ elementType.owningSet.toModelingAssistantProvider.ownedFilters.add(it)
+ }
+
+ private def createPossibleSourcesFilter(ElementTypeConfiguration type) {
+ // Don't assist in creating connections from/to connections (relationships)
+ diagramSpecificElementTypes.filter[!relationship].fold(null) [ Filter filter, elementType |
+ if (elementType.canSourceToType(type))
+ filter || elementType.toFilter
+ else
+ filter
+ ]
+ }
+
+ private def createPossibleTargetsFilter(ElementTypeConfiguration type) {
+ // Don't assist in creating connections from/to connections (relationships)
+ diagramSpecificElementTypes.filter[!relationship].fold(null) [ Filter filter, elementType |
+ if (elementType.canTargetFromType(type))
+ filter || elementType.toFilter
+ else
+ filter
+ ]
+ }
+
+}

Back to the top