From 1fb39fab57bbe2857c1d2c5df1f9bbec92270ef9 Mon Sep 17 00:00:00 2001 From: SebastianE Date: Fri, 3 May 2024 14:30:58 +0200 Subject: [PATCH] + reconnected the GTL visualization + Todo: fix some minor visualization errors --- .../plugin.xml_gen | 434 ++++++++++++++++++ .../META-INF/MANIFEST.MF | 6 +- .../visualization/IBeXPatternVisualizer.java | 115 +++-- org.emoflon.ibex.gt.gtl/plugin.xml_gen | 10 + org.emoflon.ibex.tgg.tggl/plugin.xml_gen | 10 + 5 files changed, 525 insertions(+), 50 deletions(-) create mode 100644 org.emoflon.ibex.common.slimgt.ui/plugin.xml_gen create mode 100644 org.emoflon.ibex.gt.gtl/plugin.xml_gen create mode 100644 org.emoflon.ibex.tgg.tggl/plugin.xml_gen diff --git a/org.emoflon.ibex.common.slimgt.ui/plugin.xml_gen b/org.emoflon.ibex.common.slimgt.ui/plugin.xml_gen new file mode 100644 index 00000000..d1731f01 --- /dev/null +++ b/org.emoflon.ibex.common.slimgt.ui/plugin.xml_gen @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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.gt.gtl/plugin.xml_gen b/org.emoflon.ibex.gt.gtl/plugin.xml_gen new file mode 100644 index 00000000..de48e99b --- /dev/null +++ b/org.emoflon.ibex.gt.gtl/plugin.xml_gen @@ -0,0 +1,10 @@ + + + + + + + diff --git a/org.emoflon.ibex.tgg.tggl/plugin.xml_gen b/org.emoflon.ibex.tgg.tggl/plugin.xml_gen new file mode 100644 index 00000000..1cb2094f --- /dev/null +++ b/org.emoflon.ibex.tgg.tggl/plugin.xml_gen @@ -0,0 +1,10 @@ + + + + + + +