]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / ProfileCheckContributor.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.profile.view;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.browsing.ui.CheckedState;\r
17 import org.simantics.browsing.ui.model.check.CheckedStateRule;\r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.diagram.stubs.DiagramResource;\r
22 import org.simantics.scenegraph.profile.request.ProfileActiveEntryResources;\r
23 import org.simantics.scenegraph.profile.request.ProfileEntryResources;\r
24 import org.simantics.simulation.ontology.SimulationResource;\r
25 \r
26 public class ProfileCheckContributor implements CheckedStateRule {\r
27 \r
28     @Override\r
29     public boolean isCompatible(Class<?> contentType) {\r
30         return contentType.equals(ResourcePair.class);\r
31     }\r
32 \r
33     @Override\r
34     public CheckedState getCheckedState(ReadGraph graph, Object parent)\r
35             throws DatabaseException {\r
36 \r
37         ResourcePair entry = (ResourcePair)parent;\r
38         DiagramResource DIA = DiagramResource.getInstance(graph);\r
39         SimulationResource SIMU = SimulationResource.getInstance(graph);\r
40 \r
41         if(graph.isInstanceOf(entry.getSecond(), DIA.Profile)) {\r
42 \r
43             Resource list = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries);\r
44             Collection<Resource> activeEntries = graph.syncRequest( new ProfileActiveEntryResources(entry.getFirst(), list) );\r
45             if (activeEntries.isEmpty()) {\r
46                 return CheckedState.NOT_CHECKED;\r
47             } else {\r
48                 Collection<Resource> entries = graph.syncRequest( new ProfileEntryResources(entry.getFirst(), list) );\r
49                 return entries.equals(activeEntries) ? CheckedState.CHECKED : CheckedState.GRAYED;\r
50             }\r
51 \r
52         } else if(graph.isInstanceOf(entry.getSecond(), DIA.ProfileEntry)) {\r
53             if(graph.hasStatement(entry.getFirst(), SIMU.IsActive, entry.getSecond())) return CheckedState.CHECKED;     \r
54         }\r
55 \r
56         return CheckedState.NOT_CHECKED;\r
57 \r
58     }\r
59 \r
60 }\r