]> gerrit.simantics Code Review - simantics/platform.git/blob - diagram/monitor/ObtainedFontAdapter.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / diagram / monitor / ObtainedFontAdapter.java
1 package org.simantics.modeling.ui.diagram.monitor;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5
6 import org.simantics.databoard.Bindings;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.RelationContext;
9 import org.simantics.db.Resource;
10 import org.simantics.db.Statement;
11 import org.simantics.db.common.adaption.SimpleContextualAdapter;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.layer0.property.OrderedResource;
14 import org.simantics.diagram.stubs.DiagramResource;
15 import org.simantics.operation.Layer0X;
16 import org.simantics.ui.fonts.FontDescriptor;
17
18 public class ObtainedFontAdapter extends SimpleContextualAdapter<FontDescriptor, RelationContext> {
19
20         @Override
21         public FontDescriptor adapt(ReadGraph graph, Resource source, RelationContext context) throws DatabaseException {
22                 
23             Layer0X L0X = Layer0X.getInstance(graph);
24                 DiagramResource DIA = DiagramResource.getInstance(graph);
25                 ArrayList<OrderedResource> order = new ArrayList<OrderedResource>();
26                 for(Statement stm : graph.getStatements(context.getSubject(), L0X.ObtainsProperty)) {
27                         Integer position = graph.getRelatedValue(stm.getPredicate(), L0X.NaturalNumberOrderRelation, Bindings.INTEGER);
28                         order.add(new OrderedResource(position, stm.getObject()));
29                 }
30                 if (order.size() > 1)
31                         Collections.sort(order);
32                 for(OrderedResource or : order) {
33                         FontDescriptor result = graph.getPossibleRelatedAdapter(or.r, DIA.HasFont, FontDescriptor.class);
34                         if(result != null) return result;
35                 }
36                 
37                 return null;
38                 
39         }
40
41 }