]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
849ab229de605eff9a8881dfab8679f9a21f8dcf
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.properties.widgets.factories;\r
2 \r
3 import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;\r
4 import org.simantics.databoard.binding.java.DoubleBindingDefault;\r
5 import org.simantics.db.Resource;\r
6 import org.simantics.db.WriteGraph;\r
7 import org.simantics.db.exception.DatabaseException;\r
8 import org.simantics.db.management.ISessionContext;\r
9 \r
10 public class DoublePropertyModifier extends TextModifyListenerImpl<Resource> {\r
11 \r
12     final private String propertyURI;\r
13     \r
14     public DoublePropertyModifier(ISessionContext context, String propertyURI) {\r
15         this.propertyURI = propertyURI;\r
16     }\r
17 \r
18     @Override\r
19     public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
20         if (text == null || text.equals("")) {\r
21                 if(graph.hasStatement(input, graph.getResource(propertyURI)))\r
22                         graph.deny(input, graph.getResource(propertyURI));\r
23         } else {\r
24                 graph.claimLiteral(input, graph.getResource(propertyURI), Double.parseDouble(text), DoubleBindingDefault.INSTANCE);\r
25         }\r
26     }\r
27 \r
28 }\r