diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/QueryGroupProviderSourceConnector.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/QueryGroupProviderSourceConnector.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/QueryGroupProviderSourceConnector.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/QueryGroupProviderSourceConnector.java new file mode 100644 index 00000000..e6f0adf0 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/QueryGroupProviderSourceConnector.java | |||
@@ -0,0 +1,80 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Abel Hegedus, IncQuery Labs Ltd. | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.registry.connector; | ||
10 | |||
11 | import java.util.Objects; | ||
12 | |||
13 | import tools.refinery.viatra.runtime.extensibility.IQueryGroupProvider; | ||
14 | import tools.refinery.viatra.runtime.extensibility.IQuerySpecificationProvider; | ||
15 | import tools.refinery.viatra.runtime.registry.IConnectorListener; | ||
16 | |||
17 | /** | ||
18 | * Source connector implementation that uses a {@link IQueryGroupProvider} to provide a query specifications into the | ||
19 | * registry. The query group can be later updated which triggers the removal of all specifications of the old group and | ||
20 | * the addition of all specifications from the new group. | ||
21 | * | ||
22 | * @author Abel Hegedus | ||
23 | * @since 1.3 | ||
24 | * | ||
25 | */ | ||
26 | public class QueryGroupProviderSourceConnector extends AbstractRegistrySourceConnector { | ||
27 | |||
28 | IQueryGroupProvider queryGroupProvider; | ||
29 | |||
30 | /** | ||
31 | * Creates an instance of the connector with the given identifier and the query group provider. The identifier | ||
32 | * should be unique if you want to add it to a registry as a source. | ||
33 | * | ||
34 | * @param identifier | ||
35 | * of the newly created connector | ||
36 | * @param provider | ||
37 | * that contains the query specifications handled by the connector | ||
38 | * @param includeInDefaultViews | ||
39 | * true if the specifications in the connector should be included in default views | ||
40 | */ | ||
41 | public QueryGroupProviderSourceConnector(String identifier, IQueryGroupProvider provider, boolean includeInDefaultViews) { | ||
42 | super(identifier, includeInDefaultViews); | ||
43 | this.queryGroupProvider = provider; | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Update the query group of the connector, which triggers the removal of all specifications on the old group and | ||
48 | * addition of all specifications in the given group. | ||
49 | * | ||
50 | * @param queryGroupProvider | ||
51 | * the queryGroupProvider to set | ||
52 | * @param includeInDefaultViews | ||
53 | * true if the specifications in the connector should be included in default views | ||
54 | */ | ||
55 | public void setQueryGroupProvider(IQueryGroupProvider queryGroupProvider) { | ||
56 | Objects.requireNonNull(queryGroupProvider, "Query group provider must not be null!"); | ||
57 | IQueryGroupProvider oldProvider = this.queryGroupProvider; | ||
58 | |||
59 | for (IQuerySpecificationProvider specificationProvider : oldProvider.getQuerySpecificationProviders()) { | ||
60 | for (IConnectorListener iConnectorListener : listeners) { | ||
61 | iConnectorListener.querySpecificationRemoved(this, specificationProvider); | ||
62 | } | ||
63 | } | ||
64 | for (IQuerySpecificationProvider specificationProvider : queryGroupProvider.getQuerySpecificationProviders()) { | ||
65 | for (IConnectorListener iConnectorListener : listeners) { | ||
66 | iConnectorListener.querySpecificationAdded(this, specificationProvider); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | this.queryGroupProvider = queryGroupProvider; | ||
71 | } | ||
72 | |||
73 | @Override | ||
74 | protected void sendQuerySpecificationsToListener(IConnectorListener listener) { | ||
75 | for (IQuerySpecificationProvider specificationProvider : queryGroupProvider.getQuerySpecificationProviders()) { | ||
76 | listener.querySpecificationAdded(this, specificationProvider); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | } | ||