--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 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
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.ui.workbench;\r
+\r
+import java.util.function.Consumer;\r
+import java.util.function.Supplier;\r
+\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.ui.internal.Activator;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class TitleUpdater implements Listener<String> {\r
+\r
+ private final Display display;\r
+ private final Consumer<String> callback;\r
+ private final Supplier<Boolean> disposed;\r
+\r
+ public TitleUpdater(Display display, Consumer<String> titleChangedCallback, Supplier<Boolean> disposed) {\r
+ this.display = display;\r
+ this.callback = titleChangedCallback;\r
+ this.disposed = disposed;\r
+ }\r
+\r
+ @Override\r
+ public void execute(final String result) {\r
+ display.asyncExec(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ if (!isDisposed())\r
+ callback.accept(result);\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return disposed.get();\r
+ }\r
+\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Title update failed.", t));\r
+ }\r
+\r
+}\r