]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/MappingSubgraphExtent.java
WIP: Some old-ish adapter registry initialization improvements
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / MappingSubgraphExtent.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.Statement;
17 import org.simantics.db.layer0.adapter.impl.TypeSubgraphExtent;
18 import org.simantics.db.procedure.AsyncProcedure;
19 import org.simantics.modeling.ModelingResources;
20 import org.simantics.operation.Layer0X;
21
22 public class MappingSubgraphExtent extends TypeSubgraphExtent {
23
24         final private Classifier classifier = new Classifier() {
25
26                 @Override
27                 public void classify(AsyncReadGraph graph, Statement statement, ExtentStatus objectExtent,
28                                 Callback callback) {
29
30                         if(!ExtentStatus.INTERNAL.equals(objectExtent)) return;
31                         
32                         Resource predicate = statement.getPredicate();
33
34                         Layer0X L0X = graph.getService(Layer0X.class);
35                         ModelingResources mr = graph.getService(ModelingResources.class);
36         
37                         if(mr.DiagramConnectionToConnection.equalsResource(predicate)) callback.statement(statement, true);
38                         else if(mr.DiagramToComposite.equalsResource(predicate)) callback.statement(statement, true);
39                         else if(L0X.HasTrigger.equalsResource(predicate)) callback.statement(statement, true);
40                         else if(mr.ElementToComponent.equalsResource(predicate)) callback.statement(statement, true);
41                         else if(mr.CompositeToDiagram.equalsResource(predicate)) callback.statement(statement, true);
42                         else if(mr.ComponentToElement.equalsResource(predicate)) callback.statement(statement, true);
43                         else if(mr.ConnectionToDiagramConnection.equalsResource(predicate)) callback.statement(statement, true);
44                         
45                 }
46                 
47         };
48         
49         @Override
50         public void accept(AsyncReadGraph graph, Resource resource,
51                         AsyncProcedure<Classifier> procedure, Callback callback) {
52                 procedure.execute(graph, classifier);
53         }
54
55 }