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