]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ResourceTGValueModifier.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / ResourceTGValueModifier.java
1 package org.simantics.db.layer0.util;
2
3 import org.simantics.databoard.accessor.error.AccessorException;
4 import org.simantics.databoard.binding.Binding;
5 import org.simantics.databoard.type.Datatype;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.service.SerialisationSupport;
8 import org.simantics.graph.utils.TGResourceUtil;
9 import org.simantics.graph.utils.TGResourceUtil.LongAdapter;
10
11 public class ResourceTGValueModifier implements TGValueModifier {
12
13         final private TGResourceUtil util = new TGResourceUtil();
14         final private SerialisationSupport ss;
15         
16         public ResourceTGValueModifier(SerialisationSupport ss) {
17                 this.ss = ss;
18         }
19         
20         @Override
21         public boolean mayNeedModification(Datatype type) {
22                 return util.mayHaveResource(type);
23         }
24
25         @Override
26         public Object modify(final DomainProcessorState state, Binding binding, Object value) throws DatabaseException {
27                 
28                 try {
29                         
30                         util.adaptValue( binding, value, new LongAdapter() {
31                                 @Override
32                                 public long adapt(long in) {
33                                         try {
34                                                 int shortId = ss.getTransientId(in);
35                                                 return state.ids.get(shortId);
36                                         } catch (DatabaseException e) {
37                                                 e.printStackTrace();
38                                         }
39                                         return in;
40                                 }                       
41                         });
42                         
43                         return value;
44                         
45                 } catch (AccessorException e) {
46                         
47                         throw new DatabaseException(e);
48                         
49                 }
50                 
51         }
52
53 }