=UTF-8
diff --git a/bundles/tools.vitruv.applications.viewtest/.settings/org.eclipse.jdt.core.prefs b/bundles/tools.vitruv.applications.viewtest/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..62ef3488c
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
+org.eclipse.jdt.core.compiler.compliance=17
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=17
diff --git a/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..db1945a3f
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Vitruv Viewfilter Application
+Bundle-SymbolicName: tools.vitruv.applications.viewfilter;singleton:=true
+Bundle-Version: 3.0.1.qualifier
+Automatic-Module-Name: tools.vitruv.applications.viewfilter
+Bundle-RequiredExecutionEnvironment: JavaSE-17
+Eclipse-ExtensibleAPI: true
+Require-Bundle: org.eclipse.uml2.uml;visibility:=reexport,
+ org.palladiosimulator.pcm;visibility:=reexport,
+ edu.kit.ipd.sdq.activextendannotations,
+ edu.kit.ipd.sdq.commons.util.emf,
+ edu.kit.ipd.sdq.commons.util.java,
+ tools.vitruv.framework.applications,
+ tools.vitruv.dsls.reactions.runtime,
+ tools.vitruv.applications.util.temporary
+Bundle-Vendor: vitruv.tools
diff --git a/bundles/tools.vitruv.applications.viewtest/build.properties b/bundles/tools.vitruv.applications.viewtest/build.properties
new file mode 100644
index 000000000..2c5b31414
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/build.properties
@@ -0,0 +1,7 @@
+source.. = src/,\
+ src-gen/,\
+ xtend-gen/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ plugin.xml,\
+ .
diff --git a/bundles/tools.vitruv.applications.viewtest/plugin.xml b/bundles/tools.vitruv.applications.viewtest/plugin.xml
new file mode 100644
index 000000000..828835a00
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/plugin.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/tools.vitruv.applications.pcmumlclass.tests/.polyglot.META-INF b/tests/tools.vitruv.applications.pcmumlclass.tests/.polyglot.META-INF
index e69de29bb..9fc7a3be6 100644
--- a/tests/tools.vitruv.applications.pcmumlclass.tests/.polyglot.META-INF
+++ b/tests/tools.vitruv.applications.pcmumlclass.tests/.polyglot.META-INF
@@ -0,0 +1,18 @@
+
+
+ 4.0.0
+
+ tools.vitruv
+ tests
+ 3.0.1-SNAPSHOT
+ ..\.polyglot.pom.tycho
+
+ tools.vitruv.applications.pcmumlclass.tests
+ 3.0.1-SNAPSHOT
+ eclipse-test-plugin
+ [test-bundle] Vitruv PCM-UML Class Application Tests
+
+ vitruv.tools
+
+
diff --git a/tests/tools.vitruv.applications.pcmumlclass.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.pcmumlclass.tests/META-INF/MANIFEST.MF
index 5c3e925e5..16d0187e2 100644
--- a/tests/tools.vitruv.applications.pcmumlclass.tests/META-INF/MANIFEST.MF
+++ b/tests/tools.vitruv.applications.pcmumlclass.tests/META-INF/MANIFEST.MF
@@ -19,6 +19,7 @@ Require-Bundle: tools.vitruv.testutils.vsum,
tools.vitruv.applications.testutility,
org.palladiosimulator.pcm,
edu.kit.ipd.sdq.commons.util.emf,
- slf4j.api;bundle-version="2.0.9"
+ slf4j.api;bundle-version="2.0.9",
+ org.emftext.language.java;bundle-version="1.4.1"
Export-Package: tools.vitruv.applications.pcmumlclass.tests
Bundle-Vendor: vitruv.tools
diff --git a/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF
index e6792176d..73b8196f0 100644
--- a/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF
+++ b/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF
@@ -20,7 +20,8 @@ Require-Bundle: tools.vitruv.applications.umljava,
org.apache.log4j,
org.emftext.language.java.resource.java,
org.emftext.language.java.resource,
- tools.vitruv.applications.testutility
+ tools.vitruv.applications.testutility,
+ slf4j.api;bundle-version="2.0.9"
Bundle-ClassPath: .,
target/dependency/json.jar
Bundle-Vendor: vitruv.tools
diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend
index 883fd6aee..56e1f88b2 100644
--- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend
+++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend
@@ -58,7 +58,7 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest {
@BeforeAll
def static setupJavaFactories() {
- JavaSetup.prepareFactories([new JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl()])
+ JavaSetup.prepareFactories([new JavaSOCFileResourceWithArraysDefaultFactoryImpl()])
}
@AfterEach
diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java
similarity index 86%
rename from tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java
rename to tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java
index a6f1f0598..5fc75dc5b 100644
--- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java
+++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java
@@ -4,7 +4,7 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.emftext.language.java.resource.JavaSourceOrClassFileResourceFactoryImpl;
-public class JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl
+public class JavaSOCFileResourceWithArraysDefaultFactoryImpl
extends JavaSourceOrClassFileResourceFactoryImpl {
@Override
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
index 1823f938d..62a3b5806 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
+++ b/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
@@ -19,6 +19,7 @@ Require-Bundle: tools.vitruv.testutils.vsum,
tools.vitruv.applications.testutility,
org.palladiosimulator.pcm,
edu.kit.ipd.sdq.commons.util.emf,
- slf4j.api;bundle-version="2.0.9"
+ slf4j.api;bundle-version="2.0.9",
+ org.emftext.language.java;bundle-version="1.4.1"
Export-Package: tools.vitruv.applications.viewfilter.tests
Bundle-Vendor: vitruv.tools
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/build.properties b/tests/tools.vitruv.applications.viewfilter.tests/build.properties
index 3d48e9cc3..6a209b473 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/build.properties
+++ b/tests/tools.vitruv.applications.viewfilter.tests/build.properties
@@ -6,9 +6,9 @@ bin.includes = META-INF/,\
resources/
additional.bundles = org.palladiosimulator.pcm,\
org.palladiosimulator.pcm.resources,\
- org.eclipse.uml2.uml,\
org.eclipse.emf.edit,\
org.eclipse.core.expressions,\
org.slf4j.api,\
ch.qos.logback.core,\
- ch.qos.logback.classic
+ ch.qos.logback.classic,\
+ org.eclipse.uml2.uml
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/pluginnono.xml b/tests/tools.vitruv.applications.viewfilter.tests/pluginnono.xml
new file mode 100644
index 000000000..2bc642c49
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/pluginnono.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Helper.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Helper.java
new file mode 100644
index 000000000..bc0c24d31
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Helper.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2015 Orhan Obut
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This software contains code derived from the following Android classes:
+ * android.util.Log, android.text.TextUtils.
+ */
+package com.orhanobut.logger;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.UnknownHostException;
+
+/**
+ * Helper util class to be used instead of Android methods to avoid direct dependency and enable
+ * unit testing on Android projects.
+ */
+final class Helper {
+
+ private Helper() {
+ // Hidden constructor.
+ }
+
+ /**
+ * Returns true if the string is null or 0-length.
+ *
+ * @param str the string to be examined
+ *
+ * @return true if str is null or zero length
+ */
+ static boolean isEmpty(CharSequence str) {
+ return str == null || str.length() == 0;
+ }
+
+ /**
+ * Returns true if a and b are equal, including if they are both null.
+ * Note: In platform versions 1.1 and earlier, this method only worked well if
+ * both the arguments were instances of String.
+ *
+ * @param a first CharSequence to check
+ * @param b second CharSequence to check
+ *
+ * @return true if a and b are equal
+ *
+ * NOTE: Logic slightly change due to strict policy on CI -
+ * "Inner assignments should be avoided"
+ */
+ static boolean equals(CharSequence a, CharSequence b) {
+ if (a == b) return true;
+ if (a != null && b != null) {
+ int length = a.length();
+ if (length == b.length()) {
+ if (a instanceof String && b instanceof String) {
+ return a.equals(b);
+ } else {
+ for (int i = 0; i < length; i++) {
+ if (a.charAt(i) != b.charAt(i)) return false;
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Copied from "android.util.Log.getStackTraceString()" in order to avoid usage of Android stack
+ * in unit tests.
+ *
+ * @return Stack trace in form of String
+ */
+ static String getStackTraceString(Throwable tr) {
+ if (tr == null) {
+ return "";
+ }
+
+ // This is to reduce the amount of log spew that apps do in the non-error
+ // condition of the network being unavailable.
+ Throwable t = tr;
+ while (t != null) {
+ if (t instanceof UnknownHostException) {
+ return "";
+ }
+ t = t.getCause();
+ }
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ tr.printStackTrace(pw);
+ pw.flush();
+ return sw.toString();
+ }
+
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LogAdapter.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LogAdapter.java
new file mode 100644
index 000000000..cab5d8ce7
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LogAdapter.java
@@ -0,0 +1,15 @@
+package com.orhanobut.logger;
+
+public interface LogAdapter {
+ void d(String tag, String message);
+
+ void e(String tag, String message);
+
+ void w(String tag, String message);
+
+ void i(String tag, String message);
+
+ void v(String tag, String message);
+
+ void wtf(String tag, String message);
+}
\ No newline at end of file
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LogLevel.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LogLevel.java
new file mode 100644
index 000000000..e3a33ed35
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LogLevel.java
@@ -0,0 +1,14 @@
+package com.orhanobut.logger;
+
+public enum LogLevel {
+
+ /**
+ * Prints all logs
+ */
+ FULL,
+
+ /**
+ * No log will be printed
+ */
+ NONE
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Logger.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Logger.java
new file mode 100644
index 000000000..4f6ba77bd
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Logger.java
@@ -0,0 +1,112 @@
+package com.orhanobut.logger;
+
+/**
+ * Logger is a wrapper of {@link android.util.Log}
+ * But more pretty, simple and powerful
+ */
+public final class Logger {
+ public static final int DEBUG = 3;
+ public static final int ERROR = 6;
+ public static final int ASSERT = 7;
+ public static final int INFO = 4;
+ public static final int VERBOSE = 2;
+ public static final int WARN = 5;
+
+ private static final String DEFAULT_TAG = "PRETTYLOGGER";
+
+ private static Printer printer = new LoggerPrinter();
+
+ //no instance
+ private Logger() {
+ }
+
+ /**
+ * It is used to get the settings object in order to change settings
+ *
+ * @return the settings object
+ */
+ public static Settings init() {
+ return init(DEFAULT_TAG);
+ }
+
+ /**
+ * It is used to change the tag
+ *
+ * @param tag is the given string which will be used in Logger as TAG
+ */
+ public static Settings init(String tag) {
+ printer = new LoggerPrinter();
+ return printer.init(tag);
+ }
+
+ public static void resetSettings() {
+ printer.resetSettings();
+ }
+
+ public static Printer t(String tag) {
+ return printer.t(tag, printer.getSettings().getMethodCount());
+ }
+
+ public static Printer t(int methodCount) {
+ return printer.t(null, methodCount);
+ }
+
+ public static Printer t(String tag, int methodCount) {
+ return printer.t(tag, methodCount);
+ }
+
+ public static void log(int priority, String tag, String message, Throwable throwable) {
+ printer.log(priority, tag, message, throwable);
+ }
+
+ public static void d(String message, Object... args) {
+ printer.d(message, args);
+ }
+
+ public static void d(Object object) {
+ printer.d(object);
+ }
+
+ public static void e(String message, Object... args) {
+ printer.e(null, message, args);
+ }
+
+ public static void e(Throwable throwable, String message, Object... args) {
+ printer.e(throwable, message, args);
+ }
+
+ public static void i(String message, Object... args) {
+ printer.i(message, args);
+ }
+
+ public static void v(String message, Object... args) {
+ printer.v(message, args);
+ }
+
+ public static void w(String message, Object... args) {
+ printer.w(message, args);
+ }
+
+ public static void wtf(String message, Object... args) {
+ printer.wtf(message, args);
+ }
+
+ /**
+ * Formats the json content and print it
+ *
+ * @param json the json content
+ */
+ public static void json(String json) {
+ printer.json(json);
+ }
+
+ /**
+ * Formats the json content and print it
+ *
+ * @param xml the xml content
+ */
+ public static void xml(String xml) {
+ printer.xml(xml);
+ }
+
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LoggerPrinter.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LoggerPrinter.java
new file mode 100644
index 000000000..6dfc57b7a
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/LoggerPrinter.java
@@ -0,0 +1,401 @@
+package com.orhanobut.logger;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Arrays;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+final class LoggerPrinter implements Printer {
+
+ private static final String DEFAULT_TAG = "PRETTYLOGGER";
+
+ private static final int DEBUG = 3;
+ private static final int ERROR = 6;
+ private static final int ASSERT = 7;
+ private static final int INFO = 4;
+ private static final int VERBOSE = 2;
+ private static final int WARN = 5;
+
+ /**
+ * Android's max limit for a log entry is ~4076 bytes,
+ * so 4000 bytes is used as chunk size since default charset
+ * is UTF-8
+ */
+ private static final int CHUNK_SIZE = 4000;
+
+ /**
+ * It is used for json pretty print
+ */
+ private static final int JSON_INDENT = 2;
+
+ /**
+ * The minimum stack trace index, starts at this class after two native calls.
+ */
+ private static final int MIN_STACK_OFFSET = 3;
+
+ /**
+ * Drawing toolbox
+ */
+ private static final char TOP_LEFT_CORNER = '╔';
+ private static final char BOTTOM_LEFT_CORNER = '╚';
+ private static final char MIDDLE_CORNER = '╟';
+ private static final char HORIZONTAL_DOUBLE_LINE = '║';
+ private static final String DOUBLE_DIVIDER = "════════════════════════════════════════════";
+ private static final String SINGLE_DIVIDER = "────────────────────────────────────────────";
+ private static final String TOP_BORDER = TOP_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER;
+ private static final String BOTTOM_BORDER = BOTTOM_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER;
+ private static final String MIDDLE_BORDER = MIDDLE_CORNER + SINGLE_DIVIDER + SINGLE_DIVIDER;
+
+ /**
+ * tag is used for the Log, the name is a little different
+ * in order to differentiate the logs easily with the filter
+ */
+ private String tag;
+
+ /**
+ * Localize single tag and method count for each thread
+ */
+ private final ThreadLocal localTag = new ThreadLocal();
+ private final ThreadLocal localMethodCount = new ThreadLocal();
+
+ /**
+ * It is used to determine log settings such as method count, thread info visibility
+ */
+ private final Settings settings = new Settings();
+
+ public LoggerPrinter() {
+ init(DEFAULT_TAG);
+ }
+
+ /**
+ * It is used to change the tag
+ *
+ * @param tag is the given string which will be used in Logger
+ */
+ @Override public Settings init(String tag) {
+ if (tag == null) {
+ throw new NullPointerException("tag may not be null");
+ }
+ if (tag.trim().length() == 0) {
+ throw new IllegalStateException("tag may not be empty");
+ }
+ this.tag = tag;
+ return settings;
+ }
+
+ @Override public Settings getSettings() {
+ return settings;
+ }
+
+ @Override public Printer t(String tag, int methodCount) {
+ if (tag != null) {
+ localTag.set(tag);
+ }
+ localMethodCount.set(methodCount);
+ return this;
+ }
+
+ @Override public void d(String message, Object... args) {
+ log(DEBUG, null, message, args);
+ }
+
+ @Override public void d(Object object) {
+ String message;
+ if (object.getClass().isArray()) {
+ message = Arrays.deepToString((Object[]) object);
+ } else {
+ message = object.toString();
+ }
+ log(DEBUG, null, message);
+ }
+
+ @Override public void e(String message, Object... args) {
+ e(null, message, args);
+ }
+
+ @Override public void e(Throwable throwable, String message, Object... args) {
+ log(ERROR, throwable, message, args);
+ }
+
+ @Override public void w(String message, Object... args) {
+ log(WARN, null, message, args);
+ }
+
+ @Override public void i(String message, Object... args) {
+ log(INFO, null, message, args);
+ }
+
+ @Override public void v(String message, Object... args) {
+ log(VERBOSE, null, message, args);
+ }
+
+ @Override public void wtf(String message, Object... args) {
+ log(ASSERT, null, message, args);
+ }
+
+ /**
+ * Formats the json content and print it
+ *
+ * @param json the json content
+ */
+ @Override public void json(String json) {
+ if (Helper.isEmpty(json)) {
+ d("Empty/Null json content");
+ return;
+ }
+ try {
+ json = json.trim();
+ if (json.startsWith("{")) {
+ JSONObject jsonObject = new JSONObject(json);
+ String message = jsonObject.toString(JSON_INDENT);
+ d(message);
+ return;
+ }
+ if (json.startsWith("[")) {
+ JSONArray jsonArray = new JSONArray(json);
+ String message = jsonArray.toString(JSON_INDENT);
+ d(message);
+ return;
+ }
+ e("Invalid Json");
+ } catch (JSONException e) {
+ e("Invalid Json");
+ }
+ }
+
+ /**
+ * Formats the json content and print it
+ *
+ * @param xml the xml content
+ */
+ @Override public void xml(String xml) {
+ if (Helper.isEmpty(xml)) {
+ d("Empty/Null xml content");
+ return;
+ }
+ try {
+ Source xmlInput = new StreamSource(new StringReader(xml));
+ StreamResult xmlOutput = new StreamResult(new StringWriter());
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+ transformer.transform(xmlInput, xmlOutput);
+ d(xmlOutput.getWriter().toString().replaceFirst(">", ">\n"));
+ } catch (TransformerException e) {
+ e("Invalid xml");
+ }
+ }
+
+ @Override public synchronized void log(int priority, String tag, String message, Throwable throwable) {
+ if (settings.getLogLevel() == null) {
+ return;
+ }
+ if (throwable != null && message != null) {
+ message += " : " + Helper.getStackTraceString(throwable);
+ }
+ if (throwable != null && message == null) {
+ message = Helper.getStackTraceString(throwable);
+ }
+ if (message == null) {
+ message = "No message/exception is set";
+ }
+ int methodCount = getMethodCount();
+ if (Helper.isEmpty(message)) {
+ message = "Empty/NULL log message";
+ }
+
+ logTopBorder(priority, tag);
+ logHeaderContent(priority, tag, methodCount);
+
+ //get bytes of message with system's default charset (which is UTF-8 for Android)
+ byte[] bytes = message.getBytes();
+ int length = bytes.length;
+ if (length <= CHUNK_SIZE) {
+ if (methodCount > 0) {
+ logDivider(priority, tag);
+ }
+ logContent(priority, tag, message);
+ logBottomBorder(priority, tag);
+ return;
+ }
+ if (methodCount > 0) {
+ logDivider(priority, tag);
+ }
+ for (int i = 0; i < length; i += CHUNK_SIZE) {
+ int count = Math.min(length - i, CHUNK_SIZE);
+ //create a new String with system's default charset (which is UTF-8 for Android)
+ logContent(priority, tag, new String(bytes, i, count));
+ }
+ logBottomBorder(priority, tag);
+ }
+
+ @Override public void resetSettings() {
+ settings.reset();
+ }
+
+ /**
+ * This method is synchronized in order to avoid messy of logs' order.
+ */
+ private synchronized void log(int priority, Throwable throwable, String msg, Object... args) {
+ if (settings.getLogLevel() == null) {
+ return;
+ }
+ String tag = getTag();
+ String message = createMessage(msg, args);
+ log(priority, tag, message, throwable);
+ }
+
+ private void logTopBorder(int logType, String tag) {
+ logChunk(logType, tag, TOP_BORDER);
+ }
+
+ @SuppressWarnings("StringBufferReplaceableByString")
+ private void logHeaderContent(int logType, String tag, int methodCount) {
+ StackTraceElement[] trace = Thread.currentThread().getStackTrace();
+ if (settings.isShowThreadInfo()) {
+ logChunk(logType, tag, HORIZONTAL_DOUBLE_LINE + " Thread: " + Thread.currentThread().getName());
+ logDivider(logType, tag);
+ }
+ String level = "";
+
+ int stackOffset = getStackOffset(trace) + settings.getMethodOffset();
+
+ //corresponding method count with the current stack may exceeds the stack trace. Trims the count
+ if (methodCount + stackOffset > trace.length) {
+ methodCount = trace.length - stackOffset - 1;
+ }
+
+ for (int i = methodCount; i > 0; i--) {
+ int stackIndex = i + stackOffset;
+ if (stackIndex >= trace.length) {
+ continue;
+ }
+ StringBuilder builder = new StringBuilder();
+ builder.append("║ ")
+ .append(level)
+ .append(getSimpleClassName(trace[stackIndex].getClassName()))
+ .append(".")
+ .append(trace[stackIndex].getMethodName())
+ .append(" ")
+ .append(" (")
+ .append(trace[stackIndex].getFileName())
+ .append(":")
+ .append(trace[stackIndex].getLineNumber())
+ .append(")");
+ level += " ";
+ logChunk(logType, tag, builder.toString());
+ }
+ }
+
+ private void logBottomBorder(int logType, String tag) {
+ logChunk(logType, tag, BOTTOM_BORDER);
+ }
+
+ private void logDivider(int logType, String tag) {
+ logChunk(logType, tag, MIDDLE_BORDER);
+ }
+
+ private void logContent(int logType, String tag, String chunk) {
+ String[] lines = chunk.split(System.getProperty("line.separator"));
+ for (String line : lines) {
+ logChunk(logType, tag, HORIZONTAL_DOUBLE_LINE + " " + line);
+ }
+ }
+
+ private void logChunk(int logType, String tag, String chunk) {
+ String finalTag = formatTag(tag);
+ switch (logType) {
+ case ERROR:
+ settings.getLogAdapter().e(finalTag, chunk);
+ break;
+ case INFO:
+ settings.getLogAdapter().i(finalTag, chunk);
+ break;
+ case VERBOSE:
+ settings.getLogAdapter().v(finalTag, chunk);
+ break;
+ case WARN:
+ settings.getLogAdapter().w(finalTag, chunk);
+ break;
+ case ASSERT:
+ settings.getLogAdapter().wtf(finalTag, chunk);
+ break;
+ case DEBUG:
+ // Fall through, log debug by default
+ default:
+ settings.getLogAdapter().d(finalTag, chunk);
+ break;
+ }
+ }
+
+ private String getSimpleClassName(String name) {
+ int lastIndex = name.lastIndexOf(".");
+ return name.substring(lastIndex + 1);
+ }
+
+ private String formatTag(String tag) {
+ if (!Helper.isEmpty(tag) && !Helper.equals(this.tag, tag)) {
+ return this.tag + "-" + tag;
+ }
+ return this.tag;
+ }
+
+ /**
+ * @return the appropriate tag based on local or global
+ */
+ private String getTag() {
+ String tag = localTag.get();
+ if (tag != null) {
+ localTag.remove();
+ return tag;
+ }
+ return this.tag;
+ }
+
+ private String createMessage(String message, Object... args) {
+ return args == null || args.length == 0 ? message : String.format(message, args);
+ }
+
+ private int getMethodCount() {
+ Integer count = localMethodCount.get();
+ int result = settings.getMethodCount();
+ if (count != null) {
+ localMethodCount.remove();
+ result = count;
+ }
+ if (result < 0) {
+ throw new IllegalStateException("methodCount cannot be negative");
+ }
+ return result;
+ }
+
+ /**
+ * Determines the starting index of the stack trace, after method calls made by this class.
+ *
+ * @param trace the stack trace
+ *
+ * @return the stack offset
+ */
+ private int getStackOffset(StackTraceElement[] trace) {
+ for (int i = MIN_STACK_OFFSET; i < trace.length; i++) {
+ StackTraceElement e = trace[i];
+ String name = e.getClassName();
+ if (!name.equals(LoggerPrinter.class.getName()) && !name.equals(Logger.class.getName())) {
+ return --i;
+ }
+ }
+ return -1;
+ }
+
+}
\ No newline at end of file
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Printer.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Printer.java
new file mode 100644
index 000000000..a8dce3273
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Printer.java
@@ -0,0 +1,35 @@
+package com.orhanobut.logger;
+
+public interface Printer {
+
+ Printer t(String tag, int methodCount);
+
+ Settings init(String tag);
+
+ Settings getSettings();
+
+ void d(String message, Object... args);
+
+ void d(Object object);
+
+ void e(String message, Object... args);
+
+ void e(Throwable throwable, String message, Object... args);
+
+ void w(String message, Object... args);
+
+ void i(String message, Object... args);
+
+ void v(String message, Object... args);
+
+ void wtf(String message, Object... args);
+
+ void json(String json);
+
+ void xml(String xml);
+
+ void log(int priority, String tag, String message, Throwable throwable);
+
+ void resetSettings();
+
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Settings.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Settings.java
new file mode 100644
index 000000000..6ae6ea7b8
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/Settings.java
@@ -0,0 +1,69 @@
+package com.orhanobut.logger;
+
+public final class Settings {
+
+ private int methodCount = 2;
+ private boolean showThreadInfo = true;
+ private int methodOffset = 0;
+ private LogAdapter logAdapter;
+
+ /**
+ * Determines to how logs will be printed
+ */
+ private LogLevel logLevel = LogLevel.FULL;
+
+ public Settings hideThreadInfo() {
+ showThreadInfo = false;
+ return this;
+ }
+
+ public Settings methodCount(int methodCount) {
+ if (methodCount < 0) {
+ methodCount = 0;
+ }
+ this.methodCount = methodCount;
+ return this;
+ }
+
+ public Settings logLevel(LogLevel logLevel) {
+ this.logLevel = logLevel;
+ return this;
+ }
+
+ public Settings methodOffset(int offset) {
+ this.methodOffset = offset;
+ return this;
+ }
+
+ public Settings logAdapter(LogAdapter logAdapter) {
+ this.logAdapter = logAdapter;
+ return this;
+ }
+
+ public int getMethodCount() {
+ return methodCount;
+ }
+
+ public boolean isShowThreadInfo() {
+ return showThreadInfo;
+ }
+
+ public LogLevel getLogLevel() {
+ return logLevel;
+ }
+
+ public int getMethodOffset() {
+ return methodOffset;
+ }
+
+ public LogAdapter getLogAdapter() {
+ return logAdapter;
+ }
+
+ public void reset() {
+ methodCount = 2;
+ methodOffset = 0;
+ showThreadInfo = true;
+ logLevel = LogLevel.FULL;
+ }
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/package-info.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/package-info.java
new file mode 100644
index 000000000..312539fae
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/logger/package-info.java
@@ -0,0 +1 @@
+package com.orhanobut.logger;
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/package-info.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/package-info.java
new file mode 100644
index 000000000..049674d03
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/orhanobut/package-info.java
@@ -0,0 +1 @@
+package com.orhanobut;
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/package-info.java b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/package-info.java
new file mode 100644
index 000000000..86bcb18ba
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/java/com/package-info.java
@@ -0,0 +1 @@
+package com;
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/uml/model.uml b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/uml/model.uml
new file mode 100644
index 000000000..79f7f29bc
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/resources/orhanobut/uml/model.uml
@@ -0,0 +1,394 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
index 1a4e6dbec..57a3acefd 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
@@ -1,18 +1,35 @@
package tools.vitruv.applications.viewfilter.tests
-import tools.vitruv.testutils.ViewBasedVitruvApplicationTest
-import tools.vitruv.applications.pcmumlclass.CombinedPcmToUmlClassReactionsChangePropagationSpecification
-import tools.vitruv.applications.pcmumlclass.CombinedUmlClassToPcmReactionsChangePropagationSpecification
-import org.eclipse.uml2.uml.UMLFactory
+import java.nio.file.Path
import org.eclipse.emf.common.util.URI
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.BeforeEach
+import org.eclipse.emf.ecore.EObject
+import org.emftext.language.java.containers.CompilationUnit
import org.eclipse.uml2.uml.Model
+import org.eclipse.uml2.uml.UMLFactory
import org.eclipse.xtend.lib.annotations.Accessors
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import tools.vitruv.applications.pcmumlclass.CombinedPcmToUmlClassReactionsChangePropagationSpecification
+import tools.vitruv.applications.pcmumlclass.CombinedUmlClassToPcmReactionsChangePropagationSpecification
import tools.vitruv.framework.views.View
-import org.eclipse.emf.ecore.EObject
-import java.nio.file.Path
+import tools.vitruv.testutils.ViewBasedVitruvApplicationTest
+//import tools.vitruv.applications.pcmumlclass.tests.helper.FluentUMLInterfaceBuilder
+import org.eclipse.uml2.uml.PrimitiveType
+import org.eclipse.uml2.uml.Type
+import tools.vitruv.applications.viewfilter.utils.FluentUMLClassBuilder
+import tools.vitruv.applications.viewfilter.utils.PcmUmlClassApplicationTestHelper
+import java.util.ArrayList
+import tools.vitruv.framework.vsum.internal.VirtualModelImpl
+import java.io.File
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
+import org.eclipse.emf.ecore.util.EcoreUtil
+
+import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceUtil.getFirstRootEObject
+import tools.vitruv.testutils.RegisterMetamodelsInStandalone
+import org.junit.jupiter.api.^extension.ExtendWith
+import tools.vitruv.applications.viewfilter.utils.FluentUMLPackageBuilder
+@ExtendWith(RegisterMetamodelsInStandalone)
class FirstTest extends ViewBasedVitruvApplicationTest {
@Accessors(PROTECTED_GETTER)
@@ -21,8 +38,18 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
static val UML_MODEL_NAME = "model"
@Accessors(PROTECTED_GETTER)
static val UML_MODEL_FOLDER_NAME = "model"
+ @Accessors(PROTECTED_GETTER)
+ static val MODEL_FOLDER_NAME = "model"
+ @Accessors(PROTECTED_GETTER)
+ static val MODEL_FILE_EXTENSION = "uml"
+
+ static val PROPERTY_NAME = "testAssemblyContextField"
+
+ static val UML_MODEL_FILE_PATH = "resources/orhanobut/uml/model.uml"
- protected var extension FirstTestFactory viewTestFactory
+
+ protected var FirstTestFactory viewTestFactory
+ protected var extension ViewTestFactory improvedViewTestFactory
override protected getChangePropagationSpecifications() {
return #[
@@ -34,7 +61,8 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
@BeforeEach
def void setup() {
viewTestFactory = new FirstTestFactory(virtualModel)
- createUmlModel[name = UML_MODEL_NAME]
+ improvedViewTestFactory = new ViewTestFactory(virtualModel)
+ createBiggerUmlModel[name = UML_MODEL_NAME]
}
@@ -55,9 +83,17 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
@Test
def void testCreateFilteredUmlView() {
- createFilteredUmlView();
+ var view = createFilteredUmlView();
+ view.selection
+ view.viewType
+ }
+
+ @Test
+ def void testFilterForName() {
+ createAdvancedUmlModel[name = UML_MODEL_NAME + "big"]
}
+
@@ -97,13 +133,80 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
protected def Path getUmlProjectModelPath(String modelName) {
Path.of(UML_MODEL_FOLDER_NAME).resolve(modelName + "." + UML_MODEL_FILE_EXTENSION)
}
-
+
+ protected def Path getProjectModelPath(String modelName) {
+ Path.of(MODEL_FOLDER_NAME).resolve(modelName + "." + MODEL_FILE_EXTENSION)
+ }
+
+// /**
+// * Changes the Java view containing all Java packages and classes as root elements
+// * according to the given modification function.
+// * Records the performed changes, commits the recorded changes, and closes the view afterwards.
+// */
+// def void changeJavaView((View)=>void modelModification) {
+// changeViewRecordingChanges(createJavaView, modelModification)
+// }
+
+// private def View createJavaView() {
+// createViewOfElements("Java packages and classes", #{Package, CompilationUnit})
+// }
+
+// protected def Path getProjectModelPath(String modelName) {
+// Path.of(MODEL_FOLDER_NAME).resolve(modelName + "." + MODEL_FILE_EXTENSION)
+// }
+
+
protected def void createUmlModel((Model)=>void modelInitialization) {
- changeUmlView [
- val umlModel = UMLFactory.eINSTANCE.createModel
- modelInitialization.apply(umlModel)
- createAndRegisterRoot(umlModel, UML_MODEL_NAME.umlProjectModelPath.uri)
- ]
+ changeUmlView [
+ val umlModel = UMLFactory.eINSTANCE.createModel
+ createAndRegisterRoot(umlModel, UML_MODEL_NAME.projectModelPath.uri)
+ modelInitialization.apply(umlModel)
+ ]
+ }
+
+ protected def void createBiggerUmlModel((Model)=>void modelInitialization) {
+ changeUmlView [
+ val component2Class = new FluentUMLClassBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_2_USC +
+ PcmUmlClassApplicationTestHelper.IMPL_SUFFIX, true).addDefaultConstructor.build
+ val component1Class = new FluentUMLClassBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_USC +
+ PcmUmlClassApplicationTestHelper.IMPL_SUFFIX, true).addDefaultConstructor.addAttribute(PROPERTY_NAME,
+ component2Class).build
+ val component1Package = new FluentUMLPackageBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_LSC).
+ addPackagedElement(component1Class).build
+ createAndRegisterRoot(component1Package, UML_MODEL_NAME.projectModelPath.uri)
+ //modelInitialization.apply(component1Package)
+ ]
+
+ }
+
+
+ protected def void createAdvancedUmlModel((Model)=>void modelInitialization) {
+
+ changeUmlView [
+ val resourceSet = new ResourceSetImpl()
+ val model = resourceSet.getResource(URI.createFileURI(UML_MODEL_FILE_PATH), true).firstRootEObject as Model => [
+ name = UML_MODEL_NAME
+ ]
+
+ EcoreUtil.resolveAll(model)
+ // changeJavaView [
+ // createAndRegisterRoot(model, UML_MODEL_NAME.projectModelPath.uri)
+ // ]
+ for (class : model.packagedElements.filter(org.eclipse.uml2.uml.Class).toList) {
+ //assertClassWithNameInRootPackage(class.name)
+ }
+ for (interface : model.packagedElements.filter(org.eclipse.uml2.uml.Interface).toList) {
+ //assertInterfaceWithNameInRootPackage(interface.name)
+ }
+ for (enum : model.packagedElements.filter(org.eclipse.uml2.uml.Enumeration).toList) {
+ //assertEnumWithNameInRootPackage(enum.name)
+ }
+ resourceSet.resources.forEach[unload()]
+ resourceSet.resources.clear()
+
+ createAndRegisterRoot(model, UML_MODEL_NAME.umlProjectModelPath.uri)
+ modelInitialization.apply(model)
+ ]
}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTestFactory.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTestFactory.xtend
index 1bd9b50e9..5a64c811f 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTestFactory.xtend
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTestFactory.xtend
@@ -43,9 +43,8 @@ class FirstTestFactory extends TestViewFactory {
-//-------- Boilerplate code -----------//Kakao
+//-------- Boilerplate code -----------//
-
/**
* Changes the UML view containing all UML models as root elements
* according to the given modification function.
@@ -59,6 +58,17 @@ class FirstTestFactory extends TestViewFactory {
val ViewSelector selector = viewProvider.createSelector(ViewTypeFactory.createIdentityMappingViewType(viewName));
var filteredElements = selector.selectableElements.filter[ element | rootTypes.exists[it.isInstance(element)]]
filteredElements.forEach[element | selector.setSelected(element, true)]
+// selector.selectableElements.forEach[element | selector.setSelected(element, true)]
+ var View view = selector.createView();
+ assertThat("view must not be null", view, not(equalTo(null)));
+ return view;
+ }
+
+ def View createNameFilteredViewOfElements(String viewName, Collection> rootTypes) {
+ val ViewSelector selector = viewProvider.createSelector(ViewTypeFactory.createIdentityMappingViewType(viewName));
+// var filteredElements = selector.selectableElements.filter[ element | rootTypes.exists[it.isInstance(element)]]
+// filteredElements.forEach[element | selector.setSelected(element, true)]
+ selector.selectableElements.forEach[element | selector.setSelected(element, true)]
var View view = selector.createView();
assertThat("view must not be null", view, not(equalTo(null)));
return view;
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
new file mode 100644
index 000000000..4c5a21ed8
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
@@ -0,0 +1,108 @@
+package tools.vitruv.applications.viewfilter.tests;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.function.Consumer;
+
+import tools.vitruv.framework.views.View;
+import tools.vitruv.framework.views.CommittableView;
+import tools.vitruv.framework.views.ViewProvider;
+import tools.vitruv.framework.views.ViewSelector;
+import tools.vitruv.framework.views.ViewTypeFactory;
+import tools.vitruv.testutils.TestViewFactory;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Model;
+import org.palladiosimulator.pcm.repository.RepositoryComponent;
+
+public class ViewTestFactory extends TestViewFactory {
+
+ private ViewProvider viewProvider;
+
+ public ViewTestFactory(ViewProvider viewProvider) {
+ super(viewProvider);
+ this.viewProvider = viewProvider;
+ }
+
+
+ public View createUmlView() {
+ Collection> rootTypes = createCollectionOfRootTypes(Model.class);
+ return createViewOfElements("UML", rootTypes);
+ }
+
+ public View createUmlAndPcmClassesView() {
+ Collection> rootTypes = createCollectionOfRootTypes(createCollectionOfRootTypes(RepositoryComponent.class), Model.class);
+ return createViewOfElements("UML and PCM components", rootTypes);
+ }
+
+
+ public View createFilteredUmlView() {
+ Collection> rootTypes = createCollectionOfRootTypes(Model.class);
+ return createFilteredForNoAttributesViewOfElements("UML", rootTypes);
+ }
+
+
+ //--------------Boilerplate code -----------------//
+ //
+
+ public View createFilteredViewOfElements(String viewName, Collection> rootTypes) {
+ ViewSelector selector = viewProvider.createSelector(ViewTypeFactory.createIdentityMappingViewType(viewName));
+// selector.getSelectableElements().stream()
+// .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
+// .forEach(element -> selector.setSelected(element, true));
+ selector.getSelectableElements().stream().forEach(element -> selector.setSelected(element, true));
+ View view = selector.createView();
+ assertThat("view must not be null", view, not(equalTo(null)));
+ return view;
+ }
+
+
+ /**
+ * Changes the UML view containing all UML models as root elements
+ * according to the given modification function.
+ * Records the performed changes, commits the recorded changes, and closes the view afterwards.
+ */
+ public void changeUmlView(Consumer modelModification) throws Exception {
+ changeViewRecordingChanges(createUmlView(), modelModification);
+ }
+
+
+
+//-------------End of Boilerplate code----------------//
+
+
+ public View createFilteredForNoAttributesViewOfElements(String viewName, Collection> rootTypes) {
+ ViewSelector selector = viewProvider.createSelector(ViewTypeFactory.createIdentityMappingViewType(viewName));
+ selector.getSelectableElements().stream()
+ .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
+ .filter(element -> hasNoAttribute(element))
+ .forEach(element -> selector.setSelected(element, true));
+ //selector.getSelectableElements().stream().forEach(element -> selector.setSelected(element, true));
+ View view = selector.createView();
+ assertThat("view must not be null", view, not(equalTo(null)));
+ return view;
+ }
+
+
+ private boolean hasNoAttribute(EObject object) {
+ object.eAllContents();
+
+ return true;
+ }
+
+
+ private Collection> createCollectionOfRootTypes(Collection> currentCollection, Class> additionalRootType) {
+ currentCollection.add(additionalRootType);
+ return currentCollection;
+ }
+
+ private Collection> createCollectionOfRootTypes(Class> additionalRootType) {
+ Collection> rootTypes = new LinkedList();
+ rootTypes.add(additionalRootType);
+ return rootTypes;
+ }
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/FluentUMLClassBuilder.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/FluentUMLClassBuilder.java
new file mode 100644
index 000000000..91c903d5f
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/FluentUMLClassBuilder.java
@@ -0,0 +1,63 @@
+package tools.vitruv.applications.viewfilter.utils;
+
+import java.util.List;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Interface;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+
+import edu.kit.ipd.sdq.commons.util.java.Pair;
+
+public class FluentUMLClassBuilder {
+ private final Class result;
+
+ public FluentUMLClassBuilder(String name, boolean isFinal) {
+ result = UMLFactory.eINSTANCE.createClass();
+ result.setName(name);
+ result.setIsFinalSpecialization(isFinal);
+ }
+
+ public FluentUMLClassBuilder addDefaultConstructor() {
+ result.createOwnedOperation(result.getName(), new BasicEList<>(), new BasicEList<>());
+ return this;
+ }
+
+ public FluentUMLClassBuilder addParameterizedConstructor(List> parameters) {
+ EList parameterNames = new BasicEList<>();
+ EList parameterTypes = new BasicEList<>();
+ parameters.forEach(parameter -> {
+ parameterNames.add(parameter.get0());
+ parameterTypes.add(parameter.get1());
+ });
+ result.createOwnedOperation(result.getName(), parameterNames, parameterTypes);
+ return this;
+ }
+
+ public FluentUMLClassBuilder addAttribute(String name, Type type) {
+ result.createOwnedAttribute(name, type);
+ return this;
+ }
+
+ public FluentUMLClassBuilder addAttribute(String name, Type type, int lower, int upper) {
+ result.createOwnedAttribute(name, type, lower, upper);
+ return this;
+ }
+
+ public FluentUMLClassBuilder addGeneralization(Classifier parentClassifier) {
+ result.createGeneralization(parentClassifier);
+ return this;
+ }
+
+ public FluentUMLClassBuilder addInterfaceRealization(String name, Interface realizedInterface) {
+ result.createInterfaceRealization(name, realizedInterface);
+ return this;
+ }
+
+ public Class build() {
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/FluentUMLPackageBuilder.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/FluentUMLPackageBuilder.java
new file mode 100644
index 000000000..4b42d0530
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/FluentUMLPackageBuilder.java
@@ -0,0 +1,33 @@
+package tools.vitruv.applications.viewfilter.utils;
+
+import org.eclipse.uml2.uml.UMLFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+
+public class FluentUMLPackageBuilder {
+
+ private final String name;
+ private final List packagedElements = new ArrayList<>();
+
+ public FluentUMLPackageBuilder(String name) {
+ this.name = name;
+ }
+
+ public FluentUMLPackageBuilder addPackagedElement(PackageableElement element) {
+ this.packagedElements.add(element);
+ return this;
+ }
+
+ public Package build() {
+ Package result = UMLFactory.eINSTANCE.createPackage();
+
+ result.setName(name);
+ result.getPackagedElements().addAll(packagedElements);
+
+ return result;
+ }
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/PcmUmlClassApplicationTestHelper.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/PcmUmlClassApplicationTestHelper.xtend
new file mode 100644
index 000000000..720bfcee3
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/PcmUmlClassApplicationTestHelper.xtend
@@ -0,0 +1,14 @@
+package tools.vitruv.applications.viewfilter.utils
+
+class PcmUmlClassApplicationTestHelper {
+
+ public static val IMPL_SUFFIX = "Impl"
+
+ public static val COMPOSITE_DATATYPE_NAME = "TestCompositeType"
+ public static val COMPOSITE_DATATYPE_NAME_2 = "TestCompositeType_2"
+
+ public static val COMPONENT_NAME_USC = "TestComponent"
+ public static val COMPONENT_NAME_LSC = "testComponent"
+ public static val COMPONENT_NAME_2_USC = "TestComponent_2"
+ public static val COMPONENT_NAME_2_LSC = "testComponent_2"
+}
\ No newline at end of file
From da538ced82469e0c433299ad36518023ede92a48 Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Mon, 25 Dec 2023 23:05:42 +0100
Subject: [PATCH 05/62] - some further approaches for filtering
---
.../META-INF/MANIFEST.MF | 5 +-
.../FilterSupportingViewTypeFactory.java | 14 ++
.../util/framework/FilteredViewSelector.java | 9 ++
.../framework/impl/AbstractViewType.xtend | 16 ++
.../util/framework/impl/BasicView.xtend | 151 ++++++++++++++++++
.../framework/impl/ChangeDerivingView.xtend | 105 ++++++++++++
.../framework/impl/ChangeRecordingView.xtend | 76 +++++++++
...lterSupportingIdentityMappingViewType.java | 139 ++++++++++++++++
.../util/framework/impl/ModifiableView.xtend | 14 ++
.../framework/impl/ViewCreatingViewType.java | 45 ++++++
.../selection/AbstractViewSelection.java | 55 +++++++
.../selection/ElementViewSelection.java | 24 +++
.../selectors/DirectViewElementSelector.xtend | 74 +++++++++
.../FilterSupportingViewElementSelector.java | 149 +++++++++++++++++
.../viewfilter/viewbuild/UmlViewBuilder.java | 84 ++++++++++
.../JavaConstructionSimulationTest.xtend | 8 +-
...eResourceWithArraysDefaultFactoryImpl.java | 14 --
.../META-INF/MANIFEST.MF | 4 +-
.../viewfilter/tests/FirstTest.xtend | 58 +++++--
.../viewfilter/tests/ViewTestFactory.java | 52 ++++--
20 files changed, 1049 insertions(+), 47 deletions(-)
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilterSupportingViewTypeFactory.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilteredViewSelector.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractViewType.xtend
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicView.xtend
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeDerivingView.xtend
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeRecordingView.xtend
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ModifiableView.xtend
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ViewCreatingViewType.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/AbstractViewSelection.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/ElementViewSelection.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/DirectViewElementSelector.xtend
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/UmlViewBuilder.java
delete mode 100644 tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java
diff --git a/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
index db1945a3f..602b3311e 100644
--- a/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
+++ b/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
@@ -13,5 +13,8 @@ Require-Bundle: org.eclipse.uml2.uml;visibility:=reexport,
edu.kit.ipd.sdq.commons.util.java,
tools.vitruv.framework.applications,
tools.vitruv.dsls.reactions.runtime,
- tools.vitruv.applications.util.temporary
+ tools.vitruv.applications.util.temporary,
+ tools.vitruv.framework.views;bundle-version="3.0.1"
Bundle-Vendor: vitruv.tools
+Export-Package: tools.vitruv.applications.viewfilter.util.framework,
+ tools.vitruv.applications.viewfilter.util.framework.selectors
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilterSupportingViewTypeFactory.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilterSupportingViewTypeFactory.java
new file mode 100644
index 000000000..e634c5fec
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilterSupportingViewTypeFactory.java
@@ -0,0 +1,14 @@
+package tools.vitruv.applications.viewfilter.util.framework;
+
+import tools.vitruv.applications.viewfilter.util.framework.impl.FilterSupportingIdentityMappingViewType;
+import tools.vitruv.framework.views.ViewSelector;
+import tools.vitruv.framework.views.ViewType;
+
+public class FilterSupportingViewTypeFactory {
+
+ public static ViewType extends ViewSelector> createFilterSupportingIdentityMappingViewType(String name) {
+ return new FilterSupportingIdentityMappingViewType(name);
+
+ }
+
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilteredViewSelector.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilteredViewSelector.java
new file mode 100644
index 000000000..524bd9cef
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/FilteredViewSelector.java
@@ -0,0 +1,9 @@
+package tools.vitruv.applications.viewfilter.util.framework;
+
+import tools.vitruv.framework.views.View;
+import tools.vitruv.framework.views.ViewSelector;
+
+public interface FilteredViewSelector extends ViewSelector {
+
+ View createFilteredView();
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractViewType.xtend b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractViewType.xtend
new file mode 100644
index 000000000..3d464ed06
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractViewType.xtend
@@ -0,0 +1,16 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl
+
+import org.eclipse.xtend.lib.annotations.Accessors
+import tools.vitruv.framework.views.ViewSelector
+
+import static com.google.common.base.Preconditions.checkArgument
+
+abstract package class AbstractViewType implements ViewCreatingViewType {
+ @Accessors(PUBLIC_GETTER)
+ val String name
+
+ new(String name) {
+ checkArgument(name !== null, "view type name must not be null")
+ this.name = name
+ }
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicView.xtend b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicView.xtend
new file mode 100644
index 000000000..bd2ad5b88
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicView.xtend
@@ -0,0 +1,151 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl
+
+import org.eclipse.emf.common.notify.Notification
+import org.eclipse.emf.common.notify.Notifier
+import org.eclipse.emf.common.notify.impl.AdapterImpl
+import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.emf.ecore.resource.ResourceSet
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
+import org.eclipse.xtend.lib.annotations.Accessors
+import tools.vitruv.change.atomic.hid.HierarchicalId
+import tools.vitruv.change.atomic.uuid.Uuid
+import tools.vitruv.change.composite.description.PropagatedChange
+import tools.vitruv.change.composite.description.VitruviusChange
+import tools.vitruv.change.composite.propagation.ChangePropagationListener
+import tools.vitruv.framework.views.ChangeableViewSource
+import tools.vitruv.framework.views.ViewSelection
+import tools.vitruv.framework.views.ViewSelector
+import tools.vitruv.framework.views.changederivation.StateBasedChangeResolutionStrategy
+
+import static com.google.common.base.Preconditions.checkArgument
+import static com.google.common.base.Preconditions.checkState
+
+import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories
+
+package class BasicView implements ModifiableView, ChangePropagationListener {
+ @Accessors(PUBLIC_GETTER, PROTECTED_SETTER)
+ var ViewSelection selection
+ @Accessors(PUBLIC_GETTER, PROTECTED_SETTER)
+ var ViewCreatingViewType extends ViewSelector, HierarchicalId> viewType
+ @Accessors(PUBLIC_GETTER, PROTECTED_SETTER)
+ var ChangeableViewSource viewSource
+ @Accessors(PROTECTED_GETTER)
+ var ResourceSet viewResourceSet
+ boolean modelChanged
+ @Accessors(PROTECTED_SETTER)
+ boolean viewChanged
+ boolean closed
+
+ protected new(ViewCreatingViewType extends ViewSelector, HierarchicalId> viewType, ChangeableViewSource viewSource,
+ ViewSelection selection) {
+ checkArgument(viewType !== null, "view type must not be null")
+ checkArgument(viewSource !== null, "view selection must not be null")
+ checkArgument(selection !== null, "view source must not be null")
+ this.viewType = viewType
+ this.viewSource = viewSource
+ this.selection = selection
+ viewSource.addChangePropagationListener(this)
+ viewResourceSet = new ResourceSetImpl().withGlobalFactories
+ update
+ }
+
+ override getRootObjects() {
+ checkNotClosed()
+ viewResourceSet.resources.map[contents].flatten.toList
+ }
+
+ override isModified() {
+ return viewChanged
+ }
+
+ override isOutdated() {
+ return modelChanged
+ }
+
+ override update() {
+ checkNotClosed()
+ checkState(!isModified, "cannot update from model when view is modified")
+ modelChanged = false
+ viewType.updateView(this)
+ viewChanged = false
+ viewResourceSet.addChangeListeners()
+ }
+
+ override close() throws Exception {
+ if (!closed) {
+ closed = true
+ viewResourceSet.resources.forEach[unload()]
+ viewResourceSet.resources.clear()
+ viewResourceSet.removeChangeListeners()
+ }
+ viewSource.removeChangePropagationListener(this)
+ }
+
+ override isClosed() {
+ return closed
+ }
+
+ override finishedChangePropagation(Iterable propagatedChanges) {
+ modelChanged = true
+ }
+
+ override startedChangePropagation(VitruviusChange changeToPropagate) {
+ // do nothing
+ }
+
+ override void registerRoot(EObject object, URI persistAt) {
+ checkNotClosed()
+ checkArgument(object !== null, "object to register as root must not be null")
+ checkArgument(persistAt !== null, "URI for root to register must not be null")
+ viewResourceSet.createResource(persistAt) => [
+ contents += object
+ ]
+ }
+
+ override void moveRoot(EObject object, URI newLocation) {
+ checkNotClosed()
+ checkArgument(object !== null, "object to move must not be null")
+ checkState(rootObjects.contains(object), "view must contain element %s to move", object)
+ checkArgument(newLocation !== null, "URI for new location of root must not be null")
+ viewResourceSet.resources.findFirst[contents.contains(object)].URI = newLocation
+ }
+
+ def void checkNotClosed() {
+ checkState(!closed, "view is already closed!")
+ }
+
+ private def void addChangeListeners(Notifier notifier) {
+ notifier.eAdapters += new AdapterImpl() {
+ override notifyChanged(Notification message) {
+ viewChanged = true
+ }
+ }
+ switch (notifier) {
+ ResourceSet: notifier.resources.forEach[addChangeListeners()]
+ Resource: notifier.contents.forEach[addChangeListeners()]
+ EObject: notifier.eContents.forEach[addChangeListeners]
+ }
+ }
+
+ private def void removeChangeListeners(ResourceSet resourceSet) {
+ resourceSet.allContents.forEach [
+ eAdapters.clear()
+ ]
+ }
+
+ override modifyContents((ResourceSet)=>void modificationFunction) {
+ modificationFunction.apply(viewResourceSet)
+ }
+
+ override withChangeRecordingTrait() {
+ checkNotClosed()
+ return new ChangeRecordingView(this)
+ }
+
+ override withChangeDerivingTrait(StateBasedChangeResolutionStrategy changeResolutionStrategy) {
+ checkNotClosed()
+ return new ChangeDerivingView(this, changeResolutionStrategy)
+ }
+}
\ No newline at end of file
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeDerivingView.xtend b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeDerivingView.xtend
new file mode 100644
index 000000000..f6bc723d4
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeDerivingView.xtend
@@ -0,0 +1,105 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl
+
+import java.util.ArrayList
+import java.util.HashMap
+import java.util.HashSet
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.emf.ecore.resource.ResourceSet
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
+import org.eclipse.xtend.lib.annotations.Delegate
+import tools.vitruv.change.atomic.hid.HierarchicalId
+import tools.vitruv.change.composite.description.VitruviusChange
+import tools.vitruv.change.composite.description.VitruviusChangeFactory
+import tools.vitruv.framework.views.CommittableView
+import tools.vitruv.framework.views.View
+import tools.vitruv.framework.views.changederivation.StateBasedChangeResolutionStrategy
+
+import static com.google.common.base.Preconditions.checkArgument
+import static com.google.common.base.Preconditions.checkState
+
+import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil.isPathmap
+import edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceCopier
+
+/**
+ * A {@link View} that derives changes based on the changed state of its resources and allows to propagate them
+ * back to the underlying models using the {@link #commitChanges} method.
+ */
+class ChangeDerivingView implements ModifiableView, CommittableView {
+ @Delegate
+ BasicView view
+
+ val StateBasedChangeResolutionStrategy changeResolutionStrategy
+ var ResourceSet originalStateViewResourceSet
+ var HashMap originalStateResourceMapping
+
+ protected new(BasicView view, StateBasedChangeResolutionStrategy changeResolutionStrategy) {
+ checkArgument(view !== null, "view must not be null")
+ checkState(!view.isModified, "view must not be modified")
+ checkState(!view.isOutdated, "view must not be outdated")
+ checkArgument(changeResolutionStrategy !== null, "change resolution strategy must not be null")
+ this.view = view
+ this.changeResolutionStrategy = changeResolutionStrategy
+ setupReferenceState
+ }
+
+ override update() {
+ closeOriginalState
+ view.update
+ setupReferenceState
+ }
+
+ private def setupReferenceState() {
+ originalStateViewResourceSet = new ResourceSetImpl
+ ResourceCopier.copyViewResources(view.viewResourceSet.resources, originalStateViewResourceSet)
+ originalStateResourceMapping = new HashMap
+ view.viewResourceSet.resources.forEach[resource | originalStateResourceMapping.put(resource, originalStateViewResourceSet.resources.findFirst[URI === resource.URI])]
+ }
+
+ override commitChanges() {
+ view.checkNotClosed()
+ val changes = new ArrayList()
+ val allResources = new HashSet(originalStateResourceMapping.keySet)
+ allResources.addAll(view.viewResourceSet.resources) // consider newly added resources
+ for (changedResource : allResources.filter[!URI.isPathmap]) {
+ val change = generateChange(changedResource, originalStateResourceMapping.get(changedResource))
+ changes += change
+ }
+ val change = VitruviusChangeFactory.instance.createCompositeChange(changes)
+ view.viewType.commitViewChanges(this, change)
+ view.viewChanged = false
+ }
+
+ override close() throws Exception {
+ if (!isClosed) {
+ closeOriginalState
+ }
+ view.close
+ }
+
+ private def VitruviusChange generateChange(Resource newState, Resource referenceState) {
+ if (referenceState === null) {
+ return changeResolutionStrategy.getChangeSequenceForCreated(newState)
+ } else if (newState === null) {
+ return changeResolutionStrategy.getChangeSequenceForDeleted(referenceState)
+ } else {
+ return changeResolutionStrategy.getChangeSequenceBetween(newState, referenceState)
+ }
+ }
+
+ private def closeOriginalState() {
+ originalStateViewResourceSet.resources.forEach[unload]
+ originalStateViewResourceSet.resources.clear
+ }
+
+ override withChangeRecordingTrait() {
+ val newView = view.withChangeRecordingTrait
+ closeOriginalState
+ return newView
+ }
+
+ override withChangeDerivingTrait(StateBasedChangeResolutionStrategy changeResolutionStrategy) {
+ val newView = view.withChangeDerivingTrait(changeResolutionStrategy)
+ closeOriginalState
+ return newView
+ }
+}
\ No newline at end of file
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeRecordingView.xtend b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeRecordingView.xtend
new file mode 100644
index 000000000..58ba59358
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ChangeRecordingView.xtend
@@ -0,0 +1,76 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl
+
+import org.eclipse.xtend.lib.annotations.Delegate
+import tools.vitruv.change.composite.description.VitruviusChangeResolver
+import tools.vitruv.change.composite.recording.ChangeRecorder
+import tools.vitruv.framework.views.CommittableView
+import tools.vitruv.framework.views.View
+import tools.vitruv.framework.views.changederivation.StateBasedChangeResolutionStrategy
+
+import static com.google.common.base.Preconditions.checkArgument
+import static com.google.common.base.Preconditions.checkState
+
+/**
+ * A {@link View} that records changes to its resources and allows to propagate them
+ * back to the underlying models using the {@link #commitChanges} method.
+ */
+class ChangeRecordingView implements ModifiableView, CommittableView {
+ @Delegate
+ BasicView view
+ ChangeRecorder changeRecorder
+
+ protected new(BasicView view) {
+ checkArgument(view !== null, "view must not be null")
+ checkState(!view.isModified, "view must not be modified")
+ this.view = view
+ setupChangeRecorder
+ }
+
+ override update() {
+ changeRecorder.endRecordingAndClose()
+ view.update()
+ setupChangeRecorder
+ }
+
+ private def setupChangeRecorder() {
+ changeRecorder = new ChangeRecorder(view.viewResourceSet)
+ changeRecorder.addToRecording(view.viewResourceSet)
+ changeRecorder.beginRecording()
+ }
+
+ override commitChanges() {
+ view.checkNotClosed()
+ val recordedChange = changeRecorder.endRecording()
+ val changeResolver = VitruviusChangeResolver.forHierarchicalIds(view.viewResourceSet)
+ val unresolvedChanges = changeResolver.assignIds(recordedChange)
+ view.viewType.commitViewChanges(this, unresolvedChanges)
+ view.viewChanged = false
+ changeRecorder.beginRecording()
+ }
+
+ override close() throws Exception {
+ if (!isClosed) {
+ changeRecorder.close()
+ }
+ view.close()
+ }
+
+ private def void endRecordingAndClose(ChangeRecorder recorder) {
+ if (recorder.isRecording) {
+ recorder.endRecording()
+ }
+ recorder.close()
+ }
+
+ override withChangeRecordingTrait() {
+ val newView = view.withChangeRecordingTrait
+ changeRecorder.close
+ return newView
+ }
+
+ override withChangeDerivingTrait(StateBasedChangeResolutionStrategy changeResolutionStrategy) {
+ val newView = view.withChangeDerivingTrait(changeResolutionStrategy)
+ changeRecorder.close
+ return newView
+ }
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
new file mode 100644
index 000000000..1bc14782a
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
@@ -0,0 +1,139 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.uml2.uml.internal.resource.UMLResourceImpl;
+
+import edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceCopier;
+import tools.vitruv.applications.viewfilter.util.framework.selectors.DirectViewElementSelector;
+import tools.vitruv.applications.viewfilter.util.framework.selectors.FilterSupportingViewElementSelector;
+import tools.vitruv.change.atomic.hid.HierarchicalId;
+import tools.vitruv.change.atomic.uuid.Uuid;
+import tools.vitruv.change.atomic.uuid.UuidResolver;
+import tools.vitruv.change.composite.description.VitruviusChange;
+import tools.vitruv.change.composite.description.VitruviusChangeResolver;
+import tools.vitruv.framework.views.ChangeableViewSource;
+import tools.vitruv.framework.views.View;
+import tools.vitruv.framework.views.ViewSelection;
+import tools.vitruv.framework.views.ViewSource;
+
+
+/**
+ * A view type that allows creating views based on a basic element-wise
+ * selection mechanism and providing a one-to-one (identity) mapping of elements
+ * within the {@link ViewSource} to a created {@link View}.
+ */
+public class FilterSupportingIdentityMappingViewType extends AbstractViewType, HierarchicalId> {
+ public FilterSupportingIdentityMappingViewType(String name) {
+ super(name);
+ }
+
+
+ @Override
+ public FilterSupportingViewElementSelector createSelector(ChangeableViewSource viewSource) {
+// FilterSupportingViewElementSelector test = new FilterSupportingViewElementSelector<>(this, viewSource,
+// viewSource.getViewSourceModels().stream().map(resource -> {
+// EList allElementsInViewSource = collectAllChildrenInList(resource);
+// return allElementsInViewSource.stream();
+// }).flatMap(Function.identity()).filter(it -> it != null).toList());
+// test.isSelectable(null);
+// return test;
+ return new FilterSupportingViewElementSelector<>(this, viewSource,
+ viewSource.getViewSourceModels().stream().map(resource -> {
+ if (!resource.getContents().isEmpty() && ResourceCopier.requiresFullCopy(resource)) {
+ // Some resources (like UML) can only be copied as a whole, so no option to select
+ // specific root elements
+ return Stream.of(resource.getContents().get(0));
+ }
+ return resource.getContents().stream();
+ }).flatMap(Function.identity()).filter(it -> it != null).toList());
+ }
+
+
+// private EList getAllElementsInViewSource(Resource resource) {
+// if (!resource.getContents().isEmpty() && ResourceCopier.requiresFullCopy(resource)) {
+// // Some resources (like UML) can only be copied as a whole, so no option to select
+// // specific root elements
+// EList list = new BasicEList();
+// list.add(resource.getContents().get(0));
+// return list;
+// }
+// return resource.getContents();
+// }
+
+ @Override
+ public ModifiableView createView(FilterSupportingViewElementSelector selector) {
+ checkArgument(selector.getViewType() == this, "cannot create view with selector for different view type");
+ return new BasicView(selector.getViewType(), selector.getViewSource(), selector.getSelection());
+ }
+
+ @Override
+ public void updateView(ModifiableView view) {
+ view.modifyContents((viewResourceSet) -> {
+ viewResourceSet.getResources().forEach(Resource::unload);
+ viewResourceSet.getResources().clear();
+ createViewResources(view, viewResourceSet);
+ });
+ }
+
+ @Override
+ public void commitViewChanges(ModifiableView view, VitruviusChange viewChange) {
+ ResourceSet viewSourceCopyResourceSet = withGlobalFactories(new ResourceSetImpl());
+ VitruviusChangeResolver idChangeResolver = VitruviusChangeResolver.forHierarchicalIds(viewSourceCopyResourceSet);
+ UuidResolver viewSourceCopyUuidResolver = UuidResolver.create(viewSourceCopyResourceSet);
+ VitruviusChangeResolver uuidChangeResolver = VitruviusChangeResolver.forUuids(viewSourceCopyUuidResolver);
+ Map mapping = createViewResources(view, viewSourceCopyResourceSet);
+ view.getViewSource().getUuidResolver().resolveResources(mapping, viewSourceCopyUuidResolver);
+
+ VitruviusChange resolvedChange = idChangeResolver.resolveAndApply(viewChange);
+ VitruviusChange unresolvedChanges = uuidChangeResolver.assignIds(resolvedChange);
+ view.getViewSource().propagateChange(unresolvedChanges);
+ }
+
+ private Map createViewResources(ModifiableView view, ResourceSet viewResourceSet) {
+ Collection viewSources = view.getViewSource().getViewSourceModels();
+ ViewSelection selection = view.getSelection();
+ List resourcesWithSelectedElements = viewSources.stream()
+ .filter(resource -> resource.getContents().stream().anyMatch(selection::isViewObjectSelected)).toList();
+ return ResourceCopier.copyViewSourceResources(resourcesWithSelectedElements, viewResourceSet,
+ selection::isViewObjectSelected);
+ }
+
+
+ private EList collectAllChildrenInList(Resource resource) {
+ TreeIterator contentInterator = resource.getAllContents();
+ EList children = new BasicEList();
+ while (contentInterator.hasNext()) {
+ EObject next = contentInterator.next();
+ children.addAll(collectAllChildrenInList(next));
+ children.add(next);
+ }
+ return children;
+ }
+
+
+ private EList collectAllChildrenInList(EObject resource) {
+ TreeIterator contentInterator = resource.eAllContents();
+ EList children = new BasicEList();
+ while (contentInterator.hasNext()) {
+ EObject next = contentInterator.next();
+ children.addAll(collectAllChildrenInList(next));
+ children.add(next);
+ }
+ return children;
+ }
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ModifiableView.xtend b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ModifiableView.xtend
new file mode 100644
index 000000000..55fd5fe0a
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ModifiableView.xtend
@@ -0,0 +1,14 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl
+
+import org.eclipse.emf.ecore.resource.ResourceSet
+import tools.vitruv.framework.views.ChangeableViewSource
+import tools.vitruv.framework.views.View
+
+/**
+ * A view whose contents can be modified, in particular by a view type implementation.
+ */
+interface ModifiableView extends View {
+ def void modifyContents((ResourceSet)=>void modificationFunction);
+
+ def ChangeableViewSource getViewSource()
+}
\ No newline at end of file
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ViewCreatingViewType.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ViewCreatingViewType.java
new file mode 100644
index 000000000..f92d8197d
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/ViewCreatingViewType.java
@@ -0,0 +1,45 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl;
+
+import tools.vitruv.change.composite.description.VitruviusChange;
+import tools.vitruv.framework.views.ChangeableViewSource;
+import tools.vitruv.framework.views.ViewSelector;
+import tools.vitruv.framework.views.ViewType;
+
+/**
+ * A specific view type that is able to create and update views. This is not its
+ * public interface but only for internal usage by views and their selectors.
+ *
+ * @param the type of view selector this view type uses.
+ * @param the type of Id the changes to commit must have.
+ */
+public interface ViewCreatingViewType extends ViewType {
+ /**
+ * Creates a view for the given {@link ViewSelector}. The selector must have
+ * been created by calling the {@link #createSelector} method of the same
+ * {@link ViewCreatingViewType}.
+ *
+ * @param selector the {@link ViewSelector} to create a view for
+ * @return a {@link ModifiableView} with elements according to the selector.
+ */
+ ModifiableView createView(S selector);
+
+ /**
+ * Updates a view that is created from this view type to ensure it is consistent
+ * with the virtual model.
+ *
+ * @param view is the view to be updated.
+ */
+ void updateView(ModifiableView view);
+
+ /**
+ * Commits the changes made to the view and its containing elements to the
+ * underlying {@link ChangeableViewSource}. Since view elements do not
+ * necessarily correspond to elements of the underlying view source, the view
+ * type is responsible for transforming the given {@link VitruviusChange} such
+ * that the underlying view source can process it.
+ *
+ * @param view is the modified view.
+ * @param viewChange are the changes performed to the view.
+ */
+ void commitViewChanges(ModifiableView view, VitruviusChange viewChange);
+}
\ No newline at end of file
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/AbstractViewSelection.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/AbstractViewSelection.java
new file mode 100644
index 000000000..7142fae09
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/AbstractViewSelection.java
@@ -0,0 +1,55 @@
+package tools.vitruv.applications.viewfilter.util.framework.selection;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+
+import tools.vitruv.framework.views.ModifiableViewSelection;
+
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public abstract class AbstractViewSelection implements ModifiableViewSelection {
+ final Map elementsSelection = new HashMap<>();
+
+ public AbstractViewSelection(Collection selectableElements) {
+ selectableElements.forEach(object -> this.elementsSelection
+ .put(checkNotNull(object, "element to select must not be null"), false));
+ }
+
+ public AbstractViewSelection(ModifiableViewSelection sourceViewSelection) {
+ this(sourceViewSelection.getSelectableElements());
+ for (EObject selectableElement : sourceViewSelection.getSelectableElements()) {
+ setSelected(selectableElement, sourceViewSelection.isSelected(selectableElement));
+ }
+ }
+
+ private void checkIsSelectable(EObject eObject) {
+ checkState(isSelectable(eObject), "given object %s must be contained in the selector elements", eObject);
+ }
+
+ @Override
+ public boolean isSelected(EObject eObject) {
+ return elementsSelection.getOrDefault(eObject, false);
+ }
+
+ @Override
+ public boolean isSelectable(EObject eObject) {
+ return elementsSelection.keySet().contains(eObject);
+ }
+
+ @Override
+ public Collection getSelectableElements() {
+ return Collections.unmodifiableSet(elementsSelection.keySet());
+ }
+
+ @Override
+ public void setSelected(EObject eObject, boolean selected) {
+ checkIsSelectable(eObject);
+ elementsSelection.put(eObject, selected);
+ }
+
+}
\ No newline at end of file
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/ElementViewSelection.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/ElementViewSelection.java
new file mode 100644
index 000000000..0678dc5a3
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selection/ElementViewSelection.java
@@ -0,0 +1,24 @@
+package tools.vitruv.applications.viewfilter.util.framework.selection;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+
+import tools.vitruv.framework.views.ModifiableViewSelection;
+
+public class ElementViewSelection extends AbstractViewSelection {
+
+ public ElementViewSelection(Collection selectableElements) {
+ super(selectableElements);
+ }
+
+ public ElementViewSelection(ModifiableViewSelection sourceViewSelection) {
+ super(sourceViewSelection);
+ }
+
+ @Override
+ public boolean isViewObjectSelected(EObject eObject) {
+ return isSelected(eObject);
+ }
+
+}
\ No newline at end of file
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/DirectViewElementSelector.xtend b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/DirectViewElementSelector.xtend
new file mode 100644
index 000000000..5b5f84c88
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/DirectViewElementSelector.xtend
@@ -0,0 +1,74 @@
+package tools.vitruv.applications.viewfilter.util.framework.selectors
+
+import java.util.Collection
+import org.eclipse.emf.ecore.EObject
+import org.eclipse.xtend.lib.annotations.Accessors
+import org.eclipse.xtend.lib.annotations.Delegate
+import tools.vitruv.framework.views.ChangeableViewSource
+import tools.vitruv.framework.views.ModifiableViewSelection
+import tools.vitruv.framework.views.ViewSelector
+import tools.vitruv.framework.views.ViewType
+import tools.vitruv.applications.viewfilter.util.framework.selection.ElementViewSelection
+
+import tools.vitruv.applications.viewfilter.util.framework.impl.ViewCreatingViewType
+import static com.google.common.base.Preconditions.checkArgument
+import static com.google.common.base.Preconditions.checkState
+
+/**
+ * A view selector that provides a selection of elements being view objects at
+ * the same time. This means, there is no indirection between selected elements
+ * and view elements (such as selecting types but providing instances in the view),
+ * but a selection is performed on the view elements themselves.
+ */
+class DirectViewElementSelector implements ViewSelector {
+ @Delegate
+ val ModifiableViewSelection viewSelection
+
+ @Accessors(PUBLIC_GETTER)
+ val ChangeableViewSource viewSource
+
+ @Accessors(PUBLIC_GETTER)
+ val ViewCreatingViewType, Id> viewType
+
+ /**
+ * Creates a new selector based on the given collection of selectable elements
+ * for the given {@link ViewType} and {@link ChangeableViewSource}. All arguments
+ * must not be null
.
+ * All elements will be unselected after creation.
+ *
+ * @param viewType - the {@link ViewType} to create a view for when
+ * calling {@link createView}
+ * @param viewSource - the {@link ChangeableViewSource} to create a view
+ * from
+ * @param selectableElements - the elements to select from to be used by the
+ * {@link ViewType} when creating a view
+ */
+ new(ViewCreatingViewType, Id> viewType, ChangeableViewSource viewSource,
+ Collection selectableElements) {
+ checkArgument(selectableElements !== null, "selectable elements must not be null")
+ checkArgument(viewType !== null, "view type must not be null")
+ checkArgument(viewSource !== null, "view source must not be null")
+ this.viewType = viewType
+ this.viewSource = viewSource
+ this.viewSelection = new ElementViewSelection(selectableElements)
+ }
+
+ override createView() {
+ checkState(isValid(), "the current selection is invalid, thus a view cannot be created")
+ return viewType.createView(this)
+ }
+
+ /**
+ * {@link DirectViewElementSelector}s are always valid.
+ */
+ override boolean isValid() {
+ // A basic selection is always valid. In particular, it does not require at least one element to be selected
+ // because it must be possible to create empty views upon creation of a (virtual) model.
+ true
+ }
+
+ override getSelection() {
+ return new ElementViewSelection(viewSelection)
+ }
+
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
new file mode 100644
index 000000000..7cf59d2ab
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
@@ -0,0 +1,149 @@
+package tools.vitruv.applications.viewfilter.util.framework.selectors;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.NamedElement;
+
+import com.google.common.base.Preconditions;
+
+import tools.vitruv.applications.viewfilter.util.framework.impl.ViewCreatingViewType;
+import tools.vitruv.applications.viewfilter.util.framework.selection.ElementViewSelection;
+import tools.vitruv.applications.viewfilter.viewbuild.UmlViewBuilder;
+import tools.vitruv.framework.views.ChangeableViewSource;
+import tools.vitruv.framework.views.ModifiableViewSelection;
+import tools.vitruv.framework.views.View;
+import tools.vitruv.framework.views.ViewSelection;
+import tools.vitruv.framework.views.ViewSelector;
+
+public class FilterSupportingViewElementSelector implements ViewSelector {
+
+ private ModifiableViewSelection viewSelection;
+
+ private ChangeableViewSource viewSource;
+
+ private final ViewCreatingViewType, Id> viewType;
+
+
+ public FilterSupportingViewElementSelector(ViewCreatingViewType, Id> viewType, ChangeableViewSource viewSource, Collection selectableElements) {
+ Preconditions.checkArgument((selectableElements != null), "selectable elements must not be null");
+ Preconditions.checkArgument((viewType != null), "view type must not be null");
+ Preconditions.checkArgument((viewSource != null), "view source must not be null");
+ this.viewType = viewType;
+ this.viewSource = viewSource;
+ //Copy underlying model
+ Collection selectableElementsCopy = EcoreUtil.copyAll(selectableElements);
+ ElementViewSelection _elementViewSelection = new ElementViewSelection(selectableElementsCopy);
+ this.viewSelection = _elementViewSelection;
+ selectAllElements();
+ }
+
+
+ @Override
+ public View createView() {
+ //TODO nbruening ggf noch anpassen
+ Preconditions.checkState(this.isValid(), "the current selection is invalid, thus a view cannot be created");
+ return this.viewType.createView(this);
+ }
+
+ public void selectElementsOfRootType(Collection> rootTypes) {
+ getSelectableElements().stream()
+ .filter(element -> !(rootTypes.stream().anyMatch(it -> it.isInstance(element))))
+ .forEach(element -> setSelected(element, false));
+ }
+
+ public void filterForTypeClass() {
+ getSelectableElements().stream()
+ .filter(element -> !(element instanceof org.eclipse.uml2.uml.Class))
+ .forEach(element -> setSelected(element, false));
+
+ for(EObject element : getSelectableElements()) {
+ if (element instanceof NamedElement) {
+ System.out.println(((NamedElement) element).getName() + ": " + isSelected(element));
+ } else {
+ System.out.println(element.getClass() + ": " + isSelected(element));
+ }
+ }
+
+ //getSelectableElements().stream().forEach(element -> deselect(element));
+ }
+
+ public void filterForName(String name) {
+ getSelectableElements().stream()
+ .filter(element -> !(element instanceof NamedElement))
+ .forEach(element -> setSelected(element, false));
+
+ getSelectableElements().stream()
+ .filter(element -> (element instanceof NamedElement))
+ .filter(element -> !name.equals(((NamedElement) element).getName()))
+ .forEach(element -> setSelected(element, false));
+ }
+
+ public void removeAttributes() {
+ for(EObject object : getSelectableElements()) {
+ if (isSelected(object) && (object instanceof Classifier)) {
+ Classifier currentClassifier = (Classifier) object;
+ EcoreUtil.removeAll(currentClassifier.getAllAttributes());
+ }
+ }
+ }
+
+
+
+ private void deselect(EObject element) {
+ setSelected(element, false);
+ }
+
+
+
+
+
+ private void selectAllElements() {
+ for (EObject element : getSelectableElements()) {
+ setSelected(element, true);
+ }
+ //getSelectableElements().stream().forEach(element -> setSelected(element, true));
+ }
+
+
+ @Override
+ public boolean isValid() {
+ return true;
+ }
+
+ @Override
+ public ViewSelection getSelection() {
+ return new ElementViewSelection(this.viewSelection);
+ }
+
+ public Collection getSelectableElements() {
+ return this.viewSelection.getSelectableElements();
+ }
+
+ public boolean isSelectable(final EObject eObject) {
+ return this.viewSelection.isSelectable(eObject);
+ }
+
+ public boolean isSelected(final EObject eObject) {
+ return this.viewSelection.isSelected(eObject);
+ }
+
+ public boolean isViewObjectSelected(final EObject eObject) {
+ return this.viewSelection.isViewObjectSelected(eObject);
+ }
+
+ public void setSelected(final EObject eObject, final boolean selected) {
+ this.viewSelection.setSelected(eObject, selected);
+ }
+
+ public ChangeableViewSource getViewSource() {
+ return this.viewSource;
+ }
+
+ public ViewCreatingViewType, Id> getViewType() {
+ return this.viewType;
+ }
+
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/UmlViewBuilder.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/UmlViewBuilder.java
new file mode 100644
index 000000000..319a3bea2
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/UmlViewBuilder.java
@@ -0,0 +1,84 @@
+package tools.vitruv.applications.viewfilter.viewbuild;
+
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Model;
+
+import tools.vitruv.applications.viewfilter.util.framework.FilterSupportingViewTypeFactory;
+import tools.vitruv.framework.views.View;
+import tools.vitruv.framework.views.ViewProvider;
+import tools.vitruv.framework.views.ViewSelector;
+import tools.vitruv.framework.views.ViewTypeFactory;
+
+public class UmlViewBuilder {
+
+ private ViewSelector selector;
+
+
+ private UmlViewBuilder(ViewProvider viewProvider) {
+ Collection> rootTypes = createCollectionOfRootTypes(Model.class);
+ createViewOfElements(viewProvider, "UML", rootTypes);
+ }
+
+ public static UmlViewBuilder buildUmlView(ViewProvider viewProvider) {
+ return new UmlViewBuilder(viewProvider);
+ }
+
+
+ public UmlViewBuilder filterForTypeClass() {
+ selector.getSelectableElements().stream()
+ .filter(element -> element instanceof org.eclipse.uml2.uml.Class)
+ .forEach(element -> selector.setSelected(element, true));
+ return this;
+ }
+
+
+
+
+
+
+
+
+
+
+ private void removeAttributes(EObject object) {
+
+ if (object instanceof Classifier) {
+ Classifier currentClassifier = (Classifier) object;
+
+ Classifier classifierCopy = EcoreUtil.copy(currentClassifier);
+ EcoreUtil.remove(object);
+
+ //nbruening Hier weitermachen
+ currentClassifier.allAttributes();
+ currentClassifier.getAttributes();
+
+
+ selector.setSelected(object, true);
+ }
+ }
+
+ /**
+ * Creates a view with the given name containing the provided root types (and
+ * its descendants).
+ */
+ private void createViewOfElements(ViewProvider viewProvider, String viewName, Collection> rootTypes) {
+ ViewSelector selector = viewProvider.createSelector(FilterSupportingViewTypeFactory.createFilterSupportingIdentityMappingViewType(viewName));
+ selector.getSelectableElements().stream()
+ .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
+ .forEach(element -> selector.setSelected(element, true));
+ }
+
+
+ private Collection> createCollectionOfRootTypes(Class> additionalRootType) {
+ Collection> rootTypes = new LinkedList();
+ rootTypes.add(additionalRootType);
+ return rootTypes;
+ }
+
+}
diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend
index 56e1f88b2..b44be0324 100644
--- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend
+++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend
@@ -58,7 +58,7 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest {
@BeforeAll
def static setupJavaFactories() {
- JavaSetup.prepareFactories([new JavaSOCFileResourceWithArraysDefaultFactoryImpl()])
+ JavaSetup.prepareFactories([new JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl()])
}
@AfterEach
@@ -92,9 +92,9 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest {
*/
@Test
def void testOrhanobutLoggerProject() {
- registerStdLibraryModule("java.xml")
- registerLocalLibrary(Path.of(new File("target/dependency/json.jar").absolutePath))
- transformJavaProjectAndValidateUmlModel("resources/orhanobut/java/")
+ //registerStdLibraryModule("java.xml")
+ //registerLocalLibrary(Path.of(new File("target/dependency/json.jar").absolutePath))
+ //transformJavaProjectAndValidateUmlModel("resources/orhanobut/java/")
}
private def Iterable collectJavaFilesInFolder(File folder) {
diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java
deleted file mode 100644
index 5fc75dc5b..000000000
--- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSOCFileResourceWithArraysDefaultFactoryImpl.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package tools.vitruv.applications.umljava.tests.java2uml.constructionsimulationtest;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.emftext.language.java.resource.JavaSourceOrClassFileResourceFactoryImpl;
-
-public class JavaSOCFileResourceWithArraysDefaultFactoryImpl
- extends JavaSourceOrClassFileResourceFactoryImpl {
-
- @Override
- public Resource createResource(URI uri) {
- return new JavaSourceOrClassFileResourceWithArraysDefault(uri);
- }
-}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
index 62a3b5806..a29243e3b 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
+++ b/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
@@ -6,7 +6,9 @@ Bundle-Version: 3.0.1.qualifier
Automatic-Module-Name: tools.vitruv.applications.viewfilter.tests
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: org.junit.jupiter.api,
- org.junit.jupiter.api.extension
+ org.junit.jupiter.api.extension,
+ tools.vitruv.applications.viewfilter.util.framework,
+ tools.vitruv.applications.viewfilter.util.framework.selectors
Require-Bundle: tools.vitruv.testutils.vsum,
org.eclipse.emf.compare,
org.hamcrest.core,
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
index 57a3acefd..8e475484d 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
@@ -24,11 +24,13 @@ import java.io.File
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.emf.ecore.util.EcoreUtil
-import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceUtil.getFirstRootEObject
import tools.vitruv.testutils.RegisterMetamodelsInStandalone
import org.junit.jupiter.api.^extension.ExtendWith
import tools.vitruv.applications.viewfilter.utils.FluentUMLPackageBuilder
+import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceUtil.getFirstRootEObject
+import static extension tools.vitruv.applications.testutility.uml.UmlQueryUtil.*
+
@ExtendWith(RegisterMetamodelsInStandalone)
class FirstTest extends ViewBasedVitruvApplicationTest {
@@ -51,6 +53,11 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
protected var FirstTestFactory viewTestFactory
protected var extension ViewTestFactory improvedViewTestFactory
+ @Accessors(PUBLIC_GETTER)
+ var org.eclipse.uml2.uml.Class class1
+ @Accessors(PUBLIC_GETTER)
+ var org.eclipse.uml2.uml.Class class2
+
override protected getChangePropagationSpecifications() {
return #[
new CombinedPcmToUmlClassReactionsChangePropagationSpecification,
@@ -166,17 +173,40 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
protected def void createBiggerUmlModel((Model)=>void modelInitialization) {
changeUmlView [
- val component2Class = new FluentUMLClassBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_2_USC +
- PcmUmlClassApplicationTestHelper.IMPL_SUFFIX, true).addDefaultConstructor.build
- val component1Class = new FluentUMLClassBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_USC +
- PcmUmlClassApplicationTestHelper.IMPL_SUFFIX, true).addDefaultConstructor.addAttribute(PROPERTY_NAME,
- component2Class).build
- val component1Package = new FluentUMLPackageBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_LSC).
- addPackagedElement(component1Class).build
- createAndRegisterRoot(component1Package, UML_MODEL_NAME.projectModelPath.uri)
- //modelInitialization.apply(component1Package)
+ val umlModel = UMLFactory.eINSTANCE.createModel
+ createAndRegisterRoot(umlModel, UML_MODEL_NAME.projectModelPath.uri)
+ modelInitialization.apply(umlModel)
]
+ userInteraction.addNextSingleSelection(1)
+ userInteraction.addNextTextInput("model/System.system")
+
+ changeUmlView[
+ val package1 = UMLFactory.eINSTANCE.createPackage => [
+ it.name = "niklasPackage"
+ ]
+ class1 = package1.createOwnedClass("niklasClass1", false)
+
+ userInteraction.addNextSingleSelection(1)
+ userInteraction.addNextTextInput("model/System.system")
+
+ val package2 = package1.createNestedPackage("niklasNestedPackage")
+ class2 = package2.createOwnedClass("niklasClass2", false)
+ defaultUmlModel.packagedElements += package1
+
+// val package = umlModel.createNestedPackage("test")
+// package.createOwnedClass("test", false)
+//
+// val component2Class = new FluentUMLClassBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_2_USC +
+// PcmUmlClassApplicationTestHelper.IMPL_SUFFIX, true).addDefaultConstructor.build
+// val component1Class = new FluentUMLClassBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_USC +
+// PcmUmlClassApplicationTestHelper.IMPL_SUFFIX, true).addDefaultConstructor.addAttribute(PROPERTY_NAME,
+// component2Class).build
+// val component1Package = new FluentUMLPackageBuilder(PcmUmlClassApplicationTestHelper.COMPONENT_NAME_LSC).
+// addPackagedElement(component1Class).build
+// umlModel.packagedElements.add(component1Package)
+ ]
+
}
@@ -207,7 +237,13 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
createAndRegisterRoot(model, UML_MODEL_NAME.umlProjectModelPath.uri)
modelInitialization.apply(model)
]
-}
+ }
+
+
+ //----------- UML Model queries ------
+ protected def getDefaultUmlModel(View view) {
+ view.claimUmlModel(UML_MODEL_NAME)
+ }
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
index 4c5a21ed8..2d752216c 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
@@ -3,19 +3,25 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.DynamicTest.stream;
import java.util.Collection;
import java.util.LinkedList;
import java.util.function.Consumer;
import tools.vitruv.framework.views.View;
+import tools.vitruv.applications.viewfilter.util.framework.FilterSupportingViewTypeFactory;
+import tools.vitruv.applications.viewfilter.util.framework.selectors.FilterSupportingViewElementSelector;
import tools.vitruv.framework.views.CommittableView;
import tools.vitruv.framework.views.ViewProvider;
+import tools.vitruv.framework.views.ViewSelection;
import tools.vitruv.framework.views.ViewSelector;
import tools.vitruv.framework.views.ViewTypeFactory;
import tools.vitruv.testutils.TestViewFactory;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Model;
import org.palladiosimulator.pcm.repository.RepositoryComponent;
@@ -40,9 +46,12 @@ public View createUmlAndPcmClassesView() {
}
- public View createFilteredUmlView() {
+ public View createFilteredUmlView(FirstTest test) {
Collection> rootTypes = createCollectionOfRootTypes(Model.class);
- return createFilteredForNoAttributesViewOfElements("UML", rootTypes);
+ View view = createFilteredForNoAttributesViewOfElements("UML", rootTypes);
+ view.getSelection().isViewObjectSelected(test.getClass1());
+ view.getSelection().isViewObjectSelected(test.getClass2());
+ return view;
}
@@ -51,10 +60,10 @@ public View createFilteredUmlView() {
public View createFilteredViewOfElements(String viewName, Collection> rootTypes) {
ViewSelector selector = viewProvider.createSelector(ViewTypeFactory.createIdentityMappingViewType(viewName));
-// selector.getSelectableElements().stream()
-// .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
-// .forEach(element -> selector.setSelected(element, true));
- selector.getSelectableElements().stream().forEach(element -> selector.setSelected(element, true));
+ selector.getSelectableElements().stream()
+ .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
+ .forEach(element -> selector.setSelected(element, true));
+ //selector.getSelectableElements().stream().forEach(element -> selector.setSelected(element, true));
View view = selector.createView();
assertThat("view must not be null", view, not(equalTo(null)));
return view;
@@ -76,22 +85,33 @@ public void changeUmlView(Consumer modelModification) throws Ex
public View createFilteredForNoAttributesViewOfElements(String viewName, Collection> rootTypes) {
- ViewSelector selector = viewProvider.createSelector(ViewTypeFactory.createIdentityMappingViewType(viewName));
- selector.getSelectableElements().stream()
- .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
- .filter(element -> hasNoAttribute(element))
- .forEach(element -> selector.setSelected(element, true));
- //selector.getSelectableElements().stream().forEach(element -> selector.setSelected(element, true));
+ FilterSupportingViewElementSelector selector = (FilterSupportingViewElementSelector) viewProvider.createSelector(FilterSupportingViewTypeFactory.createFilterSupportingIdentityMappingViewType(viewName));
+ //selector.selectElementsOfRootType(rootTypes);
+ selector.filterForTypeClass();
+ selector.filterForName("niklasClass2");
+// selector.getSelectableElements().stream()
+// .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
+// .forEach(element -> selector.setSelected((EObject) element, true));
+
+
View view = selector.createView();
+ ViewSelection selection = view.getSelection();
+
+
assertThat("view must not be null", view, not(equalTo(null)));
return view;
}
- private boolean hasNoAttribute(EObject object) {
- object.eAllContents();
-
- return true;
+ private void hasNoAttribute(ViewSelector selector, EObject object) {
+ if (object instanceof Classifier) {
+ selector.setSelected(object, true);
+ }
+// TreeIterator eAllContents = object.eAllContents();
+// while(eAllContents.hasNext()) {
+// EObject currentObject = eAllContents.next();
+//
+// }
}
From d51f4eac9b84fd5d2b1375713454fdbab8651655 Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Thu, 28 Dec 2023 12:18:28 +0100
Subject: [PATCH 06/62] - Introduced functionality to
FilterSupportingViewElementSelector to create Views with just the filtered
elements
---
.../FilterSupportingViewElementSelector.java | 64 +++++++++++++++++--
.../viewfilter/tests/FirstTest.xtend | 4 ++
.../viewfilter/tests/ViewTestFactory.java | 27 ++++++--
3 files changed, 83 insertions(+), 12 deletions(-)
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
index 7cf59d2ab..1ef1fc1f9 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
@@ -1,8 +1,14 @@
package tools.vitruv.applications.viewfilter.util.framework.selectors;
+import java.io.IOException;
import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.function.Function;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.NamedElement;
@@ -25,6 +31,8 @@ public class FilterSupportingViewElementSelector implements V
private ChangeableViewSource viewSource;
private final ViewCreatingViewType, Id> viewType;
+
+ private List testListObjectsToDisplay = new LinkedList();
public FilterSupportingViewElementSelector(ViewCreatingViewType, Id> viewType, ChangeableViewSource viewSource, Collection selectableElements) {
@@ -55,11 +63,20 @@ public void selectElementsOfRootType(Collection> rootTypes) {
}
public void filterForTypeClass() {
- getSelectableElements().stream()
- .filter(element -> !(element instanceof org.eclipse.uml2.uml.Class))
- .forEach(element -> setSelected(element, false));
+ for (EObject root : getSelectableElements()) {
+ if (isSelected(root)) {
+ TreeIterator contentIterator = root.eAllContents();
+ while(contentIterator.hasNext()) {
+ EObject contentElement = contentIterator.next();
+ if (contentElement instanceof org.eclipse.uml2.uml.Class) {
+ testListObjectsToDisplay.add(contentElement);
+ }
+ }
+ }
+ }
- for(EObject element : getSelectableElements()) {
+
+ for(EObject element : testListObjectsToDisplay) {
if (element instanceof NamedElement) {
System.out.println(((NamedElement) element).getName() + ": " + isSelected(element));
} else {
@@ -67,18 +84,51 @@ public void filterForTypeClass() {
}
}
- //getSelectableElements().stream().forEach(element -> deselect(element));
+
+
+
+ }
+
+ public void filterByLambda(Function filter) {
+ for (EObject root : getSelectableElements()) {
+ if (isSelected(root)) {
+ TreeIterator contentIterator = root.eAllContents();
+ while(contentIterator.hasNext()) {
+ EObject contentElement = contentIterator.next();
+ if (filter.apply(contentElement)) {
+ testListObjectsToDisplay.add(contentElement);
+ }
+ }
+ }
+ }
+
+ for (EObject object : testListObjectsToDisplay) {
+ if (object instanceof org.eclipse.uml2.uml.Class) {
+ org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
+ classifierObject.getOwnedAttributes().toArray();
+ classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
+// try {
+// classifierObject.eResource().save(null);
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ }
+
+ }
+
+ viewSelection = new ElementViewSelection(testListObjectsToDisplay);
}
public void filterForName(String name) {
getSelectableElements().stream()
.filter(element -> !(element instanceof NamedElement))
- .forEach(element -> setSelected(element, false));
+ .forEach(element -> testListObjectsToDisplay.remove(element));
getSelectableElements().stream()
.filter(element -> (element instanceof NamedElement))
.filter(element -> !name.equals(((NamedElement) element).getName()))
- .forEach(element -> setSelected(element, false));
+ .forEach(element -> testListObjectsToDisplay.remove(element));
}
public void removeAttributes() {
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
index 8e475484d..d5aebc054 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
@@ -30,6 +30,7 @@ import tools.vitruv.applications.viewfilter.utils.FluentUMLPackageBuilder
import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceUtil.getFirstRootEObject
import static extension tools.vitruv.applications.testutility.uml.UmlQueryUtil.*
+import org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl
@ExtendWith(RegisterMetamodelsInStandalone)
class FirstTest extends ViewBasedVitruvApplicationTest {
@@ -194,6 +195,9 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
class2 = package2.createOwnedClass("niklasClass2", false)
defaultUmlModel.packagedElements += package1
+ val stringPrimitiveType = package1.createOwnedPrimitiveType("niklasPrimitiveType1");
+ class2.createOwnedAttribute("niklasClass2Attribute", stringPrimitiveType, 0, 1)
+
// val package = umlModel.createNestedPackage("test")
// package.createOwnedClass("test", false)
//
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
index 2d752216c..bdb1bfbe5 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
@@ -8,6 +8,7 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.function.Consumer;
+import java.util.function.Function;
import tools.vitruv.framework.views.View;
import tools.vitruv.applications.viewfilter.util.framework.FilterSupportingViewTypeFactory;
@@ -23,6 +24,7 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.NamedElement;
import org.palladiosimulator.pcm.repository.RepositoryComponent;
public class ViewTestFactory extends TestViewFactory {
@@ -87,8 +89,9 @@ public void changeUmlView(Consumer modelModification) throws Ex
public View createFilteredForNoAttributesViewOfElements(String viewName, Collection> rootTypes) {
FilterSupportingViewElementSelector selector = (FilterSupportingViewElementSelector) viewProvider.createSelector(FilterSupportingViewTypeFactory.createFilterSupportingIdentityMappingViewType(viewName));
//selector.selectElementsOfRootType(rootTypes);
- selector.filterForTypeClass();
- selector.filterForName("niklasClass2");
+ //selector.filterForTypeClass();
+ Function function = (EObject object) -> hasNoAttribute(selector, object, "niklasClass2");
+ selector.filterByLambda(function);
// selector.getSelectableElements().stream()
// .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
// .forEach(element -> selector.setSelected((EObject) element, true));
@@ -96,6 +99,13 @@ public View createFilteredForNoAttributesViewOfElements(String viewName, Collect
View view = selector.createView();
ViewSelection selection = view.getSelection();
+ for (Object element : selector.getSelectableElements()) {
+ if (element instanceof Class) {
+ System.out.println(((Class) element).getName() + ": " + selection.isViewObjectSelected((EObject) element));
+ } else {
+ System.out.println(element.getClass() + ": " + selection.isViewObjectSelected((EObject) element));
+ }
+ }
assertThat("view must not be null", view, not(equalTo(null)));
@@ -103,10 +113,17 @@ public View createFilteredForNoAttributesViewOfElements(String viewName, Collect
}
- private void hasNoAttribute(ViewSelector selector, EObject object) {
- if (object instanceof Classifier) {
- selector.setSelected(object, true);
+ private boolean hasNoAttribute(ViewSelector selector, EObject object, String name) {
+ if (object instanceof org.eclipse.uml2.uml.Class) {
+// if (object instanceof NamedElement) {
+// if (name.equals(((NamedElement) object).getName())) {
+// return true;
+// }
+// }
+ return true;
+
}
+ return false;
// TreeIterator eAllContents = object.eAllContents();
// while(eAllContents.hasNext()) {
// EObject currentObject = eAllContents.next();
From b082263adc2250c643dbfd2e908b11446c2cfc17 Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Fri, 29 Dec 2023 19:44:02 +0100
Subject: [PATCH 07/62] It is now possible to create a view with just the
selected UML objects
---
.../META-INF/MANIFEST.MF | 1 +
.../FilterSupportingViewElementSelector.java | 148 +++++++++---------
.../META-INF/MANIFEST.MF | 1 +
.../viewfilter/tests/FirstTest.xtend | 5 +
.../viewfilter/tests/ViewTestFactory.java | 21 ++-
5 files changed, 90 insertions(+), 86 deletions(-)
diff --git a/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
index 602b3311e..5af91fe59 100644
--- a/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
+++ b/bundles/tools.vitruv.applications.viewtest/META-INF/MANIFEST.MF
@@ -17,4 +17,5 @@ Require-Bundle: org.eclipse.uml2.uml;visibility:=reexport,
tools.vitruv.framework.views;bundle-version="3.0.1"
Bundle-Vendor: vitruv.tools
Export-Package: tools.vitruv.applications.viewfilter.util.framework,
+ tools.vitruv.applications.viewfilter.util.framework.impl,
tools.vitruv.applications.viewfilter.util.framework.selectors
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
index 1ef1fc1f9..37176bb7d 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
@@ -1,23 +1,26 @@
package tools.vitruv.applications.viewfilter.util.framework.selectors;
-import java.io.IOException;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import java.util.function.Function;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
import com.google.common.base.Preconditions;
import tools.vitruv.applications.viewfilter.util.framework.impl.ViewCreatingViewType;
import tools.vitruv.applications.viewfilter.util.framework.selection.ElementViewSelection;
-import tools.vitruv.applications.viewfilter.viewbuild.UmlViewBuilder;
import tools.vitruv.framework.views.ChangeableViewSource;
import tools.vitruv.framework.views.ModifiableViewSelection;
import tools.vitruv.framework.views.View;
@@ -34,6 +37,8 @@ public class FilterSupportingViewElementSelector implements V
private List testListObjectsToDisplay = new LinkedList();
+ private Set rootList;
+
public FilterSupportingViewElementSelector(ViewCreatingViewType, Id> viewType, ChangeableViewSource viewSource, Collection selectableElements) {
Preconditions.checkArgument((selectableElements != null), "selectable elements must not be null");
@@ -45,12 +50,13 @@ public FilterSupportingViewElementSelector(ViewCreatingViewType selectableElementsCopy = EcoreUtil.copyAll(selectableElements);
ElementViewSelection _elementViewSelection = new ElementViewSelection(selectableElementsCopy);
this.viewSelection = _elementViewSelection;
- selectAllElements();
+ rootList = new HashSet();
}
@Override
public View createView() {
+ viewSelection = new ElementViewSelection(rootList);
//TODO nbruening ggf noch anpassen
Preconditions.checkState(this.isValid(), "the current selection is invalid, thus a view cannot be created");
return this.viewType.createView(this);
@@ -62,101 +68,87 @@ public void selectElementsOfRootType(Collection> rootTypes) {
.forEach(element -> setSelected(element, false));
}
- public void filterForTypeClass() {
+
+ public void addElementsToSelectionByLambda(Function filter) {
for (EObject root : getSelectableElements()) {
if (isSelected(root)) {
- TreeIterator contentIterator = root.eAllContents();
- while(contentIterator.hasNext()) {
- EObject contentElement = contentIterator.next();
- if (contentElement instanceof org.eclipse.uml2.uml.Class) {
- testListObjectsToDisplay.add(contentElement);
- }
- }
+ filterAllContents(root, filter, rootList);
}
}
-
-
- for(EObject element : testListObjectsToDisplay) {
- if (element instanceof NamedElement) {
- System.out.println(((NamedElement) element).getName() + ": " + isSelected(element));
- } else {
- System.out.println(element.getClass() + ": " + isSelected(element));
- }
- }
-
-
-
-
}
- public void filterByLambda(Function filter) {
- for (EObject root : getSelectableElements()) {
- if (isSelected(root)) {
- TreeIterator contentIterator = root.eAllContents();
- while(contentIterator.hasNext()) {
- EObject contentElement = contentIterator.next();
- if (filter.apply(contentElement)) {
- testListObjectsToDisplay.add(contentElement);
- }
- }
- }
- }
-
- for (EObject object : testListObjectsToDisplay) {
- if (object instanceof org.eclipse.uml2.uml.Class) {
- org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
- classifierObject.getOwnedAttributes().toArray();
- classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
-// try {
-// classifierObject.eResource().save(null);
-// } catch (IOException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
+
+ private void filterAllContents(EObject root, Function filter, Set rootList) {
+ Model filteredModelRoot = null;
+ Iterator contentIterator = root.eAllContents();
+ while(contentIterator.hasNext()) {
+ EObject contentElement = contentIterator.next();
+ if (filter.apply(contentElement)) {
+ //testListObjectsToDisplay.add(contentElement);
+
+ filteredModelRoot = createFilteredModelRootIfNotExistent(filteredModelRoot, root);
+ attachElementToRoot(filteredModelRoot, contentElement);
+
+ rootList.add(filteredModelRoot);
}
-
}
-
- viewSelection = new ElementViewSelection(testListObjectsToDisplay);
}
- public void filterForName(String name) {
- getSelectableElements().stream()
- .filter(element -> !(element instanceof NamedElement))
- .forEach(element -> testListObjectsToDisplay.remove(element));
+
+ private void attachElementToRoot(Model root, EObject object) {
+ if (object instanceof Type) {
+ EObject objectCopy = EcoreUtil.copy(object);
+ root.getOwnedTypes().add((Type) objectCopy);
+ } else {
+ System.out.println("Warning: Undefined type: " + object.eClass());
+ }
- getSelectableElements().stream()
- .filter(element -> (element instanceof NamedElement))
- .filter(element -> !name.equals(((NamedElement) element).getName()))
- .forEach(element -> testListObjectsToDisplay.remove(element));
}
- public void removeAttributes() {
- for(EObject object : getSelectableElements()) {
- if (isSelected(object) && (object instanceof Classifier)) {
- Classifier currentClassifier = (Classifier) object;
- EcoreUtil.removeAll(currentClassifier.getAllAttributes());
+
+ private Model createFilteredModelRootIfNotExistent(Model filteredRoot, EObject root) {
+ if (filteredRoot == null) {
+ if (root instanceof Model) {
+ return UMLFactory.eINSTANCE.createModel();
+ } else {
+ throw new ImplementationError("nbruening: Not implemented yet");
}
- }
+ }
+ return filteredRoot;
+
}
-
- private void deselect(EObject element) {
- setSelected(element, false);
+ public void removeOwnedAttributesFromClasses() {
+// for (EObject object : testListObjectsToDisplay) {
+// if (object instanceof org.eclipse.uml2.uml.Class) {
+// org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
+// classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
+// }
+// }
+
+ for (EObject root : rootList) {
+ TreeIterator content = root.eAllContents();
+ List contentList = convertTreeIterator2List(content);
+ for (EObject object : contentList) {
+ if (object instanceof org.eclipse.uml2.uml.Class) {
+ org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
+ classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
+ }
+ }
+ }
}
-
-
-
- private void selectAllElements() {
- for (EObject element : getSelectableElements()) {
- setSelected(element, true);
+ private List convertTreeIterator2List(TreeIterator content) {
+ List list = new LinkedList();
+ while(content.hasNext()) {
+ list.add(content.next());
}
- //getSelectableElements().stream().forEach(element -> setSelected(element, true));
+ return list;
}
+
@Override
public boolean isValid() {
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
index a29243e3b..943b4f89c 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
+++ b/tests/tools.vitruv.applications.viewfilter.tests/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: org.junit.jupiter.api,
org.junit.jupiter.api.extension,
tools.vitruv.applications.viewfilter.util.framework,
+ tools.vitruv.applications.viewfilter.util.framework.impl,
tools.vitruv.applications.viewfilter.util.framework.selectors
Require-Bundle: tools.vitruv.testutils.vsum,
org.eclipse.emf.compare,
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
index d5aebc054..ac2f71b85 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
@@ -31,6 +31,9 @@ import tools.vitruv.applications.viewfilter.utils.FluentUMLPackageBuilder
import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceUtil.getFirstRootEObject
import static extension tools.vitruv.applications.testutility.uml.UmlQueryUtil.*
import org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl
+import tools.vitruv.applications.viewfilter.util.framework.impl.FilterSupportingIdentityMappingViewType
+import tools.vitruv.framework.views.ViewSelector
+import tools.vitruv.applications.viewfilter.util.framework.impl.ModifiableView
@ExtendWith(RegisterMetamodelsInStandalone)
class FirstTest extends ViewBasedVitruvApplicationTest {
@@ -92,6 +95,8 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
@Test
def void testCreateFilteredUmlView() {
var view = createFilteredUmlView();
+ (viewType as FilterSupportingIdentityMappingViewType).updateView(view as ModifiableView);
+
view.selection
view.viewType
}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
index bdb1bfbe5..b2ac2ead6 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
@@ -12,11 +12,14 @@
import tools.vitruv.framework.views.View;
import tools.vitruv.applications.viewfilter.util.framework.FilterSupportingViewTypeFactory;
+import tools.vitruv.applications.viewfilter.util.framework.impl.FilterSupportingIdentityMappingViewType;
+import tools.vitruv.applications.viewfilter.util.framework.impl.ViewCreatingViewType;
import tools.vitruv.applications.viewfilter.util.framework.selectors.FilterSupportingViewElementSelector;
import tools.vitruv.framework.views.CommittableView;
import tools.vitruv.framework.views.ViewProvider;
import tools.vitruv.framework.views.ViewSelection;
import tools.vitruv.framework.views.ViewSelector;
+import tools.vitruv.framework.views.ViewType;
import tools.vitruv.framework.views.ViewTypeFactory;
import tools.vitruv.testutils.TestViewFactory;
@@ -30,6 +33,7 @@
public class ViewTestFactory extends TestViewFactory {
private ViewProvider viewProvider;
+ ViewType extends ViewSelector> viewType;
public ViewTestFactory(ViewProvider viewProvider) {
super(viewProvider);
@@ -87,11 +91,13 @@ public void changeUmlView(Consumer modelModification) throws Ex
public View createFilteredForNoAttributesViewOfElements(String viewName, Collection> rootTypes) {
- FilterSupportingViewElementSelector selector = (FilterSupportingViewElementSelector) viewProvider.createSelector(FilterSupportingViewTypeFactory.createFilterSupportingIdentityMappingViewType(viewName));
+ viewType = FilterSupportingViewTypeFactory.createFilterSupportingIdentityMappingViewType(viewName);
+ FilterSupportingViewElementSelector selector = (FilterSupportingViewElementSelector) viewProvider.createSelector(viewType);
//selector.selectElementsOfRootType(rootTypes);
//selector.filterForTypeClass();
Function function = (EObject object) -> hasNoAttribute(selector, object, "niklasClass2");
- selector.filterByLambda(function);
+ selector.addElementsToSelectionByLambda(function);
+ selector.removeOwnedAttributesFromClasses();
// selector.getSelectableElements().stream()
// .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
// .forEach(element -> selector.setSelected((EObject) element, true));
@@ -115,12 +121,11 @@ public View createFilteredForNoAttributesViewOfElements(String viewName, Collect
private boolean hasNoAttribute(ViewSelector selector, EObject object, String name) {
if (object instanceof org.eclipse.uml2.uml.Class) {
-// if (object instanceof NamedElement) {
-// if (name.equals(((NamedElement) object).getName())) {
-// return true;
-// }
-// }
- return true;
+ if (object instanceof NamedElement) {
+ if (name.equals(((NamedElement) object).getName())) {
+ return true;
+ }
+ }
}
return false;
From 2d8b6461f8d4c903eeffb0566849acbca9d3a800 Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Sat, 30 Dec 2023 22:41:44 +0100
Subject: [PATCH 08/62] Structural changes to make update of view possible
---
...lterSupportingIdentityMappingViewType.java | 12 +-
.../FilterSupportingViewElementSelector.java | 80 ++++---
.../viewfilter/viewbuild/ViewFilter.java | 150 +++++++++++++
.../viewfilter/tests/BasicViewFilterTest.java | 210 ++++++++++++++++++
.../viewfilter/tests/FirstTest.xtend | 20 +-
.../viewfilter/tests/ViewTestFactory.java | 23 +-
6 files changed, 441 insertions(+), 54 deletions(-)
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
create mode 100644 tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
index 1bc14782a..951d9aa66 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
@@ -38,6 +38,10 @@
* within the {@link ViewSource} to a created {@link View}.
*/
public class FilterSupportingIdentityMappingViewType extends AbstractViewType, HierarchicalId> {
+
+ private Map mapOriginalRoot2RootStub;
+
+
public FilterSupportingIdentityMappingViewType(String name) {
super(name);
}
@@ -78,6 +82,7 @@ public FilterSupportingViewElementSelector createSelector(Change
@Override
public ModifiableView createView(FilterSupportingViewElementSelector selector) {
checkArgument(selector.getViewType() == this, "cannot create view with selector for different view type");
+ mapOriginalRoot2RootStub = selector.getMapOriginalRoot2RootStub();
return new BasicView(selector.getViewType(), selector.getViewSource(), selector.getSelection());
}
@@ -87,6 +92,7 @@ public void updateView(ModifiableView view) {
viewResourceSet.getResources().forEach(Resource::unload);
viewResourceSet.getResources().clear();
createViewResources(view, viewResourceSet);
+
});
}
@@ -108,9 +114,11 @@ private Map createViewResources(ModifiableView view, Resourc
Collection viewSources = view.getViewSource().getViewSourceModels();
ViewSelection selection = view.getSelection();
List resourcesWithSelectedElements = viewSources.stream()
- .filter(resource -> resource.getContents().stream().anyMatch(selection::isViewObjectSelected)).toList();
+ .filter(resource -> resource.getContents().stream()
+ .anyMatch(element -> mapOriginalRoot2RootStub.get(element) != null ? selection.isViewObjectSelected(mapOriginalRoot2RootStub.get(element)) : false))
+ .toList();
return ResourceCopier.copyViewSourceResources(resourcesWithSelectedElements, viewResourceSet,
- selection::isViewObjectSelected);
+ element -> mapOriginalRoot2RootStub.get(element) != null ? selection.isViewObjectSelected(mapOriginalRoot2RootStub.get(element)) : false);
}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
index 37176bb7d..c091abce6 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
@@ -1,10 +1,12 @@
package tools.vitruv.applications.viewfilter.util.framework.selectors;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.function.Function;
@@ -21,6 +23,7 @@
import tools.vitruv.applications.viewfilter.util.framework.impl.ViewCreatingViewType;
import tools.vitruv.applications.viewfilter.util.framework.selection.ElementViewSelection;
+import tools.vitruv.applications.viewfilter.viewbuild.ViewFilter.ViewFilterBuilder;
import tools.vitruv.framework.views.ChangeableViewSource;
import tools.vitruv.framework.views.ModifiableViewSelection;
import tools.vitruv.framework.views.View;
@@ -37,7 +40,12 @@ public class FilterSupportingViewElementSelector implements V
private List testListObjectsToDisplay = new LinkedList();
- private Set rootList;
+ private Set rootListForView;
+
+ //TODO nbruening: Javadoc
+ private Map mapOriginalRoot2RootStub;
+
+ private ViewFilterBuilder viewFilterBuilder;
public FilterSupportingViewElementSelector(ViewCreatingViewType, Id> viewType, ChangeableViewSource viewSource, Collection selectableElements) {
@@ -47,16 +55,19 @@ public FilterSupportingViewElementSelector(ViewCreatingViewType selectableElementsCopy = EcoreUtil.copyAll(selectableElements);
- ElementViewSelection _elementViewSelection = new ElementViewSelection(selectableElementsCopy);
- this.viewSelection = _elementViewSelection;
- rootList = new HashSet();
+ //Collection selectableElementsCopy = EcoreUtil.copyAll(selectableElements);
+ this.viewSelection = new ElementViewSelection(selectableElements);
+ rootListForView = new HashSet();
+ mapOriginalRoot2RootStub = new HashMap();
+ viewFilterBuilder = new ViewFilterBuilder();
+
}
@Override
public View createView() {
- viewSelection = new ElementViewSelection(rootList);
+ viewSelection = new ElementViewSelection(rootListForView);
+ rootListForView.forEach(element -> setSelected(element, true));
//TODO nbruening ggf noch anpassen
Preconditions.checkState(this.isValid(), "the current selection is invalid, thus a view cannot be created");
return this.viewType.createView(this);
@@ -71,25 +82,39 @@ public void selectElementsOfRootType(Collection> rootTypes) {
public void addElementsToSelectionByLambda(Function filter) {
for (EObject root : getSelectableElements()) {
- if (isSelected(root)) {
- filterAllContents(root, filter, rootList);
- }
+ filterAllContents(root, filter, rootListForView);
}
}
- private void filterAllContents(EObject root, Function filter, Set rootList) {
- Model filteredModelRoot = null;
+ public void removeOwnedAttributesFromClasses() {
+ for (EObject root : rootListForView) {
+ TreeIterator content = root.eAllContents();
+ List contentList = convertTreeIterator2List(content);
+ for (EObject object : contentList) {
+ if (object instanceof org.eclipse.uml2.uml.Class) {
+ org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
+ classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
+ }
+ }
+ }
+ }
+
+
+ private void filterAllContents(EObject root, Function filter, Set rootListForView) {
+ Model filteredModelRootStub = null;
Iterator contentIterator = root.eAllContents();
while(contentIterator.hasNext()) {
EObject contentElement = contentIterator.next();
if (filter.apply(contentElement)) {
//testListObjectsToDisplay.add(contentElement);
- filteredModelRoot = createFilteredModelRootIfNotExistent(filteredModelRoot, root);
- attachElementToRoot(filteredModelRoot, contentElement);
+ filteredModelRootStub = createFilteredModelRootIfNotExistent(filteredModelRootStub, root);
+ EObject copyOfContentElement = EcoreUtil.copy(contentElement);
+ attachElementToRoot(filteredModelRootStub, copyOfContentElement);
- rootList.add(filteredModelRoot);
+ rootListForView.add(filteredModelRootStub);
+ mapOriginalRoot2RootStub.put(root, filteredModelRootStub);
}
}
}
@@ -119,27 +144,6 @@ private Model createFilteredModelRootIfNotExistent(Model filteredRoot, EObject r
}
- public void removeOwnedAttributesFromClasses() {
-// for (EObject object : testListObjectsToDisplay) {
-// if (object instanceof org.eclipse.uml2.uml.Class) {
-// org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
-// classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
-// }
-// }
-
- for (EObject root : rootList) {
- TreeIterator content = root.eAllContents();
- List contentList = convertTreeIterator2List(content);
- for (EObject object : contentList) {
- if (object instanceof org.eclipse.uml2.uml.Class) {
- org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
- classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
- }
- }
- }
- }
-
-
private List convertTreeIterator2List(TreeIterator content) {
List list = new LinkedList();
while(content.hasNext()) {
@@ -147,8 +151,6 @@ private List convertTreeIterator2List(TreeIterator content) {
}
return list;
}
-
-
@Override
public boolean isValid() {
@@ -187,5 +189,9 @@ public ChangeableViewSource getViewSource() {
public ViewCreatingViewType, Id> getViewType() {
return this.viewType;
}
+
+ public Map getMapOriginalRoot2RootStub() {
+ return mapOriginalRoot2RootStub;
+ }
}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
new file mode 100644
index 000000000..7b3b5a6ab
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
@@ -0,0 +1,150 @@
+package tools.vitruv.applications.viewfilter.viewbuild;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+
+public class ViewFilter {
+
+ private Set rootListForView;
+
+ //TODO nbruening: Javadoc
+ private Map mapOriginalRoot2RootStub;
+
+ private final ViewFilterBuilder builder;
+
+ private ViewFilter(ViewFilterBuilder viewFilterBuilder) {
+ builder = viewFilterBuilder;
+ }
+
+
+ public void filterElements(Collection roots) {
+ addElementsToSelectionByLambda(roots);
+ }
+
+
+ private void addElementsToSelectionByLambda(Collection roots) {
+ if (!builder.filterByLambdaActive) {
+ return;
+ }
+ for (EObject root : roots) {
+ filterAllContents(root, builder.filter, rootListForView);
+ }
+ }
+
+ public void removeOwnedAttributesFromClasses() {
+ if (!builder.removeAttributesActive) {
+ return;
+ }
+ for (EObject root : rootListForView) {
+ TreeIterator content = root.eAllContents();
+ List contentList = convertTreeIterator2List(content);
+ for (EObject object : contentList) {
+ if (object instanceof org.eclipse.uml2.uml.Class) {
+ org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
+ classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
+ }
+ }
+ }
+ }
+
+
+ private void filterAllContents(EObject root, Function filter, Set rootListForView) {
+ Model filteredModelRootStub = null;
+ Iterator contentIterator = root.eAllContents();
+ while(contentIterator.hasNext()) {
+ EObject contentElement = contentIterator.next();
+ if (filter.apply(contentElement)) {
+ //testListObjectsToDisplay.add(contentElement);
+
+ filteredModelRootStub = createFilteredModelRootIfNotExistent(filteredModelRootStub, root);
+ EObject copyOfContentElement = EcoreUtil.copy(contentElement);
+ attachElementToRoot(filteredModelRootStub, copyOfContentElement);
+
+ rootListForView.add(filteredModelRootStub);
+ mapOriginalRoot2RootStub.put(root, filteredModelRootStub);
+ }
+ }
+ }
+
+
+ private List convertTreeIterator2List(TreeIterator content) {
+ List list = new LinkedList();
+ while(content.hasNext()) {
+ list.add(content.next());
+ }
+ return list;
+ }
+
+
+ private void attachElementToRoot(Model root, EObject object) {
+ if (object instanceof Type) {
+ EObject objectCopy = EcoreUtil.copy(object);
+ root.getOwnedTypes().add((Type) objectCopy);
+ } else {
+ System.out.println("Warning: Undefined type: " + object.eClass());
+ }
+ }
+
+
+ private Model createFilteredModelRootIfNotExistent(Model filteredRoot, EObject root) {
+ if (filteredRoot == null) {
+ if (root instanceof Model) {
+ return UMLFactory.eINSTANCE.createModel();
+ } else {
+ throw new ImplementationError("nbruening: Not implemented yet");
+ }
+ }
+ return filteredRoot;
+ }
+
+
+//---------------------------------
+ /**
+ * Builder for ViewFilter
+ */
+ public static class ViewFilterBuilder {
+
+ //optional parameters
+ private Boolean filterByLambdaActive = false;
+
+ private Boolean removeAttributesActive = false;
+
+ private Function filter;
+
+
+ public ViewFilterBuilder() {
+
+ }
+
+ public ViewFilterBuilder filterByLambda(Function filter) {
+ this.filterByLambdaActive = true;
+ this.filter = filter;
+ return this;
+ }
+
+ public ViewFilterBuilder removeOwnedAttributes() {
+ this.removeAttributesActive = true;
+ return this;
+ }
+
+ public ViewFilter build() {
+ return new ViewFilter(this);
+ }
+
+
+ }
+
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
new file mode 100644
index 000000000..4dd0ef3f0
--- /dev/null
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
@@ -0,0 +1,210 @@
+package tools.vitruv.applications.viewfilter.tests;
+
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.function.Consumer;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.xtend.lib.annotations.AccessorType;
+import org.eclipse.xtend.lib.annotations.Accessors;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.eclipse.xtext.xbase.lib.InputOutput;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.Pure;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import tools.vitruv.applications.pcmumlclass.CombinedPcmToUmlClassReactionsChangePropagationSpecification;
+import tools.vitruv.applications.pcmumlclass.CombinedUmlClassToPcmReactionsChangePropagationSpecification;
+import tools.vitruv.applications.testutility.uml.UmlQueryUtil;
+import tools.vitruv.applications.viewfilter.util.framework.impl.FilterSupportingIdentityMappingViewType;
+import tools.vitruv.applications.viewfilter.util.framework.impl.ModifiableView;
+import tools.vitruv.change.propagation.ChangePropagationSpecification;
+import tools.vitruv.framework.views.CommittableView;
+import tools.vitruv.framework.views.View;
+import tools.vitruv.framework.vsum.VirtualModel;
+import tools.vitruv.testutils.RegisterMetamodelsInStandalone;
+import tools.vitruv.testutils.ViewBasedVitruvApplicationTest;
+
+@ExtendWith(RegisterMetamodelsInStandalone.class)
+public class BasicViewFilterTest extends ViewBasedVitruvApplicationTest {
+
+ @Accessors(AccessorType.PROTECTED_GETTER)
+ private static final String UML_MODEL_NAME = "model";
+
+ @Accessors(AccessorType.PROTECTED_GETTER)
+ private static final String MODEL_FOLDER_NAME = "model";
+
+ @Accessors(AccessorType.PROTECTED_GETTER)
+ private static final String MODEL_FILE_EXTENSION = "uml";
+
+ @Accessors(AccessorType.PUBLIC_GETTER)
+ private org.eclipse.uml2.uml.Class class1;
+
+ @Accessors(AccessorType.PUBLIC_GETTER)
+ private org.eclipse.uml2.uml.Class class2;
+
+ protected ViewTestFactory improvedViewTestFactory;
+
+ @Test
+ public void testCreateSystemConcept_PCM() {
+ System.out.println("Hello world");
+ }
+
+ @Test
+ public void testView() {
+ improvedViewTestFactory.createUmlView();
+ }
+
+ @Test
+ public void testCreateUmlPcmView() {
+ improvedViewTestFactory.createUmlAndPcmClassesView();
+ }
+
+ @Test
+ public void testCreateFilteredUmlView() {
+ View view = improvedViewTestFactory.createFilteredUmlView(this);
+// ((FilterSupportingIdentityMappingViewType) improvedViewTestFactory.viewType)
+// .updateView(((ModifiableView) view));
+
+ modifyModel();
+
+ view.update();
+
+ //view.getRootObjects();
+ //Object object = view.withChangeDerivingTrait().getRootObjects().toArray()[0];
+ view.getSelection();
+ view.getRootObjects();
+ view.getViewType();
+ }
+
+// @Test
+// public void testFilterForName() {
+// final Procedure1 _function = (Model it) -> {
+// it.setName((FirstTest.UML_MODEL_NAME + "big"));
+// };
+// this.createAdvancedUmlModel(_function);
+// }
+
+ @Override
+ protected Iterable extends ChangePropagationSpecification> getChangePropagationSpecifications() {
+ CombinedPcmToUmlClassReactionsChangePropagationSpecification _combinedPcmToUmlClassReactionsChangePropagationSpecification = new CombinedPcmToUmlClassReactionsChangePropagationSpecification();
+ CombinedUmlClassToPcmReactionsChangePropagationSpecification _combinedUmlClassToPcmReactionsChangePropagationSpecification = new CombinedUmlClassToPcmReactionsChangePropagationSpecification();
+ return Collections.unmodifiableList(
+ CollectionLiterals.newArrayList(
+ _combinedPcmToUmlClassReactionsChangePropagationSpecification,
+ _combinedUmlClassToPcmReactionsChangePropagationSpecification));
+ }
+
+ @BeforeEach
+ public void setup() {
+ improvedViewTestFactory = new ViewTestFactory(getVirtualModel());
+ final Procedure1 setNameFunction = (Model it) -> {
+ it.setName(UML_MODEL_NAME);
+ };
+ createBiggerUmlModel(setNameFunction);
+ }
+
+ protected void createBiggerUmlModel(final Procedure1 super Model> modelInitialization) {
+ try {
+ final Consumer firstChangeUmlFunction = (CommittableView it) -> {
+ final Model umlModel = UMLFactory.eINSTANCE.createModel();
+ createAndRegisterRoot(it, umlModel, this.getUri(getProjectModelPath(UML_MODEL_NAME)));
+ modelInitialization.apply(umlModel);
+ };
+ improvedViewTestFactory.changeUmlView(firstChangeUmlFunction);
+
+ getUserInteraction().addNextSingleSelection(1);
+ getUserInteraction().addNextTextInput("model/System.system");
+
+ final Consumer secondChangeUmlFunction = (CommittableView it) -> {
+ org.eclipse.uml2.uml.Package _createPackage = UMLFactory.eINSTANCE.createPackage();
+ Procedure1 setNameFunction = (org.eclipse.uml2.uml.Package it_1) -> {
+ it_1.setName("niklasPackage");
+ };
+
+ org.eclipse.uml2.uml.Package package1 = UMLFactory.eINSTANCE.createPackage();
+ package1.setName("niklasPackage");
+
+ class1 = package1.createOwnedClass("niklasClass1", false);
+
+ getUserInteraction().addNextSingleSelection(1);
+ getUserInteraction().addNextTextInput("model/System.system");
+ org.eclipse.uml2.uml.Package package2 = package1.createNestedPackage("niklasNestedPackage");
+
+ class2 = package2.createOwnedClass("niklasClass2", false);
+ EList _packagedElements = getDefaultUmlModel(it).getPackagedElements();
+ _packagedElements.add(package1);
+
+ // create Attribute for class2
+ PrimitiveType stringPrimitiveType = package1.createOwnedPrimitiveType("niklasPrimitiveType1");
+ class2.createOwnedAttribute("niklasClass2Attribute", stringPrimitiveType, 0, 1);
+ };
+ improvedViewTestFactory.changeUmlView(secondChangeUmlFunction);
+
+ } catch (Throwable _e) {
+ throw Exceptions.sneakyThrow(_e);
+ }
+ }
+
+
+ private void modifyModel() {
+ try {
+ getUserInteraction().addNextSingleSelection(1);
+ getUserInteraction().addNextTextInput("model/System.system");
+
+ Consumer changeUmlFunction = (CommittableView it) -> {
+ org.eclipse.uml2.uml.Package package3 = UMLFactory.eINSTANCE.createPackage();
+ package3.setName("niklasPackage3");
+
+ org.eclipse.uml2.uml.Class class3 = package3.createOwnedClass("niklasClass3", false);
+
+ class2.addKeyword("subsequentlyAddedKeyword");
+
+ final Comment comment = this.class2.createOwnedComment();
+ comment.addKeyword("bla");
+
+ getDefaultUmlModel(it).getPackagedElements().add(package3);
+ };
+
+ improvedViewTestFactory.changeUmlView(changeUmlFunction);
+ } catch (Throwable _e) {
+ throw Exceptions.sneakyThrow(_e);
+ }
+ }
+
+
+
+ protected void createAndRegisterRoot(final View view, final EObject rootObject, final URI persistenceUri) {
+ view.registerRoot(rootObject, persistenceUri);
+ }
+
+ protected Path getProjectModelPath(final String modelName) {
+ return Path.of(MODEL_FOLDER_NAME).resolve(((modelName + ".") + MODEL_FILE_EXTENSION));
+ }
+
+ protected Model getDefaultUmlModel(final View view) {
+ return UmlQueryUtil.claimUmlModel(view, UML_MODEL_NAME);
+ }
+
+ @Pure
+ public org.eclipse.uml2.uml.Class getClass1() {
+ return this.class1;
+ }
+
+ @Pure
+ public org.eclipse.uml2.uml.Class getClass2() {
+ return this.class2;
+ }
+
+}
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
index ac2f71b85..8d6aefa5e 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/FirstTest.xtend
@@ -71,7 +71,7 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
@BeforeEach
def void setup() {
- viewTestFactory = new FirstTestFactory(virtualModel)
+ //viewTestFactory = new FirstTestFactory(virtualModel)
improvedViewTestFactory = new ViewTestFactory(virtualModel)
createBiggerUmlModel[name = UML_MODEL_NAME]
}
@@ -95,6 +95,8 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
@Test
def void testCreateFilteredUmlView() {
var view = createFilteredUmlView();
+ //modifyModel()
+
(viewType as FilterSupportingIdentityMappingViewType).updateView(view as ModifiableView);
view.selection
@@ -218,6 +220,22 @@ class FirstTest extends ViewBasedVitruvApplicationTest {
}
+
+ private def void modifyModel() {
+ userInteraction.addNextSingleSelection(1)
+ userInteraction.addNextTextInput("model/System.system")
+ changeUmlView[
+ val package3 = UMLFactory.eINSTANCE.createPackage => [
+ it.name = "niklasPackage3"
+ ]
+ val class3 = package3.createOwnedClass("niklasClass3", false)
+ class2.addKeyword("subsequentlyAddedKeyword")
+ val comment = class2.createOwnedComment
+ comment.addKeyword("bla")
+ defaultUmlModel.packagedElements += package3
+ ]
+ }
+
protected def void createAdvancedUmlModel((Model)=>void modelInitialization) {
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
index b2ac2ead6..1ef5741a5 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/ViewTestFactory.java
@@ -60,6 +60,14 @@ public View createFilteredUmlView(FirstTest test) {
return view;
}
+ public View createFilteredUmlView(BasicViewFilterTest test) {
+ Collection> rootTypes = createCollectionOfRootTypes(Model.class);
+ View view = createFilteredForNoAttributesViewOfElements("UML", rootTypes);
+ view.getSelection().isViewObjectSelected(test.getClass1());
+ view.getSelection().isViewObjectSelected(test.getClass2());
+ return view;
+ }
+
//--------------Boilerplate code -----------------//
//
@@ -69,7 +77,6 @@ public View createFilteredViewOfElements(String viewName, Collection> r
selector.getSelectableElements().stream()
.filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
.forEach(element -> selector.setSelected(element, true));
- //selector.getSelectableElements().stream().forEach(element -> selector.setSelected(element, true));
View view = selector.createView();
assertThat("view must not be null", view, not(equalTo(null)));
return view;
@@ -93,15 +100,9 @@ public void changeUmlView(Consumer modelModification) throws Ex
public View createFilteredForNoAttributesViewOfElements(String viewName, Collection> rootTypes) {
viewType = FilterSupportingViewTypeFactory.createFilterSupportingIdentityMappingViewType(viewName);
FilterSupportingViewElementSelector selector = (FilterSupportingViewElementSelector) viewProvider.createSelector(viewType);
- //selector.selectElementsOfRootType(rootTypes);
- //selector.filterForTypeClass();
Function function = (EObject object) -> hasNoAttribute(selector, object, "niklasClass2");
selector.addElementsToSelectionByLambda(function);
- selector.removeOwnedAttributesFromClasses();
-// selector.getSelectableElements().stream()
-// .filter(element -> rootTypes.stream().anyMatch(it -> it.isInstance(element)))
-// .forEach(element -> selector.setSelected((EObject) element, true));
-
+ selector.removeOwnedAttributesFromClasses();
View view = selector.createView();
ViewSelection selection = view.getSelection();
@@ -113,7 +114,6 @@ public View createFilteredForNoAttributesViewOfElements(String viewName, Collect
}
}
-
assertThat("view must not be null", view, not(equalTo(null)));
return view;
}
@@ -129,11 +129,6 @@ private boolean hasNoAttribute(ViewSelector selector, EObject object, String nam
}
return false;
-// TreeIterator eAllContents = object.eAllContents();
-// while(eAllContents.hasNext()) {
-// EObject currentObject = eAllContents.next();
-//
-// }
}
From f828e70fe4300167f4b3f607f045ebc1d48d2b4b Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Thu, 4 Jan 2024 20:15:33 +0100
Subject: [PATCH 09/62] - Translated FirstTest.xtend into BasicViewTest.java,
minor fixes
Some minor fixes, added modifyView method
---
.../{ViewFilter.java => ViewFilterImpl.java} | 0
.../viewfilter/tests/BasicViewFilterTest.java | 16 ++++++++++++++++
2 files changed, 16 insertions(+)
rename bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/{ViewFilter.java => ViewFilterImpl.java} (100%)
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
similarity index 100%
rename from bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
rename to bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
index 4dd0ef3f0..9cfbc74cf 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
@@ -5,8 +5,10 @@
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.PackageableElement;
@@ -172,8 +174,22 @@ private void modifyModel() {
class2.addKeyword("subsequentlyAddedKeyword");
final Comment comment = this.class2.createOwnedComment();
+ comment.setBody("niklasCommentClass2");
+ String name = "niklasClass2";
comment.addKeyword("bla");
+ TreeIterator umlIterator = getDefaultUmlModel(it).eAllContents();
+ org.eclipse.uml2.uml.Class searchedClass = null;
+ while ((searchedClass == null) && (umlIterator.hasNext())) {
+ EObject next = umlIterator.next();
+ if (next instanceof org.eclipse.uml2.uml.Class) {
+ if (name.equals(((Classifier) next).getName())) {
+ searchedClass = (org.eclipse.uml2.uml.Class) next;
+ }
+ }
+ }
+ searchedClass.getOwnedComments().add(comment);
+
getDefaultUmlModel(it).getPackagedElements().add(package3);
};
From eaa780a6dd8c501052a49095d78c8daf8148be92 Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Thu, 4 Jan 2024 20:17:38 +0100
Subject: [PATCH 10/62] improved selection of individual elements as
preparation
Preparation to make update of filtered view work
---
.../AbstractFilterSupportingViewType.java | 15 ++
.../util/framework/impl/BasicFilterView.java | 38 ++++
...lterSupportingIdentityMappingViewType.java | 5 +-
.../impl/FilteredViewCreatingViewType.java | 8 +
.../FilterSupportingViewElementSelector.java | 213 +++++++-----------
.../viewfilter/viewbuild/ViewFilter.java | 14 ++
.../viewfilter/viewbuild/ViewFilterImpl.java | 33 ++-
7 files changed, 175 insertions(+), 151 deletions(-)
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractFilterSupportingViewType.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilteredViewCreatingViewType.java
create mode 100644 bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractFilterSupportingViewType.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractFilterSupportingViewType.java
new file mode 100644
index 000000000..b532bc621
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/AbstractFilterSupportingViewType.java
@@ -0,0 +1,15 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl;
+
+import tools.vitruv.framework.views.ViewSelector;
+
+public abstract class AbstractFilterSupportingViewType extends AbstractViewType implements FilteredViewCreatingViewType {
+
+ public AbstractFilterSupportingViewType(String name) {
+ super(name);
+ }
+
+
+
+
+
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java
new file mode 100644
index 000000000..b5a753f36
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java
@@ -0,0 +1,38 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl;
+
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
+
+import tools.vitruv.applications.viewfilter.util.framework.selection.ElementViewSelection;
+import tools.vitruv.applications.viewfilter.viewbuild.ViewFilter;
+import tools.vitruv.change.atomic.hid.HierarchicalId;
+import tools.vitruv.framework.views.ChangeableViewSource;
+import tools.vitruv.framework.views.ViewSelection;
+import tools.vitruv.framework.views.ViewSelector;
+
+public class BasicFilterView extends BasicView {
+
+ private ViewFilter viewFilter;
+
+ protected BasicFilterView(FilteredViewCreatingViewType extends ViewSelector, HierarchicalId> viewType,
+ ChangeableViewSource viewSource, ViewSelection selection, ViewFilter viewFilter) {
+ super(viewType, viewSource, selection);
+ this.viewFilter = viewFilter;
+ }
+
+ @Override
+ public void modifyContents(Procedure1 super ResourceSet> modificationFunction) {
+ super.modifyContents(modificationFunction);
+ filterSelectedElements();
+ }
+
+
+ private void filterSelectedElements() {
+ Set filteredElements = viewFilter.filterElements(getRootObjects());
+ setSelection(new ElementViewSelection(filteredElements));
+ }
+
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
index 951d9aa66..f69d9fae7 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilterSupportingIdentityMappingViewType.java
@@ -37,7 +37,7 @@
* selection mechanism and providing a one-to-one (identity) mapping of elements
* within the {@link ViewSource} to a created {@link View}.
*/
-public class FilterSupportingIdentityMappingViewType extends AbstractViewType, HierarchicalId> {
+public class FilterSupportingIdentityMappingViewType extends AbstractFilterSupportingViewType, HierarchicalId> {
private Map mapOriginalRoot2RootStub;
@@ -83,7 +83,7 @@ public FilterSupportingViewElementSelector createSelector(Change
public ModifiableView createView(FilterSupportingViewElementSelector selector) {
checkArgument(selector.getViewType() == this, "cannot create view with selector for different view type");
mapOriginalRoot2RootStub = selector.getMapOriginalRoot2RootStub();
- return new BasicView(selector.getViewType(), selector.getViewSource(), selector.getSelection());
+ return new BasicFilterView(selector.getViewType(), selector.getViewSource(), selector.getSelection(), selector.getViewFilter());
}
@Override
@@ -92,7 +92,6 @@ public void updateView(ModifiableView view) {
viewResourceSet.getResources().forEach(Resource::unload);
viewResourceSet.getResources().clear();
createViewResources(view, viewResourceSet);
-
});
}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilteredViewCreatingViewType.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilteredViewCreatingViewType.java
new file mode 100644
index 000000000..9bbfdc23b
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/FilteredViewCreatingViewType.java
@@ -0,0 +1,8 @@
+package tools.vitruv.applications.viewfilter.util.framework.impl;
+
+import tools.vitruv.framework.views.ViewSelector;
+import tools.vitruv.framework.views.ViewType;
+
+public interface FilteredViewCreatingViewType extends ViewCreatingViewType {
+
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
index c091abce6..3d3989f83 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/selectors/FilterSupportingViewElementSelector.java
@@ -1,6 +1,7 @@
package tools.vitruv.applications.viewfilter.util.framework.selectors;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -21,9 +22,12 @@
import com.google.common.base.Preconditions;
+import tools.vitruv.applications.viewfilter.util.framework.impl.FilteredViewCreatingViewType;
import tools.vitruv.applications.viewfilter.util.framework.impl.ViewCreatingViewType;
import tools.vitruv.applications.viewfilter.util.framework.selection.ElementViewSelection;
-import tools.vitruv.applications.viewfilter.viewbuild.ViewFilter.ViewFilterBuilder;
+import tools.vitruv.applications.viewfilter.viewbuild.ViewFilter;
+import tools.vitruv.applications.viewfilter.viewbuild.ViewFilterImpl;
+import tools.vitruv.applications.viewfilter.viewbuild.ViewFilterImpl.ViewFilterBuilder;
import tools.vitruv.framework.views.ChangeableViewSource;
import tools.vitruv.framework.views.ModifiableViewSelection;
import tools.vitruv.framework.views.View;
@@ -31,125 +35,56 @@
import tools.vitruv.framework.views.ViewSelector;
public class FilterSupportingViewElementSelector implements ViewSelector {
-
+
private ModifiableViewSelection viewSelection;
-
+
private ChangeableViewSource viewSource;
-
- private final ViewCreatingViewType, Id> viewType;
-
- private List testListObjectsToDisplay = new LinkedList();
-
- private Set rootListForView;
-
- //TODO nbruening: Javadoc
- private Map mapOriginalRoot2RootStub;
-
+
+ private final FilteredViewCreatingViewType, Id> viewType;
+
private ViewFilterBuilder viewFilterBuilder;
+ private ViewFilterImpl viewFilter;
- public FilterSupportingViewElementSelector(ViewCreatingViewType, Id> viewType, ChangeableViewSource viewSource, Collection selectableElements) {
- Preconditions.checkArgument((selectableElements != null), "selectable elements must not be null");
- Preconditions.checkArgument((viewType != null), "view type must not be null");
- Preconditions.checkArgument((viewSource != null), "view source must not be null");
+ public FilterSupportingViewElementSelector(
+ FilteredViewCreatingViewType, Id> viewType,
+ ChangeableViewSource viewSource, Collection selectableElements) {
+ Preconditions.checkArgument((selectableElements != null), "selectable elements must not be null");
+ Preconditions.checkArgument((viewType != null), "view type must not be null");
+ Preconditions.checkArgument((viewSource != null), "view source must not be null");
this.viewType = viewType;
this.viewSource = viewSource;
- //Copy underlying model
- //Collection selectableElementsCopy = EcoreUtil.copyAll(selectableElements);
- this.viewSelection = new ElementViewSelection(selectableElements);
- rootListForView = new HashSet();
- mapOriginalRoot2RootStub = new HashMap();
+ // Copy underlying model
+ // Collection selectableElementsCopy =
+ // EcoreUtil.copyAll(selectableElements);
+ this.viewSelection = new ElementViewSelection(selectableElements);
viewFilterBuilder = new ViewFilterBuilder();
-
+
}
-
@Override
public View createView() {
+ viewFilter = viewFilterBuilder.build();
+ Set rootListForView = getViewFilter().filterElements(getSelectableElements());
+
viewSelection = new ElementViewSelection(rootListForView);
rootListForView.forEach(element -> setSelected(element, true));
- //TODO nbruening ggf noch anpassen
- Preconditions.checkState(this.isValid(), "the current selection is invalid, thus a view cannot be created");
- return this.viewType.createView(this);
+ // TODO nbruening ggf noch anpassen
+ Preconditions.checkState(this.isValid(), "the current selection is invalid, thus a view cannot be created");
+ return this.viewType.createView(this);
}
-
+
public void selectElementsOfRootType(Collection> rootTypes) {
- getSelectableElements().stream()
- .filter(element -> !(rootTypes.stream().anyMatch(it -> it.isInstance(element))))
- .forEach(element -> setSelected(element, false));
+ getSelectableElements().stream().filter(element -> !(rootTypes.stream().anyMatch(it -> it.isInstance(element))))
+ .forEach(element -> setSelected(element, false));
}
-
-
+
public void addElementsToSelectionByLambda(Function filter) {
- for (EObject root : getSelectableElements()) {
- filterAllContents(root, filter, rootListForView);
- }
- }
-
-
- public void removeOwnedAttributesFromClasses() {
- for (EObject root : rootListForView) {
- TreeIterator content = root.eAllContents();
- List contentList = convertTreeIterator2List(content);
- for (EObject object : contentList) {
- if (object instanceof org.eclipse.uml2.uml.Class) {
- org.eclipse.uml2.uml.Class classifierObject = (org.eclipse.uml2.uml.Class) object;
- classifierObject.getOwnedAttributes().removeAll(classifierObject.getOwnedAttributes());
- }
- }
- }
- }
-
-
- private void filterAllContents(EObject root, Function filter, Set rootListForView) {
- Model filteredModelRootStub = null;
- Iterator contentIterator = root.eAllContents();
- while(contentIterator.hasNext()) {
- EObject contentElement = contentIterator.next();
- if (filter.apply(contentElement)) {
- //testListObjectsToDisplay.add(contentElement);
-
- filteredModelRootStub = createFilteredModelRootIfNotExistent(filteredModelRootStub, root);
- EObject copyOfContentElement = EcoreUtil.copy(contentElement);
- attachElementToRoot(filteredModelRootStub, copyOfContentElement);
-
- rootListForView.add(filteredModelRootStub);
- mapOriginalRoot2RootStub.put(root, filteredModelRootStub);
- }
- }
- }
-
-
- private void attachElementToRoot(Model root, EObject object) {
- if (object instanceof Type) {
- EObject objectCopy = EcoreUtil.copy(object);
- root.getOwnedTypes().add((Type) objectCopy);
- } else {
- System.out.println("Warning: Undefined type: " + object.eClass());
- }
-
- }
-
-
- private Model createFilteredModelRootIfNotExistent(Model filteredRoot, EObject root) {
- if (filteredRoot == null) {
- if (root instanceof Model) {
- return UMLFactory.eINSTANCE.createModel();
- } else {
- throw new ImplementationError("nbruening: Not implemented yet");
- }
- }
- return filteredRoot;
-
- }
-
-
- private List convertTreeIterator2List(TreeIterator content) {
- List list = new LinkedList();
- while(content.hasNext()) {
- list.add(content.next());
- }
- return list;
+ viewFilterBuilder.filterByLambda(filter);
+ }
+
+ public void removeOwnedAttributesFromClasses() {
+ viewFilterBuilder.removeOwnedAttributes();
}
@Override
@@ -158,40 +93,44 @@ public boolean isValid() {
}
@Override
- public ViewSelection getSelection() {
- return new ElementViewSelection(this.viewSelection);
- }
-
- public Collection getSelectableElements() {
- return this.viewSelection.getSelectableElements();
- }
-
- public boolean isSelectable(final EObject eObject) {
- return this.viewSelection.isSelectable(eObject);
- }
-
- public boolean isSelected(final EObject eObject) {
- return this.viewSelection.isSelected(eObject);
- }
-
- public boolean isViewObjectSelected(final EObject eObject) {
- return this.viewSelection.isViewObjectSelected(eObject);
- }
-
- public void setSelected(final EObject eObject, final boolean selected) {
- this.viewSelection.setSelected(eObject, selected);
- }
-
- public ChangeableViewSource getViewSource() {
- return this.viewSource;
- }
-
- public ViewCreatingViewType, Id> getViewType() {
- return this.viewType;
- }
-
- public Map getMapOriginalRoot2RootStub() {
- return mapOriginalRoot2RootStub;
- }
+ public ViewSelection getSelection() {
+ return new ElementViewSelection(this.viewSelection);
+ }
+
+ public Collection getSelectableElements() {
+ return this.viewSelection.getSelectableElements();
+ }
+
+ public boolean isSelectable(final EObject eObject) {
+ return this.viewSelection.isSelectable(eObject);
+ }
+
+ public boolean isSelected(final EObject eObject) {
+ return this.viewSelection.isSelected(eObject);
+ }
+
+ public boolean isViewObjectSelected(final EObject eObject) {
+ return this.viewSelection.isViewObjectSelected(eObject);
+ }
+
+ public void setSelected(final EObject eObject, final boolean selected) {
+ this.viewSelection.setSelected(eObject, selected);
+ }
+
+ public ChangeableViewSource getViewSource() {
+ return this.viewSource;
+ }
+
+ public FilteredViewCreatingViewType, Id> getViewType() {
+ return this.viewType;
+ }
+
+ public Map getMapOriginalRoot2RootStub() {
+ return getViewFilter() != null ? getViewFilter().getMapOriginalRoot2RootStub() : Collections.emptyMap();
+ }
+
+ public ViewFilter getViewFilter() {
+ return viewFilter;
+ }
}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
new file mode 100644
index 000000000..46bddcabb
--- /dev/null
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilter.java
@@ -0,0 +1,14 @@
+package tools.vitruv.applications.viewfilter.viewbuild;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+
+public interface ViewFilter {
+
+ Set filterElements(Collection roots);
+
+ Map getMapOriginalRoot2RootStub();
+}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
index 7b3b5a6ab..3bd26f5c9 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
@@ -1,6 +1,8 @@
package tools.vitruv.applications.viewfilter.viewbuild;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -16,7 +18,7 @@
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;
-public class ViewFilter {
+public class ViewFilterImpl implements ViewFilter {
private Set rootListForView;
@@ -25,13 +27,17 @@ public class ViewFilter {
private final ViewFilterBuilder builder;
- private ViewFilter(ViewFilterBuilder viewFilterBuilder) {
+ private ViewFilterImpl(ViewFilterBuilder viewFilterBuilder) {
builder = viewFilterBuilder;
+ rootListForView = new HashSet();
+ mapOriginalRoot2RootStub = new HashMap();
}
- public void filterElements(Collection roots) {
+ public Set filterElements(Collection roots) {
addElementsToSelectionByLambda(roots);
+ removeOwnedAttributesFromClasses();
+ return rootListForView;
}
@@ -44,7 +50,8 @@ private void addElementsToSelectionByLambda(Collection roots) {
}
}
- public void removeOwnedAttributesFromClasses() {
+
+ private void removeOwnedAttributesFromClasses() {
if (!builder.removeAttributesActive) {
return;
}
@@ -74,7 +81,7 @@ private void filterAllContents(EObject root, Function filter,
attachElementToRoot(filteredModelRootStub, copyOfContentElement);
rootListForView.add(filteredModelRootStub);
- mapOriginalRoot2RootStub.put(root, filteredModelRootStub);
+ getMapOriginalRoot2RootStub().put(root, filteredModelRootStub);
}
}
}
@@ -111,9 +118,14 @@ private Model createFilteredModelRootIfNotExistent(Model filteredRoot, EObject r
}
-//---------------------------------
+ public Map getMapOriginalRoot2RootStub() {
+ return mapOriginalRoot2RootStub;
+ }
+
+
+ //---------------------------------
/**
- * Builder for ViewFilter
+ * Builder for ViewFilterImpl
*/
public static class ViewFilterBuilder {
@@ -125,8 +137,7 @@ public static class ViewFilterBuilder {
private Function filter;
- public ViewFilterBuilder() {
-
+ public ViewFilterBuilder() {
}
public ViewFilterBuilder filterByLambda(Function filter) {
@@ -140,8 +151,8 @@ public ViewFilterBuilder removeOwnedAttributes() {
return this;
}
- public ViewFilter build() {
- return new ViewFilter(this);
+ public ViewFilterImpl build() {
+ return new ViewFilterImpl(this);
}
From 1618324d5583c7a176ca05174349a897ce79c77d Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Thu, 4 Jan 2024 21:31:26 +0100
Subject: [PATCH 11/62] Filtering View is now updated in case the underlying
model is modified
---
.../viewfilter/util/framework/impl/BasicFilterView.java | 9 ++++++---
.../viewfilter/viewbuild/ViewFilterImpl.java | 2 +-
.../viewfilter/tests/BasicViewFilterTest.java | 4 ++--
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java
index b5a753f36..da2de3bd4 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/util/framework/impl/BasicFilterView.java
@@ -15,7 +15,7 @@
public class BasicFilterView extends BasicView {
- private ViewFilter viewFilter;
+ private final ViewFilter viewFilter;
protected BasicFilterView(FilteredViewCreatingViewType extends ViewSelector, HierarchicalId> viewType,
ChangeableViewSource viewSource, ViewSelection selection, ViewFilter viewFilter) {
@@ -31,8 +31,11 @@ public void modifyContents(Procedure1 super ResourceSet> modificationFunction)
private void filterSelectedElements() {
- Set filteredElements = viewFilter.filterElements(getRootObjects());
- setSelection(new ElementViewSelection(filteredElements));
+ if (viewFilter != null) {
+ //If the viewFilter has already been set, use it..
+ Set filteredElements = viewFilter.filterElements(getRootObjects());
+ setSelection(new ElementViewSelection(filteredElements));
+ }
}
}
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
index 3bd26f5c9..f37ea9e49 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
@@ -29,12 +29,12 @@ public class ViewFilterImpl implements ViewFilter {
private ViewFilterImpl(ViewFilterBuilder viewFilterBuilder) {
builder = viewFilterBuilder;
- rootListForView = new HashSet();
mapOriginalRoot2RootStub = new HashMap();
}
public Set filterElements(Collection roots) {
+ rootListForView = new HashSet();
addElementsToSelectionByLambda(roots);
removeOwnedAttributesFromClasses();
return rootListForView;
diff --git a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
index 9cfbc74cf..bb1f47503 100644
--- a/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
+++ b/tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/tests/BasicViewFilterTest.java
@@ -175,7 +175,7 @@ private void modifyModel() {
final Comment comment = this.class2.createOwnedComment();
comment.setBody("niklasCommentClass2");
- String name = "niklasClass2";
+ String searchedName = "niklasClass2";
comment.addKeyword("bla");
TreeIterator umlIterator = getDefaultUmlModel(it).eAllContents();
@@ -183,7 +183,7 @@ private void modifyModel() {
while ((searchedClass == null) && (umlIterator.hasNext())) {
EObject next = umlIterator.next();
if (next instanceof org.eclipse.uml2.uml.Class) {
- if (name.equals(((Classifier) next).getName())) {
+ if (searchedName.equals(((Classifier) next).getName())) {
searchedClass = (org.eclipse.uml2.uml.Class) next;
}
}
From 270d94ee513c884a8cbf0e81310cdf41e2c5beba Mon Sep 17 00:00:00 2001
From: niklas5810 <83550711+niklas5810@users.noreply.github.com>
Date: Fri, 12 Jan 2024 09:14:21 +0100
Subject: [PATCH 12/62] - First steps for pcm support
---
.../viewfilter/viewbuild/ViewFilterImpl.java | 38 +++++++++-
.../viewfilter/tests/BasicViewFilterTest.java | 75 +++++++++++++++++++
.../viewfilter/tests/ViewTestFactory.java | 51 ++++++++++---
.../viewfilter/utils/PcmQueryUtil.xtend | 28 +++++++
.../PcmUmlClassApplicationTestHelper.xtend | 9 +++
5 files changed, 188 insertions(+), 13 deletions(-)
create mode 100644 tests/tools.vitruv.applications.viewfilter.tests/src/tools/vitruv/applications/viewfilter/utils/PcmQueryUtil.xtend
diff --git a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
index f37ea9e49..98ce3e117 100644
--- a/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
+++ b/bundles/tools.vitruv.applications.viewtest/src/tools/vitruv/applications/viewfilter/viewbuild/ViewFilterImpl.java
@@ -17,6 +17,11 @@
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;
+import org.palladiosimulator.pcm.PcmFactory;
+import org.palladiosimulator.pcm.repository.DataType;
+import org.palladiosimulator.pcm.repository.Repository;
+import org.palladiosimulator.pcm.repository.RepositoryComponent;
+import org.palladiosimulator.pcm.repository.RepositoryFactory;
public class ViewFilterImpl implements ViewFilter {
@@ -69,7 +74,7 @@ private void removeOwnedAttributesFromClasses() {
private void filterAllContents(EObject root, Function