1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.synchronization.graph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.diagram.synchronization.CopyAdvisor;
20 import org.simantics.diagram.synchronization.ISynchronizationContext;
21 import org.simantics.layer0.utils.direct.GraphUtils.ResourceTester;
24 * @author Tuukka Lehtonen
26 public class AssociativeCopyAdvisor extends GraphCopyAdvisor {
28 Map<ResourceTester, CopyAdvisor> advisors;
30 public AssociativeCopyAdvisor(Map<ResourceTester, CopyAdvisor> advisors) {
31 this.advisors = advisors;
35 public Evaluation canCopy(ISynchronizationContext context, WriteGraph graph, Resource source,
36 Resource sourceContainer, Resource targetContainer) throws DatabaseException {
37 for (Map.Entry<ResourceTester, CopyAdvisor> entry : advisors.entrySet()) {
38 if (!entry.getKey().test(graph, source))
40 Evaluation eval = entry.getValue().canCopy(context, source, sourceContainer, targetContainer);
41 if (eval == Evaluation.SUPPORTED)
44 return Evaluation.NOT_SUPPORTED;
48 public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer,
49 Resource targetContainer) throws DatabaseException {
50 for (Map.Entry<ResourceTester, CopyAdvisor> entry : advisors.entrySet()) {
51 if (!entry.getKey().test(graph, source))
53 Object copy = entry.getValue().copy(context, source, sourceContainer, targetContainer);
61 public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer,
62 Resource targetContainer, Map<Object, Object> map) throws DatabaseException {
63 for (Map.Entry<ResourceTester, CopyAdvisor> entry : advisors.entrySet()) {
64 if (!entry.getKey().test(graph, source))
66 Object copy = entry.getValue().copy(context, source, sourceContainer, targetContainer, map);
74 public Object cut(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer,
75 Resource targetContainer) throws DatabaseException {
76 for (Map.Entry<ResourceTester, CopyAdvisor> entry : advisors.entrySet()) {
77 if (!entry.getKey().test(graph, source))
79 Object cut = entry.getValue().cut(context, source, sourceContainer, targetContainer);