]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java
new file mode 100644 (file)
index 0000000..31bb1a4
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.profile.view;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.CheckedState;\r
+import org.simantics.browsing.ui.model.check.CheckedStateRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.scenegraph.profile.request.ProfileActiveEntryResources;\r
+import org.simantics.scenegraph.profile.request.ProfileEntryResources;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+\r
+public class ProfileCheckContributor implements CheckedStateRule {\r
+\r
+    @Override\r
+    public boolean isCompatible(Class<?> contentType) {\r
+        return contentType.equals(ResourcePair.class);\r
+    }\r
+\r
+    @Override\r
+    public CheckedState getCheckedState(ReadGraph graph, Object parent)\r
+            throws DatabaseException {\r
+\r
+        ResourcePair entry = (ResourcePair)parent;\r
+        DiagramResource DIA = DiagramResource.getInstance(graph);\r
+        SimulationResource SIMU = SimulationResource.getInstance(graph);\r
+\r
+        if(graph.isInstanceOf(entry.getSecond(), DIA.Profile)) {\r
+\r
+            Resource list = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries);\r
+            Collection<Resource> activeEntries = graph.syncRequest( new ProfileActiveEntryResources(entry.getFirst(), list) );\r
+            if (activeEntries.isEmpty()) {\r
+                return CheckedState.NOT_CHECKED;\r
+            } else {\r
+                Collection<Resource> entries = graph.syncRequest( new ProfileEntryResources(entry.getFirst(), list) );\r
+                return entries.equals(activeEntries) ? CheckedState.CHECKED : CheckedState.GRAYED;\r
+            }\r
+\r
+        } else if(graph.isInstanceOf(entry.getSecond(), DIA.ProfileEntry)) {\r
+            if(graph.hasStatement(entry.getFirst(), SIMU.IsActive, entry.getSecond())) return CheckedState.CHECKED;    \r
+        }\r
+\r
+        return CheckedState.NOT_CHECKED;\r
+\r
+    }\r
+\r
+}\r