]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench.search.impl/src/org/simantics/workbench/search/impl/ActiveModelsListener.java
Add missing influxdb-client-core to target platform
[simantics/platform.git] / bundles / org.simantics.workbench.search.impl / src / org / simantics / workbench / search / impl / ActiveModelsListener.java
1 /*******************************************************************************
2  * Copyright (c) 2014 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.workbench.search.impl;
13
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.Set;
17
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
23 /**
24  * @author Tuukka Lehtonen
25  */
26 class ActiveModelsListener extends DisposableListener<Collection<Resource>> {
27
28     private Runnable callback;
29     private Set<Resource> previouslyActive;
30
31     public ActiveModelsListener(Runnable callback) {
32         if (callback == null)
33             throw new NullPointerException("null callback");
34         this.callback = callback;
35     }
36
37     @Override
38     public void execute(Collection<Resource> models) {
39         Set<Resource> set = new HashSet<Resource>(models);
40         Set<Resource> previous = previouslyActive;
41         if (previous != null && !previous.equals(set))
42             callback.run();
43         previouslyActive = set;
44     }
45
46     @Override
47     public void exception(Throwable t) {
48         Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, t.getLocalizedMessage(), t));
49     }
50
51     @Override
52     public void dispose() {
53         super.dispose();
54         previouslyActive = null;
55     }
56
57 }