This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
/
ObservableCollectionHelper.java
56 lines (51 loc) · 2.83 KB
/
ObservableCollectionHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
* Copyright (c) 2010-2012, Abel Hegedus, Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Abel Hegedus - initial API and implementation
*******************************************************************************/
package org.eclipse.incquery.databinding.runtime.collection;
import org.eclipse.incquery.runtime.api.IMatcherFactory;
import org.eclipse.incquery.runtime.api.IPatternMatch;
import org.eclipse.incquery.runtime.api.IncQueryMatcher;
import org.eclipse.incquery.runtime.base.itc.alg.incscc.Direction;
import org.eclipse.incquery.runtime.triggerengine.api.ActivationState;
import org.eclipse.incquery.runtime.triggerengine.api.Agenda;
import org.eclipse.incquery.runtime.triggerengine.api.IAgenda;
import org.eclipse.incquery.runtime.triggerengine.api.IRule;
import org.eclipse.incquery.runtime.triggerengine.firing.AutomaticFiringStrategy;
/**
* Utility class to prepare a rule in an agenda for an observable collection.
* For use cases, see {@link ObservablePatternMatchSet} and {@link ObservablePatternMatchList}.
*
* @author Abel Hegedus
*
*/
public class ObservableCollectionHelper {
/**
* Constructor hidden for utility class
*/
private ObservableCollectionHelper() {
// TODO Auto-generated constructor stub
}
/**
* Creates the rule used for updating the results in the given agenda.
*
* @param observableCollection the observable collection to handle
* @param factory the {@link IMatcherFactory} used to create the rule
* @param agenda an existing {@link Agenda} where the rule is created
*/
public static <Match extends IPatternMatch, Matcher extends IncQueryMatcher<Match>> void createRuleInAgenda(IObservablePatternMatchCollection<Match> observableCollection, IMatcherFactory<Matcher> factory, IAgenda agenda) {
IRule<Match> rule = agenda.createRule(factory, false, true);
ObservableCollectionProcessor<Match> insertProc = new ObservableCollectionProcessor<Match>(Direction.INSERT, observableCollection);
ObservableCollectionProcessor<Match> deleteProc = new ObservableCollectionProcessor<Match>(Direction.DELETE, observableCollection);
rule.setStateChangeProcessor(ActivationState.APPEARED, insertProc);
rule.setStateChangeProcessor(ActivationState.DISAPPEARED, deleteProc);
AutomaticFiringStrategy firingStrategy = new AutomaticFiringStrategy(agenda.newActivationMonitor(true));
agenda.addUpdateCompleteListener(firingStrategy, true);
}
}