1 /*******************************************************************************
\r
2 * Copyright (c) 2014 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.workbench.internal.contributions.search;
\r
14 import java.util.Collection;
\r
15 import java.util.HashSet;
\r
16 import java.util.Set;
\r
18 import org.eclipse.core.runtime.IStatus;
\r
19 import org.eclipse.core.runtime.Status;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.common.procedure.adapter.DisposableListener;
\r
22 import org.simantics.workbench.internal.Activator;
\r
25 * @author Tuukka Lehtonen
\r
27 class ActiveModelsListener extends DisposableListener<Collection<Resource>> {
\r
29 private Runnable callback;
\r
30 private Set<Resource> previouslyActive;
\r
32 public ActiveModelsListener(Runnable callback) {
\r
33 if (callback == null)
\r
34 throw new NullPointerException("null callback");
\r
35 this.callback = callback;
\r
39 public void execute(Collection<Resource> models) {
\r
40 Set<Resource> set = new HashSet<Resource>(models);
\r
41 Set<Resource> previous = previouslyActive;
\r
42 if (previous != null && !previous.equals(set))
\r
44 previouslyActive = set;
\r
48 public void exception(Throwable t) {
\r
49 Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, t.getLocalizedMessage(), t));
\r
53 public void dispose() {
\r
55 previouslyActive = null;
\r