--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.workbench.internal.contributions.search;\r
+\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.procedure.adapter.DisposableListener;\r
+import org.simantics.workbench.internal.Activator;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+class ActiveModelsListener extends DisposableListener<Collection<Resource>> {\r
+\r
+ private Runnable callback;\r
+ private Set<Resource> previouslyActive;\r
+\r
+ public ActiveModelsListener(Runnable callback) {\r
+ if (callback == null)\r
+ throw new NullPointerException("null callback");\r
+ this.callback = callback;\r
+ }\r
+\r
+ @Override\r
+ public void execute(Collection<Resource> models) {\r
+ Set<Resource> set = new HashSet<Resource>(models);\r
+ Set<Resource> previous = previouslyActive;\r
+ if (previous != null && !previous.equals(set))\r
+ callback.run();\r
+ previouslyActive = set;\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, t.getLocalizedMessage(), t));\r
+ }\r
+\r
+ @Override\r
+ public void dispose() {\r
+ super.dispose();\r
+ previouslyActive = null;\r
+ }\r
+\r
+}
\ No newline at end of file