]> gerrit.simantics Code Review - simantics/platform.git/blob
544c394c52714373d7746b71d1e8b3f60d4667a8
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.diagram.profile.view;
13
14 import java.util.Collection;
15
16 import org.simantics.browsing.ui.CheckedState;
17 import org.simantics.browsing.ui.model.check.CheckedStateRule;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.diagram.stubs.DiagramResource;
22 import org.simantics.scenegraph.profile.request.ProfileActiveEntryResources;
23 import org.simantics.scenegraph.profile.request.ProfileEntryResources;
24 import org.simantics.simulation.ontology.SimulationResource;
25
26 public class ProfileCheckContributor implements CheckedStateRule {
27
28     @Override
29     public boolean isCompatible(Class<?> contentType) {
30         return contentType.equals(ResourcePair.class);
31     }
32
33     @Override
34     public CheckedState getCheckedState(ReadGraph graph, Object parent)
35             throws DatabaseException {
36
37         ResourcePair entry = (ResourcePair)parent;
38         Resource activeProfile = entry.getFirst();
39         DiagramResource DIA = DiagramResource.getInstance(graph);
40         SimulationResource SIMU = SimulationResource.getInstance(graph);
41
42         if(graph.isInstanceOf(entry.getSecond(), DIA.Profile)) {
43             Resource list = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries);
44             Collection<Resource> activeEntries = graph.syncRequest( new ProfileActiveEntryResources(activeProfile, list) );
45             if (activeEntries.isEmpty()) {
46                 return CheckedState.NOT_CHECKED;
47             } else {
48                 Collection<Resource> entries = graph.syncRequest( new ProfileEntryResources(activeProfile, list) );
49                 return entries.equals(activeEntries) ? CheckedState.CHECKED : CheckedState.GRAYED;
50             }
51
52         } else if(graph.isInstanceOf(entry.getSecond(), DIA.ProfileEntry)) {
53             if(graph.hasStatement(activeProfile, SIMU.IsActive, entry.getSecond())) return CheckedState.CHECKED;        
54         }
55
56         return CheckedState.NOT_CHECKED;
57
58     }
59
60 }