1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.typicals;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.HashSet;
\r
17 import java.util.Set;
\r
19 import org.simantics.db.ReadGraph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.common.NamedResource;
\r
22 import org.simantics.db.common.request.ObjectsWithType;
\r
23 import org.simantics.db.common.request.ResourceRead;
\r
24 import org.simantics.db.common.utils.NameUtils;
\r
25 import org.simantics.db.exception.DatabaseException;
\r
26 import org.simantics.diagram.stubs.DiagramResource;
\r
27 import org.simantics.layer0.Layer0;
\r
28 import org.simantics.modeling.ModelingResources;
\r
30 public class AvailableSynchronizationRules extends ResourceRead<Collection<NamedResource>> {
\r
32 public AvailableSynchronizationRules(Resource resource) {
\r
37 public Collection<NamedResource> perform(ReadGraph graph)
\r
38 throws DatabaseException {
\r
40 Layer0 L0 = Layer0.getInstance(graph);
\r
41 DiagramResource DIA = DiagramResource.getInstance(graph);
\r
42 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
44 Set<Resource> rules = new HashSet<Resource>();
\r
45 for(Resource element : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, DIA.Element))) {
\r
46 for (Resource rule : graph.getObjects(element, MOD.HasTypicalSynchronizationRule)) {
\r
47 ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class);
\r
48 if (r != null) rules.add(rule);
\r
52 Collection<NamedResource> result = new ArrayList<NamedResource>();
\r
53 for(Resource rule : rules) {
\r
54 String name = NameUtils.getSafeLabel(graph, rule);
\r
55 result.add(new NamedResource(name, rule));
\r