]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
2d9d76c65b06caa6632b95bd282ceef8f2d02c9e
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.properties;\r
2 \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
15 \r
16 public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl {\r
17 \r
18         \r
19     public void updatePartName(ISelection forSelection, final Callback<String> updateCallback) {\r
20         final Resource r = AdaptionUtils.adaptToSingle(forSelection, Resource.class);\r
21         if(r == null) {\r
22                 updateCallback.run("Selection properties");\r
23                 return;\r
24         }\r
25         \r
26         try {\r
27                         SimanticsUI.getSession().syncRequest(new Read<String>() {\r
28 \r
29                                 @Override\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
33                                         if(label != null)\r
34                                                 return label;\r
35                                         label = graph.getPossibleRelatedValue(r, l0.HasName);\r
36                                         if(label != null)\r
37                                                 return label;\r
38                                         return "No name for selection";\r
39                                 }\r
40                         }, new AsyncListener<String>() {\r
41 \r
42                                 @Override\r
43                                 public void execute(AsyncReadGraph graph, String result) {\r
44                                         updateCallback.run(result);\r
45                                 }\r
46 \r
47                                 @Override\r
48                                 public void exception(AsyncReadGraph graph, Throwable throwable) {\r
49                                         \r
50                                 }\r
51 \r
52                                 @Override\r
53                                 public boolean isDisposed() {\r
54                                         return false;\r
55                                 }\r
56                         });\r
57                 } catch (DatabaseException e) {\r
58                         updateCallback.run("Selection error in LabelPropertyTabContributor");\r
59                         e.printStackTrace();\r
60                 }\r
61                 \r
62     }\r
63 }\r