+ /**
+ * Clears user filters. Use refreshUserFilters() to apply the changes.
+ */
+ public void clearUserFilters() {
+ userFilters.clear();
+ }
+
+ public List<ChangeFilter> getUserFilters() {
+ return userFilters;
+ }
+
+ public void refreshUserFilters() throws DatabaseException{
+ // use user filters to set visible flags of changes.
+ // First, set all changes visible.
+ Deque<UpdateNode> stack = new ArrayDeque<>();
+ stack.push(updateTree.getRootNode());
+ while (!stack.isEmpty()) {
+ UpdateNode n = stack.pop();
+ n.setVisible(true);
+ stack.addAll(n.getChildren());
+ }
+ for (PropertyChange pc : updateList.getChanges()) {
+ pc.setVisible(true);
+ }
+ if (userFilters.size() > 0) {
+ // Create filtered changes
+ List<ChangeFilter> combined = new ArrayList<>(filters);
+ combined.addAll(userFilters);
+ GraphChanges filteredChanges = getSession().syncRequest(createFilterRead(changes, combined));
+ UpdateTree updateTreeF = getUpdateTree(filteredChanges);
+ UpdateList updateListF = getUpdateList(filteredChanges);
+ // hide changes that are not contained within the filtered changes.
+ applyVisibleFlags(updateTree.getRootNode(), updateTreeF.getRootNode());
+ applyVisibleFlags(updateList.getChanges(), updateListF.getChanges());
+ }
+ }
+
+ private void applyVisibleFlags(UpdateNode l, UpdateNode r) {
+ BijectionMap<UpdateNode, UpdateNode> comparable = new BijectionMap<>();
+ for (UpdateNode lc : l.getChildren()) {
+ for (UpdateNode rc : r.getChildren()) {
+ if (comparable.containsRight(rc))
+ continue;
+ if (lc.getResource() != null) {
+ if (lc.getResource().equals(rc.getResource())) {
+
+ comparable.map(lc, rc);
+ break;
+ }
+ } else if (rc.getResource() == null){
+ UpdateOp lop = lc.getOp();
+ UpdateOp rop = rc.getOp();
+ if (lop.getStatement() != null && lop.getStatement().equals(rop.getStatement())) {
+ comparable.map(lc, rc);
+ break;
+ }
+ }
+ }
+ }
+ for (UpdateNode lc : l.getChildren()) {
+ if (!comparable.containsLeft(lc))
+ lc.setVisible(false);
+ }
+ for (Entry<UpdateNode, UpdateNode> entry : comparable.getEntries()) {
+ applyVisibleFlags(entry.getKey(), entry.getValue());
+ }
+ }
+
+ private void applyVisibleFlags(Collection<PropertyChange> l, Collection<PropertyChange> r) {
+ BijectionMap<PropertyChange, PropertyChange> comparable = new BijectionMap<>();
+ for (PropertyChange lc : l) {
+ for (PropertyChange rc : r) {
+ if (comparable.containsRight(rc))
+ continue;
+ if (lc.getFirst() != null && lc.getFirst().equals(rc.getFirst())) {
+ comparable.map(lc, rc);
+ break;
+ }
+ if (lc.getSecond() != null && lc.getSecond().equals(rc.getSecond())) {
+ comparable.map(lc, rc);
+ break;
+ }
+ }
+ }
+ for (PropertyChange lc : l) {
+ if (!comparable.containsLeft(lc))
+ lc.setVisible(false);
+ }
+
+ }