]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/AvailableGroups.java
Removed unnecessary dependencies on org.apache.log4j
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / view / AvailableGroups.java
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.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17
18 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.request.ObjectsWithType;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.layer0.adapter.Instances;
24 import org.simantics.diagram.stubs.DiagramResource;
25
26 public class AvailableGroups extends ViewpointContributor<Resource> {
27
28     @Override
29     public Collection<?> getContribution(ReadGraph graph, Resource runtimeDiagram) throws DatabaseException {
30         
31         DiagramResource dr = DiagramResource.getInstance(graph);
32         String modelURI = graph.getPossibleRelatedValue((Resource)runtimeDiagram, dr.RuntimeDiagram_HasModelURI);
33         if (modelURI == null)
34             return Collections.emptyList();
35
36         Resource model = graph.getPossibleResource(modelURI);
37         if (model == null)
38             return Collections.emptyList();
39
40         Instances query = graph.adapt(dr.Group, Instances.class);
41         
42         ArrayList<Resource> result = new ArrayList<Resource>();
43         result.addAll(query.find(graph, model));
44         result.addAll(graph.syncRequest(new ObjectsWithType(model, L0.ConsistsOf, dr.Group)));
45         return result; 
46         
47     }
48
49 }