diff --git a/.gitignore b/.gitignore index 8b50e7c1..9438d0ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ **/xtend-gen/* !**/xtend-gen/*.keep **/bin/ -**/src-gen/* \ No newline at end of file +**/src-gen/* +**/plugin.xml_gen diff --git a/org.emoflon.ibex.common.visualization/META-INF/MANIFEST.MF b/org.emoflon.ibex.common.visualization/META-INF/MANIFEST.MF index 11fc55df..195d0138 100644 --- a/org.emoflon.ibex.common.visualization/META-INF/MANIFEST.MF +++ b/org.emoflon.ibex.common.visualization/META-INF/MANIFEST.MF @@ -11,6 +11,7 @@ Import-Package: org.apache.log4j Require-Bundle: org.moflon.core.ui, org.eclipse.ui.workbench, org.eclipse.jface, + org.emoflon.ibex.common.slimgt;bundle-version="1.0.0", org.emoflon.ibex.common.coremodel, org.emoflon.ibex.gt.gtmodel, org.eclipse.emf.ecore.editor, @@ -23,4 +24,7 @@ Require-Bundle: org.moflon.core.ui, org.eclipse.xtext.ui, org.eclipse.xtext.xbase, org.moflon.core.utilities, - org.emoflon.ibex.tgg.compiler + org.emoflon.ibex.tgg.compiler, + org.emoflon.ibex.gt.gtl, + org.emoflon.ibex.common, + org.emoflon.ibex.gt diff --git a/org.emoflon.ibex.common.visualization/src/org/emoflon/ibex/common/visualization/IBeXPatternVisualizer.java b/org.emoflon.ibex.common.visualization/src/org/emoflon/ibex/common/visualization/IBeXPatternVisualizer.java index 2a8d672a..f0a76f12 100644 --- a/org.emoflon.ibex.common.visualization/src/org/emoflon/ibex/common/visualization/IBeXPatternVisualizer.java +++ b/org.emoflon.ibex.common.visualization/src/org/emoflon/ibex/common/visualization/IBeXPatternVisualizer.java @@ -1,18 +1,24 @@ package org.emoflon.ibex.common.visualization; -import java.util.Collection; import java.util.Optional; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.presentation.EcoreEditor; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.ui.IEditorPart; -import org.emoflon.ibex.common.coremodel.IBeXCoreModel.IBeXPatternSet; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.ui.editor.XtextEditor; +import org.emoflon.ibex.common.transformation.SlimGtToIBeXCoreTransformer; +import org.emoflon.ibex.gt.gtl.gTL.EditorFile; +import org.emoflon.ibex.gt.gtl.gTL.SlimRule; +import org.emoflon.ibex.gt.gtl.util.GTLModelFlattener; +import org.emoflon.ibex.gt.gtl.util.GTLResourceManager; +import org.emoflon.ibex.gt.gtmodel.IBeXGTModel.GTModel; import org.emoflon.ibex.gt.gtmodel.IBeXGTModel.GTPattern; import org.emoflon.ibex.gt.gtmodel.IBeXGTModel.GTRule; -import org.moflon.core.ui.VisualiserUtilities; +import org.emoflon.ibex.gt.gtmodel.IBeXGTModel.IBeXGTModelFactory; +import org.emoflon.ibex.gt.transformation.GTLtoGTModelTransformer; import org.moflon.core.ui.visualisation.common.EMoflonDiagramTextProvider; /** @@ -23,11 +29,33 @@ public class IBeXPatternVisualizer implements EMoflonDiagramTextProvider { @Override public String getDiagramBody(final IEditorPart editor, final ISelection selection) { - if (selection instanceof IStructuredSelection structuredSelection) { - return visualizeSelection(structuredSelection); + EditorFile editorFile = maybeCast(XtextEditor.class).apply(editor) + .map(file -> file.getDocument().readOnly(doc -> doc.getContents().get(0))) // + .flatMap(maybeCast(EditorFile.class)).get(); + + IProject project = maybeCast(XtextEditor.class).apply(editor) // + .map(file -> file.getResource().getProject()) // + .get(); + + TextSelection textSelection = (TextSelection) selection; + for (SlimRule rule : editorFile.getRules()) { + ICompositeNode object = NodeModelUtils.getNode(rule); + if (object.getStartLine() <= textSelection.getStartLine() + 1 + && object.getEndLine() >= textSelection.getEndLine() + 1) { + try { + return visualizeSelection(project, editorFile, rule); + } catch (Exception e) { + e.printStackTrace(); + } + } } - throw new IllegalArgumentException("Invalid selection: " + selection); + try { + return visualizeSelection(project, editorFile, null); + } catch (Exception e) { + e.printStackTrace(); + return null; + } } /** @@ -35,57 +63,46 @@ public String getDiagramBody(final IEditorPart editor, final ISelection selectio * * @param selection the selection * @return the PlantUMl code for the visualization + * @throws Exception */ - private static String visualizeSelection(final IStructuredSelection selection) { - Object element = selection.getFirstElement(); - - if (isPatternSet(element)) { - return IBeXPatternPlantUMLGenerator.visualizePatternInvocations((IBeXPatternSet) element); - } - - if (isPattern(element)) { - return IBeXPatternPlantUMLGenerator.visualizeContextPattern((GTPattern) element); + private static String visualizeSelection(final IProject project, final EditorFile editorFile, + final SlimRule selection) throws Exception { + GTLResourceManager manager = new GTLResourceManager(); + GTLModelFlattener flattener = new GTLModelFlattener(manager, editorFile, true); + EditorFile flattened = flattener.getFlattenedModel(); + SlimGtToIBeXCoreTransformer transformer = new GTLtoGTModelTransformer( + flattened, project); + GTModel model = transformer.transform(); + + if (selection != null) { + Optional candidateRule = model.getRuleSet().getRules().stream() + .filter(rule -> rule.getName().equals(selection.getName())).findFirst(); + if (candidateRule.isPresent()) { + return IBeXPatternPlantUMLGenerator.visualizeRule(candidateRule.get()); + } + Optional candidatePattern = model.getPatternSet().getPatterns().stream() + .filter(pattern -> pattern.getName().equals(selection.getName())) + .map(pattern -> (GTPattern) pattern).findFirst(); + if (candidatePattern.isPresent()) { + return IBeXPatternPlantUMLGenerator.visualizeContextPattern(candidatePattern.get()); + } } - - if (isRule(element)) { - return IBeXPatternPlantUMLGenerator.visualizeRule((GTRule) element); - } - - throw new IllegalArgumentException("Invalid selection: " + element); + return IBeXPatternPlantUMLGenerator.visualizePatternInvocations(model.getPatternSet()); } @Override public boolean supportsEditor(final IEditorPart editor) { return Optional.of(editor) // - .flatMap(maybeCast(EcoreEditor.class)) // - .map(EcoreEditor::getSelection) // - .flatMap(maybeCast(TreeSelection.class)) // - .map(TreeSelection::getFirstElement) // - .filter(o -> isPatternSet(o) || isPattern(o) || isRule(o)) // + .flatMap(maybeCast(XtextEditor.class)) // + .map(file -> file.getDocument().readOnly(doc -> doc.getContents().get(0))) // + .flatMap(maybeCast(EditorFile.class)) // .isPresent(); } @Override public boolean supportsSelection(ISelection selection) { - Collection elements = VisualiserUtilities.extractEcoreSelection(selection); - if (elements == null) - return false; - - return elements.stream() - .filter(elt -> elt.eClass().getEPackage().getName().contains("org.emoflon.ibex.patternmodel")).findAny() - .isPresent(); - } - - private static boolean isPatternSet(final Object object) { - return object instanceof IBeXPatternSet; - } - - private static boolean isPattern(final Object object) { - return object instanceof GTPattern; - } - - private static boolean isRule(final Object object) { - return object instanceof GTRule; + // Note: If the editor is detected correctly, this must be true anyways! + return true; } } diff --git a/org.emoflon.ibex.common.visualization/xtend-src/org/emoflon/ibex/common/visualization/IBeXPatternPlantUMLGenerator.xtend b/org.emoflon.ibex.common.visualization/xtend-src/org/emoflon/ibex/common/visualization/IBeXPatternPlantUMLGenerator.xtend index 8427c871..9b5203e4 100644 --- a/org.emoflon.ibex.common.visualization/xtend-src/org/emoflon/ibex/common/visualization/IBeXPatternPlantUMLGenerator.xtend +++ b/org.emoflon.ibex.common.visualization/xtend-src/org/emoflon/ibex/common/visualization/IBeXPatternPlantUMLGenerator.xtend @@ -47,9 +47,9 @@ class IBeXPatternPlantUMLGenerator { «commonLayoutSettings» skinparam class { - BorderColor<> «ContextColor» + BorderColor<> «ContextColor» BorderColor<> «LocalColor» - FontColor<> «ContextColor» + FontColor<> «ContextColor» FontColor<> «LocalColor» } @@ -68,9 +68,9 @@ class IBeXPatternPlantUMLGenerator { val packageName = prefix + pattern.name ''' package "«packageName»" «IF !positive»#FFCCCC«ENDIF» {} - «visualizeNodes(pattern.signatureNodes, 'SIGNATURE', packageName)» + «visualizeNodes(pattern.signatureNodes, 'CONTEXT', packageName)» «visualizeNodes(pattern.localNodes, 'LOCAL', packageName)» - «visualizeEdges(pattern.edges, ContextColor, packageName)» + «visualizeEdges(pattern.edges, ContextColor, packageName, '')» «var j = 0» «FOR invocation : pattern.invocations» «val newPrefix = j++ + "\\"» @@ -87,6 +87,7 @@ class IBeXPatternPlantUMLGenerator { * Visualizes the create pattern. */ static def String visualizeRule(GTRule rule) { + val packageName = rule.name ''' «commonLayoutSettings» @@ -94,19 +95,34 @@ class IBeXPatternPlantUMLGenerator { BorderColor<> «ContextColor» BorderColor<> «CreateColor» FontColor<> «ContextColor» + BorderColor<> «LocalColor» + FontColor<> «LocalColor» FontColor<> «CreateColor» BorderColor<> «DeleteColor» FontColor<> «DeleteColor» } - «visualizeNodes(rule.allNodes.filter[n | rule.precondition.signatureNodes.contains(n) && rule.postcondition.signatureNodes.contains(n)].toList, 'CONTEXT', '')» - «visualizeNodes(rule.creation.nodes, 'CREATE', '')» - «visualizeEdges(rule.creation.edges, CreateColor, '')» - «visualizeNodes(rule.deletion.nodes, 'DELETE', '')» - «visualizeEdges(rule.deletion.edges, DeleteColor, '')» + package "«packageName»" {} + + «visualizeNodes(rule.precondition.signatureNodes.filter[n | !rule.deletion.nodes.contains(n)].toList, 'CONTEXT', packageName)» + «visualizeNodes(rule.precondition.localNodes.toList, 'LOCAL', packageName)» + «visualizeEdges(rule.precondition.edges.filter[e | !rule.deletion.edges.contains(e)].toList, ContextColor, packageName, '')» + «visualizeNodes(rule.creation.nodes, 'CREATE', packageName)» + «visualizeEdges(rule.creation.edges, CreateColor, packageName, '++')» + «visualizeNodes(rule.deletion.nodes, 'DELETE', packageName)» + «visualizeEdges(rule.deletion.edges, DeleteColor, packageName, '--')» + + «var j = 0» + «FOR invocation : rule.precondition.invocations» + «val newPrefix = j++ + "\\"» + «printPattern(invocation.invocation as GTPattern, newPrefix, invocation.positive)» + «FOR mapEntry : invocation.mapping.entrySet» + "«node(mapEntry.key, packageName)»" #--# "«node(mapEntry.value, newPrefix + invocation.invocation.name)»" + «ENDFOR» + «ENDFOR» center footer - = Create Pattern «rule.name» + = Rule «rule.name» end footer ''' } @@ -132,10 +148,10 @@ class IBeXPatternPlantUMLGenerator { /** * Outputs the edges. */ - private static def String visualizeEdges(List edges, String color, String nodePrefix) { + private static def String visualizeEdges(List edges, String color, String nodePrefix, String op) { ''' «FOR edge : edges» - "«node(edge.source, nodePrefix)»" -[#«color»]-> "«node(edge.target, nodePrefix)»": «» «edge.type.name» + "«node(edge.source, nodePrefix)»" -[#«color»]-> "«node(edge.target, nodePrefix)»": «» «op»«edge.type.name» «ENDFOR» ''' } diff --git a/org.emoflon.ibex.gt.gtl.ui/plugin.xml_gen b/org.emoflon.ibex.gt.gtl.ui/plugin.xml_gen deleted file mode 100644 index d1a928d8..00000000 --- a/org.emoflon.ibex.gt.gtl.ui/plugin.xml_gen +++ /dev/null @@ -1,434 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.emoflon.ibex.tgg.tggl.ui/plugin.xml_gen b/org.emoflon.ibex.tgg.tggl.ui/plugin.xml_gen deleted file mode 100644 index ea8011cf..00000000 --- a/org.emoflon.ibex.tgg.tggl.ui/plugin.xml_gen +++ /dev/null @@ -1,434 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -