1 package org.simantics.sysdyn.ui.properties;
\r
3 import org.eclipse.jface.viewers.ISelection;
\r
4 import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;
\r
5 import org.simantics.db.AsyncReadGraph;
\r
6 import org.simantics.db.ReadGraph;
\r
7 import org.simantics.db.Resource;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.db.procedure.AsyncListener;
\r
10 import org.simantics.db.request.Read;
\r
11 import org.simantics.layer0.Layer0;
\r
12 import org.simantics.ui.SimanticsUI;
\r
13 import org.simantics.ui.utils.AdaptionUtils;
\r
14 import org.simantics.utils.datastructures.Callback;
\r
16 public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl {
\r
19 public void updatePartName(ISelection forSelection, final Callback<String> updateCallback) {
\r
20 final Resource r = AdaptionUtils.adaptToSingle(forSelection, Resource.class);
\r
22 updateCallback.run("Selection properties");
\r
27 SimanticsUI.getSession().syncRequest(new Read<String>() {
\r
30 public String perform(ReadGraph graph) throws DatabaseException {
\r
31 Layer0 l0 = Layer0.getInstance(graph);
\r
32 String label = graph.getPossibleRelatedValue(r, l0.HasLabel);
\r
35 label = graph.getPossibleRelatedValue(r, l0.HasName);
\r
38 return "No name for selection";
\r
40 }, new AsyncListener<String>() {
\r
43 public void execute(AsyncReadGraph graph, String result) {
\r
44 updateCallback.run(result);
\r
48 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
53 public boolean isDisposed() {
\r
57 } catch (DatabaseException e) {
\r
58 updateCallback.run("Selection error in LabelPropertyTabContributor");
\r
59 e.printStackTrace();
\r